Search in sources :

Example 1 with HtmlResetInput

use of com.gargoylesoftware.htmlunit.html.HtmlResetInput in project htmlunit by HtmlUnit.

the class ComputedCSSStyleDeclaration method getCalculatedWidth.

private int getCalculatedWidth() {
    if (width_ != null) {
        return width_.intValue();
    }
    final Element element = getElement();
    final DomNode node = element.getDomNodeOrDie();
    if (!node.mayBeDisplayed()) {
        width_ = Integer.valueOf(0);
        return 0;
    }
    final String display = getDisplay();
    if (NONE.equals(display)) {
        width_ = Integer.valueOf(0);
        return 0;
    }
    final int width;
    final String styleWidth = super.getWidth();
    final DomNode parent = node.getParentNode();
    // width is ignored for inline elements
    if (("inline".equals(display) || StringUtils.isEmpty(styleWidth)) && parent instanceof HtmlElement) {
        // hack: TODO find a way to specify default values for different tags
        if (element instanceof HTMLCanvasElement) {
            return 300;
        }
        // Width not explicitly set.
        final String cssFloat = getCssFloat();
        if ("right".equals(cssFloat) || "left".equals(cssFloat) || ABSOLUTE.equals(getStyleAttribute(POSITION, true))) {
            // We're floating; simplistic approximation: text content * pixels per character.
            width = node.getVisibleText().length() * getBrowserVersion().getPixesPerChar();
        } else if (BLOCK.equals(display)) {
            final int windowWidth = element.getWindow().getWebWindow().getInnerWidth();
            if (element instanceof HTMLBodyElement) {
                width = windowWidth - 16;
            } else {
                // Block elements take up 100% of the parent's width.
                final HTMLElement parentJS = parent.getScriptableObject();
                width = pixelValue(parentJS, new CssValue(0, windowWidth) {

                    @Override
                    public String get(final ComputedCSSStyleDeclaration style) {
                        return style.getWidth();
                    }
                }) - (getBorderHorizontal() + getPaddingHorizontal());
            }
        } else if (node instanceof HtmlSubmitInput || node instanceof HtmlResetInput || node instanceof HtmlButtonInput || node instanceof HtmlButton || node instanceof HtmlFileInput) {
            // use asNormalizedText() here because getVisibleText() returns an empty string
            // for submit and reset buttons
            final String text = node.asNormalizedText();
            // default font for buttons is a bit smaller than the body font size
            width = 10 + (int) (text.length() * getBrowserVersion().getPixesPerChar() * 0.9);
        } else if (node instanceof HtmlTextInput || node instanceof HtmlPasswordInput) {
            final BrowserVersion browserVersion = getBrowserVersion();
            if (browserVersion.hasFeature(JS_CLIENTWIDTH_INPUT_TEXT_143)) {
                return 143;
            }
            if (browserVersion.hasFeature(JS_CLIENTWIDTH_INPUT_TEXT_173)) {
                return 173;
            }
            // FF
            width = 145;
        } else if (node instanceof HtmlRadioButtonInput || node instanceof HtmlCheckBoxInput) {
            final BrowserVersion browserVersion = getBrowserVersion();
            if (browserVersion.hasFeature(JS_CLIENTWIDTH_RADIO_CHECKBOX_10)) {
                width = 10;
            } else {
                width = 13;
            }
        } else if (node instanceof HtmlTextArea) {
            // wild guess
            width = 100;
        } else if (node instanceof HtmlImage) {
            width = ((HtmlImage) node).getWidthOrDefault();
        } else {
            // Inline elements take up however much space is required by their children.
            width = getContentWidth();
        }
    } else if (AUTO.equals(styleWidth)) {
        width = element.getWindow().getWebWindow().getInnerWidth();
    } else {
        // Width explicitly set in the style attribute, or there was no parent to provide guidance.
        width = pixelValue(element, new CssValue(0, element.getWindow().getWebWindow().getInnerWidth()) {

            @Override
            public String get(final ComputedCSSStyleDeclaration style) {
                return style.getStyleAttribute(WIDTH, true);
            }
        });
    }
    width_ = Integer.valueOf(width);
    return width;
}
Also used : HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) HtmlTextInput(com.gargoylesoftware.htmlunit.html.HtmlTextInput) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HTMLBodyElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) BaseFrameElement(com.gargoylesoftware.htmlunit.html.BaseFrameElement) Element(com.gargoylesoftware.htmlunit.javascript.host.Element) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HTMLDataElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDataElement) HTMLDivElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDivElement) HTMLSlotElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSlotElement) HTMLImageElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLImageElement) HTMLUnknownElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLUnknownElement) HTMLCanvasElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement) StyleElement(com.gargoylesoftware.htmlunit.css.StyleElement) HTMLTimeElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTimeElement) HTMLIFrameElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLIFrameElement) HTMLOutputElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOutputElement) HTMLLegendElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLegendElement) HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) HtmlPasswordInput(com.gargoylesoftware.htmlunit.html.HtmlPasswordInput) AttributedString(java.text.AttributedString) HtmlResetInput(com.gargoylesoftware.htmlunit.html.HtmlResetInput) HtmlButtonInput(com.gargoylesoftware.htmlunit.html.HtmlButtonInput) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton) HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) HTMLBodyElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement) HtmlFileInput(com.gargoylesoftware.htmlunit.html.HtmlFileInput) HTMLCanvasElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput) HtmlTextArea(com.gargoylesoftware.htmlunit.html.HtmlTextArea)

