From: <rb...@us...> - 2018-07-05 07:25:50
|
Revision: 15436 http://sourceforge.net/p/htmlunit/code/15436 Author: rbri Date: 2018-07-05 07:25:40 +0000 (Thu, 05 Jul 2018) Log Message: ----------- ff60 support (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchorTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-05 06:39:14 UTC (rev 15435) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-05 07:25:40 UTC (rev 15436) @@ -900,9 +900,13 @@ JS_FILE_SHORT_DATE_FORMAT, /** Indicates that the action property will not be expanded if defined as empty string. */ - @BrowserFeature(FF) + @BrowserFeature(FF52) JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY, + /** Indicates that the action property will not be expanded if defined as empty string. */ + @BrowserFeature({CHROME, FF60}) + JS_FORM_ACTION_EXPANDURL_NOT_DEFINED, + /** form.dispatchEvent(e) submits the form if the event is of type 'submit'. */ @BrowserFeature(FF) JS_FORM_DISPATCHEVENT_SUBMITS, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2018-07-05 06:39:14 UTC (rev 15435) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2018-07-05 07:25:40 UTC (rev 15436) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.FORMFIELD_REACHABLE_BY_ORIGINAL_NAME; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.FORM_SUBMISSION_DOWNLOWDS_ALSO_IF_ONLY_HASH_CHANGED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_ACTION_EXPANDURL_NOT_DEFINED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_DISPATCHEVENT_SUBMITS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_REJECT_INVALID_ENCODING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_SUBMIT_FORCES_DOWNLOAD; @@ -34,7 +35,6 @@ import org.apache.commons.lang3.StringUtils; -import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.FormEncodingType; import com.gargoylesoftware.htmlunit.WebAssert; import com.gargoylesoftware.htmlunit.WebClient; @@ -192,20 +192,25 @@ */ @JsxGetter public String getAction() { - String action = getHtmlForm().getActionAttribute(); - final BrowserVersion browser = getBrowserVersion(); - if (action != DomElement.ATTRIBUTE_NOT_DEFINED) { - if (action.length() == 0 && browser.hasFeature(JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY)) { - return action; - } + final String action = getHtmlForm().getActionAttribute(); - try { - action = ((HtmlPage) getHtmlForm().getPage()).getFullyQualifiedUrl(action).toExternalForm(); - } - catch (final MalformedURLException e) { - // nothing, return action attribute - } + if (action != DomElement.ATTRIBUTE_NOT_DEFINED + && action.length() == 0 + && getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY)) { + return action; } + + if (action == DomElement.ATTRIBUTE_NOT_DEFINED + && !getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_NOT_DEFINED)) { + return action; + } + + try { + return ((HtmlPage) getHtmlForm().getPage()).getFullyQualifiedUrl(action).toExternalForm(); + } + catch (final MalformedURLException e) { + // nothing, return action attribute + } return action; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchorTest.java 2018-07-05 06:39:14 UTC (rev 15435) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlAnchorTest.java 2018-07-05 07:25:40 UTC (rev 15436) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF60; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import static java.nio.charset.StandardCharsets.UTF_8; @@ -268,12 +269,13 @@ * @throws Exception if an error occurs */ @Test + @BuggyWebDriver(FF60) public void clickNestedOptionElement() throws Exception { final String html = "<html>\n" + "<body>\n" + " <a href='page2.html'>\n" - + " <select>\n" + + " <select size=2>\n" + " <option id='theOption'>test</option>\n" + " </select>\n" + " </a>\n" @@ -284,6 +286,7 @@ final WebElement option = driver.findElement(By.id("theOption")); assertEquals("option", option.getTagName()); option.click(); + assertEquals(URL_FIRST + "page2.html", driver.getCurrentUrl()); } @@ -371,6 +374,8 @@ final WebElement tester = driver.findElement(By.id("a")); tester.click(); + + Thread.sleep(100); assertEquals(2, driver.getWindowHandles().size()); } @@ -691,6 +696,7 @@ .keyUp(Keys.SHIFT) .perform(); + Thread.sleep(100); assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size()); assertEquals("Should not have navigated away", originalTitle, driver.getTitle()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2018-07-05 06:39:14 UTC (rev 15435) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2018-07-05 07:25:40 UTC (rev 15436) @@ -14,8 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import static org.junit.Assert.fail; @@ -31,9 +29,9 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -532,7 +530,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("") + @Alerts(DEFAULT = "§§URL§§", + FF52 = "", + IE = "") public void action() throws Exception { final String html = "<html>\n" @@ -551,7 +551,7 @@ */ @Test @Alerts(DEFAULT = "§§URL§§", - FF = "") + FF52 = "") public void actionEmpty() throws Exception { final String html = "<html>\n" @@ -1194,8 +1194,8 @@ */ @Test @Alerts(DEFAULT = {"", "foo4?foo=", "script4.js"}, - IE = {"", "foo0?foo=", "foo1?foo=", "foo2?foo=", "foo3?foo=", "foo4?foo=", "script4.js"}) - @NotYetImplemented({CHROME, FF}) + IE = {"", "foo0?foo=", "foo4?foo=", "script4.js"}) + @NotYetImplemented public void submitTriggersRequestNotParsed() throws Exception { final String html = "<html><head><script>\n" + "function test() {\n" @@ -1205,10 +1205,12 @@ + " f.submit();\n" + " }\n" + "}\n" - + "</script></head><body onload='test()'>\n" - + "<form>\n" - + "<input name='foo'>\n" - + "</form></body></html>"; + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <form>\n" + + " <input name='foo'>\n" + + " </form>\n" + + "</body></html>"; final MockWebConnection connection = getMockWebConnection(); for (int i = 0; i < 5; i++) { |
From: <rb...@us...> - 2018-07-09 13:29:39
|
Revision: 15446 http://sourceforge.net/p/htmlunit/code/15446 Author: rbri Date: 2018-07-09 13:29:28 +0000 (Mon, 09 Jul 2018) Log Message: ----------- ff60 support (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/KeyboardEvent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/MouseEvent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/PointerEvent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/UIEvent.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -246,6 +246,10 @@ @BrowserFeature(FF) EVENT_TYPE_KEY_EVENTS, + /** Supports vendor specific event type 'MouseWheelEvent'. */ + @BrowserFeature(IE) + EVENT_TYPE_MOUSEWHEELEVENT, + /** Supports event type 'PointerEvent'. */ @BrowserFeature(IE) EVENT_TYPE_POINTEREVENT, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -19,6 +19,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_BEFOREUNLOADEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_HASHCHANGEEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_KEY_EVENTS; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_MOUSEWHEELEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_POINTEREVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_PROGRESSEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_APPLETS_NODELIST; @@ -113,12 +114,16 @@ import com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList; import com.gargoylesoftware.htmlunit.javascript.host.event.BeforeUnloadEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.CloseEvent; +import com.gargoylesoftware.htmlunit.javascript.host.event.CompositionEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.CustomEvent; +import com.gargoylesoftware.htmlunit.javascript.host.event.DragEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; +import com.gargoylesoftware.htmlunit.javascript.host.event.FocusEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.HashChangeEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.KeyboardEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent; +import com.gargoylesoftware.htmlunit.javascript.host.event.MouseWheelEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.MutationEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.PopStateEvent; @@ -206,6 +211,9 @@ dom3EventMap.put("UIEvent", UIEvent.class); dom3EventMap.put("CustomEvent", CustomEvent.class); dom3EventMap.put("CloseEvent", CloseEvent.class); + dom3EventMap.put("CompositionEvent", CompositionEvent.class); + dom3EventMap.put("FocusEvent", FocusEvent.class); + dom3EventMap.put("DragEvent", DragEvent.class); SUPPORTED_DOM3_EVENT_TYPE_MAP = Collections.unmodifiableMap(dom3EventMap); final Map<String, Class<? extends Event>> additionalEventMap = new HashMap<>(); @@ -216,6 +224,7 @@ additionalEventMap.put("PointerEvent", PointerEvent.class); additionalEventMap.put("PopStateEvent", PopStateEvent.class); additionalEventMap.put("ProgressEvent", ProgressEvent.class); + additionalEventMap.put("MouseWheelEvent", MouseWheelEvent.class); SUPPORTED_VENDOR_EVENT_TYPE_MAP = Collections.unmodifiableMap(additionalEventMap); } @@ -1200,14 +1209,16 @@ && ("Events".equals(eventType) || "KeyEvents".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_KEY_EVENTS) || "HashChangeEvent".equals(eventType) - && getBrowserVersion().hasFeature(EVENT_TYPE_HASHCHANGEEVENT) + && getBrowserVersion().hasFeature(EVENT_TYPE_HASHCHANGEEVENT) || "BeforeUnloadEvent".equals(eventType) - && getBrowserVersion().hasFeature(EVENT_TYPE_BEFOREUNLOADEVENT) + && getBrowserVersion().hasFeature(EVENT_TYPE_BEFOREUNLOADEVENT) + || "MouseWheelEvent".equals(eventType) + && getBrowserVersion().hasFeature(EVENT_TYPE_MOUSEWHEELEVENT) || "PointerEvent".equals(eventType) - && getBrowserVersion().hasFeature(EVENT_TYPE_POINTEREVENT) + && getBrowserVersion().hasFeature(EVENT_TYPE_POINTEREVENT) || "PopStateEvent".equals(eventType) || "ProgressEvent".equals(eventType) - && getBrowserVersion().hasFeature(EVENT_TYPE_PROGRESSEVENT))) { + && getBrowserVersion().hasFeature(EVENT_TYPE_PROGRESSEVENT))) { clazz = SUPPORTED_VENDOR_EVENT_TYPE_MAP.get(eventType); if (PopStateEvent.class == clazz Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -534,7 +534,7 @@ /** * @return indicates if event propagation is stopped */ - @JsxGetter(IE) + @JsxGetter public boolean isCancelBubble() { return stopPropagation_; } @@ -542,7 +542,7 @@ /** * @param newValue indicates if event propagation is stopped */ - @JsxSetter(IE) + @JsxSetter public void setCancelBubble(final boolean newValue) { stopPropagation_ = newValue; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/KeyboardEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/KeyboardEvent.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/KeyboardEvent.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -38,6 +38,7 @@ * * @author Ahmed Ashour * @author Frank Danek + * @author Ronald Brill */ @JsxClass public class KeyboardEvent extends UIEvent { @@ -851,6 +852,9 @@ private int charCode_; private int which_; + /** Whether or not the "meta" key was pressed during the firing of the event. */ + private boolean metaKey_; + /** * Creates a new keyboard event instance. */ @@ -1130,4 +1134,19 @@ } } + /** + * Returns whether or not the "meta" key was pressed during the event firing. + * @return whether or not the "meta" key was pressed during the event firing + */ + @JsxGetter + public boolean getMetaKey() { + return metaKey_; + } + + /** + * @param metaKey whether Meta has been pressed during this event or not + */ + protected void setMetaKey(final boolean metaKey) { + metaKey_ = metaKey; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/MouseEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/MouseEvent.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/MouseEvent.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -111,6 +111,9 @@ /** Switch to disable label handling if we already processing the event triggered from label processing */ private boolean processLabelAfterBubbling_ = true; + /** Whether or not the "meta" key was pressed during the firing of the event. */ + private boolean metaKey_; + /** * Used to build the prototype. */ @@ -137,7 +140,6 @@ setShiftKey(shiftKey); setCtrlKey(ctrlKey); setAltKey(altKey); - setMetaKey(false); if (button != BUTTON_LEFT && button != BUTTON_MIDDLE && button != BUTTON_RIGHT) { throw new IllegalArgumentException("Invalid button code: " + button); @@ -318,7 +320,6 @@ setCtrlKey(ctrlKey); setAltKey(altKey); setShiftKey(shiftKey); - setMetaKey(metaKey); button_ = button; // Ignore the relatedTarget parameter; we don't support it yet. } @@ -395,4 +396,20 @@ public void disableProcessLabelAfterBubbling() { processLabelAfterBubbling_ = false; } + + /** + * Returns whether or not the "meta" key was pressed during the event firing. + * @return whether or not the "meta" key was pressed during the event firing + */ + @JsxGetter + public boolean getMetaKey() { + return metaKey_; + } + + /** + * @param metaKey whether Meta has been pressed during this event or not + */ + protected void setMetaKey(final boolean metaKey) { + metaKey_ = metaKey; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/PointerEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/PointerEvent.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/PointerEvent.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -169,7 +169,7 @@ * @param hwTimestamp the initial value of hwTimestamp * @param isPrimary the initial value of isPrimary */ - @JsxFunction + @JsxFunction(IE) public void initPointerEvent(final String type, final boolean bubbles, final boolean cancelable, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/UIEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/UIEvent.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/UIEvent.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -25,7 +25,6 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; /** * JavaScript object representing a UI event. For general information on which properties and functions should be @@ -34,6 +33,7 @@ * @author Daniel Gredler * @author Ahmed Ashour * @author Frank Danek + * @author Ronald Brill */ @JsxClass public class UIEvent extends Event { @@ -49,9 +49,6 @@ /** Specifies some detail information about the event. */ private long detail_; - /** Whether or not the "meta" key was pressed during the firing of the event. */ - private boolean metaKey_; - /** * Creates a new UI event instance. */ @@ -100,24 +97,6 @@ } /** - * @return indicates if event propagation is stopped - */ - @Override - @JsxGetter - public boolean isCancelBubble() { - return super.isCancelBubble(); - } - - /** - * @param newValue indicates if event propagation is stopped - */ - @Override - @JsxSetter - public void setCancelBubble(final boolean newValue) { - super.setCancelBubble(newValue); - } - - /** * Returns the view from which the event was generated. In browsers, this is the originating window. * * @return the view from which the event was generated @@ -147,21 +126,4 @@ // Ignore the view parameter; we always use the window. setDetail(detail); } - - /** - * Returns whether or not the "meta" key was pressed during the event firing. - * @return whether or not the "meta" key was pressed during the event firing - */ - @JsxGetter - public boolean getMetaKey() { - return metaKey_; - } - - /** - * @param metaKey whether Meta has been pressed during this event or not - */ - protected void setMetaKey(final boolean metaKey) { - metaKey_ = metaKey; - } - } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-07-09 10:23:36 UTC (rev 15445) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-07-09 13:29:28 UTC (rev 15446) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF60; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -82,7 +83,12 @@ + " var unknown = document.createElement('harhar');\n" + " var div = document.createElement('div');\n" + " var svg = document.getElementById('mySvg');\n" - + " process(" + string + ");\n" + + " try{\n" + + " process(" + string + ");\n" + + " } catch (e) {\n" + + " alert('exception');\n" + + " return;" + + " }\n" + " }\n" + "\n" + " /*\n" @@ -3017,12 +3023,211 @@ FF60 = "detail,initUIEvent(),layerX,layerY,pageX,pageY,rangeOffset,rangeParent," + "SCROLL_PAGE_DOWN,SCROLL_PAGE_UP,view,which", IE = "detail,initUIEvent(),view") - @NotYetImplemented + @NotYetImplemented({CHROME, FF}) public void uiEvent() throws Exception { testString("document.createEvent('UIEvent'), document.createEvent('Event')"); } /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.DragEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "dataTransfer", + FF52 = "dataTransfer,initDragEvent()", + FF60 = "dataTransfer,initDragEvent()", + IE = "dataTransfer,initDragEvent(),msConvertURL()") + @NotYetImplemented + public void dragEvent() throws Exception { + testString("document.createEvent('DragEvent'), document.createEvent('MouseEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "getCoalescedEvents(),height,isPrimary,pointerId,pointerType,pressure," + + "tangentialPressure,tiltX,tiltY,twist,width", + FF52 = "exception", + FF60 = "getCoalescedEvents(),height,isPrimary,pointerId,pointerType,pressure," + + "tangentialPressure,tiltX,tiltY,twist,width", + IE = "exception") + @NotYetImplemented({CHROME, FF60}) + public void pointerEvent() throws Exception { + testString("new PointerEvent('click'), document.createEvent('MouseEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "exception", + FF52 = "exception", + FF60 = "exception", + IE = "height,hwTimestamp,initPointerEvent(),isPrimary,pointerId," + + "pointerType,pressure,rotation,tiltX,tiltY,width") + @NotYetImplemented(IE) + public void pointerEvent2() throws Exception { + testString(" document.createEvent('PointerEvent'), document.createEvent('MouseEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.WheelEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "deltaMode,deltaX,deltaY,deltaZ,DOM_DELTA_LINE,DOM_DELTA_PAGE," + + "DOM_DELTA_PIXEL,wheelDelta,wheelDeltaX,wheelDeltaY", + FF52 = "exception", + FF60 = "exception", + IE = "deltaMode,deltaX,deltaY,deltaZ,DOM_DELTA_LINE,DOM_DELTA_PAGE,DOM_DELTA_PIXEL,initWheelEvent()") + @NotYetImplemented({CHROME, IE}) + public void wheelEvent() throws Exception { + testString("document.createEvent('WheelEvent'), document.createEvent('MouseEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "altKey,button,buttons,clientX,clientY,ctrlKey,fromElement,getModifierState()," + + "initMouseEvent(),layerX,layerY,metaKey,movementX,movementY,offsetX,offsetY," + + "pageX,pageY,relatedTarget,screenX,screenY,shiftKey,toElement,x,y", + FF52 = "altKey,button,buttons,clientX,clientY,ctrlKey,getModifierState(),initMouseEvent()," + + "initNSMouseEvent(),metaKey,movementX,movementY,MOZ_SOURCE_CURSOR,MOZ_SOURCE_ERASER," + + "MOZ_SOURCE_KEYBOARD,MOZ_SOURCE_MOUSE,MOZ_SOURCE_PEN,MOZ_SOURCE_TOUCH,MOZ_SOURCE_UNKNOWN," + + "mozInputSource,mozPressure,offsetX,offsetY,region,relatedTarget,screenX,screenY,shiftKey", + FF60 = "altKey,button,buttons,clientX,clientY,ctrlKey,getModifierState(),initMouseEvent()," + + "initNSMouseEvent(),metaKey,movementX,movementY,MOZ_SOURCE_CURSOR,MOZ_SOURCE_ERASER," + + "MOZ_SOURCE_KEYBOARD,MOZ_SOURCE_MOUSE,MOZ_SOURCE_PEN,MOZ_SOURCE_TOUCH,MOZ_SOURCE_UNKNOWN," + + "mozInputSource,mozPressure,offsetX,offsetY,region,relatedTarget,screenX,screenY,shiftKey,x,y", + IE = "altKey,button,buttons,clientX,clientY,ctrlKey,fromElement,getModifierState(),initMouseEvent()," + + "layerX,layerY,metaKey,offsetX,offsetY,pageX,pageY,relatedTarget,screenX,screenY,shiftKey," + + "toElement,which,x,y") + @NotYetImplemented + public void mouseEvent() throws Exception { + testString("document.createEvent('MouseEvent'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.CompositionEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "data,initCompositionEvent()", + FF60 = "data,initCompositionEvent(),locale", + FF52 = "data,initCompositionEvent(),locale", + IE = "data,initCompositionEvent(),locale") + @NotYetImplemented + public void compositionEvent() throws Exception { + testString("document.createEvent('CompositionEvent'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.FocusEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "relatedTarget", + FF52 = "exception", + FF60 = "relatedTarget", + IE = "initFocusEvent(),relatedTarget") + @NotYetImplemented + public void focusEvent() throws Exception { + testString("document.createEvent('FocusEvent'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.InputEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "data,dataTransfer,getTargetRanges(),inputType,isComposing", + FF52 = "isComposing", + FF60 = "isComposing", + IE = "exception") + @NotYetImplemented({CHROME, FF}) + public void inputEvent() throws Exception { + testString("new InputEvent('input'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.MouseWheelEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "exception", + FF52 = "exception", + FF60 = "exception", + IE = "altKey,button,buttons,clientX,clientY,ctrlKey,fromElement,getModifierState(),initMouseEvent()," + + "initMouseWheelEvent(),layerX,layerY,metaKey,offsetX,offsetY,pageX,pageY,relatedTarget," + + "screenX,screenY,shiftKey,toElement,wheelDelta,which,x,y") + @NotYetImplemented(IE) + public void mouseWheelEvent() throws Exception { + testString("document.createEvent('MouseWheelEvent'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.SVGZoomEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "exception", + FF52 = "newScale,newTranslate,previousScale,previousTranslate", + FF60 = "exception", + IE = "exception") + @NotYetImplemented(FF52) + public void svgZoomEvent() throws Exception { + testString("document.createEvent('SVGZoomEvent'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.TextEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "data,initTextEvent()", + FF52 = "data,initCompositionEvent(),locale", + FF60 = "data,initCompositionEvent(),locale", + IE = "data,DOM_INPUT_METHOD_DROP,DOM_INPUT_METHOD_HANDWRITING,DOM_INPUT_METHOD_IME," + + "DOM_INPUT_METHOD_KEYBOARD,DOM_INPUT_METHOD_MULTIMODAL,DOM_INPUT_METHOD_OPTION," + + "DOM_INPUT_METHOD_PASTE,DOM_INPUT_METHOD_SCRIPT,DOM_INPUT_METHOD_UNKNOWN," + + "DOM_INPUT_METHOD_VOICE,initTextEvent(),inputMethod,locale") + @NotYetImplemented + public void textEvent() throws Exception { + testString("document.createEvent('TextEvent'), document.createEvent('UIEvent')"); + } + + /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.event.TouchEvent}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = "altKey,changedTouches,ctrlKey,metaKey,shiftKey,targetTouches,touches", + FF52 = "exception", + FF60 = "exception", + IE = "exception") + @NotYetImplemented(CHROME) + public void touchEvent2() throws Exception { + testString("new TouchEvent('touch'), document.createEvent('UIEvent')"); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSlot}. * * @throws Exception if the test fails |
From: <rb...@us...> - 2018-07-09 18:01:47
|
Revision: 15448 http://sourceforge.net/p/htmlunit/code/15448 Author: rbri Date: 2018-07-09 18:01:08 +0000 (Mon, 09 Jul 2018) Log Message: ----------- many fixes for document.createEvent('xxx') to support the various UI events Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-07-09 16:45:18 UTC (rev 15447) +++ trunk/htmlunit/src/changes/changes.xml 2018-07-09 18:01:08 UTC (rev 15448) @@ -14,6 +14,9 @@ <action type="remove" dev="rbri"> FF45 support removed. </action> + <action type="fix" dev="rbri"> + Many fixes for document.createEvent('xxx') to support the various UI events. + </action> <action type="fix" dev="rbri" issue="1966" due-to="Atsushi Nakagawa"> Correct handling of additional parameters provided in functions setTimeout/setInterval. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-09 16:45:18 UTC (rev 15447) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-09 18:01:08 UTC (rev 15448) @@ -238,6 +238,10 @@ @BrowserFeature({CHROME, FF}) EVENT_TYPE_BEFOREUNLOADEVENT, + /** Supports event type 'FocusEvent'. */ + @BrowserFeature({CHROME, FF60, IE}) + EVENT_TYPE_FOCUSEVENT, + /** Supports event type 'HashChangeEvent'. */ @BrowserFeature({CHROME, FF}) EVENT_TYPE_HASHCHANGEEVENT, @@ -258,6 +262,14 @@ @BrowserFeature(IE) EVENT_TYPE_PROGRESSEVENT, + /** Supports event type 'SVGZoomEvent'. */ + @BrowserFeature(FF52) + EVENT_TYPE_SVGZOOMEVENT, + + /** Supports event type 'WheelEvent'. */ + @BrowserFeature({CHROME, IE}) + EVENT_TYPE_WHEELEVENT, + /** For new pages the focus points to the body node. */ @BrowserFeature(IE) FOCUS_BODY_ELEMENT_AT_START, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2018-07-09 16:45:18 UTC (rev 15447) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2018-07-09 18:01:08 UTC (rev 15448) @@ -17,11 +17,14 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONCLOSE_DOCUMENT_CREATE_NOT_SUPPORTED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONPOPSTATE_DOCUMENT_CREATE_NOT_SUPPORTED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_BEFOREUNLOADEVENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_FOCUSEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_HASHCHANGEEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_KEY_EVENTS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_MOUSEWHEELEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_POINTEREVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_PROGRESSEVENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_SVGZOOMEVENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_TYPE_WHEELEVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_APPLETS_NODELIST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_CHARSET_LOWERCASE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHORS_REQUIRES_NAME_OR_ID; @@ -128,7 +131,10 @@ import com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.PopStateEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.ProgressEvent; +import com.gargoylesoftware.htmlunit.javascript.host.event.SVGZoomEvent; +import com.gargoylesoftware.htmlunit.javascript.host.event.TextEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.UIEvent; +import com.gargoylesoftware.htmlunit.javascript.host.event.WheelEvent; import com.gargoylesoftware.htmlunit.javascript.host.html.DocumentProxy; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLAnchorElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection; @@ -212,8 +218,8 @@ dom3EventMap.put("CustomEvent", CustomEvent.class); dom3EventMap.put("CloseEvent", CloseEvent.class); dom3EventMap.put("CompositionEvent", CompositionEvent.class); - dom3EventMap.put("FocusEvent", FocusEvent.class); dom3EventMap.put("DragEvent", DragEvent.class); + dom3EventMap.put("TextEvent", TextEvent.class); SUPPORTED_DOM3_EVENT_TYPE_MAP = Collections.unmodifiableMap(dom3EventMap); final Map<String, Class<? extends Event>> additionalEventMap = new HashMap<>(); @@ -225,6 +231,9 @@ additionalEventMap.put("PopStateEvent", PopStateEvent.class); additionalEventMap.put("ProgressEvent", ProgressEvent.class); additionalEventMap.put("MouseWheelEvent", MouseWheelEvent.class); + additionalEventMap.put("FocusEvent", FocusEvent.class); + additionalEventMap.put("WheelEvent", WheelEvent.class); + additionalEventMap.put("SVGZoomEvent", SVGZoomEvent.class); SUPPORTED_VENDOR_EVENT_TYPE_MAP = Collections.unmodifiableMap(additionalEventMap); } @@ -1218,7 +1227,13 @@ && getBrowserVersion().hasFeature(EVENT_TYPE_POINTEREVENT) || "PopStateEvent".equals(eventType) || "ProgressEvent".equals(eventType) - && getBrowserVersion().hasFeature(EVENT_TYPE_PROGRESSEVENT))) { + && getBrowserVersion().hasFeature(EVENT_TYPE_PROGRESSEVENT) + || "FocusEvent".equals(eventType) + && getBrowserVersion().hasFeature(EVENT_TYPE_FOCUSEVENT) + || "SVGZoomEvent".equals(eventType) + && getBrowserVersion().hasFeature(EVENT_TYPE_SVGZOOMEVENT) + || "WheelEvent".equals(eventType) + && getBrowserVersion().hasFeature(EVENT_TYPE_WHEELEVENT))) { clazz = SUPPORTED_VENDOR_EVENT_TYPE_MAP.get(eventType); if (PopStateEvent.class == clazz Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-07-09 16:45:18 UTC (rev 15447) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-07-09 18:01:08 UTC (rev 15448) @@ -320,23 +320,34 @@ html.append("<tr>").append('\n').append("<td rowspan='2'>").append("<a name='" + name + "'>").append(name) .append("</a>").append("</td>").append('\n').append("<td>"); int implementedCount = 0; - for (int i = 0; i < realProperties.size(); i++) { - final String color; - if (implementedProperties.contains(realProperties.get(i))) { - color = "green"; - implementedCount++; - } - else { - color = "blue"; - } - html.append("<span style='color: " + color + "'>").append(realProperties.get(i)).append("</span>"); - if (i < realProperties.size() - 1) { - html.append(',').append(' '); - } - } + if (realProperties.isEmpty()) { html.append(" "); } + else if (realProperties.size() == 1 + && realProperties.contains("exception") + && implementedProperties.size() == 1 + && implementedProperties.contains("exception") + && erroredProperties.size() == 0) { + html.append(" "); + } + else { + for (int i = 0; i < realProperties.size(); i++) { + final String color; + if (implementedProperties.contains(realProperties.get(i))) { + color = "green"; + implementedCount++; + } + else { + color = "blue"; + } + html.append("<span style='color: " + color + "'>").append(realProperties.get(i)).append("</span>"); + if (i < realProperties.size() - 1) { + html.append(',').append(' '); + } + } + } + html.append("</td>").append("<td>").append(implementedCount).append('/') .append(realProperties.size()).append("</td>").append("</tr>").append('\n'); html.append("<tr>").append("<td>"); @@ -3142,7 +3153,7 @@ FF52 = "exception", FF60 = "relatedTarget", IE = "initFocusEvent(),relatedTarget") - @NotYetImplemented + @NotYetImplemented({CHROME, FF60, IE}) public void focusEvent() throws Exception { testString("document.createEvent('FocusEvent'), document.createEvent('UIEvent')"); } |
From: <rb...@us...> - 2018-07-10 16:57:19
|
Revision: 15450 http://sourceforge.net/p/htmlunit/code/15450 Author: rbri Date: 2018-07-10 16:57:10 +0000 (Tue, 10 Jul 2018) Log Message: ----------- use fixed language for our chrome driver Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-07-10 16:25:01 UTC (rev 15449) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-07-10 16:57:10 UTC (rev 15450) @@ -210,8 +210,8 @@ EDGE.scriptAcceptHeader_ = "application/javascript, */*;q=0.8"; // CHROME - CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"; - CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"; + CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"; + CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"; CHROME.applicationCodeName_ = "Mozilla"; CHROME.vendor_ = "Google Inc."; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-07-10 16:25:01 UTC (rev 15449) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2018-07-10 16:57:10 UTC (rev 15450) @@ -75,6 +75,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriverService; +import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.edge.EdgeDriverService; import org.openqa.selenium.firefox.FirefoxDriver; @@ -425,7 +426,9 @@ if (CHROME_BIN_ != null) { System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, CHROME_BIN_); } - return new ChromeDriver(); + final ChromeOptions options = new ChromeOptions(); + options.addArguments("--lang=en-US"); + return new ChromeDriver(options); } if (BrowserVersion.EDGE == getBrowserVersion()) { |
From: <rb...@us...> - 2018-07-11 17:57:34
|
Revision: 15453 http://sourceforge.net/p/htmlunit/code/15453 Author: rbri Date: 2018-07-11 17:57:29 +0000 (Wed, 11 Jul 2018) Log Message: ----------- ie expectations update (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2018-07-11 17:24:35 UTC (rev 15452) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2018-07-11 17:57:29 UTC (rev 15453) @@ -193,7 +193,6 @@ IE_FORMATS_.put("ar-SD", rightToLeft); IE_FORMATS_.put("ar-SY", rightToLeft); IE_FORMATS_.put("ar-YE", rightToLeft); - IE_FORMATS_.put("ban", mmSlash); IE_FORMATS_.put("cs", ddDot); IE_FORMATS_.put("da", ddDash); IE_FORMATS_.put("en-IN", ddDash); @@ -221,10 +220,6 @@ IE_FORMATS_.put("sl", ddDot); IE_FORMATS_.put("sq", yyyyDash); IE_FORMATS_.put("sr", ddDot); - IE_FORMATS_.put("sr-BA", mmSlash); - IE_FORMATS_.put("sr-CS", mmSlash); - IE_FORMATS_.put("sr-ME", mmSlash); - IE_FORMATS_.put("sr-RS", mmSlash); IE_FORMATS_.put("zh", "\u200EYYYY\u200E\u5E74\u200EMM\u200E\u6708\u200Edd\u200E\u65E5"); IE_FORMATS_.put("zh-HK", "\u200EYYYY\u200E\u5E74\u200EMM\u200E\u6708\u200Edd\u200E\u65E5"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java 2018-07-11 17:24:35 UTC (rev 15452) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java 2018-07-11 17:57:29 UTC (rev 15453) @@ -31,7 +31,7 @@ /** * Tests for {@link DateTimeFormat}. * - * @author Roanld Brill + * @author Ronald Brill * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) @@ -121,7 +121,7 @@ @Test @Alerts(DEFAULT = "20.12.2012", FF60 = "12/20/2012", - IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") + IE = "\u200E20\u200E.\u200E12\u200E.\u200E2012") public void format_ban() throws Exception { test("new Intl.DateTimeFormat('ban').format(date)"); } @@ -1632,7 +1632,7 @@ */ @Test @Alerts(DEFAULT = "20.12.2012.", - IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") + IE = "\u200E20\u200E.\u200E12\u200E.\u200E2012") public void format_sr_ba() throws Exception { test("new Intl.DateTimeFormat('sr-BA').format(date)"); } @@ -1642,7 +1642,7 @@ */ @Test @Alerts(DEFAULT = "20.12.2012.", - IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") + IE = "\u200E20\u200E.\u200E12\u200E.\u200E2012") public void format_sr_cs() throws Exception { test("new Intl.DateTimeFormat('sr-CS').format(date)"); } @@ -1652,7 +1652,7 @@ */ @Test @Alerts(DEFAULT = "20.12.2012.", - IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") + IE = "\u200E20\u200E.\u200E12\u200E.\u200E2012") public void format_sr_me() throws Exception { test("new Intl.DateTimeFormat('sr-ME').format(date)"); } @@ -1662,7 +1662,7 @@ */ @Test @Alerts(DEFAULT = "20.12.2012.", - IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") + IE = "\u200E20\u200E.\u200E12\u200E.\u200E2012") public void format_sr_rs() throws Exception { test("new Intl.DateTimeFormat('sr-RS').format(date)"); } |
From: <rb...@us...> - 2018-07-11 18:10:38
|
Revision: 15454 http://sourceforge.net/p/htmlunit/code/15454 Author: rbri Date: 2018-07-11 18:10:31 +0000 (Wed, 11 Jul 2018) Log Message: ----------- ie expectations update (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2018-07-11 17:57:29 UTC (rev 15453) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2018-07-11 18:10:31 UTC (rev 15454) @@ -85,15 +85,13 @@ HtmlForm form = null; final String formId = getAttributeDirect("form"); - if (DomElement.ATTRIBUTE_NOT_DEFINED == formId) { + if (DomElement.ATTRIBUTE_NOT_DEFINED == formId || !hasFeature(FORM_FORM_ATTRIBUTE_SUPPORTED)) { form = getEnclosingForm(); } else { - if (hasFeature(FORM_FORM_ATTRIBUTE_SUPPORTED)) { - final DomElement elem = getHtmlPageOrNull().getElementById(formId); - if (elem instanceof HtmlForm) { - form = (HtmlForm) elem; - } + final DomElement elem = getHtmlPageOrNull().getElementById(formId); + if (elem instanceof HtmlForm) { + form = (HtmlForm) elem; } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java 2018-07-11 17:57:29 UTC (rev 15453) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlButton2Test.java 2018-07-11 18:10:31 UTC (rev 15454) @@ -674,7 +674,7 @@ */ @Test @Alerts(DEFAULT = {"2", "second"}, - IE = {"1", "first"}) + IE = {"2", "third"}) public void externalPreferenceFrom() throws Exception { final String html = "<html><head><title>first</title></head><body>\n" @@ -712,7 +712,7 @@ */ @Test @Alerts(DEFAULT = {"2", "second"}, - IE = {"1", "first"}) + IE = {"2", "third"}) public void internalDifferentFrom() throws Exception { final String html = "<html><head><title>first</title></head><body>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2018-07-11 17:57:29 UTC (rev 15453) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2018-07-11 18:10:31 UTC (rev 15454) @@ -41,7 +41,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.FormEncodingType; import com.gargoylesoftware.htmlunit.HttpHeader; @@ -480,7 +479,6 @@ */ @Test @Alerts({"2", "third"}) - @BuggyWebDriver(IE) public void buttonWithFormAction() throws Exception { final String html = "<!DOCTYPE html>\n" + "<html><head><title>first</title></head>\n" @@ -539,9 +537,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = {"2", "third/"}, - IE = {"1", "/"}) - @NotYetImplemented(IE) + @Alerts({"2", "third/"}) public void inputTypeSubmitWithFormAction() throws Exception { final String html = "<!DOCTYPE html>\n" + "<html><head></head>\n" @@ -766,7 +762,6 @@ * @throws Exception if the test fails */ @Test - @BuggyWebDriver(IE) public void buttonWithFormTarget() throws Exception { final String html = "<!DOCTYPE html>\n" + "<html><head></head>\n" @@ -810,7 +805,6 @@ @Test @Alerts(DEFAULT = "second content", IE = "hello world") - @NotYetImplemented(IE) public void inputTypeSubmitWithFormTarget() throws Exception { final String html = "<!DOCTYPE html>\n" + "<html><head></head>\n" |
From: <rb...@us...> - 2018-07-12 19:10:58
|
Revision: 15456 http://sourceforge.net/p/htmlunit/code/15456 Author: rbri Date: 2018-07-12 19:10:53 +0000 (Thu, 12 Jul 2018) Log Message: ----------- url encoding has to use UTF-8 as codepage Issue 1973 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-12 15:36:52 UTC (rev 15455) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-12 19:10:53 UTC (rev 15456) @@ -1312,8 +1312,7 @@ return makeWebResponseForDataUrl(webRequest); default: - return loadWebResponseFromWebConnection(webRequest, ALLOWED_REDIRECTIONS_SAME_URL, - webRequest.getCharset()); + return loadWebResponseFromWebConnection(webRequest, ALLOWED_REDIRECTIONS_SAME_URL); } } @@ -1321,12 +1320,11 @@ * Loads a {@link WebResponse} from the server through the WebConnection. * @param webRequest the request * @param allowedRedirects the number of allowed redirects remaining - * @param charset the charset to use * @throws IOException if an IO problem occurs * @return the resultant {@link WebResponse} */ private WebResponse loadWebResponseFromWebConnection(final WebRequest webRequest, - final int allowedRedirects, final Charset charset) throws IOException { + final int allowedRedirects) throws IOException { URL url = webRequest.getUrl(); final HttpMethod method = webRequest.getHttpMethod(); @@ -1336,7 +1334,7 @@ WebAssert.notNull("method", method); WebAssert.notNull("parameters", parameters); - url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), charset); + url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), UTF_8); webRequest.setUrl(url); if (LOG.isDebugEnabled()) { @@ -1451,7 +1449,7 @@ for (final Map.Entry<String, String> entry : webRequest.getAdditionalHeaders().entrySet()) { wrs.setAdditionalHeader(entry.getKey(), entry.getValue()); } - return loadWebResponseFromWebConnection(wrs, allowedRedirects - 1, UTF_8); + return loadWebResponseFromWebConnection(wrs, allowedRedirects - 1); } else if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == 308) { @@ -1460,7 +1458,7 @@ for (final Map.Entry<String, String> entry : webRequest.getAdditionalHeaders().entrySet()) { wrs.setAdditionalHeader(entry.getKey(), entry.getValue()); } - return loadWebResponseFromWebConnection(wrs, allowedRedirects - 1, UTF_8); + return loadWebResponseFromWebConnection(wrs, allowedRedirects - 1); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-12 15:36:52 UTC (rev 15455) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-12 19:10:53 UTC (rev 15456) @@ -54,7 +54,7 @@ * * @param port the port * @param firstResponse the first response, must contain the full response (to start with "HTTP/1.1 200 OK") - * @param otherResponse the sebsequent response, must contain the full response (to start with "HTTP/1.1 200 OK") + * @param otherResponse the subsequent response, must contain the full response (to start with "HTTP/1.1 200 OK") */ public PrimitiveWebServer(final int port, final String firstResponse, final String otherResponse) { port_ = port; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java 2018-07-12 15:36:52 UTC (rev 15455) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java 2018-07-12 19:10:53 UTC (rev 15456) @@ -55,59 +55,6 @@ } /** - * Test that the path and query string are encoded to be valid. - * @throws Exception if something goes wrong - */ - @Test - public void loadPage_EncodeRequest() throws Exception { - final String htmlContent - = "<html><head><title>foo</title></head><body>\n" - + "</body></html>"; - - final WebClient client = getWebClient(); - - final MockWebConnection webConnection = new MockWebConnection(); - webConnection.setDefaultResponse(htmlContent); - client.setWebConnection(webConnection); - - // with query string not encoded - HtmlPage page = client.getPage("http://first?a=b c&d=\u00E9\u00E8"); - final String expected; - final boolean ie = getBrowserVersion().isIE(); - if (ie) { - expected = "?a=b%20c&d=\u00E9\u00E8"; - } - else { - expected = "?a=b%20c&d=%E9%E8"; - } - assertEquals("http://first/" + expected, page.getUrl()); - - // with query string already encoded - page = client.getPage("http://first?a=b%20c&d=%C3%A9%C3%A8"); - assertEquals("http://first/?a=b%20c&d=%C3%A9%C3%A8", page.getUrl()); - - // with query string partially encoded - page = client.getPage("http://first?a=b%20c&d=e f"); - assertEquals("http://first/?a=b%20c&d=e%20f", page.getUrl()); - - // with anchor - page = client.getPage("http://first?a=b c#myAnchor"); - assertEquals("http://first/?a=b%20c#myAnchor", page.getUrl()); - - // with query string containing encoded "&", "=", "+", ",", and "$" - page = client.getPage("http://first?a=%26%3D%20%2C%24"); - assertEquals("http://first/?a=%26%3D%20%2C%24", page.getUrl()); - - // with character to encode in path - page = client.getPage("http://first/page 1.html"); - assertEquals("http://first/page%201.html", page.getUrl()); - - // with character to encode in path - page = client.getPage("http://first/page 1.html"); - assertEquals("http://first/page%201.html", page.getUrl()); - } - - /** * Test for 3151939. The Browser removes leading '/..' from the path. * @throws Exception if something goes wrong */ Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-12 19:10:53 UTC (rev 15456) @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2002-2018 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit; + +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + +import java.net.URL; + +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; + +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; + +/** + * Tests using the {@link PrimitiveWebServer}. + * + * @author Ahmed Ashour + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class WebClient7Test extends WebDriverTestCase { + + private PrimitiveWebServer primitiveWebServer_; + + /** + * @throws Exception if an error occurs + */ + @After + public void stopServer() throws Exception { + if (primitiveWebServer_ != null) { + primitiveWebServer_.stop(); + } + shutDownAll(); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts(DEFAULT = "/test.html?a=b%20c&d=%C3%A9%C3%A8", + IE = "/test.html?a=b%20c&d=\u00E9\u00E8") + @NotYetImplemented(IE) + public void loadPage_EncodeRequest() throws Exception { + // with query string not encoded + testRequestUrlEncoding("test.html?a=b c&d=\u00E9\u00E8"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=b%20c&d=%C3%A9%C3%A8") + public void loadPage_EncodeRequest2() throws Exception { + // with query string already encoded + testRequestUrlEncoding("test.html?a=b%20c&d=%C3%A9%C3%A8"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=b%20c&d=e%20f") + public void loadPage_EncodeRequest3() throws Exception { + // with query string partially encoded + testRequestUrlEncoding("test.html?a=b%20c&d=e f"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=b%20c") + public void loadPage_EncodeRequest4() throws Exception { + // with anchor + testRequestUrlEncoding("test.html?a=b c#myAnchor"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=%26%3D%20%2C%24") + public void loadPage_EncodeRequest5() throws Exception { + // with query string containing encoded "&", "=", "+", ",", and "$" + testRequestUrlEncoding("test.html?a=%26%3D%20%2C%24"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/page%201.html") + public void loadPage_EncodeRequest6() throws Exception { + // with character to encode in path + testRequestUrlEncoding("page 1.html"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts(DEFAULT = "/test.html?param=%C2%A9", + IE = "/test.html?param=\u00A9") + @NotYetImplemented(IE) + public void loadPage_EncodeRequest7() throws Exception { + // unicode + testRequestUrlEncoding("test.html?param=\u00A9"); + } + + private void testRequestUrlEncoding(final String url) throws Exception { + final String response = "HTTP/1.1 200 OK\r\n" + + "Content-Length: 2\r\n" + + "Content-Type: text/html\r\n" + + "\r\n" + + "<html><head><title>foo</title></head><body>" + + "</body></html>"; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, response, response); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(new URL(URL_FIRST, url).toString()); + String reqUrl = primitiveWebServer_.getRequests().get(0); + if (reqUrl.contains("/favicon.ico")) { + reqUrl = primitiveWebServer_.getRequests().get(1); + } + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |
From: <rb...@us...> - 2018-07-13 14:36:18
|
Revision: 15457 http://sourceforge.net/p/htmlunit/code/15457 Author: rbri Date: 2018-07-13 14:36:14 +0000 (Fri, 13 Jul 2018) Log Message: ----------- url encoding has to use UTF-8 as codepage Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtml2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtmlTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -1334,7 +1334,8 @@ WebAssert.notNull("method", method); WebAssert.notNull("parameters", parameters); - url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), UTF_8); + url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), + webRequest.getCharset()); webRequest.setUrl(url); if (LOG.isDebugEnabled()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -14,7 +14,7 @@ */ package com.gargoylesoftware.htmlunit; -import static java.nio.charset.StandardCharsets.ISO_8859_1; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.IOException; import java.io.ObjectInputStream; @@ -62,7 +62,7 @@ private Map<String, String> additionalHeaders_ = new HashMap<>(); private Credentials urlCredentials_; private Credentials credentials_; - private transient Charset charset_ = ISO_8859_1; + private transient Charset charset_ = UTF_8; /* These two are mutually exclusive; additionally, requestBody_ should only be set for POST requests. */ private List<NameValuePair> requestParameters_ = Collections.emptyList(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -21,6 +21,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -37,6 +38,7 @@ private final String firstResponse_; private final String otherResponse_; private ServerSocket server_; + private Charset charset_ = StandardCharsets.UTF_8; private List<String> requests_ = new ArrayList<>(); /** @@ -95,7 +97,7 @@ response = otherResponse_; } first = false; - out.write(response.getBytes(StandardCharsets.UTF_8)); + out.write(response.getBytes(charset_)); } } } @@ -131,4 +133,11 @@ public void clearRequests() { requests_.clear(); } + + /** + * @param charset the charset + */ + public void setCharset(final Charset charset) { + charset_ = charset; + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient2Test.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -16,7 +16,6 @@ import static com.gargoylesoftware.htmlunit.httpclient.HtmlUnitBrowserCompatCookieSpec.EMPTY_COOKIE_NAME; -import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -28,7 +27,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.util.Cookie; @@ -43,18 +41,6 @@ public class WebClient2Test extends SimpleWebTestCase { /** - * @throws Exception if an error occurs - */ - @Test - @Alerts(DEFAULT = "http://first/?param=%A3", - IE = "http://first/?param=\u00A3") - public void encodeURL() throws Exception { - final String html = "<body onload='alert(window.location.href)'></body>"; - getMockWebConnection().setDefaultResponse(html); - loadPageWithAlerts(html, new URL("http://first/?param=\u00A3"), -1); - } - - /** * Test for 3151939. The Browser removes leading '/..' from the path. * @throws Exception if something goes wrong */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -17,10 +17,12 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import java.net.URL; +import java.nio.charset.StandardCharsets; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; @@ -121,23 +123,23 @@ * @throws Exception if something goes wrong */ @Test - @Alerts(DEFAULT = "/test.html?param=%C2%A9", - IE = "/test.html?param=\u00A9") + @Alerts(DEFAULT = "/test.html?param=%C2%A9%C2%A3", + IE = "/test.html?param=\u00A9\u00A3") @NotYetImplemented(IE) public void loadPage_EncodeRequest7() throws Exception { // unicode - testRequestUrlEncoding("test.html?param=\u00A9"); + testRequestUrlEncoding("test.html?param=\u00A9\u00A3"); } private void testRequestUrlEncoding(final String url) throws Exception { final String response = "HTTP/1.1 200 OK\r\n" - + "Content-Length: 2\r\n" + + "Content-Length: 58\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "<html><head><title>foo</title></head><body>" + "</body></html>"; - primitiveWebServer_ = new PrimitiveWebServer(PORT, response, response); + primitiveWebServer_ = new PrimitiveWebServer(PORT, response); primitiveWebServer_.start(); final WebDriver driver = getWebDriver(); @@ -151,4 +153,97 @@ assertEquals(getExpectedAlerts()[0], reqUrl); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/bug.html?k%C3%B6nig", + IE = "/bug.html?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingUTF8() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + + "</head>\n" + + "<body>\n" + + " <a id='myLink' href='bug.html?k\u00F6nig'>Click me</a>\n" + + "</body></html>"; + + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html\r\n" + + "\r\n" + + html; + + final String response = "HTTP/1.1 200 OK\r\n" + + "Content-Length: 2\r\n" + + "Content-Type: text/html\r\n" + + "\r\n" + + "<html><head><title>foo</title></head><body>" + + "</body></html>"; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, response); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + driver.findElement(By.id("myLink")).click(); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + if (reqUrl.contains("/favicon.ico")) { + reqUrl = primitiveWebServer_.getRequests().get(2); + } + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/bug.html?k%F6nig", + IE = "/bug.html?k\u00f6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingISO8859_1() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" + + "</head>\n" + + "<body>\n" + + " <a id='myLink' href='bug.html?k\u00F6nig'>Click me</a>\n" + + "</body></html>"; + + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html\r\n" + + "\r\n" + + html; + + final String response = "HTTP/1.1 200 OK\r\n" + + "Content-Length: 2\r\n" + + "Content-Type: text/html\r\n" + + "\r\n" + + "<html><head><title>foo</title></head><body>" + + "</body></html>"; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, response); + primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + driver.findElement(By.id("myLink")).click(); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + if (reqUrl.contains("/favicon.ico")) { + reqUrl = primitiveWebServer_.getRequests().get(2); + } + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -46,7 +46,6 @@ import com.gargoylesoftware.htmlunit.FormEncodingType; import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.HttpMethod; -import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.util.NameValuePair; import com.gargoylesoftware.htmlunit.util.UrlUtils; @@ -171,35 +170,6 @@ * @throws Exception if the test fails */ @Test - public void linkUrlEncoding() throws Exception { - final String html = "<html>\n" - + "<head><title>foo</title>\n" - + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" - + "</head>\n" - + "<body>\n" - + " <a href='bug.html?k\u00F6nig' id='myLink'>Click me</a>\n" - + "</body></html>"; - - final MockWebConnection webConnection = getMockWebConnection(); - webConnection.setDefaultResponse(html, "text/html", ISO_8859_1); - - final WebDriver driver = loadPage2(html); - assertEquals(URL_FIRST.toExternalForm(), driver.getCurrentUrl()); - driver.findElement(By.id("myLink")).click(); - final String linkSuffix; - if (getBrowserVersion().isIE()) { - linkSuffix = "bug.html?k\u00F6nig"; - } - else { - linkSuffix = "bug.html?k%F6nig"; - } - assertEquals(URL_FIRST + linkSuffix, driver.getCurrentUrl()); - } - - /** - * @throws Exception if the test fails - */ - @Test public void base() throws Exception { final String html = "<html><head>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtml2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtml2Test.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtml2Test.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -30,30 +30,6 @@ public class MalformedHtml2Test extends SimpleWebTestCase { /** - * @throws Exception if the test fails - */ - @Test - public void incompleteEntities() throws Exception { - final String html = "<html><head>\n" - + "<title>Test document</title>\n" - + "</head><body>\n" - + "<a href='foo?a=1©=2&prod=3' id='myLink'>my link</a>\n" - + "</body></html>"; - - final HtmlPage page = loadPage(html); - final HtmlPage page2 = page.getAnchors().get(0).click(); - - final String query; - if (getBrowserVersion().isIE()) { - query = "a=1\u00A9=2&prod=3"; - } - else { - query = "a=1%A9=2&prod=3"; - } - assertEquals(query, page2.getUrl().getQuery()); - } - - /** * Regression test for Bug #1018. * @throws Exception if an error occurs */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtmlTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtmlTest.java 2018-07-12 19:10:53 UTC (rev 15456) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/MalformedHtmlTest.java 2018-07-13 14:36:14 UTC (rev 15457) @@ -1090,4 +1090,26 @@ assertEquals(0, webDriver.findElements(By.name("main")).size()); assertEquals(1, webDriver.findElements(By.id("tester")).size()); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("§§URL§§foo?a=1©=2&prod=3") + @NotYetImplemented + public void incompleteEntities() throws Exception { + final String html = "<html><head>\n" + + "<title>Test document</title>\n" + + "</head><body>\n" + + "<a href='foo?a=1©=2&prod=3' id='myLink'>my link</a>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse("<html><head><title>foo</title></head><body></body></html>"); + expandExpectedAlertsVariables(URL_FIRST); + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("myLink")).click(); + + assertEquals(getExpectedAlerts()[0], getMockWebConnection().getLastWebRequest().getUrl()); + } } |
From: <rb...@us...> - 2018-07-14 11:58:04
|
Revision: 15461 http://sourceforge.net/p/htmlunit/code/15461 Author: rbri Date: 2018-07-14 11:57:57 +0000 (Sat, 14 Jul 2018) Log Message: ----------- url encoding has to use UTF-8 as codepage Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2018-07-14 09:47:57 UTC (rev 15460) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2018-07-14 11:57:57 UTC (rev 15461) @@ -57,6 +57,7 @@ private long loadTime_; private WebResponseData responseData_; private WebRequest request_; + private boolean defaultCharsetUtf8_; /** * Constructs with all data. @@ -180,12 +181,12 @@ // xml pages are using a different content type if (null != contentType - && PageType.XML == DefaultPageCreator.determinePageType(contentType)) { + && (defaultCharsetUtf8_ + || PageType.XML == DefaultPageCreator.determinePageType(contentType))) { return UTF_8; } + } - charset = getWebRequest().getCharset(); - } if (charset == null) { charset = ISO_8859_1; } @@ -287,4 +288,11 @@ responseData_.cleanUp(); } } + + /** + * Mark this response for using UTF-8 as default charset. + */ + public void defaultCharsetUtf8() { + defaultCharsetUtf8_ = true; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2018-07-14 09:47:57 UTC (rev 15460) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java 2018-07-14 11:57:57 UTC (rev 15461) @@ -574,6 +574,9 @@ if (LOG.isDebugEnabled()) { LOG.debug("Web response loaded successfully."); } + // this kind of web responses using UTF-8 as default encoding + webResponse.defaultCharsetUtf8(); + boolean allowOriginResponse = true; if (originHeaderValue != null) { final String value = webResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2018-07-14 09:47:57 UTC (rev 15460) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2018-07-14 11:57:57 UTC (rev 15461) @@ -748,6 +748,9 @@ if (LOG.isDebugEnabled()) { LOG.debug("Web response loaded successfully."); } + // this kind of web responses using UTF-8 as default encoding + webResponse.defaultCharsetUtf8(); + boolean allowOriginResponse = true; if (originHeaderValue != null) { String value = webResponse.getResponseHeaderValue(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java 2018-07-14 09:47:57 UTC (rev 15460) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponseTest.java 2018-07-14 11:57:57 UTC (rev 15461) @@ -107,8 +107,8 @@ public void illegalCharset() throws Exception { illegalCharset("text/html; text/html; charset=ISO-8859-1;", ISO_8859_1); illegalCharset("text/html; charset=UTF-8; charset=UTF-8", UTF_8); - illegalCharset("text/html; charset=#sda+s", UTF_8); - illegalCharset("text/html; charset=UnknownCharset", UTF_8); + illegalCharset("text/html; charset=#sda+s", ISO_8859_1); + illegalCharset("text/html; charset=UnknownCharset", ISO_8859_1); } private void illegalCharset(final String cntTypeHeader, final Charset expectedCharset) throws Exception { |
From: <rb...@us...> - 2018-07-17 18:25:38
|
Revision: 15471 http://sourceforge.net/p/htmlunit/code/15471 Author: rbri Date: 2018-07-17 18:25:30 +0000 (Tue, 17 Jul 2018) Log Message: ----------- next step in our endless encoding fight - more tests are needed Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2018-07-16 19:03:46 UTC (rev 15470) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2018-07-17 18:25:30 UTC (rev 15471) @@ -64,6 +64,7 @@ private Credentials urlCredentials_; private Credentials credentials_; private transient Charset charset_ = ISO_8859_1; + private transient Charset urlEncodingCharset_; /* These two are mutually exclusive; additionally, requestBody_ should only be set for POST requests. */ private List<NameValuePair> requestParameters_ = Collections.emptyList(); @@ -431,10 +432,20 @@ } /** - * Returns the character set to use to encode the url params. - * @return the character set to use to encode the url params + * @param charset the character set to use for url (param) encoding */ + public void setUrlEncodingCharset(final Charset charset) { + urlEncodingCharset_ = charset; + } + + /** + * @return the character set to use to encode the url (params) + */ public Charset getUrlEncodingCharset() { + if (urlEncodingCharset_ != null) { + return urlEncodingCharset_; + } + if (HttpMethod.GET == getHttpMethod() || HttpMethod.DELETE == getHttpMethod() || HttpMethod.HEAD == getHttpMethod() Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java 2018-07-16 19:03:46 UTC (rev 15470) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java 2018-07-17 18:25:30 UTC (rev 15471) @@ -170,6 +170,8 @@ final WebRequest webRequest = new WebRequest(url, browser.getHtmlAcceptHeader()); webRequest.setCharset(page.getCharset()); + // use the page encoding even if this is a GET requests + webRequest.setUrlEncodingCharset(page.getCharset()); webRequest.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); if (LOG.isDebugEnabled()) { LOG.debug( Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2018-07-16 19:03:46 UTC (rev 15470) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlLink.java 2018-07-17 18:25:30 UTC (rev 15471) @@ -227,6 +227,8 @@ final URL url = page.getFullyQualifiedUrl(getHrefAttribute()); final WebRequest request = new WebRequest(url); + // use the page encoding even if this is a GET requests + request.setUrlEncodingCharset(page.getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-16 19:03:46 UTC (rev 15470) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-17 18:25:30 UTC (rev 15471) @@ -80,14 +80,18 @@ final Socket socket = server_.accept(); final InputStream in = socket.getInputStream(); final CharArrayWriter writer = new CharArrayWriter(); + + String requestString = writer.toString(); int i; + while ((i = in.read()) != -1) { writer.append((char) i); - if (i == '\n' && writer.toString().endsWith("\r\n\r\n")) { + requestString = writer.toString(); + + if (i == '\n' && requestString.endsWith("\r\n\r\n")) { break; } } - final String requestString = writer.toString(); final String response; if (requestString.contains("/favicon.ico")) { @@ -97,7 +101,7 @@ + "Connection: Closed\r\n\r\n"; } else { - requests_.add(writer.toString()); + requests_.add(requestString); try (OutputStream out = socket.getOutputStream()) { if (first || otherResponse_ == null) { response = firstResponse_; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-16 19:03:46 UTC (rev 15470) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-17 18:25:30 UTC (rev 15471) @@ -17,6 +17,7 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import java.net.URL; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.junit.After; @@ -132,12 +133,15 @@ } private void testRequestUrlEncoding(final String url) throws Exception { + final String html = "<html>" + + "<head><title>foo</title></head>" + + "<body></body></html>"; + final String response = "HTTP/1.1 200 OK\r\n" - + "Content-Length: 58\r\n" + + "Content-Length: " + html.length() + "\r\n" + "Content-Type: text/html\r\n" + "\r\n" - + "<html><head><title>foo</title></head><body>" - + "</body></html>"; + + html; primitiveWebServer_ = new PrimitiveWebServer(PORT, response); primitiveWebServer_.start(); @@ -146,9 +150,111 @@ driver.get(new URL(URL_FIRST, url).toString()); String reqUrl = primitiveWebServer_.getRequests().get(0); - if (reqUrl.contains("/favicon.ico")) { - reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%C3%B6nig", + IE = "/test.html?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingUTF8Header() throws Exception { + urlEncoding(true, "UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%C3%B6nig", + IE = "/test.html?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingUTF8Meta() throws Exception { + urlEncoding(false, "UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%F6nig", + IE = "/test.html?k\u00f6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingISO8859_1Header() throws Exception { + urlEncoding(true, "ISO-8859-1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%F6nig", + IE = "/test.html?k\u00f6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingISO8859_1Meta() throws Exception { + urlEncoding(false, "ISO-8859-1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("/test.html?k?nig") + public void anchorUrlEncodingWindows_1251Header() throws Exception { + urlEncoding(true, "Windows-1251"); + } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("/test.html?k?nig") + public void anchorUrlEncodingWindows_1251Meta() throws Exception { + urlEncoding(false, "Windows-1251"); + } + + private void urlEncoding(final boolean header, final String charset) throws Exception { + String html = "<html>\n" + + "<head><title>foo</title>\n"; + if (!header) { + html += " <meta http-equiv='Content-Type' content='text/html; charset=" + charset + "'>\n"; } + + html += "</head>\n" + + "<body>\n" + + " <a id='myLink' href='test.html?k\u00F6nig'>Click me</a>\n" + + "</body></html>"; + + String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html"; + if (header) { + firstResponse += "; charset=" + charset; + } + firstResponse += "\r\n\r\n" + html; + + final String html2 = "<html><head></head><body>" + + "</body></html>"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html2.length() + "\r\n" + + "Content-Type: text/html\r\n" + + "\r\n" + + html2; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(Charset.forName(charset)); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + driver.findElement(By.id("myLink")).click(); + + String reqUrl = primitiveWebServer_.getRequests().get(1); reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); assertEquals(getExpectedAlerts()[0], reqUrl); @@ -158,16 +264,59 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "/bug.html?k%EF%BF%BDnig", - IE = "/bug.html?k\u00ef\u00bf\u00bdnig") + @Alerts(DEFAULT = "/test.css?k%C3%B6nig", + IE = "/test.css?k\u00c3\u00b6nig") @NotYetImplemented(IE) - public void linkUrlEncodingUTF8() throws Exception { + public void linkUrlEncodingUTF8Header() throws Exception { final String html = "<html>\n" + "<head><title>foo</title>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html; charset=UTF-8\r\n" + + "\r\n" + + html; + + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + + "\r\n" + + css; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(StandardCharsets.UTF_8); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%C3%B6nig", + IE = "/test.css?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingUTF8Meta() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + "</head>\n" + "<body>\n" - + " <a id='myLink' href='bug.html?k\u00F6nig'>Click me</a>\n" + "</body></html>"; final String firstResponse = "HTTP/1.1 200 OK\r\n" @@ -176,14 +325,56 @@ + "\r\n" + html; - final String html2 = "<html><head><title>foo</title></head><body>" + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + + "\r\n" + + css; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(StandardCharsets.UTF_8); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%F6nig", + IE = "/test.css?k\u00f6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingISO8859_1Header() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + + "</head>\n" + + "<body>\n" + "</body></html>"; + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html; charset=ISO-8859-1\r\n" + + "\r\n" + + html; + + final String css = "p { color: red; }"; + final String secondResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + html2.length() + "\r\n" - + "Content-Type: text/html\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + "\r\n" - + html2; + + css; primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); @@ -192,7 +383,6 @@ final WebDriver driver = getWebDriver(); driver.get(URL_FIRST.toString()); - driver.findElement(By.id("myLink")).click(); String reqUrl = primitiveWebServer_.getRequests().get(1); reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); @@ -204,16 +394,16 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "/bug.html?k%F6nig", - IE = "/bug.html?k\u00f6nig") + @Alerts(DEFAULT = "/test.css?k%F6nig", + IE = "/test.css?k\u00f6nig") @NotYetImplemented(IE) - public void linkUrlEncodingISO8859_1() throws Exception { + public void linkUrlEncodingISO8859_1Meta() throws Exception { final String html = "<html>\n" + "<head><title>foo</title>\n" + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + "</head>\n" + "<body>\n" - + " <a id='myLink' href='bug.html?k\u00F6nig'>Click me</a>\n" + "</body></html>"; final String firstResponse = "HTTP/1.1 200 OK\r\n" @@ -222,14 +412,15 @@ + "\r\n" + html; - final String response = "HTTP/1.1 200 OK\r\n" - + "Content-Length: 2\r\n" - + "Content-Type: text/html\r\n" + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + "\r\n" - + "<html><head><title>foo</title></head><body>" - + "</body></html>"; + + css; - primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, response); + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); primitiveWebServer_.start(); @@ -236,12 +427,8 @@ final WebDriver driver = getWebDriver(); driver.get(URL_FIRST.toString()); - driver.findElement(By.id("myLink")).click(); String reqUrl = primitiveWebServer_.getRequests().get(1); - if (reqUrl.contains("/favicon.ico")) { - reqUrl = primitiveWebServer_.getRequests().get(2); - } reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); assertEquals(getExpectedAlerts()[0], reqUrl); |
From: <rb...@us...> - 2018-07-18 07:14:24
|
Revision: 15481 http://sourceforge.net/p/htmlunit/code/15481 Author: rbri Date: 2018-07-18 07:14:15 +0000 (Wed, 18 Jul 2018) Log Message: ----------- debug at the server Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2018-07-18 07:05:05 UTC (rev 15480) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2018-07-18 07:14:15 UTC (rev 15481) @@ -382,7 +382,7 @@ httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); httpContext.removeAttribute(HttpClientContext.CREDS_PROVIDER); httpContext.removeAttribute(HttpClientContext.TARGET_AUTH_STATE); - +System.out.println("conn: " + httpMethod.getURI()); return httpMethod; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-18 07:05:05 UTC (rev 15480) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-18 07:14:15 UTC (rev 15481) @@ -1344,6 +1344,7 @@ url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), webRequest.getCharset()); webRequest.setUrl(url); +System.out.println("client: " + url); if (LOG.isDebugEnabled()) { LOG.debug("Load response for " + method + " " + url.toExternalForm()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 07:05:05 UTC (rev 15480) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 07:14:15 UTC (rev 15481) @@ -225,7 +225,7 @@ html += "</head>\n" + "<body>\n" - + " <a id='myLink' href='test.html?ku00F6nig'>Click me</a>\n" + + " <a id='myLink' href='test.html?k\u00F6nig'>Click me</a>\n" + "</body></html>"; String firstResponse = "HTTP/1.1 200 OK\r\n" |
From: <rb...@us...> - 2018-07-18 07:39:47
|
Revision: 15486 http://sourceforge.net/p/htmlunit/code/15486 Author: rbri Date: 2018-07-18 07:39:43 +0000 (Wed, 18 Jul 2018) Log Message: ----------- debug at the server Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2018-07-18 07:32:41 UTC (rev 15485) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2018-07-18 07:39:43 UTC (rev 15486) @@ -189,9 +189,7 @@ HttpResponse httpResponse = null; try { -System.out.println("#"); httpResponse = builder.build().execute(hostConfiguration, httpMethod, httpContext); -System.out.println("# done"); } catch (final SSLPeerUnverifiedException s) { // Try to use only SSLv3 instead @@ -204,7 +202,6 @@ } } catch (final Error e) { -System.out.println("##" + e); // in case a StackOverflowError occurs while the connection is leased, it won't get released. // Calling code may catch the StackOverflowError, but due to the leak, the httpClient_ may // come out of connections and throw a ConnectionPoolTimeoutException. @@ -212,10 +209,6 @@ httpClientBuilder_.remove(Thread.currentThread()); throw e; } - catch (final Throwable e) { -System.out.println("###" + e); - throw e; - } final DownloadedContent downloadedBody = downloadResponseBody(httpResponse); final long endTime = System.currentTimeMillis(); @@ -389,7 +382,6 @@ httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); httpContext.removeAttribute(HttpClientContext.CREDS_PROVIDER); httpContext.removeAttribute(HttpClientContext.TARGET_AUTH_STATE); -System.out.println("conn: " + httpMethod.getURI()); return httpMethod; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-18 07:32:41 UTC (rev 15485) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-07-18 07:39:43 UTC (rev 15486) @@ -1344,7 +1344,6 @@ url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), webRequest.getCharset()); webRequest.setUrl(url); -System.out.println("client: " + url); if (LOG.isDebugEnabled()) { LOG.debug("Load response for " + method + " " + url.toExternalForm()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 07:32:41 UTC (rev 15485) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 07:39:43 UTC (rev 15486) @@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import java.util.Locale; /** * A very simple implementation of a Web Server. @@ -71,9 +70,6 @@ * @throws IOException if an error occurs */ public void start() throws IOException { -System.out.println("start "); -System.out.println(Locale.getDefault()); -System.out.println(System.getProperty("java.version")); server_ = new ServerSocket(port_); new Thread(new Runnable() { @@ -97,7 +93,6 @@ break; } } -System.out.println("req: " + requestString); final String response; if (requestString.contains("/favicon.ico")) { @@ -114,7 +109,6 @@ response = otherResponse_; } first = false; -System.out.println("resp: " + response); out.write(response.getBytes(charset_)); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 07:32:41 UTC (rev 15485) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 07:39:43 UTC (rev 15486) @@ -51,111 +51,112 @@ shutDownAll(); } -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts(DEFAULT = "/test.html?a=b%20c&d=%C3%A9%C3%A8", -// IE = "/test.html?a=b%20c&d=\u00E9\u00E8") -// @NotYetImplemented(IE) -// public void loadPage_EncodeRequest() throws Exception { -// // with query string not encoded -// testRequestUrlEncoding("test.html?a=b c&d=\u00E9\u00E8"); -// } -// -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts("/test.html?a=b%20c&d=%C3%A9%C3%A8") -// public void loadPage_EncodeRequest2() throws Exception { -// // with query string already encoded -// testRequestUrlEncoding("test.html?a=b%20c&d=%C3%A9%C3%A8"); -// } -// -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts("/test.html?a=b%20c&d=e%20f") -// public void loadPage_EncodeRequest3() throws Exception { -// // with query string partially encoded -// testRequestUrlEncoding("test.html?a=b%20c&d=e f"); -// } -// -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts("/test.html?a=b%20c") -// public void loadPage_EncodeRequest4() throws Exception { -// // with anchor -// testRequestUrlEncoding("test.html?a=b c#myAnchor"); -// } -// -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts("/test.html?a=%26%3D%20%2C%24") -// public void loadPage_EncodeRequest5() throws Exception { -// // with query string containing encoded "&", "=", "+", ",", and "$" -// testRequestUrlEncoding("test.html?a=%26%3D%20%2C%24"); -// } -// -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts("/page%201.html") -// public void loadPage_EncodeRequest6() throws Exception { -// // with character to encode in path -// testRequestUrlEncoding("page 1.html"); -// } -// -// /** -// * Test that the path and query string are encoded to be valid. -// * @throws Exception if something goes wrong -// */ -// @Test -// @Alerts(DEFAULT = "/test.html?param=%C2%A9%C2%A3", -// IE = "/test.html?param=\u00A9\u00A3") -// @NotYetImplemented(IE) -// public void loadPage_EncodeRequest7() throws Exception { -// // unicode -// testRequestUrlEncoding("test.html?param=\u00A9\u00A3"); -// } -// -// private void testRequestUrlEncoding(final String url) throws Exception { -// final String html = "<html>" -// + "<head><title>foo</title></head>" -// + "<body></body></html>"; -// -// final String response = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + html.length() + "\r\n" -// + "Content-Type: text/html\r\n" -// + "\r\n" -// + html; -// -// primitiveWebServer_ = new PrimitiveWebServer(PORT, response); -// primitiveWebServer_.start(); -// -// final WebDriver driver = getWebDriver(); -// -// driver.get(new URL(URL_FIRST, url).toString()); -// String reqUrl = primitiveWebServer_.getRequests().get(0); -// reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); -// -// assertEquals(getExpectedAlerts()[0], reqUrl); -// } + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts(DEFAULT = "/test.html?a=b%20c&d=%C3%A9%C3%A8", + IE = "/test.html?a=b%20c&d=\u00E9\u00E8") + @NotYetImplemented(IE) + public void loadPage_EncodeRequest() throws Exception { + // with query string not encoded + testRequestUrlEncoding("test.html?a=b c&d=\u00E9\u00E8"); + } /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=b%20c&d=%C3%A9%C3%A8") + public void loadPage_EncodeRequest2() throws Exception { + // with query string already encoded + testRequestUrlEncoding("test.html?a=b%20c&d=%C3%A9%C3%A8"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=b%20c&d=e%20f") + public void loadPage_EncodeRequest3() throws Exception { + // with query string partially encoded + testRequestUrlEncoding("test.html?a=b%20c&d=e f"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=b%20c") + public void loadPage_EncodeRequest4() throws Exception { + // with anchor + testRequestUrlEncoding("test.html?a=b c#myAnchor"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/test.html?a=%26%3D%20%2C%24") + public void loadPage_EncodeRequest5() throws Exception { + // with query string containing encoded "&", "=", "+", ",", and "$" + testRequestUrlEncoding("test.html?a=%26%3D%20%2C%24"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts("/page%201.html") + public void loadPage_EncodeRequest6() throws Exception { + // with character to encode in path + testRequestUrlEncoding("page 1.html"); + } + + /** + * Test that the path and query string are encoded to be valid. + * @throws Exception if something goes wrong + */ + @Test + @Alerts(DEFAULT = "/test.html?param=%C2%A9%C2%A3", + IE = "/test.html?param=\u00A9\u00A3") + @NotYetImplemented(IE) + public void loadPage_EncodeRequest7() throws Exception { + // unicode + testRequestUrlEncoding("test.html?param=\u00A9\u00A3"); + } + + private void testRequestUrlEncoding(final String url) throws Exception { + final String html = "<html>" + + "<head><title>foo</title></head>" + + "<body></body></html>"; + + final String response = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html\r\n" + + "Connection: close\r\n" + + "\r\n" + + html; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, response); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(new URL(URL_FIRST, url).toString()); + String reqUrl = primitiveWebServer_.getRequests().get(0); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** * @throws Exception if the test fails */ @Test @@ -263,180 +264,188 @@ assertEquals(getExpectedAlerts()[0], reqUrl); } -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.css?k%C3%B6nig", -// IE = "/test.css?k\u00c3\u00b6nig") -// @NotYetImplemented(IE) -// public void linkUrlEncodingUTF8Header() throws Exception { -// final String html = "<html>\n" -// + "<head><title>foo</title>\n" -// + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" -// + "</head>\n" -// + "<body>\n" -// + "</body></html>"; -// -// final String firstResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + html.length() + "\r\n" -// + "Content-Type: text/html; charset=UTF-8\r\n" -// + "\r\n" -// + html; -// -// final String css = "p { color: red; }"; -// -// final String secondResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + css.length() + "\r\n" -// + "Content-Type: text/css\r\n" -// + "\r\n" -// + css; -// -// primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); -// primitiveWebServer_.setCharset(StandardCharsets.UTF_8); -// primitiveWebServer_.start(); -// -// final WebDriver driver = getWebDriver(); -// -// driver.get(URL_FIRST.toString()); -// -// String reqUrl = primitiveWebServer_.getRequests().get(1); -// reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); -// -// assertEquals(getExpectedAlerts()[0], reqUrl); -// } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.css?k%C3%B6nig", -// IE = "/test.css?k\u00c3\u00b6nig") -// @NotYetImplemented(IE) -// public void linkUrlEncodingUTF8Meta() throws Exception { -// final String html = "<html>\n" -// + "<head><title>foo</title>\n" -// + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" -// + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" -// + "</head>\n" -// + "<body>\n" -// + "</body></html>"; -// -// final String firstResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + html.length() + "\r\n" -// + "Content-Type: text/html\r\n" -// + "\r\n" -// + html; -// -// final String css = "p { color: red; }"; -// -// final String secondResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + css.length() + "\r\n" -// + "Content-Type: text/css\r\n" -// + "\r\n" -// + css; -// -// primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); -// primitiveWebServer_.setCharset(StandardCharsets.UTF_8); -// primitiveWebServer_.start(); -// -// final WebDriver driver = getWebDriver(); -// -// driver.get(URL_FIRST.toString()); -// -// String reqUrl = primitiveWebServer_.getRequests().get(1); -// reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); -// -// assertEquals(getExpectedAlerts()[0], reqUrl); -// } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.css?k%F6nig", -// IE = "/test.css?k\u00f6nig") -// @NotYetImplemented(IE) -// public void linkUrlEncodingISO8859_1Header() throws Exception { -// final String html = "<html>\n" -// + "<head><title>foo</title>\n" -// + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" -// + "</head>\n" -// + "<body>\n" -// + "</body></html>"; -// -// final String firstResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + html.length() + "\r\n" -// + "Content-Type: text/html; charset=ISO-8859-1\r\n" -// + "\r\n" -// + html; -// -// final String css = "p { color: red; }"; -// -// final String secondResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + css.length() + "\r\n" -// + "Content-Type: text/css\r\n" -// + "\r\n" -// + css; -// -// primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); -// primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); -// primitiveWebServer_.start(); -// -// final WebDriver driver = getWebDriver(); -// -// driver.get(URL_FIRST.toString()); -// -// String reqUrl = primitiveWebServer_.getRequests().get(1); -// reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); -// -// assertEquals(getExpectedAlerts()[0], reqUrl); -// } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.css?k%F6nig", -// IE = "/test.css?k\u00f6nig") -// @NotYetImplemented(IE) -// public void linkUrlEncodingISO8859_1Meta() throws Exception { -// final String html = "<html>\n" -// + "<head><title>foo</title>\n" -// + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" -// + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" -// + "</head>\n" -// + "<body>\n" -// + "</body></html>"; -// -// final String firstResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + html.length() + "\r\n" -// + "Content-Type: text/html\r\n" -// + "\r\n" -// + html; -// -// final String css = "p { color: red; }"; -// -// final String secondResponse = "HTTP/1.1 200 OK\r\n" -// + "Content-Length: " + css.length() + "\r\n" -// + "Content-Type: text/css\r\n" -// + "\r\n" -// + css; -// -// primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); -// primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); -// primitiveWebServer_.start(); -// -// final WebDriver driver = getWebDriver(); -// -// driver.get(URL_FIRST.toString()); -// -// String reqUrl = primitiveWebServer_.getRequests().get(1); -// reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); -// -// assertEquals(getExpectedAlerts()[0], reqUrl); -// } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%C3%B6nig", + IE = "/test.css?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingUTF8Header() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html; charset=UTF-8\r\n" + + "Connection: close\r\n" + + "\r\n" + + html; + + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + + "Connection: close\r\n" + + "\r\n" + + css; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(StandardCharsets.UTF_8); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%C3%B6nig", + IE = "/test.css?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingUTF8Meta() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html\r\n" + + "Connection: close\r\n" + + "\r\n" + + html; + + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + + "Connection: close\r\n" + + "\r\n" + + css; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(StandardCharsets.UTF_8); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%F6nig", + IE = "/test.css?k\u00f6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingISO8859_1Header() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html; charset=ISO-8859-1\r\n" + + "Connection: close\r\n" + + "\r\n" + + html; + + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + + "Connection: close\r\n" + + "\r\n" + + css; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%F6nig", + IE = "/test.css?k\u00f6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingISO8859_1Meta() throws Exception { + final String html = "<html>\n" + + "<head><title>foo</title>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" + + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + final String firstResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + html.length() + "\r\n" + + "Content-Type: text/html\r\n" + + "Connection: close\r\n" + + "\r\n" + + html; + + final String css = "p { color: red; }"; + + final String secondResponse = "HTTP/1.1 200 OK\r\n" + + "Content-Length: " + css.length() + "\r\n" + + "Content-Type: text/css\r\n" + + "Connection: close\r\n" + + "\r\n" + + css; + + primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); + primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); + primitiveWebServer_.start(); + + final WebDriver driver = getWebDriver(); + + driver.get(URL_FIRST.toString()); + + String reqUrl = primitiveWebServer_.getRequests().get(1); + reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); + + assertEquals(getExpectedAlerts()[0], reqUrl); + } + // BaseFrameElement.java (2 matches) // HtmlApplet.java // HtmlArea.java |
From: <rb...@us...> - 2018-07-18 19:33:02
|
Revision: 15487 http://sourceforge.net/p/htmlunit/code/15487 Author: rbri Date: 2018-07-18 19:32:57 +0000 (Wed, 18 Jul 2018) Log Message: ----------- next step in our endless encoding fight - fix iframe and frameset url encoding Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2018-07-18 07:39:43 UTC (rev 15486) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2018-07-18 19:32:57 UTC (rev 15487) @@ -179,6 +179,7 @@ } try { final WebRequest request = new WebRequest(url); + request.setCharset(getPage().getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, getPage().getUrl().toExternalForm()); getPage().getEnclosingWindow().getWebClient().getPage(enclosedWindow_, request); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 07:39:43 UTC (rev 15486) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 19:32:57 UTC (rev 15487) @@ -97,7 +97,9 @@ final String response; if (requestString.contains("/favicon.ico")) { response = "HTTP/1.1 404 Not Found\r\n" - + "Content-Length: 0\r\n\r\n"; + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"; } else { requests_.add(requestString); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 07:39:43 UTC (rev 15486) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 19:32:57 UTC (rev 15487) @@ -18,7 +18,6 @@ import java.net.URL; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import org.junit.After; import org.junit.Test; @@ -164,104 +163,58 @@ IE = "/test.html?k\u00c3\u00b6nig") @NotYetImplemented(IE) public void anchorUrlEncodingUTF8Header() throws Exception { - urlEncoding(true, "UTF-8"); + anchorUrlEncoding(true, "UTF-8"); } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.html?k%C3%B6nig", -// IE = "/test.html?k\u00c3\u00b6nig") -// @NotYetImplemented(IE) -// public void anchorUrlEncodingUTF8Meta() throws Exception { -// urlEncoding(false, "UTF-8"); -// } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.html?k%F6nig", -// IE = "/test.html?k\u00f6nig") -// @NotYetImplemented(IE) -// public void anchorUrlEncodingISO8859_1Header() throws Exception { -// urlEncoding(true, "ISO-8859-1"); -// } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts(DEFAULT = "/test.html?k%F6nig", -// IE = "/test.html?k\u00f6nig") -// @NotYetImplemented(IE) -// public void anchorUrlEncodingISO8859_1Meta() throws Exception { -// urlEncoding(false, "ISO-8859-1"); -// } -// -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts("/test.html?k?nig") -// public void anchorUrlEncodingWindows_1251Header() throws Exception { -// urlEncoding(true, "Windows-1251"); -// } -// /** -// * @throws Exception if the test fails -// */ -// @Test -// @Alerts("/test.html?k?nig") -// public void anchorUrlEncodingWindows_1251Meta() throws Exception { -// urlEncoding(false, "Windows-1251"); -// } - private void urlEncoding(final boolean header, final String charset) throws Exception { - String html = "<html>\n" - + "<head><title>foo</title>\n"; - if (!header) { - html += " <meta http-equiv='Content-Type' content='text/html; charset=" + charset + "'>\n"; - } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%C3%B6nig", + IE = "/test.html?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingUTF8Meta() throws Exception { + anchorUrlEncoding(false, "UTF-8"); + } - html += "</head>\n" - + "<body>\n" - + " <a id='myLink' href='test.html?k\u00F6nig'>Click me</a>\n" - + "</body></html>"; + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%F6nig", + IE = "/test.html?k\u00f6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingISO8859_1Header() throws Exception { + anchorUrlEncoding(true, "ISO-8859-1"); + } - String firstResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + html.length() + "\r\n" - + "Content-Type: text/html"; - if (header) { - firstResponse += "; charset=" + charset; - } - firstResponse += "\r\n" - + "Connection: close\r\n" - + "\r\n" + html; + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%F6nig", + IE = "/test.html?k\u00f6nig") + @NotYetImplemented(IE) + public void anchorUrlEncodingISO8859_1Meta() throws Exception { + anchorUrlEncoding(false, "ISO-8859-1"); + } - final String html2 = "<html><head></head><body>" - + "</body></html>"; + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("/test.html?k?nig") + public void anchorUrlEncodingWindows_1251Header() throws Exception { + anchorUrlEncoding(true, "Windows-1251"); + } - final String secondResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + html2.length() + "\r\n" - + "Content-Type: text/html; charset=" + charset + "\r\n" - + "Connection: close\r\n" - + "\r\n" - + html2; - - primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); - primitiveWebServer_.setCharset(Charset.forName(charset)); - primitiveWebServer_.start(); - - final WebDriver driver = getWebDriver(); - - driver.get(URL_FIRST.toString()); - driver.findElement(By.id("myLink")).click(); - - String reqUrl = primitiveWebServer_.getRequests().get(1); - reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); - - assertEquals(getExpectedAlerts()[0], reqUrl); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("/test.html?k?nig") + public void anchorUrlEncodingWindows_1251Meta() throws Exception { + anchorUrlEncoding(false, "Windows-1251"); } /** @@ -272,41 +225,7 @@ IE = "/test.css?k\u00c3\u00b6nig") @NotYetImplemented(IE) public void linkUrlEncodingUTF8Header() throws Exception { - final String html = "<html>\n" - + "<head><title>foo</title>\n" - + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" - + "</head>\n" - + "<body>\n" - + "</body></html>"; - - final String firstResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + html.length() + "\r\n" - + "Content-Type: text/html; charset=UTF-8\r\n" - + "Connection: close\r\n" - + "\r\n" - + html; - - final String css = "p { color: red; }"; - - final String secondResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + css.length() + "\r\n" - + "Content-Type: text/css\r\n" - + "Connection: close\r\n" - + "\r\n" - + css; - - primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); - primitiveWebServer_.setCharset(StandardCharsets.UTF_8); - primitiveWebServer_.start(); - - final WebDriver driver = getWebDriver(); - - driver.get(URL_FIRST.toString()); - - String reqUrl = primitiveWebServer_.getRequests().get(1); - reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); - - assertEquals(getExpectedAlerts()[0], reqUrl); + linkUrlEncoding(true, "UTF-8"); } /** @@ -317,42 +236,51 @@ IE = "/test.css?k\u00c3\u00b6nig") @NotYetImplemented(IE) public void linkUrlEncodingUTF8Meta() throws Exception { - final String html = "<html>\n" - + "<head><title>foo</title>\n" - + " <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" - + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" - + "</head>\n" - + "<body>\n" - + "</body></html>"; + linkUrlEncoding(false, "UTF-8"); + } - final String firstResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + html.length() + "\r\n" - + "Content-Type: text/html\r\n" - + "Connection: close\r\n" - + "\r\n" - + html; + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%F6nig", + IE = "/test.css?k\u00f6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingISO8859_1Header() throws Exception { + linkUrlEncoding(true, "ISO_8859_1"); + } - final String css = "p { color: red; }"; + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.css?k%F6nig", + IE = "/test.css?k\u00f6nig") + @NotYetImplemented(IE) + public void linkUrlEncodingISO8859_1Meta() throws Exception { + linkUrlEncoding(false, "ISO_8859_1"); + } - final String secondResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + css.length() + "\r\n" - + "Content-Type: text/css\r\n" - + "Connection: close\r\n" - + "\r\n" - + css; + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%C3%B6nig", + IE = "/test.html?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void iframeUrlEncodingUTF8Header() throws Exception { + iframeUrlEncoding(true, "UTF-8"); + } - primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); - primitiveWebServer_.setCharset(StandardCharsets.UTF_8); - primitiveWebServer_.start(); - - final WebDriver driver = getWebDriver(); - - driver.get(URL_FIRST.toString()); - - String reqUrl = primitiveWebServer_.getRequests().get(1); - reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); - - assertEquals(getExpectedAlerts()[0], reqUrl); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%C3%B6nig", + IE = "/test.html?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void iframeUrlEncodingUTF8Meta() throws Exception { + iframeUrlEncoding(false, "UTF-8"); } /** @@ -359,40 +287,77 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "/test.css?k%F6nig", - IE = "/test.css?k\u00f6nig") + @Alerts(DEFAULT = "/test.html?k%F6nig", + IE = "/test.html?k\u00f6nig") @NotYetImplemented(IE) - public void linkUrlEncodingISO8859_1Header() throws Exception { - final String html = "<html>\n" - + "<head><title>foo</title>\n" - + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" - + "</head>\n" + public void iframeUrlEncodingISO8859_1Header() throws Exception { + framesetUrlEncoding("ISO_8859_1"); + } + + private void anchorUrlEncoding(final boolean header, final String charset) throws Exception { + urlEncoding(header, charset, + null, + " <a id='myLink' href='test.html?k\u00F6nig'>Click me</a>", + true); + } + + private void linkUrlEncoding(final boolean header, final String charset) throws Exception { + urlEncoding(header, charset, + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>", + "", + false); + } + + private void iframeUrlEncoding(final boolean header, final String charset) throws Exception { + urlEncoding(header, charset, + " <iframe src='test.html?k\u00F6nig'></iframe> ", + "", + false); + } + + private void urlEncoding(final boolean header, final String charset, + final String addHeader, + final String addHtml, + final boolean click) throws Exception { + String html = "<html>\n" + + "<head><title>foo</title>\n"; + if (!header) { + html += " <meta http-equiv='Content-Type' content='text/html; charset=" + charset + "'>\n"; + } + if (addHeader != null) { + html += addHeader + "\n"; + } + + html += "</head>\n" + "<body>\n" + + addHtml + "\n" + "</body></html>"; - final String firstResponse = "HTTP/1.1 200 OK\r\n" + String firstResponse = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + html.length() + "\r\n" - + "Content-Type: text/html; charset=ISO-8859-1\r\n" + + "Content-Type: text/html"; + if (header) { + firstResponse += "; charset=" + charset; + } + firstResponse += "\r\n" + "Connection: close\r\n" - + "\r\n" - + html; + + "\r\n" + html; - final String css = "p { color: red; }"; - - final String secondResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + css.length() + "\r\n" - + "Content-Type: text/css\r\n" + final String secondResponse = "HTTP/1.1 404 Not Found\r\n" + + "Content-Length: 0\r\n" + "Connection: close\r\n" - + "\r\n" - + css; + + "\r\n"; primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); - primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); + primitiveWebServer_.setCharset(Charset.forName(charset)); primitiveWebServer_.start(); final WebDriver driver = getWebDriver(); driver.get(URL_FIRST.toString()); + if (click) { + driver.findElement(By.id("myLink")).click(); + } String reqUrl = primitiveWebServer_.getRequests().get(1); reqUrl = reqUrl.substring(4, reqUrl.indexOf("HTTP/1.1") - 1); @@ -404,36 +369,42 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "/test.css?k%F6nig", - IE = "/test.css?k\u00f6nig") + @Alerts(DEFAULT = "/test.html?k%C3%B6nig", + IE = "/test.html?k\u00c3\u00b6nig") @NotYetImplemented(IE) - public void linkUrlEncodingISO8859_1Meta() throws Exception { + public void framesetUrlEncodingUTF8() throws Exception { + framesetUrlEncoding("UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.html?k%F6nig", + IE = "/test.html?k\u00f6nig") + @NotYetImplemented(IE) + public void framesetUrlEncodingISO8859_1() throws Exception { + framesetUrlEncoding("ISO_8859_1"); + } + + private void framesetUrlEncoding(final String charset) throws Exception { final String html = "<html>\n" - + "<head><title>foo</title>\n" - + " <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" - + " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>" - + "</head>\n" - + "<body>\n" - + "</body></html>"; + + "<frameset><frame src='test.html?k\u00F6nig'></frameset>\n" + + "</html>"; final String firstResponse = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + html.length() + "\r\n" - + "Content-Type: text/html\r\n" + + "Content-Type: text/html; charset=" + charset + "\r\n" + "Connection: close\r\n" - + "\r\n" - + html; + + "\r\n" + html; - final String css = "p { color: red; }"; - - final String secondResponse = "HTTP/1.1 200 OK\r\n" - + "Content-Length: " + css.length() + "\r\n" - + "Content-Type: text/css\r\n" + final String secondResponse = "HTTP/1.1 404 Not Found\r\n" + + "Content-Length: 0\r\n" + "Connection: close\r\n" - + "\r\n" - + css; + + "\r\n"; primitiveWebServer_ = new PrimitiveWebServer(PORT, firstResponse, secondResponse); - primitiveWebServer_.setCharset(StandardCharsets.ISO_8859_1); + primitiveWebServer_.setCharset(Charset.forName(charset)); primitiveWebServer_.start(); final WebDriver driver = getWebDriver(); @@ -446,7 +417,6 @@ assertEquals(getExpectedAlerts()[0], reqUrl); } -// BaseFrameElement.java (2 matches) // HtmlApplet.java // HtmlArea.java // HtmlEmbed.java @@ -454,4 +424,5 @@ // HtmlImage.java // HtmlImageInput.java // HtmlObject.java + } |
From: <rb...@us...> - 2018-07-19 18:26:22
|
Revision: 15488 http://sourceforge.net/p/htmlunit/code/15488 Author: rbri Date: 2018-07-19 18:26:06 +0000 (Thu, 19 Jul 2018) Log Message: ----------- next step in our endless encoding fight - fix area and image Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java 2018-07-18 19:32:57 UTC (rev 15487) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlArea.java 2018-07-19 18:26:06 UTC (rev 15488) @@ -91,6 +91,7 @@ "Not a valid url: " + getHrefAttribute()); } final WebRequest request = new WebRequest(url); + request.setCharset(page.getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); final WebWindow webWindow = enclosingPage.getEnclosingWindow(); webClient.getPage( Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2018-07-18 19:32:57 UTC (rev 15487) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2018-07-19 18:26:06 UTC (rev 15488) @@ -463,6 +463,7 @@ final URL url = page.getFullyQualifiedUrl(src); final String accept = webclient.getBrowserVersion().getImgAcceptHeader(); final WebRequest request = new WebRequest(url, accept); + request.setCharset(page.getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-18 19:32:57 UTC (rev 15487) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PrimitiveWebServer.java 2018-07-19 18:26:06 UTC (rev 15488) @@ -103,17 +103,18 @@ } else { requests_.add(requestString); - try (OutputStream out = socket.getOutputStream()) { - if (first || otherResponse_ == null) { - response = firstResponse_; - } - else { - response = otherResponse_; - } - first = false; - out.write(response.getBytes(charset_)); + if (first || otherResponse_ == null) { + response = firstResponse_; } + else { + response = otherResponse_; + } + first = false; } + + try (OutputStream out = socket.getOutputStream()) { + out.write(response.getBytes(charset_)); + } } } catch (final SocketException e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-18 19:32:57 UTC (rev 15487) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient7Test.java 2018-07-19 18:26:06 UTC (rev 15488) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF60; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import java.net.URL; @@ -26,6 +27,7 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; /** @@ -221,6 +223,98 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "/area.html?k%C3%B6nig", + IE = "/area.html?k\u00c3\u00b6nig") + @BuggyWebDriver(FF60) + @NotYetImplemented(IE) + public void areaUrlEncodingUTF8Header() throws Exception { + areaUrlEncoding(true, "UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/area.html?k%C3%B6nig", + IE = "/area.html?k\u00c3\u00b6nig") + @BuggyWebDriver(FF60) + @NotYetImplemented(IE) + public void areaUrlEncodingUTF8Meta() throws Exception { + areaUrlEncoding(false, "UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/area.html?k%F6nig", + IE = "/area.html?k\u00f6nig") + @BuggyWebDriver(FF60) + @NotYetImplemented(IE) + public void areaUrlEncodingISO8859_1Header() throws Exception { + areaUrlEncoding(true, "ISO-8859-1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/area.html?k%F6nig", + IE = "/area.html?k\u00f6nig") + @BuggyWebDriver(FF60) + @NotYetImplemented(IE) + public void areaUrlEncodingISO8859_1Meta() throws Exception { + areaUrlEncoding(false, "ISO-8859-1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.gif?k%C3%B6nig", + IE = "/test.gif?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void imageUrlEncodingUTF8Header() throws Exception { + imageUrlEncoding(true, "UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.gif?k%C3%B6nig", + IE = "/test.gif?k\u00c3\u00b6nig") + @NotYetImplemented(IE) + public void imageUrlEncodingUTF8Meta() throws Exception { + imageUrlEncoding(false, "UTF-8"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.gif?k%F6nig", + IE = "/test.gif?k\u00f6nig") + @NotYetImplemented(IE) + public void imageUrlEncodingISO8859_1Header() throws Exception { + imageUrlEncoding(true, "ISO_8859_1"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "/test.gif?k%F6nig", + IE = "/test.gif?k\u00f6nig") + @NotYetImplemented(IE) + public void imageUrlEncodingISO8859_1Meta() throws Exception { + imageUrlEncoding(false, "ISO_8859_1"); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = "/test.css?k%C3%B6nig", IE = "/test.css?k\u00c3\u00b6nig") @NotYetImplemented(IE) @@ -301,6 +395,26 @@ true); } + private void areaUrlEncoding(final boolean header, final String charset) throws Exception { + urlEncoding(header, charset, + null, + " <img id='myImg' usemap='#dot' width='100' height='100'" + + " src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAA" + + "HElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='>\n" + + " <map name='dot'>\n" + + " <area id='myLink' shape='rect' coords='0,0,42,42' href='area.html?k\u00F6nig'/>\n" + + " <map>\n", + true); + } + + private void imageUrlEncoding(final boolean header, final String charset) throws Exception { + urlEncoding(header, charset, + null, + " <img id='myImg' src='test.gif?k\u00F6nig'>" + + " <button id='myLink' onClick='document.getElementById(\"myImg\").width'></button>", + true); + } + private void linkUrlEncoding(final boolean header, final String charset) throws Exception { urlEncoding(header, charset, " <link rel='stylesheet' type='text/css' href='test.css?k\u00F6nig'>", @@ -418,11 +532,8 @@ } // HtmlApplet.java -// HtmlArea.java // HtmlEmbed.java // HtmlForm.java -// HtmlImage.java // HtmlImageInput.java // HtmlObject.java - } |
From: <rb...@us...> - 2018-07-21 12:09:22
|
Revision: 15490 http://sourceforge.net/p/htmlunit/code/15490 Author: rbri Date: 2018-07-21 12:09:18 +0000 (Sat, 21 Jul 2018) Log Message: ----------- HTMLxxxInput.reset() results in a wrong state of the selection delegate Issue 1969 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/changes/changes.xml 2018-07-21 12:09:18 UTC (rev 15490) @@ -8,6 +8,9 @@ <body> <release version="2.32" date="xx 2018" description="Bugfixes, FIREFOX_45 removed, FIREFOX_60 added"> + <action type="fix" dev="rbri" issue="1969"> + HTMLxxxInput.reset() results in a wrong state of the selection delegate. + </action> <action type="add" dev="rbri"> FF60 ESR support. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -156,8 +156,18 @@ /** * {@inheritDoc} + * @see HtmlInput#reset() */ @Override + public void reset() { + super.reset(); + setSelectionEnd(0); + } + + /** + * {@inheritDoc} + */ + @Override public DomNode cloneNode(final boolean deep) { final HtmlEmailInput newnode = (HtmlEmailInput) super.cloneNode(deep); newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -174,14 +174,6 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return new HtmlNumberInput(getQualifiedName(), getPage(), getAttributesMap()); - } - - /** - * {@inheritDoc} - */ - @Override public void setDefaultValue(final String defaultValue) { final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); setDefaultValue(defaultValue, modifyValue); @@ -205,8 +197,18 @@ /** * {@inheritDoc} + * @see HtmlInput#reset() */ @Override + public void reset() { + super.reset(); + setSelectionEnd(0); + } + + /** + * {@inheritDoc} + */ + @Override public DomNode cloneNode(final boolean deep) { final HtmlNumberInput newnode = (HtmlNumberInput) super.cloneNode(deep); newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -158,14 +158,6 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return new HtmlPasswordInput(getQualifiedName(), getPage(), getAttributesMap()); - } - - /** - * {@inheritDoc} - */ - @Override protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) { super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners, @@ -194,8 +186,18 @@ /** * {@inheritDoc} + * @see HtmlInput#reset() */ @Override + public void reset() { + super.reset(); + setSelectionEnd(0); + } + + /** + * {@inheritDoc} + */ + @Override public DomNode cloneNode(final boolean deep) { final HtmlPasswordInput newnode = (HtmlPasswordInput) super.cloneNode(deep); newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -150,4 +150,14 @@ return newnode; } + + /** + * {@inheritDoc} + * @see HtmlInput#reset() + */ + @Override + public void reset() { + super.reset(); + setSelectionEnd(0); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -544,14 +544,6 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return new HtmlTextArea(getQualifiedName(), getPage(), getAttributesMap()); - } - - /** - * {@inheritDoc} - */ - @Override protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) { if ("name".equals(qualifiedName)) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -180,17 +180,19 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return new HtmlTextInput(getQualifiedName(), getPage(), getAttributesMap()); + public void setDefaultValue(final String defaultValue) { + final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); + setDefaultValue(defaultValue, modifyValue); } /** * {@inheritDoc} + * @see HtmlInput#reset() */ @Override - public void setDefaultValue(final String defaultValue) { - final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); - setDefaultValue(defaultValue, modifyValue); + public void reset() { + super.reset(); + setSelectionEnd(0); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -156,8 +156,18 @@ /** * {@inheritDoc} + * @see HtmlInput#reset() */ @Override + public void reset() { + super.reset(); + setSelectionEnd(0); + } + + /** + * {@inheritDoc} + */ + @Override public DomNode cloneNode(final boolean deep) { final HtmlUrlInput newnode = (HtmlUrlInput) super.cloneNode(deep); newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -49,4 +49,29 @@ input.type("ab...@em..."); assertEquals("ab...@em...", input.getValueAttribute()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='email' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlEmailInput input = (HtmlEmailInput) page.getElementById("foo"); + + input.type("ab...@em..."); + input.reset(); + input.type("xy...@em..."); + + assertEquals("xy...@em...", input.getValueAttribute()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -49,4 +49,29 @@ input.type("4711"); assertEquals("4711", input.getValueAttribute()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='number' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlNumberInput input = (HtmlNumberInput) page.getElementById("foo"); + + input.type("4711"); + input.reset(); + input.type("0815"); + + assertEquals("0815", input.getValueAttribute()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -107,4 +107,29 @@ input.type("4711"); assertEquals("4711", input.getValueAttribute()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='password' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlPasswordInput input = (HtmlPasswordInput) page.getElementById("foo"); + + input.type("4711"); + input.reset(); + input.type("0815"); + + assertEquals("0815", input.getValueAttribute()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -49,4 +49,29 @@ input.type("4711"); assertEquals("4711", input.getValueAttribute()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='tel' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlTelInput input = (HtmlTelInput) page.getElementById("foo"); + + input.type("4711"); + input.reset(); + input.type("0815"); + + assertEquals("0815", input.getValueAttribute()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextAreaTest.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -292,4 +292,51 @@ final HtmlTextArea t = page.getHtmlElementById("t"); t.removeFocus(); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndClone() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <textarea id='foo'></textarea>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlTextArea input = (HtmlTextArea) page.getElementById("foo"); + input = (HtmlTextArea) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getTextContent()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <textarea id='foo'></textarea>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlTextArea input = (HtmlTextArea) page.getElementById("foo"); + + input.type("4711"); + input.reset(); + input.type("0815"); + + assertEquals("0815", input.getTextContent()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput2Test.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -360,4 +360,51 @@ assertEquals(1, getMockWebConnection().getRequestCount()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndClone() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlTextInput input = (HtmlTextInput) page.getElementById("foo"); + input = (HtmlTextInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlTextInput input = (HtmlTextInput) page.getElementById("foo"); + + input.type("4711"); + input.reset(); + input.type("0815"); + + assertEquals("0815", input.getValueAttribute()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java 2018-07-19 19:07:50 UTC (rev 15489) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java 2018-07-21 12:09:18 UTC (rev 15490) @@ -49,4 +49,29 @@ input.type("4711"); assertEquals("4711", input.getValueAttribute()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndReset() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='url' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + final HtmlUrlInput input = (HtmlUrlInput) page.getElementById("foo"); + + input.type("4711"); + input.reset(); + input.type("0815"); + + assertEquals("0815", input.getValueAttribute()); + } } |
From: <rb...@us...> - 2018-07-21 12:37:14
|
Revision: 15491 http://sourceforge.net/p/htmlunit/code/15491 Author: rbri Date: 2018-07-21 12:36:53 +0000 (Sat, 21 Jul 2018) Log Message: ----------- setting window.clientInformation is ignored in IE Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-07-21 12:09:18 UTC (rev 15490) +++ trunk/htmlunit/src/changes/changes.xml 2018-07-21 12:36:53 UTC (rev 15491) @@ -8,6 +8,9 @@ <body> <release version="2.32" date="xx 2018" description="Bugfixes, FIREFOX_45 removed, FIREFOX_60 added"> + <action type="fix" dev="rbri"> + Setting window.clientInformation is ignored in IE. + </action> <action type="fix" dev="rbri" issue="1969"> HTMLxxxInput.reset() results in a wrong state of the selection delegate. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-07-21 12:09:18 UTC (rev 15490) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-07-21 12:36:53 UTC (rev 15491) @@ -624,6 +624,14 @@ } /** + * special setter for IE to ignore this call. + * @param ignore parame gets ignored + */ + @JsxSetter(IE) + public void setClientInformation(final Object ignore) { + } + + /** * Returns the JavaScript property {@code clipboardData}. * @return the {@link DataTransfer} */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2018-07-21 12:09:18 UTC (rev 15490) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2018-07-21 12:36:53 UTC (rev 15491) @@ -2385,4 +2385,25 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = {"[object Navigator]", "##test##"}, + IE = {"[object Navigator]", "[object Navigator]"}, + FF = {"undefined", "##test##"}) + public void clientInformation() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(window.clientInformation);\n" + + " window.clientInformation = '##test##';\n" + + " alert(window.clientInformation);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-07-25 17:38:55
|
Revision: 15495 http://sourceforge.net/p/htmlunit/code/15495 Author: rbri Date: 2018-07-25 17:38:50 +0000 (Wed, 25 Jul 2018) Log Message: ----------- event listeners had to be functions, other types are ignored Issue 1976 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ApplicationCache.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MessagePort.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainerTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/worker/WorkerTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/changes/changes.xml 2018-07-25 17:38:50 UTC (rev 15495) @@ -8,6 +8,9 @@ <body> <release version="2.32" date="xx 2018" description="Bugfixes, FIREFOX_45 removed, FIREFOX_60 added"> + <action type="fix" dev="rbri" issue="1976"> + Event listeners had to be functions, other types are ignored. + </action> <action type="fix" dev="rbri"> Setting window.clientInformation is ignored in IE. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ApplicationCache.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ApplicationCache.java 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ApplicationCache.java 2018-07-25 17:38:50 UTC (rev 15495) @@ -29,8 +29,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - /** * <p>A collection of offline resources as defined in the HTML5 spec. * Intended to support offline web applications.</p> @@ -224,10 +222,7 @@ } private void setHandlerForJavaScript(final String eventName, final Object handler) { - if (handler == null || handler instanceof Scriptable) { - getEventListenersContainer().setEventHandler(eventName, handler); - } - // Otherwise, fail silently. + getEventListenersContainer().setEventHandler(eventName, handler); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MessagePort.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MessagePort.java 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/MessagePort.java 2018-07-25 17:38:50 UTC (rev 15495) @@ -32,7 +32,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent; import net.sourceforge.htmlunit.corejs.javascript.ContextFactory; -import net.sourceforge.htmlunit.corejs.javascript.Function; /** * A JavaScript object for {@code MessagePort}. @@ -82,10 +81,7 @@ } private void setHandlerForJavaScript(final String eventName, final Object handler) { - if (handler == null || handler instanceof Function) { - getEventListenersContainer().setEventHandler(eventName, handler); - } - // Otherwise, fail silently. + getEventListenersContainer().setEventHandler(eventName, handler); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-07-25 17:38:50 UTC (rev 15495) @@ -1194,7 +1194,7 @@ */ @JsxSetter public void setOnload(final Object onload) { - getEventListenersContainer().setEventHandler(Event.TYPE_LOAD, onload); + setHandlerForJavaScript(Event.TYPE_LOAD, onload); } /** @@ -1203,7 +1203,7 @@ */ @JsxSetter public void setOnblur(final Object onblur) { - getEventListenersContainer().setEventHandler(Event.TYPE_BLUR, onblur); + setHandlerForJavaScript(Event.TYPE_BLUR, onblur); } /** @@ -1377,10 +1377,7 @@ } private void setHandlerForJavaScript(final String eventName, final Object handler) { - if (handler == null || handler instanceof Function) { - getEventListenersContainer().setEventHandler(eventName, handler); - } - // Otherwise, fail silently. + getEventListenersContainer().setEventHandler(eventName, handler); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-07-25 17:38:50 UTC (rev 15495) @@ -57,7 +57,7 @@ static class TypeContainer implements Serializable { private List<Scriptable> capturingListeners_; private List<Scriptable> bubblingListeners_; - private Object handler_; + private Function handler_; TypeContainer() { capturingListeners_ = Collections.unmodifiableList(new ArrayList<Scriptable>()); @@ -65,7 +65,7 @@ } private TypeContainer(final List<Scriptable> capturingListeners, - final List<Scriptable> bubblingListeners, final Object handler) { + final List<Scriptable> bubblingListeners, final Function handler) { capturingListeners_ = Collections.unmodifiableList(new ArrayList<>(capturingListeners)); bubblingListeners_ = Collections.unmodifiableList(new ArrayList<>(bubblingListeners)); handler_ = handler; @@ -206,10 +206,15 @@ * @param value the new property */ public void setEventHandler(final String eventType, final Object value) { - Object handler = value; - if (handler == Undefined.instance) { + final Function handler; + + // Otherwise, ignore silently. + if (value == Undefined.instance || !(value instanceof Function)) { handler = null; } + else { + handler = (Function) value; + } final TypeContainer container = getTypeContainer(eventType); container.handler_ = handler; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainerTest.java 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainerTest.java 2018-07-25 17:38:50 UTC (rev 15495) @@ -25,6 +25,7 @@ * Tests for {@link EventListenersContainer}. * * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class EventListenersContainerTest extends WebDriverTestCase { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/worker/WorkerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/worker/WorkerTest.java 2018-07-22 17:37:11 UTC (rev 15494) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/worker/WorkerTest.java 2018-07-25 17:38:50 UTC (rev 15495) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.worker; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import java.net.URL; import org.junit.After; @@ -23,6 +25,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -29,6 +32,7 @@ * Unit tests for {@code Worker}. * * @author Marc Guillemot + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class WorkerTest extends WebDriverTestCase { @@ -164,4 +168,57 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("function") + public void onmessageFunction() throws Exception { + final String html = "<html><body><script>\n" + + " var myWorker = new Worker('worker.js');\n" + + " myWorker.onmessage = function(e) {};\n" + + " alert(typeof myWorker.onmessage);\n" + + "</script></body></html>\n"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "null", + IE = "exception Error") + @NotYetImplemented(IE) + public void onmessageNumber() throws Exception { + final String html = "<html><body><script>\n" + + " var myWorker = new Worker('worker.js');\n" + + " try {\n" + + " myWorker.onmessage = 17;\n" + + " alert(myWorker.onmessage);\n" + + " } catch(e) { alert('exception ' + e.name); }\n" + + "</script></body></html>\n"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "null", + IE = "HtmlUnit") + @NotYetImplemented(IE) + public void onmessageString() throws Exception { + final String html = "<html><body><script>\n" + + " var myWorker = new Worker('worker.js');\n" + + " try {\n" + + " myWorker.onmessage = 'HtmlUnit';\n" + + " alert(myWorker.onmessage);\n" + + " } catch(e) { alert('exception ' + e.name); }\n" + + "</script></body></html>\n"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-07-28 15:41:48
|
Revision: 15496 http://sourceforge.net/p/htmlunit/code/15496 Author: rbri Date: 2018-07-28 15:41:38 +0000 (Sat, 28 Jul 2018) Log Message: ----------- CHROME 68 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageInputTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/changes/changes.xml 2018-07-28 15:41:38 UTC (rev 15496) @@ -7,7 +7,7 @@ </properties> <body> - <release version="2.32" date="xx 2018" description="Bugfixes, FIREFOX_45 removed, FIREFOX_60 added"> + <release version="2.32" date="xx 2018" description="Bugfixes, FIREFOX_45 removed, FIREFOX_60 added, CHROME 68"> <action type="fix" dev="rbri" issue="1976"> Event listeners had to be functions, other types are ignored. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -210,8 +210,8 @@ EDGE.scriptAcceptHeader_ = "application/javascript, */*;q=0.8"; // CHROME - CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"; - CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"; + CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36"; + CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36"; CHROME.applicationCodeName_ = "Mozilla"; CHROME.vendor_ = "Google Inc."; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -1057,7 +1057,7 @@ JS_LABEL_FORM_NULL, /** location.hash returns an encoded hash. */ - @BrowserFeature(FF) + @BrowserFeature({CHROME, FF}) JS_LOCATION_HASH_HASH_IS_ENCODED, /** @@ -1066,7 +1066,7 @@ * for url 'http://localhost/something/#%C3%BC'.<br> * IE evaluates to #%C3%BC. */ - @BrowserFeature(FF) + @BrowserFeature({CHROME, FF}) JS_LOCATION_HASH_IS_DECODED, /** @@ -1082,7 +1082,7 @@ * for url 'http://localhost/something/#ü'.<br> * IE evaluates to #ü. */ - @BrowserFeature(FF) + @BrowserFeature({CHROME, FF}) JS_LOCATION_HREF_HASH_IS_ENCODED, /** Map ignores the argument constructor. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -3015,7 +3015,7 @@ VOLUME("volume", "volume"), /** The style property {@code webkitAlignContent}. */ - WEBKIT_ALIGN_CONTENT("webkitAlignContent", "webkit-align-content", ff("normal")), + WEBKIT_ALIGN_CONTENT("webkitAlignContent", "webkit-align-content", chrome("normal"), ff("normal")), /** The style property {@code WebkitAlignContent}. */ WEBKIT_ALIGN_CONTENT_("WebkitAlignContent", "webkit-align-content", ff("normal")), @@ -3024,7 +3024,7 @@ WEBKIT_ALIGN_CONTENT__("-webkit-align-content", "webkit-align-content", ff("normal")), /** The style property {@code webkitAlignItems}. */ - WEBKIT_ALIGN_ITEMS("webkitAlignItems", "webkit-align-items", ff("normal")), + WEBKIT_ALIGN_ITEMS("webkitAlignItems", "webkit-align-items", chrome("normal"), ff("normal")), /** The style property {@code WebkitAlignItems}. */ WEBKIT_ALIGN_ITEMS_("WebkitAlignItems", "webkit-align-items", ff("normal")), @@ -3033,7 +3033,7 @@ WEBKIT_ALIGN_ITEMS__("-webkit-align-items", "webkit-align-items", ff("normal")), /** The style property {@code webkitAlignSelf}. */ - WEBKIT_ALIGN_SELF("webkitAlignSelf", "webkit-align-self", ff("auto")), + WEBKIT_ALIGN_SELF("webkitAlignSelf", "webkit-align-self", chrome("auto"), ff("auto")), /** The style property {@code WebkitAlignSelf}. */ WEBKIT_ALIGN_SELF_("WebkitAlignSelf", "webkit-align-self", ff("auto")), @@ -3042,7 +3042,8 @@ WEBKIT_ALIGN_SELF__("-webkit-align-self", "webkit-align-self", ff("auto")), /** The style property {@code webkitAnimation}. */ - WEBKIT_ANIMATION("webkitAnimation", "webkit-animation", ff("")), + WEBKIT_ANIMATION("webkitAnimation", "webkit-animation", + chrome("none 0s ease 0s 1 normal none running"), ff("")), /** The style property {@code WebkitAnimation}. */ WEBKIT_ANIMATION_("WebkitAnimation", "webkit-animation", ff("")), @@ -3051,7 +3052,7 @@ WEBKIT_ANIMATION__("-webkit-animation", "webkit-animation", ff("")), /** The style property {@code webkitAnimationDelay}. */ - WEBKIT_ANIMATION_DELAY("webkitAnimationDelay", "webkit-animation-delay", ff("0s")), + WEBKIT_ANIMATION_DELAY("webkitAnimationDelay", "webkit-animation-delay", chrome("0s"), ff("0s")), /** The style property {@code WebkitAnimationDelay}. */ WEBKIT_ANIMATION_DELAY_("WebkitAnimationDelay", "webkit-animation-delay", ff("0s")), @@ -3060,7 +3061,8 @@ WEBKIT_ANIMATION_DELAY__("-webkit-animation-delay", "webkit-animation-delay", ff("0s")), /** The style property {@code webkitAnimationDirection}. */ - WEBKIT_ANIMATION_DIRECTION("webkitAnimationDirection", "webkit-animation-direction", ff("normal")), + WEBKIT_ANIMATION_DIRECTION("webkitAnimationDirection", "webkit-animation-direction", + chrome("normal"), ff("normal")), /** The style property {@code WebkitAnimationDirection}. */ WEBKIT_ANIMATION_DIRECTION_("WebkitAnimationDirection", "webkit-animation-direction", ff("normal")), @@ -3069,7 +3071,7 @@ WEBKIT_ANIMATION_DIRECTION__("-webkit-animation-direction", "webkit-animation-direction", ff("normal")), /** The style property {@code webkitAnimationDuration}. */ - WEBKIT_ANIMATION_DURATION("webkitAnimationDuration", "webkit-animation-duration", ff("0s")), + WEBKIT_ANIMATION_DURATION("webkitAnimationDuration", "webkit-animation-duration", chrome("0s"), ff("0s")), /** The style property {@code WebkitAnimationDuration}. */ WEBKIT_ANIMATION_DURATION_("WebkitAnimationDuration", "webkit-animation-duration", ff("0s")), @@ -3078,7 +3080,7 @@ WEBKIT_ANIMATION_DURATION__("-webkit-animation-duration", "webkit-animation-duration", ff("0s")), /** The style property {@code webkitAnimationFillMode}. */ - WEBKIT_ANIMATION_FILL_MODE("webkitAnimationFillMode", "webkit-animation-fill-mode", ff("none")), + WEBKIT_ANIMATION_FILL_MODE("webkitAnimationFillMode", "webkit-animation-fill-mode", chrome("none"), ff("none")), /** The style property {@code WebkitAnimationFillMode}. */ WEBKIT_ANIMATION_FILL_MODE_("WebkitAnimationFillMode", "webkit-animation-fill-mode", ff("none")), @@ -3088,7 +3090,7 @@ /** The style property {@code webkitAnimationIterationCount}. */ WEBKIT_ANIMATION_ITERATION_COUNT("webkitAnimationIterationCount", "webkit-animation-iteration-count", - ff("1")), + chrome("1"), ff("1")), /** The style property {@code WebkitAnimationIterationCount}. */ WEBKIT_ANIMATION_ITERATION_COUNT_("WebkitAnimationIterationCount", "webkit-animation-iteration-count", @@ -3099,7 +3101,7 @@ ff("1")), /** The style property {@code webkitAnimationName}. */ - WEBKIT_ANIMATION_NAME("webkitAnimationName", "webkit-animation-name", ff("none")), + WEBKIT_ANIMATION_NAME("webkitAnimationName", "webkit-animation-name", chrome("none"), ff("none")), /** The style property {@code WebkitAnimationName}. */ WEBKIT_ANIMATION_NAME_("WebkitAnimationName", "webkit-animation-name", ff("none")), @@ -3108,7 +3110,8 @@ WEBKIT_ANIMATION_NAME__("-webkit-animation-name", "webkit-animation-name", ff("none")), /** The style property {@code webkitAnimationPlayState}. */ - WEBKIT_ANIMATION_PLAY_STATE("webkitAnimationPlayState", "webkit-animation-play-state", ff("running")), + WEBKIT_ANIMATION_PLAY_STATE("webkitAnimationPlayState", "webkit-animation-play-state", + chrome("running"), ff("running")), /** The style property {@code WebkitAnimationPlayState}. */ WEBKIT_ANIMATION_PLAY_STATE_("WebkitAnimationPlayState", "webkit-animation-play-state", ff("running")), @@ -3118,7 +3121,7 @@ /** The style property {@code webkitAnimationTimingFunction}. */ WEBKIT_ANIMATION_TIMING_FUNCTION("webkitAnimationTimingFunction", "webkit-animation-timing-function", - ff("ease")), + chrome("ease"), ff("ease")), /** The style property {@code WebkitAnimationTimingFunction}. */ WEBKIT_ANIMATION_TIMING_FUNCTION_("WebkitAnimationTimingFunction", "webkit-animation-timing-function", @@ -3136,7 +3139,7 @@ /** The style property {@code webkitBackfaceVisibility}. */ WEBKIT_BACKFACE_VISIBILITY("webkitBackfaceVisibility", "webkit-backface-visibility", - ff("visible")), + chrome("visible"), ff("visible")), /** The style property {@code WebkitBackfaceVisibility}. */ WEBKIT_BACKFACE_VISIBILITY_("WebkitBackfaceVisibility", "webkit-backface-visibility", @@ -3147,7 +3150,8 @@ ff("visible")), /** The style property {@code webkitBackgroundClip}. */ - WEBKIT_BACKGROUND_CLIP("webkitBackgroundClip", "webkit-background-clip", ff("border-box")), + WEBKIT_BACKGROUND_CLIP("webkitBackgroundClip", "webkit-background-clip", + chrome("border-box"), ff("border-box")), /** The style property {@code WebkitBackgroundClip}. */ WEBKIT_BACKGROUND_CLIP_("WebkitBackgroundClip", "webkit-background-clip", ff("border-box")), @@ -3156,7 +3160,8 @@ WEBKIT_BACKGROUND_CLIP__("-webkit-background-clip", "webkit-background-clip", ff("border-box")), /** The style property {@code webkitBackgroundOrigin}. */ - WEBKIT_BACKGROUND_ORIGIN("webkitBackgroundOrigin", "webkit-background-origin", ff("padding-box")), + WEBKIT_BACKGROUND_ORIGIN("webkitBackgroundOrigin", "webkit-background-origin", + chrome("padding-box"), ff("padding-box")), /** The style property {@code WebkitBackgroundOrigin}. */ WEBKIT_BACKGROUND_ORIGIN_("WebkitBackgroundOrigin", "webkit-background-origin", ff("padding-box")), @@ -3165,7 +3170,7 @@ WEBKIT_BACKGROUND_ORIGIN__("-webkit-background-origin", "webkit-background-origin", ff("padding-box")), /** The style property {@code webkitBackgroundSize}. */ - WEBKIT_BACKGROUND_SIZE("webkitBackgroundSize", "webkit-background-size", ff("auto auto")), + WEBKIT_BACKGROUND_SIZE("webkitBackgroundSize", "webkit-background-size", chrome("auto"), ff("auto auto")), /** The style property {@code WebkitBackgroundSize}. */ WEBKIT_BACKGROUND_SIZE_("WebkitBackgroundSize", "webkit-background-size", ff("auto auto")), @@ -3199,7 +3204,7 @@ /** The style property {@code webkitBorderBottomLeftRadius}. */ WEBKIT_BORDER_BOTTOM_LEFT_RADIUS("webkitBorderBottomLeftRadius", "webkit-border-bottom-left-radius", - ff("0px")), + chrome("0px"), ff("0px")), /** The style property {@code WebkitBorderBottomLeftRadius}. */ WEBKIT_BORDER_BOTTOM_LEFT_RADIUS_("WebkitBorderBottomLeftRadius", "webkit-border-bottom-left-radius", @@ -3211,7 +3216,7 @@ /** The style property {@code webkitBorderBottomRightRadius}. */ WEBKIT_BORDER_BOTTOM_RIGHT_RADIUS("webkitBorderBottomRightRadius", "webkit-border-bottom-right-radius", - ff("0px")), + chrome("0px"), ff("0px")), /** The style property {@code WebkitBorderBottomRightRadius}. */ WEBKIT_BORDER_BOTTOM_RIGHT_RADIUS_("WebkitBorderBottomRightRadius", "webkit-border-bottom-right-radius", @@ -3247,7 +3252,7 @@ WEBKIT_BORDER_IMAGE__("-webkit-border-image", "webkit-border-image", ff("")), /** The style property {@code webkitBorderRadius}. */ - WEBKIT_BORDER_RADIUS("webkitBorderRadius", "webkit-border-radius", ff("")), + WEBKIT_BORDER_RADIUS("webkitBorderRadius", "webkit-border-radius", chrome("0px"), ff("")), /** The style property {@code WebkitBorderRadius}. */ WEBKIT_BORDER_RADIUS_("WebkitBorderRadius", "webkit-border-radius", ff("")), @@ -3268,7 +3273,8 @@ WEBKIT_BORDER_START_WIDTH("webkitBorderStartWidth", "webkit-border-start-width", chrome("0px")), /** The style property {@code webkitBorderTopLeftRadius}. */ - WEBKIT_BORDER_TOP_LEFT_RADIUS("webkitBorderTopLeftRadius", "webkit-border-top-left-radius", ff("0px")), + WEBKIT_BORDER_TOP_LEFT_RADIUS("webkitBorderTopLeftRadius", "webkit-border-top-left-radius", + chrome("0px"), ff("0px")), /** The style property {@code WebkitBorderTopLeftRadius}. */ WEBKIT_BORDER_TOP_LEFT_RADIUS_("WebkitBorderTopLeftRadius", "webkit-border-top-left-radius", ff("0px")), @@ -3278,7 +3284,8 @@ ff("0px")), /** The style property {@code webkitBorderTopRightRadius}. */ - WEBKIT_BORDER_TOP_RIGHT_RADIUS("webkitBorderTopRightRadius", "webkit-border-top-right-radius", ff("0px")), + WEBKIT_BORDER_TOP_RIGHT_RADIUS("webkitBorderTopRightRadius", "webkit-border-top-right-radius", + chrome("0px"), ff("0px")), /** The style property {@code WebkitBorderTopRightRadius}. */ WEBKIT_BORDER_TOP_RIGHT_RADIUS_("WebkitBorderTopRightRadius", "webkit-border-top-right-radius", ff("0px")), @@ -3357,7 +3364,7 @@ WEBKIT_BOX_REFLECT("webkitBoxReflect", "webkit-box-reflect", chrome("none")), /** The style property {@code webkitBoxShadow}. */ - WEBKIT_BOX_SHADOW("webkitBoxShadow", "webkit-box-shadow", ff("none")), + WEBKIT_BOX_SHADOW("webkitBoxShadow", "webkit-box-shadow", chrome("none"), ff("none")), /** The style property {@code WebkitBoxShadow}. */ WEBKIT_BOX_SHADOW_("WebkitBoxShadow", "webkit-box-shadow", ff("none")), @@ -3366,7 +3373,7 @@ WEBKIT_BOX_SHADOW__("-webkit-box-shadow", "webkit-box-shadow", ff("none")), /** The style property {@code webkitBoxSizing}. */ - WEBKIT_BOX_SIZING("webkitBoxSizing", "webkit-box-sizing", ff("content-box")), + WEBKIT_BOX_SIZING("webkitBoxSizing", "webkit-box-sizing", chrome("content-box"), ff("content-box")), /** The style property {@code WebkitBoxSizing}. */ WEBKIT_BOX_SIZING_("WebkitBoxSizing", "webkit-box-sizing", ff("content-box")), @@ -3374,6 +3381,9 @@ /** The style property {@code -webkit-box-sizing}. */ WEBKIT_BOX_SIZING__("-webkit-box-sizing", "webkit-box-sizing", ff("content-box")), + /** The style property {@code webkitClipPath}. */ + WEBKIT_CLIP_PATH("webkitClipPath", "webkit-clip-path", chrome("none")), + /** The style property {@code webkitColumnBreakAfter}. */ WEBKIT_COLUMN_BREAK_AFTER("webkitColumnBreakAfter", "webkit-column-break-after", chrome("auto")), @@ -3383,8 +3393,35 @@ /** The style property {@code webkitColumnBreakInside}. */ WEBKIT_COLUMN_BREAK_INSIDE("webkitColumnBreakInside", "webkit-column-break-inside", chrome("auto")), + /** The style property {@code webkitColumnCount}. */ + WEBKIT_COLUMN_COUNT("webkitColumnCount", "webkit-column-count", chrome("auto")), + + /** The style property {@code webkitColumnGap}. */ + WEBKIT_COLUMN_GAP("webkitColumnGap", "webkit-column-gap", chrome("normal")), + + /** The style property {@code webkitColumnRule}. */ + WEBKIT_COLUMN_RULE("webkitColumnRule", "webkit-column-rule", chrome("0px none rgb(0, 0, 0)")), + + /** The style property {@code webkitColumnRuleColor}. */ + WEBKIT_COLUMN_RULE_COLOR("webkitColumnRuleColor", "webkit-column-rule-color", chrome("rgb(0, 0, 0)")), + + /** The style property {@code webkitColumnRuleStyle}. */ + WEBKIT_COLUMN_RULE_STYLE("webkitColumnRuleStyle", "webkit-column-rule-style", chrome("none")), + + /** The style property {@code webkitColumnRuleWidth}. */ + WEBKIT_COLUMN_RULE_WIDTH("webkitColumnRuleWidth", "webkit-column-rule-width", chrome("0px")), + + /** The style property {@code webkitColumnSpan}. */ + WEBKIT_COLUMN_SPAN("webkitColumnSpan", "webkit-column-rule-span", chrome("none")), + + /** The style property {@code webkitColumnWidth}. */ + WEBKIT_COLUMN_WIDTH("webkitColumnWidth", "webkit-column-width", chrome("auto")), + + /** The style property {@code webkitColumns}. */ + WEBKIT_COLUMNS("webkitColumns", "webkit-columns", chrome("auto auto")), + /** The style property {@code webkitFilter}. */ - WEBKIT_FILTER("webkitFilter", "webkit-filter", ff("none")), + WEBKIT_FILTER("webkitFilter", "webkit-filter", chrome("none"), ff("none")), /** The style property {@code WebkitFilter}. */ WEBKIT_FILTER_("WebkitFilter", "webkit-filter", ff("none")), @@ -3393,7 +3430,7 @@ WEBKIT_FILTER__("-webkit-filter", "webkit-filter", ff("none")), /** The style property {@code webkitFlex}. */ - WEBKIT_FLEX("webkitFlex", "webkit-flex", ff("")), + WEBKIT_FLEX("webkitFlex", "webkit-flex", chrome("0 1 auto"), ff("")), /** The style property {@code WebkitFlex}. */ WEBKIT_FLEX_("WebkitFlex", "webkit-flex", ff("")), @@ -3402,7 +3439,7 @@ WEBKIT_FLEX__("-webkit-flex", "webkit-flex", ff("")), /** The style property {@code webkitFlexBasis}. */ - WEBKIT_FLEX_BASIS("webkitFlexBasis", "webkit-flex-basis", ff("auto")), + WEBKIT_FLEX_BASIS("webkitFlexBasis", "webkit-flex-basis", chrome("auto"), ff("auto")), /** The style property {@code WebkitFlexBasis}. */ WEBKIT_FLEX_BASIS_("WebkitFlexBasis", "webkit-flex-basis", ff("auto")), @@ -3411,7 +3448,7 @@ WEBKIT_FLEX_BASIS__("-webkit-flex-basis", "webkit-flex-basis", ff("auto")), /** The style property {@code webkitFlexDirection}. */ - WEBKIT_FLEX_DIRECTION("webkitFlexDirection", "webkit-flex-direction", ff("row")), + WEBKIT_FLEX_DIRECTION("webkitFlexDirection", "webkit-flex-direction", chrome("row"), ff("row")), /** The style property {@code WebkitFlexDirection}. */ WEBKIT_FLEX_DIRECTION_("WebkitFlexDirection", "webkit-flex-direction", ff("row")), @@ -3420,7 +3457,7 @@ WEBKIT_FLEX_DIRECTION__("-webkit-flex-direction", "webkit-flex-direction", ff("row")), /** The style property {@code webkitFlexFlow}. */ - WEBKIT_FLEX_FLOW("webkitFlexFlow", "webkit-flex-flow", ff("")), + WEBKIT_FLEX_FLOW("webkitFlexFlow", "webkit-flex-flow", chrome("row nowrap"), ff("")), /** The style property {@code WebkitFlexFlow}. */ WEBKIT_FLEX_FLOW_("WebkitFlexFlow", "webkit-flex-flow", ff("")), @@ -3429,7 +3466,7 @@ WEBKIT_FLEX_FLOW__("-webkit-flex-flow", "webkit-flex-flow", ff("")), /** The style property {@code webkitFlexGrow}. */ - WEBKIT_FLEX_GROW("webkitFlexGrow", "webkit-flex-grow", ff("0")), + WEBKIT_FLEX_GROW("webkitFlexGrow", "webkit-flex-grow", chrome("0"), ff("0")), /** The style property {@code WebkitFlexGrow}. */ WEBKIT_FLEX_GROW_("WebkitFlexGrow", "webkit-flex-grow", ff("0")), @@ -3438,7 +3475,7 @@ WEBKIT_FLEX_GROW__("-webkit-flex-grow", "webkit-flex-grow", ff("0")), /** The style property {@code webkitFlexShrink}. */ - WEBKIT_FLEX_SHRINK("webkitFlexShrink", "webkit-flex-shrink", ff("1")), + WEBKIT_FLEX_SHRINK("webkitFlexShrink", "webkit-flex-shrink", chrome("1"), ff("1")), /** The style property {@code WebkitFlexShrink}. */ WEBKIT_FLEX_SHRINK_("WebkitFlexShrink", "webkit-flex-shrink", ff("1")), @@ -3447,7 +3484,7 @@ WEBKIT_FLEX_SHRINK__("-webkit-flex-shrink", "webkit-flex-shrink", ff("1")), /** The style property {@code webkitFlexWrap}. */ - WEBKIT_FLEX_WRAP("webkitFlexWrap", "webkit-flex-wrap", ff("nowrap")), + WEBKIT_FLEX_WRAP("webkitFlexWrap", "webkit-flex-wrap", chrome("nowrap"), ff("nowrap")), /** The style property {@code WebkitFlexWrap}. */ WEBKIT_FLEX_WRAP_("WebkitFlexWrap", "webkit-flex-wrap", ff("nowrap")), @@ -3455,6 +3492,9 @@ /** The style property {@code -webkit-flex-wrap}. */ WEBKIT_FLEX_WRAP__("-webkit-flex-wrap", "webkit-flex-wrap", ff("nowrap")), + /** The style property {@code webkitFontFeatureSettings}. */ + WEBKIT_FONT_FEATURE_SETTINGS("webkitFontFeatureSettings", "webkit-font-feature-settings", chrome("normal")), + /** The style property {@code webkitFontSizeDelta}. */ WEBKIT_FONT_SIZE_DELTA("webkitFontSizeDelta", "webkit-font-size-delta", chrome("")), @@ -3468,7 +3508,7 @@ WEBKIT_HYPHENATE_CHARACTER("webkitHyphenateCharacter", "webkit-hyphenate-character", chrome("auto")), /** The style property {@code webkitJustifyContent}. */ - WEBKIT_JUSTIFY_CONTENT("webkitJustifyContent", "webkit-justify-content", ff("normal")), + WEBKIT_JUSTIFY_CONTENT("webkitJustifyContent", "webkit-justify-content", chrome("normal"), ff("normal")), /** The style property {@code WebkitJustifyContent}. */ WEBKIT_JUSTIFY_CONTENT_("WebkitJustifyContent", "webkit-justify-content", ff("normal")), @@ -3646,8 +3686,11 @@ /** The style property {@code webkitMinLogicalWidth}. */ WEBKIT_MIN_LOGICAL_WIDTH("webkitMinLogicalWidth", "webkit-min-logical-width", chrome("0px")), + /** The style property {@code webkitOpacity}. */ + WEBKIT_OPACITY("webkitOpacity", "webkit-opacity", chrome("1")), + /** The style property {@code webkitOrder}. */ - WEBKIT_ORDER("webkitOrder", "webkit-order", ff("0")), + WEBKIT_ORDER("webkitOrder", "webkit-order", chrome("0"), ff("0")), /** The style property {@code WebkitOrder}. */ WEBKIT_ORDER_("WebkitOrder", "webkit-order", ff("0")), @@ -3668,7 +3711,7 @@ WEBKIT_PADDING_START("webkitPaddingStart", "webkit-padding-start", chrome("0px")), /** The style property {@code webkitPerspective}. */ - WEBKIT_PERSPECTIVE("webkitPerspective", "webkit-perspective", ff("none")), + WEBKIT_PERSPECTIVE("webkitPerspective", "webkit-perspective", chrome("none"), ff("none")), /** The style property {@code WebkitPerspective}. */ WEBKIT_PERSPECTIVE_("WebkitPerspective", "webkit-perspective", ff("none")), @@ -3677,7 +3720,8 @@ WEBKIT_PERSPECTIVE__("-webkit-perspective", "webkit-perspective", ff("none")), /** The style property {@code webkitPerspectiveOrigin}. */ - WEBKIT_PERSPECTIVE_ORIGIN("webkitPerspectiveOrigin", "webkit-perspective-origin", ff("625px 172.5px")), + WEBKIT_PERSPECTIVE_ORIGIN("webkitPerspectiveOrigin", "webkit-perspective-origin", + chrome("456.5px 161px"), ff("625px 172.5px")), /** The style property {@code WebkitPerspectiveOrigin}. */ WEBKIT_PERSPECTIVE_ORIGIN_("WebkitPerspectiveOrigin", "webkit-perspective-origin", ff("625px 172.5px")), @@ -3700,6 +3744,15 @@ /** The style property {@code webkitRubyPosition}. */ WEBKIT_RUBY_POSITION("webkitRubyPosition", "webkit-ruby-position", chrome("before")), + /** The style property {@code webkitShapeImageThreshold}. */ + WEBKIT_SHAPE_IMAGE_THRESHOLD("webkitShapeImageThreshold", "webkit-shape-image-threshold", chrome("0")), + + /** The style property {@code webkitShapeMargin}. */ + WEBKIT_SHAPE_MARGIN("webkitShapeMargin", "webkit-shape-margin", chrome("0px")), + + /** The style property {@code webkitShapeOutside}. */ + WEBKIT_SHAPE_OUTSIDE("webkitShapeOutside", "webkit-shape-outside", chrome("none")), + /** The style property {@code webkitTapHighlightColor}. */ WEBKIT_TAP_HIGHLIGHT_COLOR("webkitTapHighlightColor", "webkit-tap-highlight-color", chrome("rgba(0, 0, 0, 0.18)")), @@ -3745,7 +3798,7 @@ WEBKIT_TEXT_SECURITY("webkitTextSecurity", "webkit-text-security", chrome("none")), /** The style property {@code webkitTextSizeAdjust}. */ - WEBKIT_TEXT_SIZE_ADJUST("webkitTextSizeAdjust", "webkit-text-size-adjust", ff("auto")), + WEBKIT_TEXT_SIZE_ADJUST("webkitTextSizeAdjust", "webkit-text-size-adjust", chrome("auto"), ff("auto")), /** The style property {@code WebkitTextSizeAdjust}. */ WEBKIT_TEXT_SIZE_ADJUST_("WebkitTextSizeAdjust", "webkit-text-size-adjust", ff("auto")), @@ -3784,7 +3837,7 @@ WEBKIT_TEXT_STROKE_WIDTH__("-webkit-text-stroke-width", "webkit-text-stroke-width", ff("0px")), /** The style property {@code webkitTransform}. */ - WEBKIT_TRANSFORM("webkitTransform", "webkit-transform", ff("none")), + WEBKIT_TRANSFORM("webkitTransform", "webkit-transform", chrome("none"), ff("none")), /** The style property {@code WebkitTransform}. */ WEBKIT_TRANSFORM_("WebkitTransform", "webkit-transform", ff("none")), @@ -3793,7 +3846,8 @@ WEBKIT_TRANSFORM__("-webkit-transform", "webkit-transform", ff("none")), /** The style property {@code webkitTransformOrigin}. */ - WEBKIT_TRANSFORM_ORIGIN("webkitTransformOrigin", "webkit-transform-origin", ff("625px 172.5px")), + WEBKIT_TRANSFORM_ORIGIN("webkitTransformOrigin", "webkit-transform-origin", + chrome("620px 161px"), ff("625px 172.5px")), /** The style property {@code WebkitTransformOrigin}. */ WEBKIT_TRANSFORM_ORIGIN_("WebkitTransformOrigin", "webkit-transform-origin", ff("625px 172.5px")), @@ -3811,7 +3865,7 @@ WEBKIT_TRANSFORM_ORIGIN_Z("webkitTransformOriginZ", "webkit-transform-origin-z", chrome("")), /** The style property {@code webkitTransformStyle}. */ - WEBKIT_TRANSFORM_STYLE("webkitTransformStyle", "webkit-transform-style", ff("flat")), + WEBKIT_TRANSFORM_STYLE("webkitTransformStyle", "webkit-transform-style", chrome("flat"), ff("flat")), /** The style property {@code WebkitTransformStyle}. */ WEBKIT_TRANSFORM_STYLE_("WebkitTransformStyle", "webkit-transform-style", ff("flat")), @@ -3820,7 +3874,7 @@ WEBKIT_TRANSFORM_STYLE__("-webkit-transform-style", "webkit-transform-style", ff("flat")), /** The style property {@code webkitTransition}. */ - WEBKIT_TRANSITION("webkitTransition", "webkit-transition", ff("")), + WEBKIT_TRANSITION("webkitTransition", "webkit-transition", chrome("all 0s ease 0s"), ff("")), /** The style property {@code WebkitTransition}. */ WEBKIT_TRANSITION_("WebkitTransition", "webkit-transition", ff("")), @@ -3829,7 +3883,7 @@ WEBKIT_TRANSITION__("-webkit-transition", "webkit-transition", ff("")), /** The style property {@code webkitTransitionDelay}. */ - WEBKIT_TRANSITION_DELAY("webkitTransitionDelay", "webkit-transition-delay", ff("0s")), + WEBKIT_TRANSITION_DELAY("webkitTransitionDelay", "webkit-transition-delay", chrome("0s"), ff("0s")), /** The style property {@code WebkitTransitionDelay}. */ WEBKIT_TRANSITION_DELAY_("WebkitTransitionDelay", "webkit-transition-delay", ff("0s")), @@ -3838,7 +3892,7 @@ WEBKIT_TRANSITION_DELAY__("-webkit-transition-delay", "webkit-transition-delay", ff("0s")), /** The style property {@code webkitTransitionDuration}. */ - WEBKIT_TRANSITION_DURATION("webkitTransitionDuration", "webkit-transition-duration", ff("0s")), + WEBKIT_TRANSITION_DURATION("webkitTransitionDuration", "webkit-transition-duration", chrome("0s"), ff("0s")), /** The style property {@code WebkitTransitionDuration}. */ WEBKIT_TRANSITION_DURATION_("WebkitTransitionDuration", "webkit-transition-duration", ff("0s")), @@ -3847,7 +3901,7 @@ WEBKIT_TRANSITION_DURATION__("-webkit-transition-duration", "webkit-transition-duration", ff("0s")), /** The style property {@code webkitTransitionProperty}. */ - WEBKIT_TRANSITION_PROPERTY("webkitTransitionProperty", "webkit-transition-property", ff("all")), + WEBKIT_TRANSITION_PROPERTY("webkitTransitionProperty", "webkit-transition-property", chrome("all"), ff("all")), /** The style property {@code WebkitTransitionProperty}. */ WEBKIT_TRANSITION_PROPERTY_("WebkitTransitionProperty", "webkit-transition-property", ff("all")), @@ -3857,7 +3911,7 @@ /** The style property {@code webkitTransitionTimingFunction}. */ WEBKIT_TRANSITION_TIMING_FUNCTION("webkitTransitionTimingFunction", "webkit-transition-timing-function", - ff("ease")), + chrome("ease"), ff("ease")), /** The style property {@code WebkitTransitionTimingFunction}. */ WEBKIT_TRANSITION_TIMING_FUNCTION_("WebkitTransitionTimingFunction", "webkit-transition-timing-function", @@ -3874,7 +3928,7 @@ WEBKIT_USER_MODIFY("webkitUserModify", "webkit-user-modify", chrome("read-only")), /** The style property {@code webkitUserSelect}. */ - WEBKIT_USER_SELECT("webkitUserSelect", "webkit-user-select", ff("auto")), + WEBKIT_USER_SELECT("webkitUserSelect", "webkit-user-select", chrome("auto"), ff("auto")), /** The style property {@code WebkitUserSelect}. */ WEBKIT_USER_SELECT_("WebkitUserSelect", "webkit-user-select", ff("auto")), Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -76,7 +76,7 @@ commonFormats.put("", mmSlash); commonFormats.put("ar", "dd\u200F/MM\u200F/YYYY"); commonFormats.put("ar-SA", "d\u200F/M\u200F/YYYY هـ"); - commonFormats.put("ban", ddDot); + commonFormats.put("ban", mmSlash); commonFormats.put("be", ddDot); commonFormats.put("bg", ddDot + "\u200E \u0433."); commonFormats.put("ca", ddSlash); @@ -153,9 +153,9 @@ commonFormats.put("sq", ddDot); FF_52_FORMATS_.putAll(commonFormats); + FF_52_FORMATS_.put("ban", ddDot); FF_60_FORMATS_.putAll(commonFormats); - FF_60_FORMATS_.put("ban", mmSlash); CHROME_FORMATS_.put("be", yyyyDash); CHROME_FORMATS_.put("en-CA", yyyyDash); @@ -165,7 +165,6 @@ CHROME_FORMATS_.put("es-US", ddSlash); CHROME_FORMATS_.put("fr-CH", ddDot); CHROME_FORMATS_.put("hr", ddDotBlankDot); - CHROME_FORMATS_.put("in", ddDot); CHROME_FORMATS_.put("in-ID", ddSlash); CHROME_FORMATS_.put("is", yyyyDash); CHROME_FORMATS_.put("iw", ddDot); @@ -193,6 +192,7 @@ IE_FORMATS_.put("ar-SD", rightToLeft); IE_FORMATS_.put("ar-SY", rightToLeft); IE_FORMATS_.put("ar-YE", rightToLeft); + IE_FORMATS_.put("ban", ddDot); IE_FORMATS_.put("cs", ddDot); IE_FORMATS_.put("da", ddDash); IE_FORMATS_.put("en-IN", ddDash); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -50,7 +50,7 @@ public class ExternalTest { /** Chrome driver. */ - static String CHROME_DRIVER_ = "2.40"; + static String CHROME_DRIVER_ = "2.41"; /** Gecko driver. */ static String GECKO_DRIVER_ = "0.21.0"; /** IE driver. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -2765,7 +2765,7 @@ + "volume,webkitAudioDecodedByteCount,webkitDecodedFrameCount," + "webkitDisplayingFullscreen,webkitDroppedFrameCount," + "webkitEnterFullscreen(),webkitEnterFullScreen()," - + "webkitExitFullScreen(),webkitExitFullscreen(),webkitSupportsFullscreen,webkitVideoDecodedByteCount," + + "webkitExitFullscreen(),webkitExitFullScreen(),webkitSupportsFullscreen,webkitVideoDecodedByteCount," + "width", FF52 = "addTextTrack(),autoplay,buffered,canPlayType(),controls,crossOrigin,currentSrc,currentTime," + "defaultMuted,defaultPlaybackRate,duration,ended,error,fastSeek(),getVideoPlaybackQuality()," @@ -3296,21 +3296,21 @@ + "linkColor,links,location,onabort,onauxclick,onbeforecopy," + "onbeforecut,onbeforepaste,onblur,oncancel,oncanplay,oncanplaythrough,onchange,onclick,onclose," + "oncontextmenu,oncopy,oncuechange,oncut,ondblclick,ondrag,ondragend,ondragenter,ondragleave," - + "ondragover,ondragstart,ondrop,ondurationchange,onemptied,onended,onerror,onfocus," + + "ondragover,ondragstart,ondrop,ondurationchange,onemptied,onended,onerror,onfocus,onfreeze," + "ongotpointercapture,oninput,oninvalid,onkeydown,onkeypress,onkeyup,onload,onloadeddata," + "onloadedmetadata,onloadstart,onlostpointercapture,onmousedown,onmouseenter,onmouseleave,onmousemove," + "onmouseout,onmouseover,onmouseup,onmousewheel,onpaste,onpause,onplay,onplaying,onpointercancel," + "onpointerdown,onpointerenter,onpointerleave,onpointerlockchange,onpointerlockerror,onpointermove," + "onpointerout,onpointerover,onpointerup,onprogress,onratechange,onreadystatechange,onreset,onresize," - + "onscroll,onsearch,onseeked,onseeking,onselect,onselectionchange,onselectstart,onstalled," + + "onresume,onscroll,onsearch,onseeked,onseeking,onselect,onselectionchange,onselectstart,onstalled," + "onsubmit,onsuspend,ontimeupdate,ontoggle,onvisibilitychange,onvolumechange,onwaiting," + "onwebkitfullscreenchange," - + "onwebkitfullscreenerror,onwheel,open(),origin,plugins,pointerLockElement,preferredStylesheetSet," + + "onwebkitfullscreenerror,onwheel,open(),origin,plugins,pointerLockElement," + "prepend(),queryCommandEnabled(),queryCommandIndeterm(),queryCommandState(),queryCommandSupported()," + "queryCommandValue(),querySelector(),querySelectorAll(),readyState,referrer,registerElement()," + "releaseEvents(),rootElement," - + "scripts,scrollingElement,selectedStylesheetSet,styleSheets,title,URL," - + "visibilityState,vlinkColor," + + "scripts,scrollingElement,styleSheets,title,URL," + + "visibilityState,vlinkColor,wasDiscarded," + "webkitCancelFullScreen(),webkitCurrentFullScreenElement,webkitExitFullscreen()," + "webkitFullscreenElement,webkitFullscreenEnabled,webkitHidden,webkitIsFullScreen," + "webkitVisibilityState,write(),writeln(),xmlEncoding,xmlStandalone,xmlVersion", Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -2078,9 +2078,10 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "exception", - FF = "function DOMRectList() {\n [native code]\n}") - @NotYetImplemented(FF) + @Alerts(DEFAULT = "function DOMRectList() {\n [native code]\n}", + CHROME = "function DOMRectList() { [native code] }", + IE = "exception") + @NotYetImplemented({CHROME, FF}) public void domRectList() throws Exception { test("DOMRectList"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.general; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; @@ -1302,9 +1303,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "undefined", - FF = "function") - @NotYetImplemented(FF) + @Alerts(DEFAULT = "function", + IE = "undefined") + @NotYetImplemented({CHROME, FF}) public void domRectList() throws Exception { test("DOMRectList"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageInputTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImageInputTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -73,7 +73,7 @@ */ @Test @Alerts(DEFAULT = "§§URL§§?button.x=0&button.y=0", - CHROME = "§§URL§§?button.x=30&button.y=8", + CHROME = "§§URL§§?button.x=28&button.y=8", IE = "§§URL§§?button.x=14&button.y=15") @NotYetImplemented({CHROME, IE}) public void click_NoPosition_NoValue() throws Exception { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -148,9 +148,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"#a b", "§§URL§§#a b", "#a%20b", "§§URL§§#a%20b", "#abc;,/?:@&=+$-_.!~*()ABC123foo", + @Alerts(DEFAULT = {"#a%20b", "§§URL§§#a%20b", "#a%20b", "§§URL§§#a%20b", "#abc;,/?:@&=+$-_.!~*()ABC123foo", "#%25%20%5E%5B%5D%7C%22%3C%3E%7B%7D%5C"}, - FF = {"#a%20b", "§§URL§§#a%20b", "#a%20b", "§§URL§§#a%20b", "#abc;,/?:@&=+$-_.!~*()ABC123foo", + IE = {"#a b", "§§URL§§#a b", "#a%20b", "§§URL§§#a%20b", "#abc;,/?:@&=+$-_.!~*()ABC123foo", "#%25%20%5E%5B%5D%7C%22%3C%3E%7B%7D%5C"}) public void hashEncoding() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -177,7 +177,7 @@ */ @Test @Alerts({"#myDataTable=foo%3Dojkoj", "§§URL§§#myDataTable=foo%3Dojkoj"}) - @NotYetImplemented(FF) + @NotYetImplemented({CHROME, FF}) public void hashEncoding2() throws Exception { final String html = "<html><body><script>\n" + "window.location.hash = 'myDataTable=foo%3Dojkoj';\n" @@ -194,7 +194,6 @@ @Test @Alerts(DEFAULT = {"#%C3%BC%C3%B6%C3%A4", "§§URL§§#%C3%BC%C3%B6%C3%A4"}, IE = {"#üöä", "§§URL§§#üöä"}) - @NotYetImplemented(CHROME) public void hashEncoding3() throws Exception { final String html = "<html><body><script>\n" + "window.location.hash = 'üöä';\n" @@ -209,8 +208,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "#<a>foobar</a>", - FF = "#%3Ca%3Efoobar%3C/a%3E") + @Alerts(DEFAULT = "#%3Ca%3Efoobar%3C/a%3E", + IE = "#<a>foobar</a>") public void hash() throws Exception { checkHash(URL_FIRST + "?#<a>foobar</a>"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -1793,7 +1793,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = "92", + @Alerts(CHROME = "47", FF52 = "50", FF60 = "48", IE = "100") @@ -1822,7 +1822,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = "58", + @Alerts(CHROME = "54", FF52 = "96", FF60 = "94", IE = "114") Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -1789,7 +1789,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "96", + @Alerts(DEFAULT = "51", FF52 = "56", FF60 = "54", IE = "102") @@ -1818,7 +1818,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "62", + @Alerts(DEFAULT = "58", FF52 = "102", FF60 = "100", IE = "116") Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java 2018-07-28 15:41:38 UTC (rev 15496) @@ -119,8 +119,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "20.12.2012", - FF60 = "12/20/2012", + @Alerts(DEFAULT = "12/20/2012", + FF52 = "20.12.2012", IE = "\u200E20\u200E.\u200E12\u200E.\u200E2012") public void format_ban() throws Exception { test("new Intl.DateTimeFormat('ban').format(date)"); @@ -1174,7 +1174,6 @@ */ @Test @Alerts(DEFAULT = "20/12/2012", - CHROME = "20.12.2012", IE = "\u200E20\u200E/\u200E12\u200E/\u200E2012") public void format_in() throws Exception { test("new Intl.DateTimeFormat('in').format(date)"); Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt 2018-07-28 15:41:38 UTC (rev 15496) @@ -293,8 +293,24 @@ vectorEffect verticalAlign visibility +webkitAlignContent +webkitAlignItems +webkitAlignSelf +webkitAnimation +webkitAnimationDelay +webkitAnimationDirection +webkitAnimationDuration +webkitAnimationFillMode +webkitAnimationIterationCount +webkitAnimationName +webkitAnimationPlayState +webkitAnimationTimingFunction webkitAppRegion webkitAppearance +webkitBackfaceVisibility +webkitBackgroundClip +webkitBackgroundOrigin +webkitBackgroundSize webkitBorderAfter webkitBorderAfterColor webkitBorderAfterStyle @@ -303,6 +319,8 @@ webkitBorderBeforeColor webkitBorderBeforeStyle webkitBorderBeforeWidth +webkitBorderBottomLeftRadius +webkitBorderBottomRightRadius webkitBorderEnd webkitBorderEndColor webkitBorderEndStyle @@ -309,10 +327,13 @@ webkitBorderEndWidth webkitBorderHorizontalSpacing webkitBorderImage +webkitBorderRadius webkitBorderStart webkitBorderStartColor webkitBorderStartStyle webkitBorderStartWidth +webkitBorderTopLeftRadius +webkitBorderTopRightRadius webkitBorderVerticalSpacing webkitBoxAlign webkitBoxDecorationBreak @@ -322,13 +343,35 @@ webkitBoxOrient webkitBoxPack webkitBoxReflect +webkitBoxShadow +webkitBoxSizing +webkitClipPath webkitColumnBreakAfter webkitColumnBreakBefore webkitColumnBreakInside +webkitColumnCount +webkitColumnGap +webkitColumnRule +webkitColumnRuleColor +webkitColumnRuleStyle +webkitColumnRuleWidth +webkitColumnSpan +webkitColumnWidth +webkitColumns +webkitFilter +webkitFlex +webkitFlexBasis +webkitFlexDirection +webkitFlexFlow +webkitFlexGrow +webkitFlexShrink +webkitFlexWrap +webkitFontFeatureSettings webkitFontSizeDelta webkitFontSmoothing webkitHighlight webkitHyphenateCharacter +webkitJustifyContent webkitLineBreak webkitLineClamp webkitLocale @@ -365,15 +408,22 @@ webkitMaxLogicalWidth webkitMinLogicalHeight webkitMinLogicalWidth +webkitOpacity +webkitOrder webkitPaddingAfter webkitPaddingBefore webkitPaddingEnd webkitPaddingStart +webkitPerspective +webkitPerspectiveOrigin webkitPerspectiveOriginX webkitPerspectiveOriginY webkitPrintColorAdjust webkitRtlOrdering webkitRubyPosition +webkitShapeImageThreshold +webkitShapeMargin +webkitShapeOutside webkitTapHighlightColor webkitTextCombine webkitTextDecorationsInEffect @@ -384,14 +434,24 @@ webkitTextFillColor webkitTextOrientation webkitTextSecurity +webkitTextSizeAdjust webkitTextStroke webkitTextStrokeColor webkitTextStrokeWidth +webkitTransform +webkitTransformOrigin webkitTransformOriginX webkitTransformOriginY webkitTransformOriginZ +webkitTransformStyle +webkitTransition +webkitTransitionDelay +webkitTransitionDuration +webkitTransitionProperty +webkitTransitionTimingFunction webkitUserDrag webkitUserModify +webkitUserSelect webkitWritingMode whiteSpace widows Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt 2018-07-28 15:41:38 UTC (rev 15496) @@ -292,8 +292,24 @@ vectorEffect verticalAlign visibility +webkitAlignContent +webkitAlignItems +webkitAlignSelf +webkitAnimation +webkitAnimationDelay +webkitAnimationDirection +webkitAnimationDuration +webkitAnimationFillMode +webkitAnimationIterationCount +webkitAnimationName +webkitAnimationPlayState +webkitAnimationTimingFunction webkitAppRegion webkitAppearance +webkitBackfaceVisibility +webkitBackgroundClip +webkitBackgroundOrigin +webkitBackgroundSize webkitBorderAfter webkitBorderAfterColor webkitBorderAfterStyle @@ -302,6 +318,8 @@ webkitBorderBeforeColor webkitBorderBeforeStyle webkitBorderBeforeWidth +webkitBorderBottomLeftRadius +webkitBorderBottomRightRadius webkitBorderEnd webkitBorderEndColor webkitBorderEndStyle @@ -308,10 +326,13 @@ webkitBorderEndWidth webkitBorderHorizontalSpacing webkitBorderImage +webkitBorderRadius webkitBorderStart webkitBorderStartColor webkitBorderStartStyle webkitBorderStartWidth +webkitBorderTopLeftRadius +webkitBorderTopRightRadius webkitBorderVerticalSpacing webkitBoxAlign webkitBoxDecorationBreak @@ -321,13 +342,35 @@ webkitBoxOrient webkitBoxPack webkitBoxReflect +webkitBoxShadow +webkitBoxSizing +webkitClipPath webkitColumnBreakAfter webkitColumnBreakBefore webkitColumnBreakInside +webkitColumnCount +webkitColumnGap +webkitColumnRule +webkitColumnRuleColor +webkitColumnRuleStyle +webkitColumnRuleWidth +webkitColumnSpan +webkitColumnWidth +webkitColumns +webkitFilter +webkitFlex +webkitFlexBasis +webkitFlexDirection +webkitFlexFlow +webkitFlexGrow +webkitFlexShrink +webkitFlexWrap +webkitFontFeatureSettings webkitFontSizeDelta webkitFontSmoothing webkitHighlight webkitHyphenateCharacter +webkitJustifyContent webkitLineBreak webkitLineClamp webkitLocale @@ -364,15 +407,22 @@ webkitMaxLogicalWidth webkitMinLogicalHeight webkitMinLogicalWidth +webkitOpacity +webkitOrder webkitPaddingAfter webkitPaddingBefore webkitPaddingEnd webkitPaddingStart +webkitPerspective +webkitPerspectiveOrigin webkitPerspectiveOriginX webkitPerspectiveOriginY webkitPrintColorAdjust webkitRtlOrdering webkitRubyPosition +webkitShapeImageThreshold +webkitShapeMargin +webkitShapeOutside webkitTapHighlightColor webkitTextCombine webkitTextDecorationsInEffect @@ -383,14 +433,24 @@ webkitTextFillColor webkitTextOrientation webkitTextSecurity +webkitTextSizeAdjust webkitTextStroke webkitTextStrokeColor webkitTextStrokeWidth +webkitTransform +webkitTransformOrigin webkitTransformOriginX webkitTransformOriginY webkitTransformOriginZ +webkitTransformStyle +webkitTransition +webkitTransitionDelay +webkitTransitionDuration +webkitTransitionProperty +webkitTransitionTimingFunction webkitUserDrag webkitUserModify +webkitUserSelect webkitWritingMode whiteSpace widows Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt 2018-07-28 15:41:38 UTC (rev 15496) @@ -292,8 +292,24 @@ vectorEffect=:none verticalAlign=:baseline visibility=:visible +webkitAlignContent=:normal +webkitAlignItems=:normal +webkitAlignSelf=:auto +webkitAnimation=:none 0s ease 0s 1 normal none running +webkitAnimationDelay=:0s +webkitAnimationDirection=:normal +webkitAnimationDuration=:0s +webkitAnimationFillMode=:none +webkitAnimationIterationCount=:1 +webkitAnimationName=:none +webkitAnimationPlayState=:running +webkitAnimationTimingFunction=:ease webkitAppRegion=:none webkitAppearance=:none +webkitBackfaceVisibility=:visible +webkitBackgroundClip=:border-box +webkitBackgroundOrigin=:padding-box +webkitBackgroundSize=:auto webkitBorderAfter=:0px none rgb(0, 0, 0) webkitBorderAfterColor=:rgb(0, 0, 0) webkitBorderAfterStyle=:none @@ -302,6 +318,8 @@ webkitBorderBeforeColor=:rgb(0, 0, 0) webkitBorderBeforeStyle=:none webkitBorderBeforeWidth=:0px +webkitBorderBottomLeftRadius=:0px +webkitBorderBottomRightRadius=:0px webkitBorderEnd=:0px none rgb(0, 0, 0) webkitBorderEndColor=:rgb(0, 0, 0) webkitBorderEndStyle=:none @@ -308,10 +326,13 @@ webkitBorderEndWidth=:0px webkitBorderHorizontalSpacing=:0px webkitBorderImage=:none +webkitBorderRadius=:0px webkitBorderStart=:0px none rgb(0, 0, 0) webkitBorderStartColor=:rgb(0, 0, 0) webkitBorderStartStyle=:none webkitBorderStartWidth=:0px +webkitBorderTopLeftRadius=:0px +webkitBorderTopRightRadius=:0px webkitBorderVerticalSpacing=:0px webkitBoxAlign=:stretch webkitBoxDecorationBreak=:slice @@ -321,13 +342,35 @@ webkitBoxOrient=:horizontal webkitBoxPack=:start webkitBoxReflect=:none +webkitBoxShadow=:none +webkitBoxSizing=:content-box +webkitClipPath=:none webkitColumnBreakAfter=:auto webkitColumnBreakBefore=:auto webkitColumnBreakInside=:auto +webkitColumnCount=:auto +webkitColumnGap=:normal +webkitColumnRule=:0px none rgb(0, 0, 0) +webkitColumnRuleColor=:rgb(0, 0, 0) +webkitColumnRuleStyle=:none +webkitColumnRuleWidth=:0px +webkitColumnSpan=:none +webkitColumnWidth=:auto +webkitColumns=:auto auto +webkitFilter=:none +webkitFlex=:0 1 auto +webkitFlexBasis=:auto +webkitFlexDirection=:row +webkitFlexFlow=:row nowrap +webkitFlexGrow=:0 +webkitFlexShrink=:1 +webkitFlexWrap=:nowrap +webkitFontFeatureSettings=:normal webkitFontSizeDelta=: webkitFontSmoothing=:auto webkitHighlight=:none webkitHyphenateCharacter=:auto +webkitJustifyContent=:normal webkitLineBreak=:auto webkitLineClamp=:none webkitLocale=:auto @@ -364,15 +407,22 @@ webkitMaxLogicalWidth=:none webkitMinLogicalHeight=:0px webkitMinLogicalWidth=:0px +webkitOpacity=:1 +webkitOrder=:0 webkitPaddingAfter=:0px webkitPaddingBefore=:0px webkitPaddingEnd=:0px webkitPaddingStart=:0px +webkitPerspective=:none +webkitPerspectiveOrigin=:456.5px 161px webkitPerspectiveOriginX=: webkitPerspectiveOriginY=: webkitPrintColorAdjust=:economy webkitRtlOrdering=:logical webkitRubyPosition=:before +webkitShapeImageThreshold=:0 +webkitShapeMargin=:0px +webkitShapeOutside=:none webkitTapHighlightColor=:rgba(0, 0, 0, 0.18) webkitTextCombine=:none webkitTextDecorationsInEffect=:none @@ -383,14 +433,24 @@ webkitTextFillColor=:rgb(0, 0, 0) webkitTextOrientation=:vertical-right webkitTextSecurity=:none +webkitTextSizeAdjust=:auto webkitTextStroke=: webkitTextStrokeColor=:rgb(0, 0, 0) webkitTextStrokeWidth=:0px +webkitTransform=:none +webkitTransformOrigin=:620px 161px webkitTransformOriginX=: webkitTransformOriginY=: webkitTransformOriginZ=: +webkitTransformStyle=:flat +webkitTransition=:all 0s ease 0s +webkitTransitionDelay=:0s +webkitTransitionDuration=:0s +webkitTransitionProperty=:all +webkitTransitionTimingFunction=:ease webkitUserDrag=:auto webkitUserModify=:read-only +webkitUserSelect=:auto webkitWritingMode=:horizontal-tb whiteSpace=:normal widows=:2 Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt 2018-07-25 17:38:50 UTC (rev 15495) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt 2018-07-28 15:41:38 UTC (rev 15496) @@ -292,8 +292,24 @@ vectorEffect=: verticalAlign=: visibility=: +webkitAlignContent=: +webkitAlignItems=: +webkitAlignSelf=: +webkitAnimation=: +webkitAnimationDelay=: +webkitAnimationDirection=: +webkitAnimationDuration=: +webkitAnimationFillMode=: +webkitAnimationIterationCount=: +webkitAnimationName=: +webkitAnimationPlayState=: +webkitAnimationTimingFunction=: webkitAppRegion=: webkitAppearance=: +webkitBackfaceVisibility=: +webkitBackgroundClip=: +webkitBackgroundOrigin=: +webkitBackgroundSize=: webkitBorderAfter=: webkitBorderAfterColor=: webkitBorderAfterStyle=: @@ -302,6 +318,8 @@ webkitBorderBeforeColor=: webkitBorderBeforeStyle=: webkitBorderBeforeWidth=: +webkitBorderBottomLeftRadius=: +webkitBorderBottomRightRadius=: webkitBorderEnd=: webkitBorderEndColor=: webkitBorderEndStyle=: @@ -308,10 +326,13 @@ webkitBorderEndWidth=: webkitBorderHorizontalSpacing=: webkitBorderImage=: +webkitBorderRadius=: webkitBorderStart=: webkitBorderStartColor=: webkitBorderStartStyle=: webkitBorderStartWidth=: +webkitBorderTopLeftRadius=: +webkitBorderTopRightRadius=: webkitBorderVerticalSpacing=: webkitBoxAlign=: webkitBoxDecorationBreak=: @@ -321,13 +342,35 @@ webkitBoxOrient=: webkitBoxPack=: webkitBoxReflect=: +webkitBoxShadow=: +webkitBoxSizing=: +webkitClipPath=: webkitColumnBreakAfter=: webkitColumnBreakBefore=: webkitColumnBreakInside=: +webkitColumnCount=: +webkitColumnGap=: +webkitColumnRule=: +webkitColumnRuleColor=: +webkitColumnRuleStyle=: +webkitColumnRuleWidth=: +webkitColumnSpan=: +webkitColumnWidth=: +webkitColumns=: +webkitFilter=: +webkitFlex=: +webkitFlexBasis=: +webkitFlexDirection=: +webkitFlexFlow=: +webkitFlexGrow=: +webkitFlexShrink=: +webkitFlexWrap=: +webk... [truncated message content] |
From: <rb...@us...> - 2018-08-02 18:30:15
|
Revision: 15508 http://sourceforge.net/p/htmlunit/code/15508 Author: rbri Date: 2018-08-02 18:30:12 +0000 (Thu, 02 Aug 2018) Log Message: ----------- Add missing default delegating methods getContentLength(), cleanUp(), and defaultCharsetUtf8() to WebResponseWrapper Issue 1978 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-08-02 17:53:13 UTC (rev 15507) +++ trunk/htmlunit/src/changes/changes.xml 2018-08-02 18:30:12 UTC (rev 15508) @@ -8,6 +8,10 @@ <body> <release version="2.33" date="xxxx, 2018" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1978" due-to="Atsushi Nakagawa"> + Add missing default delegating methods getContentLength(), cleanUp(), and defaultCharsetUtf8() + to WebResponseWrapper. + </action> <action type="update" dev="rbri"> Major cleanup for neko and switch to xerces 2.12.0 </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java 2018-08-02 17:53:13 UTC (rev 15507) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java 2018-08-02 18:30:12 UTC (rev 15508) @@ -31,6 +31,7 @@ * @author Marc Guillemot * @author Ahmed Ashour * @author Ronald Brill + * @author Atsushi Nakagawa */ public class WebResponseWrapper extends WebResponse { @@ -51,6 +52,15 @@ /** * {@inheritDoc} + * The default behavior of this method is to return getContentLength() on the wrapped webResponse object. + */ + @Override + public long getContentLength() { + return wrappedWebResponse_.getContentLength(); + } + + /** + * {@inheritDoc} * The default behavior of this method is to return getContentAsStream() on the wrapped webResponse object. */ @Override @@ -166,4 +176,22 @@ public WebRequest getWebRequest() { return wrappedWebResponse_.getWebRequest(); } + + /** + * {@inheritDoc} + * The default behavior of this method is to call cleanUp() on the wrapped webResponse object. + */ + @Override + public void cleanUp() { + wrappedWebResponse_.cleanUp(); + } + + /** + * {@inheritDoc} + * The default behavior of this method is to call defaultCharsetUtf8() on the wrapped webResponse object. + */ + @Override + public void defaultCharsetUtf8() { + wrappedWebResponse_.defaultCharsetUtf8(); + } } |
From: <rb...@us...> - 2018-08-09 19:39:08
|
Revision: 15512 http://sourceforge.net/p/htmlunit/code/15512 Author: rbri Date: 2018-08-09 19:39:03 +0000 (Thu, 09 Aug 2018) Log Message: ----------- fix DomNodeIterator traverses uncles of (sub)root Issue 1982 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNodeIterator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeIteratorTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeIteratorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNodeIterator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNodeIterator.java 2018-08-05 17:08:38 UTC (rev 15511) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNodeIterator.java 2018-08-09 19:39:03 UTC (rev 15512) @@ -191,12 +191,12 @@ * traversal) from the given node. */ private DomNode getFirstUncleNode(final DomNode node) { - if (node == root_ || node == null) { + if (node == null || node == root_) { return null; } final DomNode parent = node.getParentNode(); - if (parent == null) { + if (parent == null || parent == root_) { return null; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeIteratorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeIteratorTest.java 2018-08-05 17:08:38 UTC (rev 15511) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomNodeIteratorTest.java 2018-08-09 19:39:03 UTC (rev 15512) @@ -17,10 +17,12 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.WebDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.w3c.dom.traversal.NodeFilter; import org.w3c.dom.traversal.NodeIterator; import com.gargoylesoftware.htmlunit.BrowserRunner; @@ -31,6 +33,7 @@ * Tests for {@link DomNodeIterator}. * * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public final class DomNodeIteratorTest extends WebDriverTestCase { @@ -55,10 +58,51 @@ if (driver instanceof HtmlUnitDriver) { final WebWindow webWindow = getWebWindowOf((HtmlUnitDriver) driver); final HtmlPage page = (HtmlPage) webWindow.getEnclosedPage(); - final NodeIterator iterator = page.createNodeIterator(page.getDocumentElement(), - org.w3c.dom.traversal.NodeFilter.SHOW_ALL, null, + final NodeIterator iterator = page.createNodeIterator(page.getDocumentElement(), NodeFilter.SHOW_ALL, null, true); assertThat(iterator.nextNode(), instanceOf(HtmlHtml.class)); } } + + /** + * Test case for issue 1982. + * @throws Exception if the test fails + */ + @Test + public void subroot() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "</head>\n" + + "<body>\n" + + "<table>\n" + + " <tr id='1'>\n" + + " <td id='11'>11</td>\n" + + " <td id='12'>12</td>\n" + + " </tr>\n" + + " <tr id='2'>\n" + + " <td id='21'>21</td>\n" + + " <td id='22'>22</td>\n" + + " </tr>\n" + + "</table>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + final WebWindow webWindow = getWebWindowOf((HtmlUnitDriver) driver); + final HtmlPage page = (HtmlPage) webWindow.getEnclosedPage(); + + final HtmlElement subroot = (HtmlElement) page.getElementById("1"); + final NodeIterator iterator = page.createNodeIterator(subroot, NodeFilter.SHOW_ELEMENT, null, true); + + HtmlElement element = (HtmlElement) iterator.nextNode(); + Assert.assertEquals("1", element.getId()); + + element = (HtmlElement) iterator.nextNode(); + Assert.assertEquals("11", element.getId()); + + element = (HtmlElement) iterator.nextNode(); + Assert.assertEquals("12", element.getId()); + + Assert.assertNull(iterator.nextNode()); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeIteratorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeIteratorTest.java 2018-08-05 17:08:38 UTC (rev 15511) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeIteratorTest.java 2018-08-09 19:39:03 UTC (rev 15512) @@ -135,4 +135,47 @@ loadPageWithAlerts2(html); } + + /** + * Test case for issue 1982. + * @throws Exception if the test fails + */ + @Test + @Alerts({"1", "11", "12"}) + public void subroot() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " if (document.createNodeIterator) {\n" + + " var nodeIterator = document.createNodeIterator(\n" + + " document.getElementById('1'),\n" + + " NodeFilter.SHOW_ELEMENT );\n" + + + " var currentNode;\n" + + " while (currentNode = nodeIterator.nextNode()) {\n" + + " alert(currentNode.id);\n" + + " }\n" + + " }\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "<div id='before'>before</div>\n" + + "<table>\n" + + " <tr id='1'>\n" + + " <td id='11'>11</td>\n" + + " <td id='12'>12</td>\n" + + " </tr>\n" + + " <tr id='2'>\n" + + " <td id='21'>21</td>\n" + + " <td id='22'>22</td>\n" + + " </tr>\n" + + "</table>\n" + + "<div id='after'>after</div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-08-10 18:13:28
|
Revision: 15515 http://sourceforge.net/p/htmlunit/code/15515 Author: rbri Date: 2018-08-10 18:13:24 +0000 (Fri, 10 Aug 2018) Log Message: ----------- fix the order of the windows returned by WebClient.getTopLevelWindows() Issue 1979 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-08-10 16:51:51 UTC (rev 15514) +++ trunk/htmlunit/src/changes/changes.xml 2018-08-10 18:13:24 UTC (rev 15515) @@ -8,6 +8,10 @@ <body> <release version="2.33" date="xxxx, 2018" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1979" due-to="Atsushi Nakagawa"> + Fix the order of the windows returned by WebClient.getTopLevelWindows() + to be again the same as WebClient.getWebWindows(). + </action> <action type="fix" dev="rbri" issue="1980" due-to="Atsushi Nakagawa"> Improved support for javascript named function expressions. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-08-10 16:51:51 UTC (rev 15514) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-08-10 18:13:24 UTC (rev 15515) @@ -37,12 +37,10 @@ import java.net.URLDecoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Date; -import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -171,7 +169,8 @@ private PageCreator pageCreator_ = new DefaultPageCreator(); private final Set<WebWindowListener> webWindowListeners_ = new HashSet<>(5); - private final Deque<TopLevelWindow> topLevelWindows_ = new ArrayDeque<>(); // top-level windows + private final List<TopLevelWindow> topLevelWindows_ = + Collections.synchronizedList(new ArrayList<TopLevelWindow>()); // top-level windows private final List<WebWindow> windows_ = Collections.synchronizedList(new ArrayList<WebWindow>()); // all windows private transient List<WeakReference<JavaScriptJobManager>> jobManagers_ = Collections.synchronizedList(new ArrayList<WeakReference<JavaScriptJobManager>>()); @@ -1502,6 +1501,8 @@ /** * Returns an immutable list of open web windows (whether they are top level windows or not). * This is a snapshot; future changes are not reflected by this list. + * <p> + * The list is ordered by age, the oldest one first. * * @return an immutable list of open web windows (whether they are top level windows or not) * @see #getWebWindowByName(String) @@ -1528,6 +1529,8 @@ /** * Returns an immutable list of open top level windows. * This is a snapshot; future changes are not reflected by this list. + * <p> + * The list is ordered by age, the oldest one first. * * @return an immutable list of open top level windows * @see #getWebWindowByName(String) @@ -1816,18 +1819,25 @@ if (webClient_.topLevelWindows_.isEmpty()) { // Must always have at least window, and there are no top-level windows left; must create one. final TopLevelWindow newWindow = new TopLevelWindow("", webClient_); - webClient_.topLevelWindows_.push(newWindow); + webClient_.topLevelWindows_.add(newWindow); webClient_.setCurrentWindow(newWindow); } else { // The current window is now the previous top-level window. - webClient_.setCurrentWindow(webClient_.topLevelWindows_.peek()); + webClient_.setCurrentWindow( + webClient_.topLevelWindows_.get(webClient_.topLevelWindows_.size() - 1)); } } } else if (window == webClient_.getCurrentWindow()) { // The current window is now the last top-level window. - webClient_.setCurrentWindow(webClient_.topLevelWindows_.peek()); + if (webClient_.topLevelWindows_.isEmpty()) { + webClient_.setCurrentWindow(null); + } + else { + webClient_.setCurrentWindow( + webClient_.topLevelWindows_.get(webClient_.topLevelWindows_.size() - 1)); + } } } @@ -1876,7 +1886,7 @@ final WebWindow window = event.getWebWindow(); if (window instanceof TopLevelWindow) { final TopLevelWindow tlw = (TopLevelWindow) window; - webClient_.topLevelWindows_.push(tlw); + webClient_.topLevelWindows_.add(tlw); } // Page is not loaded yet, don't set it now as current window. } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2018-08-10 16:51:51 UTC (rev 15514) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2018-08-10 18:13:24 UTC (rev 15515) @@ -2173,28 +2173,59 @@ conn.setResponse(URL_SECOND, "<html><body></body></html>"); client.setWebConnection(conn); + final WebWindow firstWindow = client.getWebWindows().get(0); + assertEquals(1, client.getWebWindows().size()); assertEquals(1, client.getTopLevelWindows().size()); + assertEquals(client.getCurrentWindow(), client.getWebWindows().get(0)); + assertEquals(client.getCurrentWindow(), client.getTopLevelWindows().get(0)); + assertEquals(firstWindow, client.getWebWindows().get(0)); + assertEquals(firstWindow, client.getTopLevelWindows().get(0)); client.getPage(URL_FIRST); assertEquals(2, client.getWebWindows().size()); assertEquals(1, client.getTopLevelWindows().size()); + assertEquals(client.getCurrentWindow(), client.getWebWindows().get(0)); + assertEquals(client.getCurrentWindow(), client.getTopLevelWindows().get(0)); + assertEquals(firstWindow, client.getWebWindows().get(0)); + assertEquals(firstWindow, client.getTopLevelWindows().get(0)); client.getPage(URL_SECOND); assertEquals(1, client.getWebWindows().size()); assertEquals(1, client.getTopLevelWindows().size()); + assertEquals(client.getCurrentWindow(), client.getWebWindows().get(0)); + assertEquals(client.getCurrentWindow(), client.getTopLevelWindows().get(0)); + assertEquals(firstWindow, client.getWebWindows().get(0)); + assertEquals(firstWindow, client.getTopLevelWindows().get(0)); client.openWindow(URL_SECOND, "a"); assertEquals(2, client.getWebWindows().size()); assertEquals(2, client.getTopLevelWindows().size()); + assertEquals(client.getCurrentWindow(), client.getWebWindows().get(1)); + assertEquals(client.getCurrentWindow(), client.getTopLevelWindows().get(1)); + assertEquals(client.getWebWindows().get(1), client.getTopLevelWindows().get(1)); + assertEquals(firstWindow, client.getWebWindows().get(0)); + assertEquals(firstWindow, client.getTopLevelWindows().get(0)); + assertNotEquals(firstWindow, client.getWebWindows().get(1)); + assertNotEquals(firstWindow, client.getTopLevelWindows().get(1)); client.openWindow(URL_SECOND, "b"); assertEquals(3, client.getWebWindows().size()); assertEquals(3, client.getTopLevelWindows().size()); + assertEquals(client.getCurrentWindow(), client.getWebWindows().get(2)); + assertEquals(client.getCurrentWindow(), client.getTopLevelWindows().get(2)); + assertEquals(firstWindow, client.getWebWindows().get(0)); + assertEquals(firstWindow, client.getTopLevelWindows().get(0)); + assertEquals(client.getWebWindows().get(1), client.getTopLevelWindows().get(1)); + assertNotEquals(firstWindow, client.getWebWindows().get(1)); + assertNotEquals(firstWindow, client.getTopLevelWindows().get(1)); + assertEquals(client.getWebWindows().get(2), client.getTopLevelWindows().get(2)); + assertNotEquals(firstWindow, client.getWebWindows().get(2)); + assertNotEquals(firstWindow, client.getTopLevelWindows().get(2)); client.close(); |
From: <rb...@us...> - 2018-08-12 12:32:29
|
Revision: 15516 http://sourceforge.net/p/htmlunit/code/15516 Author: rbri Date: 2018-08-12 12:32:23 +0000 (Sun, 12 Aug 2018) Log Message: ----------- method Date.toUTCString() is available in Rhino; remove our own impl Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-08-10 18:13:24 UTC (rev 15515) +++ trunk/htmlunit/src/changes/changes.xml 2018-08-12 12:32:23 UTC (rev 15516) @@ -8,12 +8,15 @@ <body> <release version="2.33" date="xxxx, 2018" description="Bugfixes"> + <action type="update" dev="rbri"> + Method Date.toUTCString() is available in Rhino; remove our own impl. + </action> <action type="fix" dev="rbri" issue="1979" due-to="Atsushi Nakagawa"> Fix the order of the windows returned by WebClient.getTopLevelWindows() to be again the same as WebClient.getWebWindows(). </action> <action type="fix" dev="rbri" issue="1980" due-to="Atsushi Nakagawa"> - Improved support for javascript named function expressions. + Improved support for javascript named function expressions (core-js). </action> <action type="fix" dev="rbri" issue="1982" due-to="Steve Harney"> DomNodeIterator no longer traverses uncles of root node. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java 2018-08-10 18:13:24 UTC (rev 15515) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java 2018-08-12 12:32:23 UTC (rev 15516) @@ -19,9 +19,7 @@ import java.util.Date; import java.util.Locale; -import java.util.TimeZone; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.FastDateFormat; import com.gargoylesoftware.htmlunit.BrowserVersion; @@ -39,8 +37,6 @@ */ public final class DateCustom { - private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC"); - private DateCustom() { } /** @@ -94,20 +90,6 @@ return format.format(getDateValue(thisObj)); } - /** - * Converts a date to a UTC string. Special version for IE - * @param context the JavaScript context - * @param thisObj the scriptable - * @param args the arguments passed into the method - * @param function the function - * @return converted string - */ - public static String toUTCString( - final Context context, final Scriptable thisObj, final Object[] args, final Function function) { - final Date date = new Date(getDateValue(thisObj)); - return DateFormatUtils.format(date, "EEE, d MMM yyyy HH:mm:ss z", UTC_TIME_ZONE, Locale.ENGLISH); - } - private static long getDateValue(final Scriptable thisObj) { final Date date = (Date) Context.jsToJava(thisObj, Date.class); return date.getTime(); |
From: <rb...@us...> - 2018-08-14 19:17:51
|
Revision: 15517 http://sourceforge.net/p/htmlunit/code/15517 Author: rbri Date: 2018-08-14 19:17:44 +0000 (Tue, 14 Aug 2018) Log Message: ----------- give this fix a try (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-12 12:32:23 UTC (rev 15516) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-14 19:17:44 UTC (rev 15517) @@ -85,9 +85,9 @@ import com.gargoylesoftware.htmlunit.javascript.PostponedAction; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.host.Window; -import com.gargoylesoftware.htmlunit.javascript.host.dom.Node; import com.gargoylesoftware.htmlunit.javascript.host.event.BeforeUnloadEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; +import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection; import com.gargoylesoftware.htmlunit.util.EncodingSniffer; @@ -94,6 +94,7 @@ import com.gargoylesoftware.htmlunit.util.UrlUtils; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.ContextFactory; import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.Script; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; @@ -1206,18 +1207,23 @@ // Execute the specified event on the document element. final WebWindow window = getEnclosingWindow(); if (window.getScriptableObject() instanceof Window) { - final DomElement element = getDocumentElement(); - if (element == null) { // happens for instance if document.documentElement has been removed from parent - return true; - } final Event event; if (eventType.equals(Event.TYPE_BEFORE_UNLOAD)) { - event = new BeforeUnloadEvent(element, eventType); + event = new BeforeUnloadEvent(this, eventType); } else { - event = new Event(element, eventType); + event = new Event(this, eventType); } - final ScriptResult result = element.fireEvent(event); + + // This is the same as DomElement.fireEvent() and was copied + // here so it could be used with HtmlPage. + if (LOG.isDebugEnabled()) { + LOG.debug("Firing " + event); + } + final EventTarget jsNode = this.getScriptableObject(); + final ContextFactory cf = ((JavaScriptEngine) getWebClient().getJavaScriptEngine()).getContextFactory(); + final ScriptResult result = cf.call(cx -> jsNode.fireEvent(event)); + if (!isOnbeforeunloadAccepted(this, event, result)) { return false; } @@ -1245,7 +1251,12 @@ else { event = new Event(frame, eventType); } - final ScriptResult result = ((Node) frame.getScriptableObject()).executeEventLocally(event); + // This fires the "load" event for the <frame> element which, like all non-window + // load events, propagates up to Document but not Window. The "load" event for + // <frameset> on the other hand, like that of <body>, is handled above where it is + // fired against Document and directed to Window. + final ScriptResult result = frame.fireEvent(event); + if (!isOnbeforeunloadAccepted((HtmlPage) frame.getPage(), event, result)) { return false; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-08-12 12:32:23 UTC (rev 15516) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-08-14 19:17:44 UTC (rev 15517) @@ -19,10 +19,10 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -29,7 +29,6 @@ import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.html.DomNode; -import com.gargoylesoftware.htmlunit.html.HtmlBody; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; @@ -54,35 +53,81 @@ private static final Log LOG = LogFactory.getLog(EventListenersContainer.class); - static class TypeContainer implements Serializable { - private List<Scriptable> capturingListeners_; - private List<Scriptable> bubblingListeners_; - private Function handler_; + private static class TypeContainer implements Serializable { + public static final TypeContainer EMPTY = new TypeContainer(); + // This sentinel value could be some singleton instance but null + // isn't used for anything else so why not. + private static final Scriptable EVENT_HANDLER_PLACEHOLDER = null; + + private final List<Scriptable> capturingListeners_; + private final List<Scriptable> bubblingListeners_; + private final List<Scriptable> atTargetListeners_; + private final Function handler_; + TypeContainer() { - capturingListeners_ = Collections.unmodifiableList(new ArrayList<Scriptable>()); - bubblingListeners_ = Collections.unmodifiableList(new ArrayList<Scriptable>()); + capturingListeners_ = Collections.emptyList(); + bubblingListeners_ = Collections.emptyList(); + atTargetListeners_ = Collections.emptyList(); + handler_ = null; } private TypeContainer(final List<Scriptable> capturingListeners, - final List<Scriptable> bubblingListeners, final Function handler) { - capturingListeners_ = Collections.unmodifiableList(new ArrayList<>(capturingListeners)); - bubblingListeners_ = Collections.unmodifiableList(new ArrayList<>(bubblingListeners)); + final List<Scriptable> bubblingListeners, final List<Scriptable> atTargetListeners, + final Function handler) { + capturingListeners_ = capturingListeners; + bubblingListeners_ = bubblingListeners; + atTargetListeners_ = atTargetListeners; handler_ = handler; } - private List<Scriptable> getListeners(final boolean useCapture) { - if (useCapture) { - return capturingListeners_; + private List<Scriptable> getListeners(final int eventPhase) { + switch (eventPhase) { + case Event.CAPTURING_PHASE: + return capturingListeners_; + case Event.AT_TARGET: + return atTargetListeners_; + case Event.BUBBLING_PHASE: + return bubblingListeners_; + default: + throw new UnsupportedOperationException("eventPhase: " + eventPhase); } - return bubblingListeners_; } - private synchronized boolean addListener(final Scriptable listener, final boolean useCapture) { - final List<Scriptable> listeners = getListeners(useCapture); + public TypeContainer setPropertyHandler(final Function propertyHandler) { + if (propertyHandler != null) { + // If we already have a handler then the position of the existing + // placeholder should not be changed so just change the handler + if (handler_ != null) { + if (propertyHandler == handler_) { + return this; + } + return withPropertyHandler(propertyHandler); + } + // Insert the placeholder and set the handler + return withPropertyHandler(propertyHandler).addListener(EVENT_HANDLER_PLACEHOLDER, false); + } + else { + if (handler_ == null) { + return this; + } + return removeListener(EVENT_HANDLER_PLACEHOLDER, false).withPropertyHandler(null); + } + } + + private TypeContainer withPropertyHandler(final Function propertyHandler) { + return new TypeContainer(capturingListeners_, bubblingListeners_, atTargetListeners_, propertyHandler); + } + + public TypeContainer addListener(final Scriptable listener, final boolean useCapture) { + + List<Scriptable> capturingListeners = capturingListeners_; + List<Scriptable> bubblingListeners = bubblingListeners_; + final List<Scriptable> listeners = useCapture ? capturingListeners : bubblingListeners; + if (listeners.contains(listener)) { - return false; + return this; } List<Scriptable> newListeners = new ArrayList<>(listeners.size() + 1); @@ -91,21 +136,29 @@ newListeners = Collections.unmodifiableList(newListeners); if (useCapture) { - capturingListeners_ = newListeners; + capturingListeners = newListeners; } else { - bubblingListeners_ = newListeners; + bubblingListeners = newListeners; } - return true; + List<Scriptable> atTargetListeners = new ArrayList<>(atTargetListeners_.size() + 1); + atTargetListeners.addAll(atTargetListeners_); + atTargetListeners.add(listener); + atTargetListeners = Collections.unmodifiableList(atTargetListeners); + + return new TypeContainer(capturingListeners, bubblingListeners, atTargetListeners, handler_); } - private synchronized void removeListener(final Scriptable listener, final boolean useCapture) { - final List<Scriptable> listeners = getListeners(useCapture); + public TypeContainer removeListener(final Scriptable listener, final boolean useCapture) { + List<Scriptable> capturingListeners = capturingListeners_; + List<Scriptable> bubblingListeners = bubblingListeners_; + final List<Scriptable> listeners = useCapture ? capturingListeners : bubblingListeners; + final int idx = listeners.indexOf(listener); if (idx < 0) { - return; + return this; } List<Scriptable> newListeners = new ArrayList<>(listeners); @@ -113,20 +166,32 @@ newListeners = Collections.unmodifiableList(newListeners); if (useCapture) { - capturingListeners_ = newListeners; + capturingListeners = newListeners; } else { - bubblingListeners_ = newListeners; + bubblingListeners = newListeners; } + + List<Scriptable> atTargetListeners = new ArrayList<>(atTargetListeners_); + atTargetListeners.remove(listener); + atTargetListeners = Collections.unmodifiableList(atTargetListeners); + + return new TypeContainer(capturingListeners, bubblingListeners, atTargetListeners, handler_); } + // Refactoring note: This method doesn't appear to be used @Override protected TypeContainer clone() { - return new TypeContainer(capturingListeners_, bubblingListeners_, handler_); + return new TypeContainer(capturingListeners_, bubblingListeners_, atTargetListeners_, handler_); } } - private final Map<String, TypeContainer> typeContainers_ = new HashMap<>(); + // Refactoring note: This seems ad-hoc.. Shouldn't synchronization be orchestrated between + // JS thread and main thread at a much higher layer? Anyways, to preserve behaviour of prior + // coding where 'synchronized' was used more explicitly, we're using a ConcurrentHashMap here + // and using ConcurrentMap.compute() to mutate below so that mutations are atomic. This for + // example avoids the case where two concurrent addListener()s can result in either being lost. + private final ConcurrentMap<String, TypeContainer> typeContainers_ = new ConcurrentHashMap<>(); private final EventTarget jsNode_; /** @@ -151,9 +216,17 @@ return true; } - final TypeContainer container = getTypeContainer(type); - final boolean added = container.addListener(listener, useCapture); - if (!added) { + final boolean[] added = {false}; + typeContainers_.compute(type.toLowerCase(Locale.ROOT), (k, container) -> { + if (container == null) { + container = TypeContainer.EMPTY; + } + final TypeContainer newContainer = container.addListener(listener, useCapture); + added[0] = newContainer != container; + return newContainer; + }); + + if (!added[0]) { if (LOG.isDebugEnabled()) { LOG.debug(type + " listener already registered, skipping it (" + listener + ")"); } @@ -164,7 +237,7 @@ private TypeContainer getTypeContainer(final String type) { final String typeLC = type.toLowerCase(Locale.ROOT); - return typeContainers_.computeIfAbsent(typeLC, k -> new TypeContainer()); + return typeContainers_.getOrDefault(typeLC, TypeContainer.EMPTY); } /** @@ -172,14 +245,10 @@ * * @param eventType the event type * @param useCapture whether to use capture of not - * @return the listeners list + * @return the listeners list (empty list when empty) */ public List<Scriptable> getListeners(final String eventType, final boolean useCapture) { - final TypeContainer container = typeContainers_.get(eventType.toLowerCase(Locale.ROOT)); - if (container != null) { - return container.getListeners(useCapture); - } - return null; + return getTypeContainer(eventType).getListeners(useCapture ? Event.CAPTURING_PHASE : Event.BUBBLING_PHASE); } /** @@ -194,10 +263,8 @@ return; } - final TypeContainer container = typeContainers_.get(eventType.toLowerCase(Locale.ROOT)); - if (container != null) { - container.removeListener(listener, useCapture); - } + typeContainers_.computeIfPresent(eventType.toLowerCase(Locale.ROOT), + (k, container) -> container.removeListener(listener, useCapture)); } /** @@ -216,11 +283,15 @@ handler = (Function) value; } - final TypeContainer container = getTypeContainer(eventType); - container.handler_ = handler; + typeContainers_.compute(eventType.toLowerCase(Locale.ROOT), (k, container) -> { + if (container == null) { + container = TypeContainer.EMPTY; + } + return container.setPropertyHandler(handler); + }); } - private ScriptResult executeEventListeners(final boolean useCapture, final Event event, final Object[] args) { + private ScriptResult executeEventListeners(final int eventPhase, final Event event, final Object[] args) { final DomNode node = jsNode_.getDomNodeOrNull(); // some event don't apply on all kind of nodes, for instance "blur" if (node != null && !node.handles(event)) { @@ -228,8 +299,9 @@ } ScriptResult allResult = null; - final List<Scriptable> listeners = getListeners(event.getType(), useCapture); - if (listeners != null && !listeners.isEmpty()) { + final TypeContainer container = getTypeContainer(event.getType()); + final List<Scriptable> listeners = container.getListeners(eventPhase); + if (!listeners.isEmpty()) { event.setCurrentTarget(jsNode_); final HtmlPage page; @@ -250,7 +322,12 @@ } // no need for a copy, listeners are copy on write - for (final Scriptable listener : listeners) { + for (Scriptable listener : listeners) { + boolean isPropertyHandler = false; + if (listener == TypeContainer.EVENT_HANDLER_PLACEHOLDER) { + listener = container.handler_; + isPropertyHandler = true; + } Function function = null; Scriptable thisObject = null; if (listener instanceof Function) { @@ -267,7 +344,8 @@ if (function != null) { final ScriptResult result = page.executeJavaScriptFunction(function, thisObject, args, node); - if (event.isPropagationStopped()) { + // Return value is only honoured for property handlers (Chrome/FF) + if (isPropertyHandler) { allResult = result; } if (jsNode_.getBrowserVersion().hasFeature(EVENT_FALSE_RESULT)) { @@ -290,53 +368,14 @@ return allResult; } - private ScriptResult executeEventHandler(final Event event, final Object[] propHandlerArgs) { - final DomNode node = jsNode_.getDomNodeOrNull(); - // some event don't apply on all kind of nodes, for instance "blur" - if (node != null && !node.handles(event)) { - return null; - } - final Function handler = getEventHandler(event.getType()); - if (handler != null) { - event.setCurrentTarget(jsNode_); - final HtmlPage page = (HtmlPage) (node != null - ? node.getPage() - : jsNode_.getWindow().getWebWindow().getEnclosedPage()); - if (LOG.isDebugEnabled()) { - LOG.debug("Executing " + event.getType() + " handler for " + node); - } - return page.executeJavaScriptFunction(handler, jsNode_, - propHandlerArgs, page); - } - return null; - } - /** * Executes bubbling listeners. * @param event the event * @param args arguments - * @param propHandlerArgs handler arguments * @return the result */ - public ScriptResult executeBubblingListeners(final Event event, final Object[] args, - final Object[] propHandlerArgs) { - ScriptResult result = null; - - // the handler declared as property if any (not on body, as handler declared on body goes to the window) - final DomNode domNode = jsNode_.getDomNodeOrNull(); - if (!(domNode instanceof HtmlBody)) { - result = executeEventHandler(event, propHandlerArgs); - if (event.isPropagationStopped()) { - return result; - } - } - - // the registered listeners (if any) - final ScriptResult newResult = executeEventListeners(false, event, args); - if (newResult != null) { - result = newResult; - } - return result; + public ScriptResult executeBubblingListeners(final Event event, final Object[] args) { + return executeEventListeners(Event.BUBBLING_PHASE, event, args); } /** @@ -346,20 +385,26 @@ * @return the result */ public ScriptResult executeCapturingListeners(final Event event, final Object[] args) { - return executeEventListeners(true, event, args); + return executeEventListeners(Event.CAPTURING_PHASE, event, args); } /** + * Executes listeners for events targeting the node. (non-propagation phase) + * @param event the event + * @param args the arguments + * @return the result + */ + public ScriptResult executeAtTargetListeners(final Event event, final Object[] args) { + return executeEventListeners(Event.AT_TARGET, event, args); + } + + /** * Returns an event handler. * @param eventType the event name (e.g. "click") * @return the handler function, {@code null} if the property is null or not a function */ public Function getEventHandler(final String eventType) { - final TypeContainer container = typeContainers_.get(eventType.toLowerCase(Locale.ROOT)); - if (container == null) { - return null; - } - return (Function) container.handler_; + return getTypeContainer(eventType).handler_; } /** @@ -368,50 +413,10 @@ * @return {@code true} if there are any event listeners for the specified event, {@code false} otherwise */ boolean hasEventListeners(final String eventType) { - final TypeContainer container = typeContainers_.get(eventType); - return container != null - && (container.handler_ instanceof Function - || !container.bubblingListeners_.isEmpty() - || !container.capturingListeners_.isEmpty()); + return !getTypeContainer(eventType).atTargetListeners_.isEmpty(); } /** - * Executes listeners. - * - * @param event the event - * @param args the arguments - * @param propHandlerArgs handler arguments - * @return the result - */ - ScriptResult executeListeners(final Event event, final Object[] args, final Object[] propHandlerArgs) { - // the registered capturing listeners (if any) - event.setEventPhase(Event.CAPTURING_PHASE); - ScriptResult result = executeEventListeners(true, event, args); - if (event.isPropagationStopped()) { - return result; - } - - // the handler declared as property (if any) - event.setEventPhase(Event.AT_TARGET); - ScriptResult newResult = executeEventHandler(event, propHandlerArgs); - if (newResult != null) { - result = newResult; - } - if (event.isPropagationStopped()) { - return result; - } - - // the registered bubbling listeners (if any) - event.setEventPhase(Event.BUBBLING_PHASE); - newResult = executeEventListeners(false, event, args); - if (newResult != null) { - result = newResult; - } - - return result; - } - - /** * {@inheritDoc} */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-12 12:32:23 UTC (rev 15516) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-14 19:17:44 UTC (rev 15517) @@ -40,7 +40,6 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLabelElement; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Function; @@ -98,13 +97,11 @@ final Window window = getWindow(); final Object[] args = new Object[] {event}; - // handlers declared as property on a node don't receive the event as argument for IE - final Object[] propHandlerArgs = args; - final Event previousEvent = window.getCurrentEvent(); window.setCurrentEvent(event); try { - return eventListenersContainer.executeListeners(event, args, propHandlerArgs); + event.setEventPhase(Event.AT_TARGET); + return eventListenersContainer.executeAtTargetListeners(event, args); } finally { window.setCurrentEvent(previousEvent); // reset event @@ -125,16 +122,16 @@ final Event previousEvent = window.getCurrentEvent(); window.setCurrentEvent(event); + // The load event has some unnatural behaviour that we need to handle specially + final boolean isLoadEvent = Event.TYPE_LOAD.equals(event.getType()); + try { - // window's listeners - final EventListenersContainer windowsListeners = window.getEventListenersContainer(); + // These can be null if we aren't tied to a DOM node + final DomNode ourNode = getDomNodeOrNull(); + final DomNode ourParentNode = (ourNode != null) ? ourNode.getParentNode() : null; - // capturing phase - event.setEventPhase(Event.CAPTURING_PHASE); - final boolean windowEventIfDetached = getBrowserVersion().hasFeature(JS_EVENT_WINDOW_EXECUTE_IF_DITACHED); - boolean isAttached = false; - for (DomNode node = getDomNodeOrNull(); node != null; node = node.getParentNode()) { + for (DomNode node = ourNode; node != null; node = node.getParentNode()) { if (node instanceof Document || node instanceof DomDocumentFragment) { isAttached = true; break; @@ -141,68 +138,99 @@ } } - if (isAttached || windowEventIfDetached) { - result = windowsListeners.executeCapturingListeners(event, args); - if (event.isPropagationStopped()) { - return result; + // Determine the propagation path which is fixed here and not affected by + // DOM tree modification from intermediate listeners (tested in Chrome) + final List<EventTarget> propagationPath = new ArrayList<>(); + + // The window 'load' event targets Document but paths Window only (tested in Chrome/FF) + if (!isLoadEvent || !(ourNode instanceof Document)) { + // We go on the propagation path first + if (isAttached || !(this instanceof HTMLElement)) { + propagationPath.add(this); } + // Then add all our parents if we have any (pure JS object such as XMLHttpRequest + // and MessagePort, etc. will not have any parents) + for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) { + final EventTarget jsNode = parent.getScriptableObject(); + if (isAttached || !(jsNode instanceof HTMLElement)) { + propagationPath.add(jsNode); + } + } } - final List<EventTarget> eventTargetList = new ArrayList<>(); - EventTarget eventTarget = this; - while (eventTarget != null) { - if (isAttached) { - eventTargetList.add(eventTarget); + // The 'load' event for other elements target that element and but does not path Window + // (see Note in https://www.w3.org/TR/DOM-Level-3-Events/#event-type-load) + if (!isLoadEvent || ourNode instanceof Document) { + if (isAttached || getBrowserVersion().hasFeature(JS_EVENT_WINDOW_EXECUTE_IF_DITACHED)) { + propagationPath.add(window); } - final DomNode domNode = eventTarget.getDomNodeOrNull(); - eventTarget = null; - if (domNode != null && domNode.getParentNode() != null) { - eventTarget = domNode.getParentNode().getScriptableObject(); - } } final boolean ie = getBrowserVersion().hasFeature(JS_CALL_RESULT_IS_LAST_RETURN_VALUE); - for (int i = eventTargetList.size() - 1; i >= 0; i--) { - final EventTarget jsNode = eventTargetList.get(i); - final EventListenersContainer elc = jsNode.eventListenersContainer_; - if (elc != null && isAttached) { - final ScriptResult r = elc.executeCapturingListeners(event, args); - result = ScriptResult.combine(r, result, ie); - if (event.isPropagationStopped()) { - return result; + + // Refactoring note: Not sure of the reasoning for this but preserving nonetheless: Nodes + // are traversed if they're attached or if they're non-HTMLElement. However, the capturing + // phase only traverses nodes that are attached + if (isAttached) { + // capturing phase + event.setEventPhase(Event.CAPTURING_PHASE); + + for (int i = propagationPath.size() - 1; i >= 1; i--) { + final EventTarget jsNode = propagationPath.get(i); + final EventListenersContainer elc = jsNode.eventListenersContainer_; + if (elc != null) { + final ScriptResult r = elc.executeCapturingListeners(event, args); + result = ScriptResult.combine(r, result, ie); + if (event.isPropagationStopped()) { + return result; + } } } } - // handlers declared as property on a node don't receive the event as argument for IE - final Object[] propHandlerArgs = args; - - // bubbling phase + // at target phase event.setEventPhase(Event.AT_TARGET); - eventTarget = this; - HtmlLabel label = null; - final boolean processLabelAfterBubbling = event.processLabelAfterBubbling(); - while (eventTarget != null) { - final EventTarget jsNode = eventTarget; + if (!propagationPath.isEmpty()) { + // Note: This element is not always the same as event.getTarget(): + // e.g. the 'load' event targets Document but "at target" is on Window. + final EventTarget jsNode = propagationPath.get(0); final EventListenersContainer elc = jsNode.eventListenersContainer_; - if (elc != null && !(jsNode instanceof Window) && (isAttached || !(jsNode instanceof HTMLElement))) { - final ScriptResult r = elc.executeBubblingListeners(event, args, propHandlerArgs); + if (elc != null) { + final ScriptResult r = elc.executeAtTargetListeners(event, args); result = ScriptResult.combine(r, result, ie); if (event.isPropagationStopped()) { return result; } } - final DomNode domNode = eventTarget.getDomNodeOrNull(); - eventTarget = null; - if (domNode != null && domNode.getParentNode() != null) { - eventTarget = domNode.getParentNode().getScriptableObject(); + } + + // Refactoring note: This should probably be done further down + HtmlLabel label = null; + if (event.processLabelAfterBubbling()) { + for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) { + if (parent instanceof HtmlLabel) { + label = (HtmlLabel) parent; + break; + } } + } + + // bubbling phase + if (event.isBubbles()) { + // This belongs here inside the block because events that don't bubble never set + // eventPhase = 3 (tested in Chrome) event.setEventPhase(Event.BUBBLING_PHASE); - if (eventTarget != null - && label == null - && processLabelAfterBubbling && eventTarget instanceof HTMLLabelElement) { - label = (HtmlLabel) eventTarget.getDomNodeOrNull(); + for (int i = 1, size = propagationPath.size(); i < size; i++) { + final EventTarget jsNode = propagationPath.get(i); + final EventListenersContainer elc = jsNode.eventListenersContainer_; + if (elc != null) { + final ScriptResult r = elc.executeBubblingListeners(event, args); + result = ScriptResult.combine(r, result, ie); + if (event.isPropagationStopped()) { + return result; + } + } } } @@ -218,10 +246,6 @@ } } - if (isAttached || windowEventIfDetached) { - final ScriptResult r = windowsListeners.executeBubblingListeners(event, args, propHandlerArgs); - result = ScriptResult.combine(r, result, ie); - } } finally { event.endFire(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-12 12:32:23 UTC (rev 15516) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-14 19:17:44 UTC (rev 15517) @@ -16,9 +16,13 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; +import java.io.InputStream; import java.net.URL; +import java.util.Collections; +import java.util.List; import java.util.Map; +import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -31,6 +35,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; +import com.gargoylesoftware.htmlunit.util.NameValuePair; /** * Tests for {@link Window}. @@ -1572,4 +1577,574 @@ loadPageWithAlerts2(html); } + + /** + * Tests the ordering of DOMContentLoaded for window and document + * as well as how capturing / bubbling phases are handled. + * Tests the ordering of load for window and document, and how they + * relate to the onload property of 'body'. + * Verifies handling of the at target phase. + * Checks the state of event.eventPhase for a non-bubbling event after the bubbling phase. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"window DOMContentLoaded 1 capture", + "window DOMContentLoaded 2 capture", + "document DOMContentLoaded 1", + "document DOMContentLoaded 1 capture", + "document DOMContentLoaded 2", + "document DOMContentLoaded 2 capture", + "window DOMContentLoaded 1", + "window DOMContentLoaded 2", + "window at load 1", + "window at load 1 capture", + "window at load 2", + "onload 2", + "window at load 2 capture", + "after"}, + IE = {"window DOMContentLoaded 1 capture", + "window DOMContentLoaded 2 capture", + "document DOMContentLoaded 1", + "document DOMContentLoaded 1 capture", + "document DOMContentLoaded 2", + "document DOMContentLoaded 2 capture", + "window DOMContentLoaded 1", + "window DOMContentLoaded 2", + "window at load 1", + "window at load 1 capture", + "window at load 2", + "onload 2", + "window at load 2 capture", + "document at load 1 capture", + "document at load 2 capture", + "document at load 1 capture", + "document at load 2 capture", + "after"}) + public void onload() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " document.getElementById('log').value += msg + '\\n';\n" + + " }\n" + + // These 'load' events and 'onload' property below target 'document' when fired + // but path 'window' only. (Chrome/FF) + // This is unlike other events where the path always includes the target and + // all ancestors up to 'window'. Ascertaining this is possible by inspecting + // the 'event' object which is a property of 'window' in Chrome, or + // obtained via the first parameter of the event function in FF: e.g. function (event) { log('xyz', event) } + + " window.addEventListener('load', function () { log('window at load 1') })\n" + + // This 'onload' callback is called when the 'load' event is fired. + // Ordering of the call is preserved with respect to other 'load' callbacks and is relative to + // the position the property is set. Subsequent overwriting of 'window.onload' with another + // valid function does not move this position. However, setting 'window.onload' to null or a + // non-function value will reset the position and a new position us determined the next time + // the property is set. The 'body' tag with an 'onload' property behaves synonymously as + // writing 'window.onload = function () { ... }' + // at the position the 'body' tag appears. + //window.onload = function () { log('onload 1') } + + + " window.addEventListener('load', function () { log('window at load 1 capture') }, true)\n" + // This 'DOMContentLoaded' event targets 'document' and paths [window, document] as expected. (Chrome/FF) + + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 1') })\n" + + " window.addEventListener('DOMContentLoaded', " + + "function () { log('window DOMContentLoaded 1 capture') }, true)\n" + + + " document.addEventListener('load', function () { log('document at load 1') })\n" + + " document.addEventListener('load', function () { log('document at load 1 capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 1') })\n" + + " document.addEventListener('DOMContentLoaded', " + + "function () { log('document DOMContentLoaded 1 capture') }, true)\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "<script>\n" + + " window.addEventListener('load', function () { log('window at load 2') })\n" + //window.onload = null + //window.onload = 123 + + " window.onload = function () { log('onload 2') }\n" + + " window.addEventListener('load', function () { log('window at load 2 capture') }, true)\n" + + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 2') })\n" + + " window.addEventListener('DOMContentLoaded', " + + "function () { log('window DOMContentLoaded 2 capture') }, true)\n" + + + " document.addEventListener('load', function () { log('document at load 2 capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 2') })\n" + + " document.addEventListener('DOMContentLoaded', " + + "function () { log('document DOMContentLoaded 2 capture') }, true)\n" + + // This is for testing the state of event.eventPhase afterwards + + " window.addEventListener('load', " + + "function (event) { var x = event; " + + "window.setTimeout(function () { log('after', x.eventPhase) }, 100) }, true)\n" + + "</script>\n" + + " <textarea id='log' rows=40 cols=80></textarea>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * Tests load and error events of 'script' tags. + * Checks that they should be using EventTarget.fireEvent() + * rather than Event.executeEventLocally(). + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"document DOMContentLoaded", + "window DOMContentLoaded", + "window at load", + "window at load capture", + "body onload"}, + IE = {"document DOMContentLoaded", + "window DOMContentLoaded", + "window at load", + "window at load capture", + "document at load capture", + "body onload"}) + public void onloadScript() throws Exception { + getMockWebConnection().setResponse(URL_SECOND, ""); + + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " document.getElementById('log').value += msg + '\\n';\n" + + " }\n" + + + " window.addEventListener('load', function () { log('window at load') })\n" + + " window.addEventListener('load', function () { log('window at load capture') }, true)\n" + + " window.addEventListener('error', function () { log('window at error') })\n" + + " window.addEventListener('error', function () { log('window at error capture') }, true)\n" + + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded') })\n" + + + " document.addEventListener('load', function () { log('document at load') })\n" + + " document.addEventListener('load', function () { log('document at load capture') }, true)\n" + + " document.addEventListener('error', function () { log('document at error') })\n" + + " document.addEventListener('error', function () { log('document at error capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded') })\n" + + + "</script>\n" + + "</head>\n" + + "<body onload='log(\"body onload\")'>\n" + + " <script src='" + URL_SECOND + "' onload='log(\"element 1 onload\")' " + + "onerror='log(\"element 1 onerror\")'></script>\n" + + " <script src='missing.txt' onload='log(\"element 2 onload\")' " + + "onerror='log(\"element 2 onerror\")'></script>\n" + + + " <textarea id='log' rows=40 cols=80></textarea>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * Tests load and error events of 'img' tags. + * Checks that they should be using EventTarget.fireEvent() + * rather than Event.executeEventLocally(). + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"window at error capture", + "document at error capture", + "element 2 onerror", + "document DOMContentLoaded", + "window DOMContentLoaded", + "document at load capture", + "element 1 onload", + "window at load", + "window at load capture", + "body onload"}, + CHROME = {"document DOMContentLoaded", + "window DOMContentLoaded", + "window at error capture", + "document at error capture", + "element 2 onerror", + "document at load capture", + "element 1 onload", + "window at load", + "window at load capture", + "body onload"}, + IE = {"document at load capture", + "element 1 onload", + "document DOMContentLoaded", + "window DOMContentLoaded", + "window at load", + "window at load capture", + "body onload", + "document at load capture", + "window at error capture", + "document at error capture", + "element 2 onerror"}) + public void onloadImg() throws Exception { + final URL urlImage = new URL(URL_FIRST, "img.jpg"); + try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) { + final byte[] directBytes = IOUtils.toByteArray(is); + final List<NameValuePair> emptyList = Collections.emptyList(); + getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", emptyList); + } + + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " document.getElementById('log').value += msg + '\\n';\n" + + " }\n" + + + " window.addEventListener('load', function () { log('window at load') })\n" + + " window.addEventListener('load', function () { log('window at load capture') }, true)\n" + + " window.addEventListener('error', function () { log('window at error') })\n" + + " window.addEventListener('error', function () { log('window at error capture') }, true)\n" + + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded') })\n" + + + " document.addEventListener('load', function () { log('document at load') })\n" + + " document.addEventListener('load', function () { log('document at load capture') }, true)\n" + + " document.addEventListener('error', function () { log('document at error') })\n" + + " document.addEventListener('error', function () { log('document at error capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded') })\n" + + + "</script>\n" + + "</head>\n" + + "<body onload='log(\"body onload\")'>\n" + + " <img src='" + urlImage + "' onload='log(\"element 1 onload\")' " + + "onerror='log(\"element 1 onerror\")'>\n" + + " <img src='' onload='log(\"element 2 onload\")' " + + "onerror='log(\"element 2 onerror\")'>\n" + + + " <textarea id='log' rows=40 cols=80></textarea>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * Same as {@link #onload()} but from frame. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"framing window DOMContentLoaded 1 capture", + "framing document DOMContentLoaded 1", + "framing document DOMContentLoaded 1 capture", + "framing window DOMContentLoaded 1", + "window DOMContentLoaded 1 capture", + "window DOMContentLoaded 2 capture", + "document DOMContentLoaded 1", + "document DOMContentLoaded 1 capture", + "document DOMContentLoaded 2", + "document DOMContentLoaded 2 capture", + "window DOMContentLoaded 1", + "window DOMContentLoaded 2", + "window at load 1", + "window at load 1 capture", + "window at load 2", + "onload 2", + "window at load 2 capture", + "framing document at load 1 capture", + "frame onload", + "framing window at load 1", + "framing window at load 1 capture", + "frameset onload", + "after"}, + IE = {"framing window DOMContentLoaded 1 capture", + "framing document DOMContentLoaded 1", + "framing document DOMContentLoaded 1 capture", + "framing window DOMContentLoaded 1", + "framing document at load 1 capture", + "window DOMContentLoaded 1 capture", + "window DOMContentLoaded 2 capture", + "document DOMContentLoaded 1", + "document DOMContentLoaded 1 capture", + "document DOMContentLoaded 2", + "document DOMContentLoaded 2 capture", + "window DOMContentLoaded 1", + "window DOMContentLoaded 2", + "window at load 1", + "window at load 1 capture", + "window at load 2", + "onload 2", + "window at load 2 capture", + "framing document at load 1 capture", + "frame onload", + "framing window at load 1", + "framing window at load 1 capture", + "frameset onload", + "document at load 1 capture", + "document at load 2 capture", + "document at load 1 capture", + "document at load 2 capture", + "after"}) + public void onloadFrame() throws Exception { + + final String content = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " window.parent.document.title += msg + ';';\n" + + " }\n" + + + " window.addEventListener('load', function () { log('window at load 1') })\n" + + + " window.addEventListener('load', function () { log('window at load 1 capture') }, true)\n" + + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 1') })\n" + + " window.addEventListener('DOMContentLoaded', " + + "function () { log('window DOMContentLoaded 1 capture') }, true)\n" + + + " document.addEventListener('load', function () { log('document at load 1') })\n" + + " document.addEventListener('load', function () { log('document at load 1 capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 1') })\n" + + " document.addEventListener('DOMContentLoaded', " + + "function () { log('document DOMContentLoaded 1 capture') }, true)\n" + + "</script>\n" + + "</head>\n" + + "<body >\n" + + "<script>\n" + + " window.addEventListener('load', function () { log('window at load 2') })\n" + + " window.onload = function () { log('onload 2') }\n" + + " window.addEventListener('load', function () { log('window at load 2 capture') }, true)\n" + + " window.addEventListener('DOMContentLoaded', function () { log('window DOMContentLoaded 2') })\n" + + " window.addEventListener('DOMContentLoaded', " + + "function () { log('window DOMContentLoaded 2 capture') }, true)\n" + + + " document.addEventListener('load', function () { log('document at load 2 capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', function () { log('document DOMContentLoaded 2') })\n" + + " document.addEventListener('DOMContentLoaded', " + + "function () { log('document DOMContentLoaded 2 capture') }, true)\n" + + + " window.addEventListener('load', " + + "function (event) { var x = event; " + + "window.setTimeout(function () { log('after', x.eventPhase) }, 100) }, true)\n" + + "</script>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse(content); + + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " window.document.title += msg + ';';\n" + + " }\n" + + + " window.addEventListener('load', function () { log('framing window at load 1') })\n" + + " window.addEventListener('load', function () { log('framing window at load 1 capture') }, true)\n" + + " window.addEventListener('DOMContentLoaded', " + + "function () { log('framing window DOMContentLoaded 1') })\n" + + " window.addEventListener('DOMContentLoaded', " + + "function () { log('framing window DOMContentLoaded 1 capture') }, true)\n" + + // should not fire because bubbles = false + + " document.addEventListener('load', " + + "function () { log('framing document at load 1') })\n" + + " document.addEventListener('load', " + + "function () { log('framing document at load 1 capture') }, true)\n" + + " document.addEventListener('DOMContentLoaded', " + + "function () { log('framing document DOMContentLoaded 1') })\n" + + " document.addEventListener('DOMContentLoaded', " + + "function () { log('framing document DOMContentLoaded 1 capture') }, true)\n" + + "</script>\n" + + "</head>\n" + + "<frameset onload='log(\"frameset onload\")'>\n" + + "<frame src='test_onload.html' onload='log(\"frame onload\")'>\n" + + "</frameset>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + Thread.sleep(200); + final String text = driver.getTitle().trim().replaceAll(";", "\n").trim(); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * Tests propagation of a more or less basic event (click event) with regards to + * handling of the capturing / bubbling / at target phases. + * Tests listener and property handler ordering. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"window at click 1 capture", + "window at click 2 capture", + "onclick 2", + "i1 at click 1", + "i1 at click 1 capture", + "i1 at click 2", + "i1 at click 2 capture", + "window at click 1", + "window at click 2"}) + public void propagation() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " document.getElementById('log').value += msg + '\\n';\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + " <input id='tester' type='button' value='test' onclick='log(\"onclick\")'>\n" + + " <textarea id='log' rows=40 cols=80></textarea>\n" + + + "<script>\n" + + " window.addEventListener('click', function () { log('window at click 1') })\n" + + " window.addEventListener('click', function () { log('window at click 1 capture') }, true)\n" + + " window.addEventListener('click', function () { log('window at click 2') })\n" + + " window.addEventListener('click', function () { log('window at click 2 capture') }, true)\n" + + + " tester.addEventListener('click', function () { log('i1 at click 1') })\n" + + " tester.addEventListener('click', function () { log('i1 at click 1 capture') }, true)\n" + + " tester.addEventListener('click', function () { log('i1 at click 2') })\n" + + " tester.onclick = function () { log('onclick 2') }\n" + + " tester.addEventListener('click', function () { log('i1 at click 2 capture') }, true)\n" + + "</script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("tester")).click(); + + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** + * Similar as {@link #propagation()} except with a deeper propagation path. + * Check bubbling propagation after modification of the DOM tree by an intermediate listener. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"d1 at click 1 capture", + "d1 at click 2 capture", + "d2 at click 1 capture", + "d2 at click 2 capture", + "d3 at click 1", + "d3 onclick", + "d3 at click 1 capture", + "d3 at click 2", + "d3 at click 2 capture", + "d2 at click 1", + "d2 onclick", + ... [truncated message content] |
From: <rb...@us...> - 2018-08-15 08:01:28
|
Revision: 15519 http://sourceforge.net/p/htmlunit/code/15519 Author: rbri Date: 2018-08-15 08:01:20 +0000 (Wed, 15 Aug 2018) Log Message: ----------- next step in event refactoring (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-15 07:14:08 UTC (rev 15518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-15 08:01:20 UTC (rev 15519) @@ -899,10 +899,6 @@ @BrowserFeature(FF) JS_EVENT_DISTINGUISH_PRINTABLE_KEY, - /** Executes the window event listeners if the node is detached from the document. */ - @BrowserFeature(CHROME) - JS_EVENT_WINDOW_EXECUTE_IF_DITACHED, - /** Whether {@code FileReader} includes content type or not. */ @BrowserFeature(FF) JS_FILEREADER_CONTENT_TYPE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-15 07:14:08 UTC (rev 15518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-15 08:01:20 UTC (rev 15519) @@ -141,6 +141,7 @@ * @author Ronald Brill * @author Frank Danek * @author Joerg Werner + * @author Atsushi Nakagawa */ public class HtmlPage extends SgmlPage { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-08-15 07:14:08 UTC (rev 15518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-08-15 08:01:20 UTC (rev 15519) @@ -48,6 +48,7 @@ * @author Ahmed Ashour * @author Frank Danek * @author Ronald Brill + * @author Atsushi Nakagawa */ public class EventListenersContainer implements Serializable { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-15 07:14:08 UTC (rev 15518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-15 08:01:20 UTC (rev 15519) @@ -15,7 +15,6 @@ package com.gargoylesoftware.htmlunit.javascript.host.event; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CALL_RESULT_IS_LAST_RETURN_VALUE; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_EVENT_WINDOW_EXECUTE_IF_DITACHED; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; @@ -26,10 +25,8 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.w3c.dom.Document; import com.gargoylesoftware.htmlunit.ScriptResult; -import com.gargoylesoftware.htmlunit.html.DomDocumentFragment; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -39,7 +36,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.host.Window; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; +import com.gargoylesoftware.htmlunit.javascript.host.dom.Document; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Function; @@ -49,6 +46,8 @@ * A JavaScript object for {@code EventTarget}. * * @author Ahmed Ashour + * @author Ronald Brill + * @author Atsushi Nakagawa */ @JsxClass({CHROME, FF, EDGE}) @JsxClass(isJSObject = false, value = IE) @@ -122,45 +121,41 @@ final Event previousEvent = window.getCurrentEvent(); window.setCurrentEvent(event); - // The load event has some unnatural behaviour that we need to handle specially - final boolean isLoadEvent = Event.TYPE_LOAD.equals(event.getType()); - try { // These can be null if we aren't tied to a DOM node final DomNode ourNode = getDomNodeOrNull(); final DomNode ourParentNode = (ourNode != null) ? ourNode.getParentNode() : null; - boolean isAttached = false; - for (DomNode node = ourNode; node != null; node = node.getParentNode()) { - if (node instanceof Document || node instanceof DomDocumentFragment) { - isAttached = true; - break; - } - } - // Determine the propagation path which is fixed here and not affected by // DOM tree modification from intermediate listeners (tested in Chrome) final List<EventTarget> propagationPath = new ArrayList<>(); - // The window 'load' event targets Document but paths Window only (tested in Chrome/FF) - if (!isLoadEvent || !(ourNode instanceof Document)) { - // We go on the propagation path first - if (isAttached || !(this instanceof HTMLElement)) { - propagationPath.add(this); + // We're added to the propagation path first + propagationPath.add(this); + + // Then add all our parents if we have any (pure JS object such as XMLHttpRequest + // and MessagePort, etc. will not have any parents) + for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) { + propagationPath.add(parent.getScriptableObject()); + } + + // The load event has some unnatural behaviour that we need to handle specially + if (Event.TYPE_LOAD.equals(event.getType())) { + + // The Window load event targets Document but paths Window only (tested in Chrome/FF) + if (this instanceof Document) { + propagationPath.clear(); + propagationPath.add(window); } - // Then add all our parents if we have any (pure JS object such as XMLHttpRequest - // and MessagePort, etc. will not have any parents) - for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) { - final EventTarget jsNode = parent.getScriptableObject(); - if (isAttached || !(jsNode instanceof HTMLElement)) { - propagationPath.add(jsNode); - } + else { + // The load event for other elements target that element and but path only + // up to Document and not Window, so do nothing here + // (see Note in https://www.w3.org/TR/DOM-Level-3-Events/#event-type-load) } } - // The 'load' event for other elements target that element and but does not path Window - // (see Note in https://www.w3.org/TR/DOM-Level-3-Events/#event-type-load) - if (!isLoadEvent || ourNode instanceof Document) { - if (isAttached || getBrowserVersion().hasFeature(JS_EVENT_WINDOW_EXECUTE_IF_DITACHED)) { + else { + // Add Window if the the propagation path reached Document + if (propagationPath.get(propagationPath.size() - 1) instanceof Document) { propagationPath.add(window); } } @@ -167,22 +162,17 @@ final boolean ie = getBrowserVersion().hasFeature(JS_CALL_RESULT_IS_LAST_RETURN_VALUE); - // Refactoring note: Not sure of the reasoning for this but preserving nonetheless: Nodes - // are traversed if they're attached or if they're non-HTMLElement. However, the capturing - // phase only traverses nodes that are attached - if (isAttached) { - // capturing phase - event.setEventPhase(Event.CAPTURING_PHASE); + // capturing phase + event.setEventPhase(Event.CAPTURING_PHASE); - for (int i = propagationPath.size() - 1; i >= 1; i--) { - final EventTarget jsNode = propagationPath.get(i); - final EventListenersContainer elc = jsNode.eventListenersContainer_; - if (elc != null) { - final ScriptResult r = elc.executeCapturingListeners(event, args); - result = ScriptResult.combine(r, result, ie); - if (event.isPropagationStopped()) { - return result; - } + for (int i = propagationPath.size() - 1; i >= 1; i--) { + final EventTarget jsNode = propagationPath.get(i); + final EventListenersContainer elc = jsNode.eventListenersContainer_; + if (elc != null) { + final ScriptResult r = elc.executeCapturingListeners(event, args); + result = ScriptResult.combine(r, result, ie); + if (event.isPropagationStopped()) { + return result; } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-15 07:14:08 UTC (rev 15518) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-15 08:01:20 UTC (rev 15519) @@ -52,6 +52,7 @@ * @author Daniel Gredler * @author Frank Danek * @author Ronald Brill + * @author Atsushi Nakagawa */ @RunWith(BrowserRunner.class) public class Window3Test extends WebDriverTestCase { @@ -1889,7 +1890,6 @@ "document at load 2 capture", "after"}) public void onloadFrame() throws Exception { - final String content = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" @@ -1977,15 +1977,15 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = {"window at click 1 capture", - "window at click 2 capture", - "onclick 2", - "i1 at click 1", - "i1 at click 1 capture", - "i1 at click 2", - "i1 at click 2 capture", - "window at click 1", - "window at click 2"}) + @Alerts({"window at click 1 capture", + "window at click 2 capture", + "onclick 2", + "i1 at click 1", + "i1 at click 1 capture", + "i1 at click 2", + "i1 at click 2 capture", + "window at click 1", + "window at click 2"}) public void propagation() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" @@ -2027,21 +2027,25 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = {"d1 at click 1 capture", - "d1 at click 2 capture", - "d2 at click 1 capture", - "d2 at click 2 capture", - "d3 at click 1", - "d3 onclick", - "d3 at click 1 capture", - "d3 at click 2", - "d3 at click 2 capture", - "d2 at click 1", - "d2 onclick", - "d2 at click 2", - "d1 at click 1", - "d1 onclick", - "d1 at click 2"}) + @Alerts({"window at click 1 capture", + "window at click 2 capture", + "d1 at click 1 capture", + "d1 at click 2 capture", + "d2 at click 1 capture", + "d2 at click 2 capture", + "d3 at click 1", + "d3 onclick", + "d3 at click 1 capture", + "d3 at click 2", + "d3 at click 2 capture", + "d2 at click 1", + "d2 onclick", + "d2 at click 2", + "d1 at click 1", + "d1 onclick", + "d1 at click 2", + "window at click 1", + "window at click 2"}) public void propagationNested() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" @@ -2062,6 +2066,11 @@ + " <textarea id='log' rows=40 cols=80></textarea>\n" + "<script>\n" + + " window.addEventListener('click', function () { log('window at click 1') })\n" + + " window.addEventListener('click', function () { log('window at click 1 capture') }, true)\n" + + " window.addEventListener('click', function () { log('window at click 2') })\n" + + " window.addEventListener('click', function () { log('window at click 2 capture') }, true)\n" + + " d1.addEventListener('click', function () { log('d1 at click 1') })\n" + " d1.onclick = function () { log('d1 onclick') }\n" + " d1.addEventListener('click', function () { log('d1 at click 1 capture') }, true)\n" @@ -2090,6 +2099,91 @@ } /** + * Similar as {@link #propagationNested()} but clicking a detached element. + * Check bubbling propagation after modification of the DOM tree by an intermediate listener. + * + * @throws Exception if the test fails + */ + @Test + @Alerts({"window at click 1 capture", + "window at click 2 capture", + "begin detach click", + "d2 at click 1 capture", + "d2 at click 2 capture", + "d3 at click 1", + "d3 onclick", + "d3 at click 1 capture", + "d3 at click 2", + "d3 at click 2 capture", + "d2 at click 1", + "d2 onclick", + "d2 at click 2", + "end detach click", + "window at click 1", + "window at click 2"}) + public void propagationNestedDetached() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function log(msg) {\n" + + " document.getElementById('log').value += msg + '\\n';\n" + + " }\n" + + + " function detachAndClick() {\n" + + " log('begin detach click')\n" + + " var d2 = window.d2, d3 = window.d3\n" + + " d2.parentNode.removeChild(d2);\n" + + " d3.click();\n" + + " log('end detach click')\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + " <div id='d1' style='width: 150px; height: 150px; background-color: blue'>\n" + + " <div id='d2' style='width: 100px; height: 100px; background-color: green'>\n" + + " <div id='d3' style='width: 50px; height: 50px; background-color: red'>\n" + + " </div>\n" + + " </div>\n" + + " </div>\n" + + " <input id='detach_click' type='button' value='Detach & click' onclick='detachAndClick()'>\n" + + + " <textarea id='log' rows=40 cols=80></textarea>\n" + + + "<script>\n" + + " d2 = window.d2, d3 = window.d3\n" // Save because "Detach & click" removes them + + " window.addEventListener('click', function () { log('window at click 1') })\n" + + " window.addEventListener('click', function () { log('window at click 1 capture') }, true)\n" + + " window.addEventListener('click', function () { log('window at click 2') })\n" + + " window.addEventListener('click', function () { log('window at click 2 capture') }, true)\n" + + + " d1.addEventListener('click', function () { log('d1 at click 1') })\n" + + " d1.onclick = function () { log('d1 onclick') }\n" + + " d1.addEventListener('click', function () { log('d1 at click 1 capture') }, true)\n" + + " d1.addEventListener('click', function () { log('d1 at click 2') })\n" + + " d1.addEventListener('click', function () { log('d1 at click 2 capture') }, true)\n" + + + " d2.addEventListener('click', function () { log('d2 at click 1') })\n" + + " d2.onclick = function () { log('d2 onclick'); d2.parentNode.removeChild(d2) }\n" + + " d2.addEventListener('click', function () { log('d2 at click 1 capture') }, true)\n" + + " d2.addEventListener('click', function () { log('d2 at click 2') })\n" + + " d2.addEventListener('click', function () { log('d2 at click 2 capture') }, true)\n" + + + " d3.addEventListener('click', function () { log('d3 at click 1') })\n" + + " d3.onclick = function () { log('d3 onclick') }\n" + + " d3.addEventListener('click', function () { log('d3 at click 1 capture') }, true)\n" + + " d3.addEventListener('click', function () { log('d3 at click 2') })\n" + + " d3.addEventListener('click', function () { log('d3 at click 2 capture') }, true)\n" + + "</script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("detach_click")).click(); + + final String text = driver.findElement(By.id("log")).getAttribute("value").trim().replaceAll("\r", ""); + assertEquals(String.join("\n", getExpectedAlerts()), text); + } + + /** * This test determines that the return value of listeners are apparently * ignored and only that of the property handler is used. * @@ -2096,11 +2190,11 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = {"listener: stop propagation & return false", - "FIRED a1", - "listener: return true", - "property: return false", - "listener: return true"}) + @Alerts({"listener: stop propagation & return false", + "FIRED a1", + "listener: return true", + "property: return false", + "listener: return true"}) public void stopPropagation() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" |
From: <rb...@us...> - 2018-08-17 18:17:35
|
Revision: 15525 http://sourceforge.net/p/htmlunit/code/15525 Author: rbri Date: 2018-08-17 18:17:29 +0000 (Fri, 17 Aug 2018) Log Message: ----------- next step in event refactoring (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -154,9 +154,9 @@ @BrowserFeature(IE) DOM_NORMALIZE_REMOVE_CHILDREN, - /** Event false result. */ - @BrowserFeature(IE) - EVENT_FALSE_RESULT, + /** Indicates handler return value is only used if returnValue is the default value. */ + @BrowserFeature({CHROME, FF}) + EVENT_BEFORE_UNLOAD_USES_HANDLER_RETURN_ONLY_IF_FIRST, /** Triggers the onfocus onfocusin blur onfocusout events in this order. */ @BrowserFeature(CHROME) @@ -234,6 +234,10 @@ @BrowserFeature(FF60) EVENT_ONPOPSTATE_DOCUMENT_CREATE_NOT_SUPPORTED, + /** Indicates if event.returnValue is backed by !event.defaultPrevented. */ + @BrowserFeature({CHROME, EDGE}) + EVENT_RETURN_VALUE_IS_PREVENT_DEFAULT, + /** Supports event type 'BeforeUnloadEvent'. */ @BrowserFeature({CHROME, FF}) EVENT_TYPE_BEFOREUNLOADEVENT, @@ -638,10 +642,6 @@ @BrowserFeature(IE) JS_BOUNDINGCLIENTRECT_THROWS_IF_DISCONNECTED, - /** If we're emulating IE, the overall JavaScript return value is the last return value. */ - @BrowserFeature(IE) - JS_CALL_RESULT_IS_LAST_RETURN_VALUE, - /** toDataURL for canvas returns the CHROME version of the PNG. */ @BrowserFeature(CHROME) JS_CANVAS_DATA_URL_CHROME_PNG, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -90,45 +90,24 @@ * * @param newResult the new {@link ScriptResult} (may be {@code null}) * @param originalResult the original {@link ScriptResult} (may be {@code null}) - * @param ie whether or not we are emulating IE * @return a composite {@link ScriptResult}, based on the two input {@link ScriptResult}s */ - public static ScriptResult combine(final ScriptResult newResult, final ScriptResult originalResult, - final boolean ie) { + public static ScriptResult combine(final ScriptResult newResult, final ScriptResult originalResult) { final Object jsResult; final Page page; - // If we're emulating IE, the overall JavaScript return value is the last return value. - // If we're emulating FF, the overall JavaScript return value is false if the return value - // was false at any level. - if (ie) { - if (newResult != null && !ScriptResult.isUndefined(newResult)) { - jsResult = newResult.getJavaScriptResult(); - } - else if (originalResult != null) { - jsResult = originalResult.getJavaScriptResult(); - } - else if (newResult != null) { - jsResult = newResult.getJavaScriptResult(); - } - else { - jsResult = null; - } + if (ScriptResult.isFalse(newResult)) { + jsResult = newResult.getJavaScriptResult(); } + else if (originalResult != null) { + jsResult = originalResult.getJavaScriptResult(); + } + else if (newResult != null) { + jsResult = newResult.getJavaScriptResult(); + } else { - if (ScriptResult.isFalse(newResult)) { - jsResult = newResult.getJavaScriptResult(); - } - else if (originalResult != null) { - jsResult = originalResult.getJavaScriptResult(); - } - else if (newResult != null) { - jsResult = newResult.getJavaScriptResult(); - } - else { - jsResult = null; - } + jsResult = null; } // The new page is always the newest page. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -17,7 +17,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_FOCUS_FOCUS_IN_BLUR_OUT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_FOCUS_IN_FOCUS_OUT_BLUR; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.FOCUS_BODY_ELEMENT_AT_START; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CALL_RESULT_IS_LAST_RETURN_VALUE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DEFERRED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IGNORES_UTF8_BOM_SOMETIMES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.PAGE_SELECTION_RANGE_FROM_SELECTABLE_TEXT_INPUT; @@ -99,7 +98,6 @@ import net.sourceforge.htmlunit.corejs.javascript.Script; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; /** * A representation of an HTML page returned from a server. @@ -1289,10 +1287,9 @@ } private boolean isOnbeforeunloadAccepted(final HtmlPage page, final Event event, final ScriptResult result) { - if (event.getType().equals(Event.TYPE_BEFORE_UNLOAD)) { - final boolean ie = hasFeature(JS_CALL_RESULT_IS_LAST_RETURN_VALUE); - final String message = getBeforeUnloadMessage(event, result, ie); - if (message != null) { + if (event instanceof BeforeUnloadEvent) { + if (((BeforeUnloadEvent) event).isBeforeUnloadMessageSet()) { + final String message = Context.toString(event.getReturnValue()); final OnbeforeunloadHandler handler = getWebClient().getOnbeforeunloadHandler(); if (handler == null) { LOG.warn("document.onbeforeunload() returned a string in event.returnValue," @@ -1306,30 +1303,6 @@ return true; } - private static String getBeforeUnloadMessage(final Event event, final ScriptResult result, final boolean ie) { - String message = null; - if (event.getReturnValue() != Undefined.instance) { - if (!ie || event.getReturnValue() != null || result == null || result.getJavaScriptResult() == null - || result.getJavaScriptResult() == Undefined.instance) { - message = Context.toString(event.getReturnValue()); - } - } - else { - if (result != null) { - if (ie) { - if (result.getJavaScriptResult() != Undefined.instance) { - message = Context.toString(result.getJavaScriptResult()); - } - } - else if (result.getJavaScriptResult() != null - && result.getJavaScriptResult() != Undefined.instance) { - message = Context.toString(result.getJavaScriptResult()); - } - } - } - return message; - } - /** * If a refresh has been specified either through a meta tag or an HTTP * response header, then perform that refresh. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -14,10 +14,12 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.event; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_BEFORE_UNLOAD_USES_HANDLER_RETURN_ONLY_IF_FIRST; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -34,6 +36,8 @@ * * @author Frank Danek * @author Ahmed Ashour + * @author Ronald Brill + * @author Atsushi Nakagawa */ @JsxClass public class BeforeUnloadEvent extends Event { @@ -64,11 +68,35 @@ super(domNode, type); setBubbles(false); - setReturnValue(Undefined.instance); + setReturnValue(getReturnValueDefault(getBrowserVersion())); } + @Override + public void initEvent(final String type, final boolean bubbles, final boolean cancelable) { + super.initEvent(type, bubbles, cancelable); + setReturnValue(getReturnValueDefault(getBrowserVersion())); + } + + private static Object getReturnValueDefault(final BrowserVersion browserVersion) { + if (browserVersion.isChrome() || browserVersion.isFirefox()) { + return ""; + } + return Undefined.instance; + } + + @Override + protected boolean isReturnValueBackedByPreventDefault() { + return false; + } + /** - * Returns the return value associated with the event. + * @return {@code true} if returnValue holds the beforeunload message + */ + public boolean isBeforeUnloadMessageSet() { + return !getReturnValueDefault(getBrowserVersion()).equals(getReturnValue()); + } + + /** * @return the return value associated with the event */ @Override @@ -86,4 +114,18 @@ public void setReturnValue(final Object returnValue) { super.setReturnValue(returnValue); } + + @Override + void handlePropertyHandlerReturnValue(final Object returnValue) { + super.handlePropertyHandlerReturnValue(returnValue); + + final BrowserVersion browserVersion = getBrowserVersion(); + + if (!Undefined.isUndefined(returnValue) && (returnValue != null || browserVersion.isIE())) { + if (!browserVersion.hasFeature(EVENT_BEFORE_UNLOAD_USES_HANDLER_RETURN_ONLY_IF_FIRST) + || !getReturnValueDefault(browserVersion).equals(getReturnValue())) { + setReturnValue(returnValue); + } + } + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_FOCUS_FOCUS_IN_BLUR_OUT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONLOAD_CANCELABLE_FALSE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_RETURN_VALUE_IS_PREVENT_DEFAULT; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; @@ -35,6 +36,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import net.sourceforge.htmlunit.corejs.javascript.Undefined; @@ -57,6 +59,7 @@ * @author Rob Di Marco * @author Ronald Brill * @author Frank Danek + * @author Atsushi Nakagawa */ @JsxClass public class Event extends SimpleScriptable { @@ -181,7 +184,7 @@ private boolean stopImmediatePropagation_; private Object returnValue_; private boolean preventDefault_; - + private Boolean returnValueIsPreventDefault_; /** * The current event phase. This is a W3C standard attribute. One of {@link #NONE}, * {@link #CAPTURING_PHASE}, {@link #AT_TARGET} or {@link #BUBBLING_PHASE}. @@ -581,10 +584,23 @@ } /** + * @return true if returnValue is backed by the same storage as preventDefault. + */ + protected boolean isReturnValueBackedByPreventDefault() { + if (returnValueIsPreventDefault_ == null) { + returnValueIsPreventDefault_ = getBrowserVersion().hasFeature(EVENT_RETURN_VALUE_IS_PREVENT_DEFAULT); + } + return returnValueIsPreventDefault_; + } + + /** * Returns the return value associated with the event. * @return the return value associated with the event */ public Object getReturnValue() { + if (isReturnValueBackedByPreventDefault()) { + return !preventDefault_; + } return returnValue_; } @@ -593,10 +609,25 @@ * @param returnValue the return value associated with the event */ public void setReturnValue(final Object returnValue) { - returnValue_ = returnValue; + if (isReturnValueBackedByPreventDefault()) { + preventDefault_ = !ScriptRuntime.toBoolean(returnValue); + } + else { + returnValue_ = returnValue; + } } /** + * Handles the return values of property handlers. + * @param returnValue the return value returned by the property handler + */ + void handlePropertyHandlerReturnValue(final Object returnValue) { + if (Boolean.FALSE.equals(returnValue)) { + preventDefault(); + } + } + + /** * Returns the property name associated with the event. * @return the property name associated with the event */ @@ -621,9 +652,6 @@ final Method readMethod = klass.getMethod("getReturnValue"); final Method writeMethod = klass.getMethod("setReturnValue", Object.class); defineProperty("returnValue", null, readMethod, writeMethod, ScriptableObject.EMPTY); - if ("Event".equals(klass.getSimpleName())) { - setReturnValue(Boolean.TRUE); - } } catch (final Exception e) { throw Context.throwAsScriptRuntimeEx(e); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -14,8 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.event; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_FALSE_RESULT; - import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; @@ -345,21 +343,14 @@ if (function != null) { final ScriptResult result = page.executeJavaScriptFunction(function, thisObject, args, node); - // Return value is only honoured for property handlers (Chrome/FF) + // Return value is only honored for property handlers (Tested in Chrome/FF/IE11) if (isPropertyHandler) { allResult = result; + event.handlePropertyHandlerReturnValue(result.getJavaScriptResult()); + + // This return value is now all but unused and can be refactored away + allResult = null; } - if (jsNode_.getBrowserVersion().hasFeature(EVENT_FALSE_RESULT)) { - if (ScriptResult.isFalse(result)) { - allResult = result; - } - else { - final Object eventReturnValue = event.getReturnValue(); - if (eventReturnValue instanceof Boolean && !((Boolean) eventReturnValue).booleanValue()) { - allResult = new ScriptResult(Boolean.FALSE, page); - } - } - } } if (event.isImmediatePropagationStopped()) { return allResult; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.event; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CALL_RESULT_IS_LAST_RETURN_VALUE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; @@ -152,8 +151,6 @@ } } - final boolean ie = getBrowserVersion().hasFeature(JS_CALL_RESULT_IS_LAST_RETURN_VALUE); - // capturing phase event.setEventPhase(Event.CAPTURING_PHASE); @@ -162,7 +159,7 @@ final EventListenersContainer elc = jsNode.eventListenersContainer_; if (elc != null) { final ScriptResult r = elc.executeCapturingListeners(event, args); - result = ScriptResult.combine(r, result, ie); + result = ScriptResult.combine(r, result); if (event.isPropagationStopped()) { return result; } @@ -179,7 +176,7 @@ final EventListenersContainer elc = jsNode.eventListenersContainer_; if (elc != null) { final ScriptResult r = elc.executeAtTargetListeners(event, args); - result = ScriptResult.combine(r, result, ie); + result = ScriptResult.combine(r, result); if (event.isPropagationStopped()) { return result; } @@ -208,7 +205,7 @@ final EventListenersContainer elc = jsNode.eventListenersContainer_; if (elc != null) { final ScriptResult r = elc.executeBubblingListeners(event, args); - result = ScriptResult.combine(r, result, ie); + result = ScriptResult.combine(r, result); if (event.isPropagationStopped()) { return result; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent2Test.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent2Test.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -152,5 +152,4 @@ onbeforeunload("e.returnValue = 'Hello';\n" + "return 'Hello'"); } - } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event3Test.java 2018-08-16 14:32:55 UTC (rev 15524) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event3Test.java 2018-08-17 18:17:29 UTC (rev 15525) @@ -14,8 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.event; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; - import java.util.ArrayList; import java.util.List; @@ -221,7 +219,6 @@ */ @Test @Alerts("false") // here not alerts! ;-) - @NotYetImplemented(IE) public void eventBubblingReturns_2() throws Exception { final boolean changesPage = Boolean.parseBoolean(getExpectedAlerts()[0]); testEventBubblingReturns("return true; ", "return false;", "return true; ", changesPage); |