Example 2 with HtmlResetInput

use of com.gargoylesoftware.htmlunit.html.HtmlResetInput in project faces by jakartaee.

the class URLClient method cbuttonRenderEncodeNonPassthroughTest.

/*
   * @class.setup_props: webServerHost; webServerPort; ts_home;
   */
/**
 * @testName: cbuttonRenderEncodeNonPassthroughTest
 *
 * @assertion_ids: PENDING
 *
 * @test_Strategy: Render several command buttons within a form using
 *                 combinations of the various non-passthrough attributes to
 *                 ensure the command button and the non-passthrough
 *                 attributes are properly rendered.
 *
 * @since 1.2
 */
public void cbuttonRenderEncodeNonPassthroughTest() throws Fault {
    StringBuilder messages = new StringBuilder(64);
    Formatter formatter = new Formatter(messages);
    List<HtmlPage> pages = new ArrayList<HtmlPage>();
    pages.add(getPage(CONTEXT_ROOT + "/faces/encodetest_facelet.xhtml"));
    for (HtmlPage page : pages) {
        HtmlSubmitInput button1 = (HtmlSubmitInput) getInputIncludingId(page, "command1");
        // begin validate command1
        if (button1 == null) {
            formatter.format("Unable to find rendered" + " command button containing ID 'command1' %n");
        } else {
            if (!"Click Me".equals(button1.getValueAttribute())) {
                formatter.format("Expected value attribute for command1 to" + " be 'Click Me', found '%s' %n", button1.getValueAttribute());
            }
            if (!"submit".equals(button1.getTypeAttribute())) {
                formatter.format("Expected type attribute for command1 to " + "be 'submit', found '%s' %n", button1.getTypeAttribute());
            }
        }
        HtmlSubmitInput button2 = (HtmlSubmitInput) getInputIncludingId(page, "command2");
        if (button2 == null) {
            formatter.format("Unable to find rendered" + " command button containing ID 'command2' %n");
        } else {
            if (!"Click Me".equals(button2.getValueAttribute())) {
                formatter.format("Expected value attribute for command2 to" + " be 'Click Me', found '%s' %n", button2.getValueAttribute());
            }
            if (!"submit".equals(button2.getTypeAttribute())) {
                formatter.format("Expected type attribute for command2 to " + "be 'submit', found '%s' %n", button2.getTypeAttribute());
            }
        }
        HtmlResetInput button3 = (HtmlResetInput) getInputIncludingId(page, "command3");
        if (button3 == null) {
            formatter.format("Unable to find rendered" + " command button containing ID 'command3' %n");
        } else {
            if (!"Click Me".equals(button3.getValueAttribute())) {
                formatter.format("Expected value attribute for command3 to" + " be 'Click Me', found '%s' %n", button3.getValueAttribute());
            }
            if (!"reset".equals(button3.getTypeAttribute())) {
                formatter.format("Expected type attribute for command3 to " + "be 'reset', found '%s' %n", button3.getTypeAttribute());
            }
        }
        HtmlSubmitInput button4 = (HtmlSubmitInput) getInputIncludingId(page, "command4");
        if (button4 == null) {
            formatter.format("Unable to find rendered" + " command button containing ID 'command4' %n");
        } else {
            if (!"Click Me".equals(button4.getValueAttribute())) {
                formatter.format("Expected value attribute for command4 to" + " be 'Click Me', found '%s' %n", button4.getValueAttribute());
            }
            if (!"submit".equals(button4.getTypeAttribute())) {
                formatter.format("Expected type attribute for command4 with an" + " invalid type attribute value specified to " + "be 'submit', found '%s' %n", button4.getTypeAttribute());
            }
        }
        HtmlSubmitInput button5 = (HtmlSubmitInput) getInputIncludingId(page, "command5");
        if (button5 == null) {
            formatter.format("Unable to find rendered" + " command button containing ID 'command5' %n");
        } else {
            if (!"Click Me".equals(button5.getValueAttribute())) {
                formatter.format("Expected value attribute for command5 to" + " be 'Click Me', found '%s' %n", button5.getValueAttribute());
            }
            if (!"submit".equals(button5.getTypeAttribute())) {
                formatter.format("Expected type attribute for command5 to " + "be 'submit', found '%s' %n", button5.getTypeAttribute());
            }
            if (!"Color: red;".equals(button5.getAttribute("class"))) {
                formatter.format("Expected class attribute for command5 to" + " be 'Color: red;', found '%s %n", button5.getAttribute("class"));
            }
        }
        HtmlImageInput button6 = (HtmlImageInput) getInputIncludingId(page, "command6");
        if (button6 == null) {
            formatter.format("Unable to find rendered" + " command button (as image) containing ID " + "'command6' %n");
        } else {
            if ("Click Me".equals(button6.getValueAttribute())) {
                formatter.format("Didn't expect the value attribute for " + "command6 to be rendered, found '%s' %n", button6.getValueAttribute());
            }
            if (!"image".equals(button6.getTypeAttribute())) {
                formatter.format("Expected type attribute for command6 " + "to be 'image', found '%s' %n", button6.getTypeAttribute());
            }
            String expectedImgSrc = "pnglogo.png";
            if (!button6.getSrcAttribute().contains(expectedImgSrc)) {
                formatter.format("Unexpected result for '%s' Attribute!%n" + "Expected: '%s'%n, " + "Received: '%s'%n", "src", expectedImgSrc, button6.getSrcAttribute());
            }
        }
        HtmlSubmitInput button7 = (HtmlSubmitInput) getInputIncludingId(page, "command7");
        if (!validateExistence("command7", "input", button7, formatter)) {
            handleTestStatus(messages);
            return;
        } else {
            if (!"disabled".equals(button7.getDisabledAttribute())) {
                formatter.format("(button7) Expected the disabled attribute " + "to be rendered as '%s', instead found '%s' %n", "disabled", button7.getDisabledAttribute());
            }
        }
        HtmlSubmitInput button8 = (HtmlSubmitInput) getInputIncludingId(page, "command8");
        if (!validateExistence("command8", "input", button8, formatter)) {
            handleTestStatus(messages);
            return;
        } else {
            if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(button8.getDisabledAttribute())) {
                formatter.format("(command8) Expected the disabled attribute " + "to not be rendered when the disabled " + "attribute was specified as false in the JSP" + " %n.");
            }
        }
        HtmlSubmitInput button9 = (HtmlSubmitInput) getInputIncludingId(page, "command9");
        if (!validateExistence("command9", "input", button9, formatter)) {
            handleTestStatus(messages);
            return;
        } else {
            if (!"readonly".equals(button9.getReadOnlyAttribute())) {
                formatter.format("(button9) Expected the readonly attribute " + "to be rendered as '%s', instead found '%s' %n", "readonly", button9.getReadOnlyAttribute());
            }
        }
        HtmlSubmitInput button10 = (HtmlSubmitInput) getInputIncludingId(page, "command10");
        if (!validateExistence("command10", "input", button10, formatter)) {
            handleTestStatus(messages);
            return;
        } else {
            if (!HtmlElement.ATTRIBUTE_NOT_DEFINED.equals(button10.getDisabledAttribute())) {
                formatter.format("(button10) Expected the disabled attribute " + "to not be rendered when the disabled " + "attribute was specified as false in the JSP" + " %n.");
            }
        }
        // ------------------------------------------------------------ case
        // 11
        HtmlSubmitInput button11 = (HtmlSubmitInput) getInputIncludingId(page, "command11");
        if (!validateExistence("command11", "input", button11, formatter)) {
            handleTestStatus(messages);
            return;
        }
        // Test for Styleclass attribute.
        String clazzAttrOne = button11.getAttribute("class");
        if (!"blue".equals(clazzAttrOne)) {
            formatter.format("Unexpected rendered value for the " + "\"styleClass\" attribute on the '%s' tag with the " + "id of '%s'. %nExpected: '%s' %nFound: '%s' %n", "h:commandButton", "onoff", "blue", clazzAttrOne);
        }
        // Test for Value attribute.
        String valueAttrOne = button11.getValueAttribute();
        if (!"onoff".equals(valueAttrOne)) {
            formatter.format("Unexpected rendered value for the " + "\"title\" attribute on the '%s' tag with the " + "id of '%s'. %nExpected: '%s' %nFound: '%s' %n", "h:commandButton", "onoff", "onoff", valueAttrOne);
        }
        // Test for Title attribute.
        String titleAttrOne = button11.getAttribute("title");
        if (!"onoff".equals(titleAttrOne)) {
            formatter.format("Unexpected rendered value for the " + "\"title\" attribute on the '%s' tag with the " + "id of '%s'. %nExpected: '%s' %nFound: '%s' %n", "h:commandButton", "onoff", "onoff", titleAttrOne);
        }
        // display test result
        handleTestStatus(messages);
    }
}
Also used : HtmlImageInput(com.gargoylesoftware.htmlunit.html.HtmlImageInput) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlSubmitInput(com.gargoylesoftware.htmlunit.html.HtmlSubmitInput) Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) HtmlResetInput(com.gargoylesoftware.htmlunit.html.HtmlResetInput)

Aggregations

HtmlResetInput (com.gargoylesoftware.htmlunit.html.HtmlResetInput)2 HtmlSubmitInput (com.gargoylesoftware.htmlunit.html.HtmlSubmitInput)2 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 StyleElement (com.gargoylesoftware.htmlunit.css.StyleElement)1 BaseFrameElement (com.gargoylesoftware.htmlunit.html.BaseFrameElement)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)1 HtmlButtonInput (com.gargoylesoftware.htmlunit.html.HtmlButtonInput)1 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlFileInput (com.gargoylesoftware.htmlunit.html.HtmlFileInput)1 HtmlImage (com.gargoylesoftware.htmlunit.html.HtmlImage)1 HtmlImageInput (com.gargoylesoftware.htmlunit.html.HtmlImageInput)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 HtmlPasswordInput (com.gargoylesoftware.htmlunit.html.HtmlPasswordInput)1 HtmlRadioButtonInput (com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput)1 HtmlTextArea (com.gargoylesoftware.htmlunit.html.HtmlTextArea)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)1