From: <rb...@us...> - 2018-08-20 06:41:51
|
Revision: 15530 http://sourceforge.net/p/htmlunit/code/15530 Author: rbri Date: 2018-08-20 06:39:52 +0000 (Mon, 20 Aug 2018) Log Message: ----------- next step in event refactoring (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeTest.java 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-17 19:48:56 UTC (rev 15529) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/BeforeUnloadEvent.java 2018-08-20 06:39:52 UTC (rev 15530) @@ -117,7 +117,7 @@ if (!Undefined.isUndefined(returnValue) && (returnValue != null || browserVersion.isIE())) { if (!browserVersion.hasFeature(EVENT_BEFORE_UNLOAD_USES_HANDLER_RETURN_ONLY_IF_FIRST) - || !getReturnValueDefault(browserVersion).equals(getReturnValue())) { + || getReturnValueDefault(browserVersion).equals(getReturnValue())) { setReturnValue(returnValue); } } 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-17 19:48:56 UTC (rev 15529) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-20 06:39:52 UTC (rev 15530) @@ -112,6 +112,16 @@ * @return the result */ public ScriptResult fireEvent(final Event event) { + fireEventImpl(event); + // This is deprecated but there're still a few places using ScriptResult.getNewPage() + return new ScriptResult(null, getWindow().getWebWindow().getWebClient().getCurrentWindow().getEnclosedPage()); + } + + /** + * Fires the event on the node with capturing and bubbling phase. + * @param event the event + */ + private void fireEventImpl(final Event event) { final Window window = getWindow(); final Object[] args = new Object[] {event}; @@ -161,7 +171,7 @@ final ScriptResult r = elc.executeCapturingListeners(event, args); result = ScriptResult.combine(r, result); if (event.isPropagationStopped()) { - return result; + return; } } } @@ -178,7 +188,7 @@ final ScriptResult r = elc.executeAtTargetListeners(event, args); result = ScriptResult.combine(r, result); if (event.isPropagationStopped()) { - return result; + return; } } } @@ -207,7 +217,7 @@ final ScriptResult r = elc.executeBubblingListeners(event, args); result = ScriptResult.combine(r, result); if (event.isPropagationStopped()) { - return result; + return; } } } @@ -230,8 +240,6 @@ event.endFire(); window.setCurrentEvent(previousEvent); // reset event } - - return result; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node2Test.java 2018-08-17 19:48:56 UTC (rev 15529) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node2Test.java 2018-08-20 06:39:52 UTC (rev 15530) @@ -14,17 +14,10 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.dom; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPage; @@ -53,122 +46,9 @@ + " var b = document.getElementById('b');\n" + " a.replaceChild(b, b);\n" + "}\n" - + "</script></head><body onload='doTest()'><div id='a'><div id='b'/></div></html>"; + + "</script></head>\n" + + "<body onload='doTest()'><div id='a'><div id='b'/></div></html>"; final HtmlPage page = loadPageWithAlerts(html); assertNotNull(page.getHtmlElementById("b").getParentNode()); } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({"1", "2"}) - public void eventListener() throws Exception { - final String html - = "<html><head>\n" - + "<script>\n" - + " function clicking1() {\n" - + " alert(1);\n" - + " }\n" - + " function clicking2() {\n" - + " alert(2);\n" - + " }\n" - + " function test() {\n" - + " var e = document.getElementById('myAnchor');\n" - + " e.addEventListener('click', clicking1, false);\n" - + " e.addEventListener('click', clicking2, false);\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + " <a href='" + URL_SECOND + "' id='myAnchor'>Click me</a>\n" - + "</body></html>"; - - final List<String> collectedAlerts = new ArrayList<>(); - final HtmlPage page = loadPage(html, collectedAlerts); - final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); - //IE doesn't have specific order - Collections.sort(collectedAlerts); - assertEquals(getExpectedAlerts(), collectedAlerts); - assertEquals(URL_SECOND.toExternalForm(), page2.getUrl().toExternalForm()); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({"1", "2"}) - public void eventListener_return_false() throws Exception { - final String html - = "<html><head>\n" - + "<script>\n" - + " function clicking1() {\n" - + " alert(1);\n" - + " }\n" - + " function clicking2() {\n" - + " alert(2);\n" - + " return false;\n" - + " }\n" - + " function test() {\n" - + " var e = document.getElementById('myAnchor');\n" - + " e.addEventListener('click', clicking1, false);\n" - + " e.addEventListener('click', clicking2, false);\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + " <a href='" + URL_SECOND + "' id='myAnchor'>Click me</a>\n" - + "</body></html>"; - - final List<String> collectedAlerts = new ArrayList<>(); - final HtmlPage page = loadPage(html, collectedAlerts); - final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); - //IE doesn't have specific order - Collections.sort(collectedAlerts); - assertEquals(getExpectedAlerts(), collectedAlerts); - - final URL expectedURL; - if (getBrowserVersion().isIE()) { - expectedURL = URL_FIRST; - } - else { - expectedURL = URL_SECOND; - } - assertEquals(expectedURL.toExternalForm(), page2.getUrl().toExternalForm()); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({"1", "2", "§§URL§§second/"}) - public void eventListener_returnValue_false() throws Exception { - final String html - = "<html><head>\n" - + "<script>\n" - + " function clicking1() {\n" - + " alert(1);\n" - + " }\n" - + " function clicking2() {\n" - + " alert(2);\n" - + " if (window.event)\n" - + " window.event.returnValue = false;\n" - + " }\n" - + " function test() {\n" - + " var e = document.getElementById('myAnchor');\n" - + " e.addEventListener('click', clicking1, false);\n" - + " e.addEventListener('click', clicking2, false);\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + " <a href='" + URL_SECOND + "' id='myAnchor'>Click me</a>\n" - + "</body></html>"; - - expandExpectedAlertsVariables(URL_FIRST); - - final List<String> collectedAlerts = new ArrayList<>(); - final HtmlPage page = loadPage(html, collectedAlerts); - final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); - //IE doesn't have specific order - Collections.sort(collectedAlerts); - assertEquals(ArrayUtils.subarray(getExpectedAlerts(), 0, 2), collectedAlerts); - - assertEquals(getExpectedAlerts()[2], page2.getUrl().toExternalForm()); - } - } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeTest.java 2018-08-17 19:48:56 UTC (rev 15529) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeTest.java 2018-08-20 06:39:52 UTC (rev 15530) @@ -19,6 +19,7 @@ import static com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callLoadXMLDocumentFromString; import static com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest.callSerializeXMLDocumentToString; +import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -1279,4 +1280,110 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"1", "2", "§§URL§§second"}) + public void eventListener() throws Exception { + final String html + = "<html><head>\n" + + "<script>\n" + + " function clicking1() {\n" + + " alert(1);\n" + + " }\n" + + " function clicking2() {\n" + + " alert(2);\n" + + " }\n" + + " function test() {\n" + + " var e = document.getElementById('myAnchor');\n" + + " e.addEventListener('click', clicking1, false);\n" + + " e.addEventListener('click', clicking2, false);\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <a href='second' id='myAnchor'>Click me</a>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse("<html><body>Test</body></html>"); + expandExpectedAlertsVariables(URL_FIRST); + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("myAnchor")).click(); + verifyAlerts(driver, ArrayUtils.subarray(getExpectedAlerts(), 0, 2)); + Thread.sleep(200); // FF60 WebDriver + assertEquals(getExpectedAlerts()[2], driver.getCurrentUrl()); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"1", "2", "§§URL§§second"}) + public void eventListener_return_false() throws Exception { + final String html + = "<html><head>\n" + + "<script>\n" + + " function clicking1() {\n" + + " alert(1);\n" + + " }\n" + + " function clicking2() {\n" + + " alert(2);\n" + + " return false;\n" + + " }\n" + + " function test() {\n" + + " var e = document.getElementById('myAnchor');\n" + + " e.addEventListener('click', clicking1, false);\n" + + " e.addEventListener('click', clicking2, false);\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <a href='second' id='myAnchor'>Click me</a>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse("<html><body>Test</body></html>"); + expandExpectedAlertsVariables(URL_FIRST); + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("myAnchor")).click(); + verifyAlerts(driver, ArrayUtils.subarray(getExpectedAlerts(), 0, 2)); + Thread.sleep(200); // FF60 WebDriver + assertEquals(getExpectedAlerts()[2], driver.getCurrentUrl()); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"1", "2", "§§URL§§second"}, + CHROME = {"1", "2", "§§URL§§"}) + public void eventListener_returnValue_false() throws Exception { + final String html + = "<html><head>\n" + + "<script>\n" + + " function clicking1() {\n" + + " alert(1);\n" + + " }\n" + + " function clicking2() {\n" + + " alert(2);\n" + + " if (window.event)\n" + + " window.event.returnValue = false;\n" + + " }\n" + + " function test() {\n" + + " var e = document.getElementById('myAnchor');\n" + + " e.addEventListener('click', clicking1, false);\n" + + " e.addEventListener('click', clicking2, false);\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + " <a href='second' id='myAnchor'>Click me</a>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse("<html><body>Test</body></html>"); + expandExpectedAlertsVariables(URL_FIRST); + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("myAnchor")).click(); + verifyAlerts(driver, ArrayUtils.subarray(getExpectedAlerts(), 0, 2)); + Thread.sleep(200); // FF60 WebDriver + assertEquals(getExpectedAlerts()[2], driver.getCurrentUrl()); + } } |
From: <rb...@us...> - 2018-08-20 17:30:09
|
Revision: 15531 http://sourceforge.net/p/htmlunit/code/15531 Author: rbri Date: 2018-08-20 17:30:03 +0000 (Mon, 20 Aug 2018) Log Message: ----------- next step in event refactoring (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 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-20 06:39:52 UTC (rev 15530) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-08-20 17:30:03 UTC (rev 15531) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.event; -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.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; @@ -21,7 +20,6 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE; -import java.lang.reflect.Method; import java.util.LinkedList; import com.gargoylesoftware.htmlunit.ScriptResult; @@ -35,6 +33,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; @@ -181,6 +180,7 @@ private boolean stopPropagation_; private boolean stopImmediatePropagation_; private boolean preventDefault_; + private boolean returnValue_; /** * The current event phase. This is a W3C standard attribute. One of {@link #NONE}, @@ -229,6 +229,8 @@ target_ = target; currentTarget_ = target; type_ = type; + returnValue_ = true; + setParentScope(target); setPrototype(getPrototype(getClass())); @@ -268,6 +270,7 @@ public void eventCreated() { setBubbles(false); setCancelable(false); + returnValue_ = true; } /** @@ -609,17 +612,7 @@ type_ = type; bubbles_ = bubbles; cancelable_ = cancelable; - if (TYPE_BEFORE_UNLOAD.equals(type) && getBrowserVersion().hasFeature(EVENT_FOCUS_FOCUS_IN_BLUR_OUT)) { - try { - final Class<?> klass = getClass(); - final Method readMethod = klass.getMethod("getReturnValue"); - final Method writeMethod = klass.getMethod("setReturnValue", Object.class); - defineProperty("returnValue", null, readMethod, writeMethod, ScriptableObject.EMPTY); - } - catch (final Exception e) { - throw Context.throwAsScriptRuntimeEx(e); - } - } + returnValue_ = true; } /** @@ -668,4 +661,20 @@ public boolean processLabelAfterBubbling() { return false; } + + /** + * @return the return value property + */ + @JsxGetter(CHROME) + public Object getReturnValue() { + return returnValue_; + } + + /** + * @param newValue the new return value + */ + @JsxSetter(CHROME) + public void setReturnValue(final Object newValue) { + returnValue_ = ScriptRuntime.toBoolean(newValue); + } } 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-20 06:39:52 UTC (rev 15530) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-20 17:30:03 UTC (rev 15531) @@ -2164,7 +2164,7 @@ + " 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.onclick = function () { log('d2 onclick'); if (d2.parentNode) 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" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 2018-08-20 06:39:52 UTC (rev 15530) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 2018-08-20 17:30:03 UTC (rev 15531) @@ -969,4 +969,72 @@ verifyAlerts(driver, getExpectedAlerts()); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"undefined", "undefined"}, + CHROME = {"true", "boolean"}) + public void returnValue() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " try {\n" + + " var event = document.createEvent('Event');\n" + + " alert(event.returnValue);\n" + + " alert(typeof event.returnValue);\n" + + " } catch (e) { alert('exception') }\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"undefined", "undefined", + "false", "boolean", + "undefined", "undefined", + "test", "string", + "0", "number"}, + CHROME = {"true", "boolean", + "false", "boolean", + "false", "boolean", + "true", "boolean", + "false", "boolean"}) + public void returnValueSetter() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " try {\n" + + " var event = document.createEvent('Event');\n" + + " alert(event.returnValue);\n" + + " alert(typeof event.returnValue);\n" + + + " event.returnValue = false;\n" + + " alert(event.returnValue);\n" + + " alert(typeof event.returnValue);\n" + + + " event.returnValue = undefined;\n" + + " alert(event.returnValue);\n" + + " alert(typeof event.returnValue);\n" + + + " event.returnValue = 'test';\n" + + " alert(event.returnValue);\n" + + " alert(typeof event.returnValue);\n" + + + " event.returnValue = 0;\n" + + " alert(event.returnValue);\n" + + " alert(typeof event.returnValue);\n" + + " } catch (e) { alert('exception') }\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-08-20 17:36:24
|
Revision: 15532 http://sourceforge.net/p/htmlunit/code/15532 Author: rbri Date: 2018-08-20 17:36:20 +0000 (Mon, 20 Aug 2018) Log Message: ----------- preventDefault is available in Chrome also Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 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-20 17:30:03 UTC (rev 15531) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-08-20 17:36:20 UTC (rev 15532) @@ -529,7 +529,7 @@ * called for this event. Otherwise this attribute must return {@code false}. * @return {@code true} if this event has been cancelled or not */ - @JsxGetter({FF, IE, EDGE}) + @JsxGetter public boolean isDefaultPrevented() { return cancelable_ && preventDefault_; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 2018-08-20 17:30:03 UTC (rev 15531) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 2018-08-20 17:36:20 UTC (rev 15532) @@ -974,6 +974,27 @@ * @throws Exception if the test fails */ @Test + @Alerts({"false", "boolean"}) + public void defaultPrevented() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head><title>foo</title><script>\n" + + " function test() {\n" + + " try {\n" + + " var event = document.createEvent('Event');\n" + + " alert(event.defaultPrevented);\n" + + " alert(typeof event.defaultPrevented);\n" + + " } catch (e) { alert('exception') }\n" + + " }\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = {"undefined", "undefined"}, CHROME = {"true", "boolean"}) public void returnValue() throws Exception { |
From: <rb...@us...> - 2018-08-20 17:58:02
|
Revision: 15533 http://sourceforge.net/p/htmlunit/code/15533 Author: rbri Date: 2018-08-20 17:57:58 +0000 (Mon, 20 Aug 2018) Log Message: ----------- next step in event refactoring (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 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-20 17:36:20 UTC (rev 15532) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event.java 2018-08-20 17:57:58 UTC (rev 15533) @@ -676,5 +676,6 @@ @JsxSetter(CHROME) public void setReturnValue(final Object newValue) { returnValue_ = ScriptRuntime.toBoolean(newValue); + preventDefault_ = !returnValue_; } } 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-20 17:36:20 UTC (rev 15532) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2018-08-20 17:57:58 UTC (rev 15533) @@ -2191,11 +2191,28 @@ * @throws Exception if the test fails */ @Test - @Alerts({"listener: stop propagation & return false", + @Alerts(DEFAULT = {"listener: stop propagation & return false", "FIRED a1", "listener: return true", "property: return false", - "listener: return true"}) + "listener: return true", + "listener: prevented=false returnValue: undefined -> false (false)", + "listener: prevented=false returnValue: false -> true (true)", + "listener: prevented=false returnValue: true -> preventDefault() (true)", + "property: prevented=true returnValue: true -> return true", + "listener: prevented=true returnValue: true -> x (x)", + "listener: prevented=true returnValue: x -> null (null)"}, + CHROME = {"listener: stop propagation & return false", + "FIRED a1", + "listener: return true", + "property: return false", + "listener: return true", + "listener: prevented=false returnValue: true -> false (false)", + "listener: prevented=true returnValue: false -> true (true)", + "listener: prevented=false returnValue: true -> preventDefault() (false)", + "property: prevented=true returnValue: false -> return true", + "listener: prevented=true returnValue: false -> x (true)", + "listener: prevented=false returnValue: true -> null (false)"}) public void stopPropagation() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" @@ -2208,6 +2225,7 @@ + "<body>\n" + " <div><a id='a1' href='javascript:log(\"FIRED a1\")'>test: listener return false</a></div>\n" + " <div><a id='a2' href='javascript:log(\"FIRED a2\")'>test: property return false</a></div>\n" + + " <div><a id='a3' href='javascript:log(\"FIRED a3\")'>test: listener returnValue = false</a></div>\n" + " <textarea id='log' rows=40 cols=80></textarea>\n" @@ -2218,20 +2236,58 @@ + "log('listener: stop propagation & return false');" + "event.stopPropagation(); return false })\n" - // The only return value that matters is the value from the 'onclick' property. The 'return false' below - // prevents "href' being processed. - + " a2.addEventListener('click'," - + " function (event) { log('listener: return true'); event.stopPropagation(); return true })\n" - + " a2.onclick = function () { log('property: return false'); return false }\n" - + " a2.addEventListener('click', function (event) { log('listener: return true'); return true })\n" + // The only return value that matters is the value from the 'onclick' property. The 'return false' below + // prevents "href' being processed. + + " a2.addEventListener('click'," + + " function (event) { log('listener: return true'); event.stopPropagation(); return true })\n" + + " a2.onclick = function () { log('property: return false'); return false }\n" + + " a2.addEventListener('click', function (event) { log('listener: return true'); return true })\n" - // Uncommenting this causes a2 to fire because propagation is - // stopped before 'onclick' property is processed. - // Again, the 'return false' here is ineffective. - // The return values of non-property handlers are probably ignored. (tested in Chrome/FF) - //window.addEventListener("click", function (event) { - // log('window: stop propagation & return false'); - // event.stopPropagation(); return false }, true) + // Uncommenting this causes a2 to fire because propagation is + // stopped before 'onclick' property is processed. + // Again, the 'return false' here is ineffective. + // The return values of non-property handlers are probably ignored. (tested in Chrome/FF) + //window.addEventListener("click", function (event) { + // log('window: stop propagation & return false'); + // event.stopPropagation(); return false }, true) + + // In Chrome/Edge, this sets event.returnValue to 'false' + // which is synonymous with setting 'event.defaultPrevented' + // In FF/IE11, event.returnValue is settable but does not appear to be used for anything + + " a3.addEventListener('click', function (event) {" + + " var a = event.returnValue, p = event.defaultPrevented, b = false; event.returnValue = b;" + + " log('listener: prevented=' + p + ' returnValue: ' + a " + + "+ ' -> ' + b + ' (' + event.returnValue + ')') })\n" + // This shows it's possible to set event.returnValue back to 'true' from 'false' + + " a3.addEventListener('click', function (event) {" + + " var a = event.returnValue, p = event.defaultPrevented, b = true; event.returnValue = b;" + + " log('listener: prevented=' + p + ' returnValue: ' + a " + + "+ ' -> ' + b + ' (' + event.returnValue + ')') })\n" + // The value of event.returnValue is consistent across multiple listener calls of the same event + + " a3.addEventListener('click', function (event) {" + + " var a = event.returnValue, p = event.defaultPrevented, " + + "b = 'preventDefault()'; event.preventDefault();" + + " log('listener: prevented=' + p + ' returnValue: ' + a " + + "+ ' -> ' + b + ' (' + event.returnValue + ')') })\n" + // This shows a property handler returning 'true' will not change event.returnValue if it's already 'false' + + " a3.onclick = function (event) {" + + " var a = event.returnValue, p = event.defaultPrevented; b = true;" + + " log('property: prevented=' + p + ' returnValue: ' + a + ' -> return ' + b); return b }\n" + // Instead of returning 'true', the property handler can directly set + // event.returnValue to set it to 'true' from 'false' + //+ " a3.onclick = function (event) {" + //+ " var a = event.returnValue, p = event.defaultPrevented; b = true;" + //+ " log('property: prevented=' + p + ' returnValue: ' + a + ' -> true'); event.returnValue = b }\n" + // These shows setting event.returnValue cannot be set to a non-boolean + // value in Chrome/Edge but can in (FF/IE11) + + " a3.addEventListener('click', function (event) {" + + " var a = event.returnValue, p = event.defaultPrevented, b = 'x'; event.returnValue = b;" + + " log('listener: prevented=' + p + ' returnValue: ' + a " + + "+ ' -> ' + b + ' (' + event.returnValue + ')') })\n" + + " a3.addEventListener('click', function (event) {" + + " var a = event.returnValue, p = event.defaultPrevented, b = null; event.returnValue = b;" + + " log('listener: prevented=' + p + ' returnValue: ' + a " + + "+ ' -> ' + b + ' (' + event.returnValue + ')') })\n" + "</script>\n" + "</body></html>"; @@ -2238,6 +2294,7 @@ final WebDriver driver = loadPage2(html); driver.findElement(By.id("a1")).click(); driver.findElement(By.id("a2")).click(); + driver.findElement(By.id("a3")).click(); final String text = driver.getTitle().trim().replaceAll(";", "\n").trim(); assertEquals(String.join("\n", getExpectedAlerts()), text); |
From: <rb...@us...> - 2018-08-23 07:21:24
|
Revision: 15537 http://sourceforge.net/p/htmlunit/code/15537 Author: rbri Date: 2018-08-23 07:21:10 +0000 (Thu, 23 Aug 2018) Log Message: ----------- switch to rhino for the typed arrays Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/ImageData.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/Crypto.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8Array.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArray.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1363,10 +1363,6 @@ @BrowserFeature(IE) JS_TREEWALKER_FILTER_FUNCTION_ONLY, - /** Types arrays can be constructed with {@code null}. */ - @BrowserFeature({CHROME, FF60}) - JS_TYPED_ARRAYS_NULL, - /** Setting the property align to arbitrary values is allowed. */ @BrowserFeature({CHROME, FF}) JS_TYPE_ACCEPTS_ARBITRARY_VALUES, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -81,19 +81,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.XPathExpression; import com.gargoylesoftware.htmlunit.javascript.host.webkitURL; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBuffer; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferView; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferViewBase; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.DataView; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Float32Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Float64Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Int16Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Int32Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Int8Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint16Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint32Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint8Array; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.Uint8ClampedArray; import com.gargoylesoftware.htmlunit.javascript.host.budget.BudgetService; import com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasCaptureMediaStream; import com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasCaptureMediaStreamTrack; @@ -614,14 +601,7 @@ WebSocket.class, WheelEvent.class, Window.class, Worker.class, XMLDocument.class, XMLHttpRequest.class, XMLHttpRequestEventTarget.class, XMLHttpRequestUpload.class, XMLSerializer.class, XPathEvaluator.class, XPathExpression.class, - XPathNSResolver.class, XPathResult.class, XSLTProcessor.class, - - // we will use the Rhino stuff as soon as possible - ArrayBuffer.class, ArrayBufferView.class, ArrayBufferViewBase.class, - DataView.class, - Float32Array.class, Float64Array.class, - Int16Array.class, Int32Array.class, Int8Array.class, - Uint16Array.class, Uint32Array.class, Uint8Array.class, Uint8ClampedArray.class + XPathNSResolver.class, XPathResult.class, XSLTProcessor.class }; /** Cache of browser versions and their corresponding JavaScript configurations. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextDecoder.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -26,12 +26,12 @@ 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.host.arrays.ArrayBuffer; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBufferView; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Undefined; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBufferView; /** * A JavaScript object for {@code TextDecoder}. @@ -388,16 +388,16 @@ return ""; } - ArrayBuffer arrayBuffer = null; - if (buffer instanceof ArrayBuffer) { - arrayBuffer = (ArrayBuffer) buffer; + NativeArrayBuffer arrayBuffer = null; + if (buffer instanceof NativeArrayBuffer) { + arrayBuffer = (NativeArrayBuffer) buffer; } - else if (buffer instanceof ArrayBufferView) { - arrayBuffer = ((ArrayBufferView) buffer).getBuffer(); + else if (buffer instanceof NativeArrayBufferView) { + arrayBuffer = ((NativeArrayBufferView) buffer).getBuffer(); } if (arrayBuffer != null) { - return new String(arrayBuffer.getBytes(), Charset.forName(encoding_)); + return new String(arrayBuffer.getBuffer(), Charset.forName(encoding_)); } throw ScriptRuntime.typeError("Argument 1 of TextDecoder.decode could not be" Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoder.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -24,10 +24,12 @@ 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.host.arrays.Uint8Array; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import net.sourceforge.htmlunit.corejs.javascript.Undefined; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8Array; /** * A JavaScript object for {@code TextEncoder}. @@ -58,9 +60,12 @@ * @return returns a Uint8Array containing the text given encoded . */ @JsxFunction - public Uint8Array encode(final Object toEncode) { + public NativeUint8Array encode(final Object toEncode) { if (Undefined.instance == toEncode) { - return new Uint8Array(new byte[0], getWindow()); + final NativeUint8Array result = new NativeUint8Array(0); + result.setParentScope(getParentScope()); + result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); + return result; } final String txt; @@ -72,6 +77,13 @@ } final byte[] bytes = txt.getBytes(StandardCharsets.UTF_8); - return new Uint8Array(bytes, getWindow()); + + final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes.length); + System.arraycopy(bytes, 0, arrayBuffer.getBuffer(), 0, bytes.length); + + final NativeUint8Array result = new NativeUint8Array(arrayBuffer, 0, bytes.length); + result.setParentScope(getParentScope()); + result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName())); + return result; } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -17,7 +17,6 @@ import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.concurrent.Future; import org.apache.commons.lang3.ArrayUtils; @@ -41,7 +40,6 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; -import com.gargoylesoftware.htmlunit.javascript.host.arrays.ArrayBuffer; import com.gargoylesoftware.htmlunit.javascript.host.event.CloseEvent; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; @@ -51,7 +49,9 @@ import net.sourceforge.htmlunit.corejs.javascript.Function; 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; +import net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer; /** * A JavaScript object for {@code WebSocket}. @@ -391,8 +391,8 @@ if (content instanceof String) { outgoingSession_.getRemote().sendString((String) content); } - else if (content instanceof ArrayBuffer) { - final byte[] bytes = ((ArrayBuffer) content).getBytes(); + else if (content instanceof NativeArrayBuffer) { + final byte[] bytes = ((NativeArrayBuffer) content).getBuffer(); final ByteBuffer buffer = ByteBuffer.wrap(bytes); outgoingSession_.getRemote().sendBytes(buffer); } @@ -460,9 +460,10 @@ } super.onWebSocketBinary(data, offset, length); - final ArrayBuffer buffer = new ArrayBuffer(Arrays.copyOfRange(data, offset, length)); + final NativeArrayBuffer buffer = new NativeArrayBuffer(length); + System.arraycopy(data, offset, buffer.getBuffer(), 0, length); buffer.setParentScope(getParentScope()); - buffer.setPrototype(getPrototype(buffer.getClass())); + buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); final MessageEvent msgEvent = new MessageEvent(buffer); msgEvent.setOrigin(getUrl()); Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBuffer.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,148 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; - -import net.sourceforge.htmlunit.corejs.javascript.Context; -import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; - -/** - * A data type that is used to represent a generic, fixed-length binary data buffer. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - */ -@JsxClass -public class ArrayBuffer extends SimpleScriptable { - - private byte[] bytes_; - - /** - * Ctor. - */ - public ArrayBuffer() { - } - - /** - * Ctor with given bytes. - * @param bytes the initial bytes - */ - public ArrayBuffer(final byte[] bytes) { - bytes_ = bytes; - } - - /** - * The constructor. - * @param length the size, in bytes, of the array buffer to create. - */ - @JsxConstructor - public void constructor(final int length) { - if (length < 0) { - throw ScriptRuntime.rangeError("invalid array length '" + length + "'."); - } - bytes_ = new byte[length]; - } - - /** - * Returns the size, in bytes, of the array. This is established during construction and cannot be changed. - * @return the byte length. - */ - @JsxGetter - public int getByteLength() { - return bytes_.length; - } - - /** - * Returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes - * from begin, inclusive, up to end, exclusive. - * @param begin byte index to start slicing - * @param end (optional) byte index to end slicing - * @return the newly created ArrayBuffer - */ - @JsxFunction - public ArrayBuffer slice(final Object begin, final Object end) { - if (begin == Undefined.instance || begin instanceof Boolean) { - throw Context.reportRuntimeError("Invalid type " + begin.getClass().getName()); - } - - final double beginNumber = Context.toNumber(begin); - final int beginInt; - if (Double.isNaN(beginNumber)) { - beginInt = 0; - } - else if (Double.isInfinite(beginNumber)) { - if (beginNumber > 0) { - final byte[] byteArray = new byte[0]; - return new ArrayBuffer(byteArray); - } - beginInt = 0; - } - else { - beginInt = (int) beginNumber; - if (beginInt != beginNumber) { - throw Context.reportRuntimeError("Invalid type " + begin.getClass().getName()); - } - } - - double endNumber; - if (end == Undefined.instance) { - endNumber = getByteLength(); - } - else { - endNumber = Context.toNumber(end); - } - - if (Double.isNaN(endNumber) || Double.isInfinite(endNumber) || endNumber < beginInt) { - endNumber = beginInt; - } - - final byte[] byteArray = new byte[(int) endNumber - beginInt]; - System.arraycopy(bytes_, beginInt, byteArray, 0, byteArray.length); - return new ArrayBuffer(byteArray); - } - - byte getByte(final int index) { - return bytes_[index]; - } - - /** - * Sets the bytes. - * @param index the starting index - * @param array the array - */ - public void setBytes(final int index, final byte[] array) { - int i = array.length - 1; - if (index + i >= bytes_.length) { - i = bytes_.length - index - 1; - } - for ( ; i >= 0; i--) { - bytes_[index + i] = array[i]; - } - } - - /** - * @return the bytes - */ - public byte[] getBytes() { - return bytes_; - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferView.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,88 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; - -/** - * The ArrayBufferView type describes a particular view on the contents of an {@link ArrayBuffer}'s data. - * - * @author Ahmed Ashour - * @author Frank Danek - */ -@JsxClass(isJSObject = false) -public class ArrayBufferView extends SimpleScriptable { - - private ArrayBuffer buffer_; - private int byteLength_; - private int byteOffset_; - - /** - * The constructor. - * @param buffer the array buffer - * @param byteOffset the byte offset - * @param length the length - */ - protected void constructor(final ArrayBuffer buffer, final int byteOffset, final int length) { - buffer_ = buffer; - byteOffset_ = byteOffset; - byteLength_ = length; - } - - /** - * Returns the buffer this view references. - * @return the buffer - */ - @JsxGetter - public ArrayBuffer getBuffer() { - return buffer_; - } - - /** - * Sets the buffer. - * @param buffer the buffer - */ - protected void setBuffer(final ArrayBuffer buffer) { - buffer_ = buffer; - } - - /** - * Returns the length, in bytes, of the view. - * @return the length - */ - @JsxGetter - public int getByteLength() { - return byteLength_; - } - - /** - * Sets the bytes length. - * @param byteLength the bytes length - */ - protected void setByteLength(final int byteLength) { - byteLength_ = byteLength; - } - - /** - * Returns the offset, in bytes, to the first byte of the view within the {@link ArrayBuffer}. - * @return the offset - */ - @JsxGetter - public int getByteOffset() { - return byteOffset_; - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/ArrayBufferViewBase.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,245 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TYPED_ARRAYS_NULL; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; - -import net.sourceforge.htmlunit.corejs.javascript.Context; -import net.sourceforge.htmlunit.corejs.javascript.NativeArray; -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; -import net.sourceforge.htmlunit.corejs.javascript.Wrapper; - -/** - * The parent class of all typed arrays, {@link DataView} is not included. - * - * @author Ahmed Ashour - * @author Marc Guillemot - * @author Frank Danek - * @author Ronald Brill - */ -@JsxClass(isJSObject = false) -public class ArrayBufferViewBase extends ArrayBufferView { - - /** - * The constructor. - * - * @param object the object - * @param byteOffset optional byteOffset - * @param length optional length - */ - public void constructor(final Object object, final Object byteOffset, final Object length) { - if (object instanceof Number) { - constructor(((Number) object).intValue()); - } - else if (object instanceof NativeArray) { - constructor((NativeArray) object); - } - else if (object instanceof ArrayBufferViewBase) { - constructor((ArrayBufferViewBase) object); - } - else if (object instanceof ArrayBuffer) { - final ArrayBuffer array = (ArrayBuffer) object; - - double dbByteOffset = Context.toNumber(byteOffset); - if (Double.isNaN(dbByteOffset)) { - dbByteOffset = 0; - } - - double dbLength = Context.toNumber(length); - if (Double.isNaN(dbLength)) { - dbLength = array.getByteLength(); - } - super.constructor(array, (int) dbByteOffset, (int) dbLength); - } - else if (object == Undefined.instance || getBrowserVersion().hasFeature(JS_TYPED_ARRAYS_NULL)) { - constructor(0); - } - else { - throw ScriptRuntime.typeError("invalid arguments"); - } - } - - private void constructor(final int length) { - final int byteLength = length * getBytesPerElement(); - setByteLength(byteLength); - initBuffer(byteLength); - } - - private void constructor(final NativeArray array) { - final int byteLength = (int) array.getLength() * getBytesPerElement(); - setByteLength(byteLength); - initBuffer(byteLength); - set(array, 0); - } - - private void constructor(final ArrayBufferViewBase array) { - final int byteLength = array.getLength() * getBytesPerElement(); - setByteLength(byteLength); - initBuffer(byteLength); - set(array, 0); - } - - private void initBuffer(final int lengthInBytes) { - final ArrayBuffer buffer = new ArrayBuffer(); - buffer.constructor(lengthInBytes); - buffer.setPrototype(getPrototype(buffer.getClass())); - buffer.setParentScope(getParentScope()); - setBuffer(buffer); - } - - /** - * Returns the number of entries in the array. - * @return the number of entries - */ - @JsxGetter - public int getLength() { - return getByteLength() / getBytesPerElement(); - } - - /** - * Sets multiple values in the typed array, reading input values from a specified array. - * @param sourceArray the source array - * @param offset the offset into the target array at which to begin writing values from the source one - */ - @JsxFunction - public void set(final ScriptableObject sourceArray, final int offset) { - final Object lengthProperty = ScriptableObject.getProperty(sourceArray, "length"); - if (lengthProperty instanceof Number) { - final int length = ((Number) lengthProperty).intValue(); - for (int i = 0; i < length; i++) { - final Object value = sourceArray.get(i, sourceArray); - if (value == Scriptable.NOT_FOUND || value == Undefined.instance) { - put(i + offset, this, Double.NaN); - } - else if (value == null) { - put(i + offset, this, 0); - } - else if (value instanceof Wrapper) { - put(i + offset, this, ((Wrapper) value).unwrap()); - } - else { - put(i + offset, this, value); - } - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public Object get(final int index, final Scriptable start) { - final int offset = index * getBytesPerElement() + getByteOffset(); - final ArrayBuffer buffer = getBuffer(); - if (buffer == null) { - return Scriptable.NOT_FOUND; - } - return fromArray(buffer.getBytes(), offset); - } - - /** - * {@inheritDoc} - */ - @Override - public void put(final int index, final Scriptable start, final Object value) { - getBuffer().setBytes(index * getBytesPerElement() + getByteOffset(), - value == null ? toByteArray(null) : toByteArray(Context.toNumber(value))); - } - - /** - * Converts the provided number to byte array. - * @param number the number - * @return the byte array - */ - protected byte[] toByteArray(final Number number) { - return null; - } - - /** - * Converts the provided byte array to number. - * @param array the array - * @param offset the offset - * @return the byte array - */ - protected Object fromArray(final byte[] array, final int offset) { - return null; - } - - /** - * Returns a new view on the ArrayBuffer store for this object. - * @param begin the offset to the first element in the array to be referenced by the new object - * @param end the end offset (exclusive), optional to return at the end. - * @return the newly created array - */ - @JsxFunction - public ArrayBufferView subarray(final int begin, Object end) { - if (end == Undefined.instance) { - end = getLength(); - } - try { - final ArrayBufferView object = getClass().newInstance(); - object.setPrototype(getPrototype()); - object.setParentScope(getParentScope()); - object.constructor(getBuffer(), begin, ((Number) end).intValue() - begin); - return object; - } - catch (final Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Returns the size in bytes of an item in this array. - * @return the size of bytes of an item - */ - protected int getBytesPerElement() { - return 1; - } - - /** - * @return the string version - */ - @JsxFunction(functionName = "toString") - public String jsToString() { - final int arrayLength = getLength(); - final StringBuilder builder = new StringBuilder(); - if (arrayLength > 0) { - builder.append(ScriptRuntime.toString(get(0, this))); - } - for (int i = 1; i < arrayLength; i++) { - builder.append(','); - builder.append(ScriptRuntime.toString(get(i, this))); - } - return builder.toString(); - } - - /** - * {@inheritDoc} - */ - @Override - public Object getDefaultValue(final Class<?> hint) { - if (String.class.equals(hint) || hint == null) { - return jsToString(); - } - return super.getDefaultValue(hint); - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/DataView.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,265 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; - -import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; - -/** - * The ArrayBufferView type describes a particular view on the contents of an {@link ArrayBuffer}'s data. - * - * @author Ahmed Ashour - * @author Frank Danek - */ -@JsxClass -public class DataView extends ArrayBufferView { - - /** - * JavaScript constructor. - * @param array the array - * @param byteOffset the byte offset - * @param length the length - */ - @JsxConstructor - public void constructor(final Object array, final int byteOffset, Object length) { - if (!(array instanceof ArrayBuffer)) { - throw ScriptRuntime.typeError("First argument to DataView constructor must be an ArrayBuffer"); - } - if (length == Undefined.instance) { - length = ((ArrayBuffer) array).getByteLength(); - } - super.constructor((ArrayBuffer) array, byteOffset, ((Number) length).intValue()); - } - - /** - * Gets a signed 8-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @return the byte - */ - @JsxFunction - public byte getInt8(final int byteOffset) { - return getBuffer().getBytes()[getByteOffset() + byteOffset]; - } - - /** - * Sets the given signed 8-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - */ - @JsxFunction - public void setInt8(final int byteOffset, final int value) { - final byte[] array = getBuffer().getBytes(); - array[getByteOffset() + byteOffset] = (byte) value; - } - - /** - * Gets a signed 16-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public short getInt16(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getShort(getByteOffset() + byteOffset); - } - - /** - * Sets the given signed 16-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setInt16(final int byteOffset, final int value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putShort(getByteOffset() + byteOffset, (short) value); - } - - /** - * Gets a signed 32-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public int getInt32(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getInt(getByteOffset() + byteOffset); - } - - /** - * Sets the given signed 32-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setInt32(final int byteOffset, final int value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putInt(getByteOffset() + byteOffset, value); - } - - /** - * Gets an unsigned 8-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @return the value - */ - @JsxFunction - public int getUint8(final int byteOffset) { - return getBuffer().getBytes()[getByteOffset() + byteOffset] & 0xFF; - } - - /** - * Sets the given unsigned 8-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - */ - @JsxFunction - public void setUint8(final int byteOffset, final int value) { - setInt8(byteOffset, value); - } - - /** - * Gets an unsigned 16-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public int getUint16(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getShort(getByteOffset() + byteOffset) & 0xFFFF; - } - - /** - * Sets the given unsigned 16-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setUint16(final int byteOffset, final int value, final boolean littleEndian) { - setInt16(byteOffset, value, littleEndian); - } - - /** - * Gets an unsigned 32-bit integer at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public long getUint32(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getInt(getByteOffset() + byteOffset) & 0xFFFFFFFFL; - } - - /** - * Sets the given unsigned 32-bit integer at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setUint32(final int byteOffset, final int value, final boolean littleEndian) { - setInt32(byteOffset, value, littleEndian); - } - - /** - * Gets a 32-bit floating point number at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public float getFloat32(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getFloat(getByteOffset() + byteOffset); - } - - /** - * Sets the given 32-bit floating point number at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setFloat32(final int byteOffset, final double value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putFloat(getByteOffset() + byteOffset, (float) value); - } - - /** - * Gets a 64-bit floating point number at the specified byte offset from the start of the view. - * @param byteOffset the byte offset - * @param littleEndian whether the value is stored in little- or big-endian format - * @return the value - */ - @JsxFunction - public double getFloat64(final int byteOffset, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - return buff.getDouble(getByteOffset() + byteOffset); - } - - /** - * Sets the given 32-bit floating point number at the specified offset. - * @param byteOffset the byte offset - * @param value the value - * @param littleEndian whether the value is stored in little- or big-endian format - */ - @JsxFunction - public void setFloat64(final int byteOffset, final double value, final boolean littleEndian) { - final ByteBuffer buff = ByteBuffer.wrap(getBuffer().getBytes()); - if (littleEndian) { - buff.order(ByteOrder.LITTLE_ENDIAN); - } - buff.putDouble(getByteOffset() + byteOffset, value); - } -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,82 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of 32-bit floating point numbers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Float32Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 4; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - buff.putFloat(number != null ? number.floatValue() : Float.NaN); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getFloat(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,82 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of 64-bit floating point numbers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Float64Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 8; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - buff.putDouble(number != null ? number.doubleValue() : Double.NaN); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getDouble(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of twos-complement 16-bit signed integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Int16Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 2; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - if (number == null || Double.isInfinite(number.doubleValue())) { - buff.putShort((short) 0); - return buff.array(); - } - buff.putShort(number.shortValue()); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getShort(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of twos-complement 32-bit signed integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Int32Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 4; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - if (number == null || Double.isInfinite(number.doubleValue())) { - buff.putInt(0); - return buff.array(); - } - buff.putInt(number.intValue()); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getInt(offset); - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,77 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of twos-complement 8-bit signed integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Int8Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 1; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - if (number == null || Double.isInfinite(number.doubleValue())) { - return new byte[] {0}; - } - return new byte[] {number.byteValue()}; - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - return array[offset]; - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * 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.javascript.host.arrays; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; - -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; - -/** - * Represents an array of unsigned 16-bit integers. - * - * @author Ahmed Ashour - * @author Frank Danek - * @author Ronald Brill - * @author Michael Rimov - */ -@JsxClass -public class Uint16Array extends ArrayBufferViewBase { - - /** The size, in bytes, of each array element. */ - @JsxConstant - public static final int BYTES_PER_ELEMENT = 2; - - /** - * {@inheritDoc} - */ - @Override - @JsxConstructor - public void constructor(final Object object, final Object byteOffset, final Object length) { - super.constructor(object, byteOffset, length); - } - - /** - * {@inheritDoc} - */ - @Override - protected byte[] toByteArray(final Number number) { - final ByteBuffer buff = ByteBuffer.allocate(BYTES_PER_ELEMENT); - buff.order(ByteOrder.LITTLE_ENDIAN); - if (number == null || Double.isInfinite(number.doubleValue())) { - buff.putShort((short) 0); - return buff.array(); - } - buff.putShort(number.shortValue()); - return buff.array(); - } - - /** - * {@inheritDoc} - */ - @Override - protected Object fromArray(final byte[] array, final int offset) { - if (offset < 0 || offset >= array.length) { - return Scriptable.NOT_FOUND; - } - final ByteBuffer buff = ByteBuffer.wrap(array); - buff.order(ByteOrder.LITTLE_ENDIAN); - return buff.getShort(offset) & 0xFFFF; - } - - /** - * {@inheritDoc} - */ - @Override - protected int getBytesPerElement() { - return BYTES_PER_ELEMENT; - } - -} Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java 2018-08-21 05:38:42 UTC (rev 15536) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32Array.java 2018-08-23 07:21:10 UTC (rev 15537) @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2002-2018 Garg... [truncated message content] |
From: <rb...@us...> - 2018-08-23 13:39:01
|
Revision: 15539 http://sourceforge.net/p/htmlunit/code/15539 Author: rbri Date: 2018-08-23 13:38:51 +0000 (Thu, 23 Aug 2018) Log Message: ----------- test fixes Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArrayTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/changes/changes.xml 2018-08-23 13:38:51 UTC (rev 15539) @@ -9,6 +9,9 @@ <body> <release version="2.33" date="xxxx, 2018" description="Bugfixes"> <action type="update" dev="rbri"> + We are using the typed array implementation from Rhino now, our own impl is gone. + </action> + <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"> Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ExternalTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -54,7 +54,7 @@ /** Gecko driver. */ static String GECKO_DRIVER_ = "0.21.0"; /** IE driver. */ - static String IE_DRIVER_ = "3.13.0.0"; + static String IE_DRIVER_ = "3.14.0.0"; /** * Tests that POM dependencies are the latest. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextEncoderTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -85,7 +85,7 @@ + "<body onload='doTest()'>\n" + "</body></html>"; - loadPageWithAlerts2(html, 7777777); + loadPageWithAlerts2(html); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float32ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -161,9 +165,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({TestedBrowser.FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -185,7 +190,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Float32Array]", "[object Float32Array]", + "[object Float32Array]", "[object Float32Array]", + "[object Float32Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -215,7 +224,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Float32Array") + @Alerts(DEFAULT = "Float32Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Float64ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -161,9 +165,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -185,7 +190,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Float64Array]", "[object Float64Array]", + "[object Float64Array]", "[object Float64Array]", + "[object Float64Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -215,7 +224,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Float64Array") + @Alerts(DEFAULT = "Float64Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int16ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -255,9 +259,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -279,7 +284,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Int16Array]", "[object Int16Array]", + "[object Int16Array]", "[object Int16Array]", + "[object Int16Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -309,7 +318,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Int16Array") + @Alerts(DEFAULT = "Int16Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int32ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -161,9 +165,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -185,7 +190,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Int32Array]", "[object Int32Array]", + "[object Int32Array]", "[object Int32Array]", + "[object Int32Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -215,7 +224,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Int32Array") + @Alerts(DEFAULT = "Int32Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Int8ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -229,9 +233,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -253,7 +258,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Int8Array]", "[object Int8Array]", + "[object Int8Array]", "[object Int8Array]", + "[object Int8Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -283,7 +292,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Int8Array") + @Alerts(DEFAULT = "Int8Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint16ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -162,9 +166,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -186,7 +191,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Uint16Array]", "[object Uint16Array]", + "[object Uint16Array]", "[object Uint16Array]", + "[object Uint16Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -216,7 +225,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Uint16Array") + @Alerts(DEFAULT = "Uint16Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint32ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -183,9 +187,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -207,7 +212,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Uint32Array]", "[object Uint32Array]", + "[object Uint32Array]", "[object Uint32Array]", + "[object Uint32Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -237,7 +246,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Uint32Array") + @Alerts(DEFAULT = "Uint32Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -162,9 +166,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({TestedBrowser.FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -237,7 +242,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Uint8Array]", "[object Uint8Array]", + "[object Uint8Array]", "[object Uint8Array]", + "[object Uint8Array]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -267,7 +276,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Uint8Array") + @Alerts(DEFAULT = "Uint8Array", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArrayTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/arrays/Uint8ClampedArrayTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.arrays; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -163,9 +167,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "0", - FF60 = "0") + @Alerts(DEFAULT = "0", + FF52 = "exception", + IE = "exception") + @NotYetImplemented({FF52, IE}) public void nullConstructor() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -187,7 +192,11 @@ * @throws Exception if the test fails */ @Test - @Alerts({"", "0", "1", "1,3", "1,3,4,7,11,0,123"}) + @Alerts(DEFAULT = {"", "0", "1", "1,3", "1,3,4,7,11,0,123"}, + IE = {"[object Uint8ClampedArray]", "[object Uint8ClampedArray]", + "[object Uint8ClampedArray]", "[object Uint8ClampedArray]", + "[object Uint8ClampedArray]"}) + @NotYetImplemented(IE) public void asString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -217,7 +226,9 @@ * @throws Exception if the test fails */ @Test - @Alerts("Uint8ClampedArray") + @Alerts(DEFAULT = "Uint8ClampedArray", + IE = "undefined") + @NotYetImplemented(IE) public void name() throws Exception { final String html = "<html><head><title>foo</title><script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java 2018-08-23 07:21:40 UTC (rev 15538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/crypto/CryptoTest.java 2018-08-23 13:38:51 UTC (rev 15539) @@ -35,7 +35,7 @@ */ @Test @Alerts(DEFAULT = {"true", "true", "true", "false", "false", "false"}, - IE = {"true", "exception"}) + IE = {"true", "true", "true", "exception"}) public void getRandomValues() throws Exception { final String html = "<html><head><script>\n" + "try {\n" @@ -51,7 +51,7 @@ + "catch(e) { alert('exception'); }\n" + "</script></head></html>"; - loadPageWithAlerts2(html, 777777); + loadPageWithAlerts2(html); } /** |
From: <rb...@us...> - 2018-08-27 18:41:26
|
Revision: 15545 http://sourceforge.net/p/htmlunit/code/15545 Author: rbri Date: 2018-08-27 18:41:21 +0000 (Mon, 27 Aug 2018) Log Message: ----------- improved calculation of the left offset Issue 1986 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-08-24 18:34:16 UTC (rev 15544) +++ trunk/htmlunit/src/changes/changes.xml 2018-08-27 18:41:21 UTC (rev 15545) @@ -8,6 +8,9 @@ <body> <release version="2.33" date="xxxx, 2018" description="Bugfixes"> + <action type="update" dev="rbri" issue="1986"> + Improved calculation of the left offset. + </action> <action type="update" dev="rbri"> We are using the typed array implementation from Rhino now, our own impl is gone. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2018-08-24 18:34:16 UTC (rev 15544) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2018-08-27 18:41:21 UTC (rev 15545) @@ -131,6 +131,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; /** * An object for a CSSStyleDeclaration, which is computed. @@ -1504,9 +1505,11 @@ else if (STATIC.equals(p)) { // We need to calculate the horizontal displacement caused by *previous* siblings. left = 0; - for (DomNode n = getDomNodeOrDie(); n != null; n = n.getPreviousSibling()) { - if (n.getScriptableObject() instanceof HTMLElement) { - final HTMLElement e = n.getScriptableObject(); + DomNode prev = getElement().getDomNodeOrDie().getPreviousSibling(); + while (prev != null) { + final Scriptable prevScriptable = prev.getScriptableObject(); + if (prevScriptable instanceof HTMLElement) { + final HTMLElement e = (HTMLElement) prevScriptable; final ComputedCSSStyleDeclaration style = e.getWindow().getComputedStyle(e, null); final String d = style.getDisplay(); if ("block".equals(d)) { @@ -1516,12 +1519,16 @@ left += style.getCalculatedWidth(true, true); } } - else if (n.getScriptableObject() instanceof Text) { - left += n.getTextContent().length() * getBrowserVersion().getPixesPerChar(); + else if (prevScriptable instanceof Text) { + final String content = prev.getTextContent(); + if (content != null) { + left += content.trim().length() * getBrowserVersion().getPixesPerChar(); + } } - if (n instanceof HtmlTableRow) { + if (prev instanceof HtmlTableRow) { break; } + prev = prev.getPreviousSibling(); } } else { @@ -1857,5 +1864,4 @@ } return pixelValue(element, value) + "px"; } - } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2018-08-24 18:34:16 UTC (rev 15544) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2018-08-27 18:41:21 UTC (rev 15545) @@ -2202,4 +2202,24 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts("true") + public void boundingClientRectIgnoreSiblingWhitespace() throws Exception { + final String html = "<html><body>\n" + + "<table>\n" + + "<tr>\n" + + " <td> \n\t <div id='a'>a</div></td>\n" + + "</tr>\n" + + "</table>\n" + + "<script>\n" + + " var e = document.getElementById('a');\n" + + " alert(e.getBoundingClientRect().left < 12);\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-08-30 08:13:37
|
Revision: 15556 http://sourceforge.net/p/htmlunit/code/15556 Author: rbri Date: 2018-08-30 08:13:33 +0000 (Thu, 30 Aug 2018) Log Message: ----------- event refactoring - fix the remaining test case Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/TypingTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-28 17:44:31 UTC (rev 15555) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-08-30 08:13:33 UTC (rev 15556) @@ -415,6 +415,10 @@ @BrowserFeature({CHROME, FF}) HTMLELEMENT_ALIGN_INVALID, + /** Detaching the active element from the dom tree triggers no keyup event. */ + @BrowserFeature(IE) + HTMLELEMENT_DETACH_ACTIVE_TRIGGERS_NO_KEYUP_EVENT, + /** Removing the active element from the dom tree triggers the onblur event. */ @BrowserFeature(CHROME) HTMLELEMENT_REMOVE_ACTIVE_TRIGGERS_BLUR_EVENT, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2018-08-28 17:44:31 UTC (rev 15555) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2018-08-30 08:13:33 UTC (rev 15556) @@ -1185,6 +1185,10 @@ nextSibling_ = null; previousSibling_ = null; parent_ = null; + attachedToPage_ = false; + for (DomNode descendant : getDescendants()) { + descendant.attachedToPage_ = false; + } } private void fireRemoval(final DomNode exParent) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2018-08-28 17:44:31 UTC (rev 15555) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2018-08-30 08:13:33 UTC (rev 15556) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.html; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLELEMENT_DETACH_ACTIVE_TRIGGERS_NO_KEYUP_EVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLELEMENT_REMOVE_ACTIVE_TRIGGERS_BLUR_EVENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.KEYBOARD_EVENT_SPECIAL_KEYPRESS; @@ -537,7 +538,7 @@ } final Event keyDown = new KeyboardEvent(this, Event.TYPE_KEY_DOWN, c, - shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_); + shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_); final ScriptResult keyDownResult = fireEvent(keyDown); if (!keyDown.isAborted(keyDownResult)) { @@ -555,15 +556,32 @@ if (this instanceof HtmlTextInput || this instanceof HtmlTextArea || this instanceof HtmlPasswordInput) { - fireKeyboardEvent(Event.TYPE_INPUT, c, shiftPressed_ || isShiftNeeded); + fireEvent(new KeyboardEvent(this, Event.TYPE_INPUT, c, + shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_)); } - fireKeyboardEvent(Event.TYPE_KEY_UP, c, shiftPressed_ || isShiftNeeded); + HtmlElement eventSource = this; + if (!isAttachedToPage()) { + final BrowserVersion browserVersion = page.getWebClient().getBrowserVersion(); + if (browserVersion.hasFeature(HTMLELEMENT_DETACH_ACTIVE_TRIGGERS_NO_KEYUP_EVENT)) { + eventSource = null; + } + else { + eventSource = page.getBody(); + } + } - if (isShiftNeeded) { - final Event shiftUp = new KeyboardEvent(this, Event.TYPE_KEY_UP, KeyboardEvent.DOM_VK_SHIFT, - false, ctrlPressed_, altPressed_); - fireEvent(shiftUp); + if (eventSource != null) { + final Event keyUp = new KeyboardEvent(this, Event.TYPE_KEY_UP, c, + shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_); + eventSource.fireEvent(keyUp); + + if (isShiftNeeded) { + final Event shiftUp = new KeyboardEvent(this, Event.TYPE_KEY_UP, + KeyboardEvent.DOM_VK_SHIFT, + false, ctrlPressed_, altPressed_); + eventSource.fireEvent(shiftUp); + } } final HtmlForm form = getEnclosingForm(); @@ -578,10 +596,6 @@ return webClient.getCurrentWindow().getEnclosedPage(); } - private void fireKeyboardEvent(final String eventType, final char c, final boolean shift) { - fireEvent(new KeyboardEvent(this, eventType, c, shift, ctrlPressed_, altPressed_)); - } - /** * Simulates typing the specified key code while this element has focus, returning the page contained * by this element's window after typing. Note that it may or may not be the same as the original page, Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/TypingTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/TypingTest.java 2018-08-28 17:44:31 UTC (rev 15555) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/TypingTest.java 2018-08-30 08:13:33 UTC (rev 15556) @@ -28,6 +28,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; /** * Modified from @@ -343,11 +344,10 @@ */ @Test @Alerts(DEFAULT = {"keydown (target) keyup (target) keyup (body)", - "keydown (target) keyup (target) keyup (body) keydown (target) a pressed; removing"}, - CHROME = {"keydown (target) keyup (target) keyup (body)", - "keydown (target) keyup (target) keyup (body) keydown (target) a pressed; removing keyup (body)"}, - FF60 = {"keydown (target) keyup (target) keyup (body)", - "keydown (target) keyup (target) keyup (body) keydown (target) a pressed; removing keyup (body)"}) + "keydown (target) a pressed; removing keyup (body)"}, + IE = {"keydown (target) keyup (target) keyup (body)", + "keydown (target) a pressed; removing"}) + @BuggyWebDriver public void canSafelyTypeOnElementThatIsRemovedFromTheDomOnKeyPress() { final WebDriver driver = getWebDriver("/key_tests/remove_on_keypress.html"); @@ -358,12 +358,10 @@ input.sendKeys("b"); assertEquals(getExpectedAlerts()[0], getValueText(log).replace('\n', ' ')); + log.clear(); input.sendKeys("a"); - // Some drivers (IE, Firefox) do not always generate the final keyup event since the element - // is removed from the DOM in response to the keypress (note, this is a product of how events - // are generated and does not match actual user behavior). assertEquals(getExpectedAlerts()[1], getValueText(log).replace('\n', ' ')); } |
From: <rb...@us...> - 2018-08-30 19:28:19
|
Revision: 15559 http://sourceforge.net/p/htmlunit/code/15559 Author: rbri Date: 2018-08-30 19:28:16 +0000 (Thu, 30 Aug 2018) Log Message: ----------- another cleanup step Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java 2018-08-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/ScriptResult.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -27,18 +27,13 @@ /** The object that was returned from the script engine. */ private final Object javaScriptResult_; - /** The page that is currently loaded at the end of the script execution. */ - private final Page newPage_; - /** * Creates a new instance. * * @param javaScriptResult the object that was returned from the script engine - * @param newPage the page that is currently loaded at the end of the script execution */ - public ScriptResult(final Object javaScriptResult, final Page newPage) { + public ScriptResult(final Object javaScriptResult) { javaScriptResult_ = javaScriptResult; - newPage_ = newPage; } /** @@ -50,19 +45,11 @@ } /** - * Returns the page that is loaded at the end of the script execution. - * @return the new page - */ - public Page getNewPage() { - return newPage_; - } - - /** * {@inheritDoc} */ @Override public String toString() { - return "ScriptResult[result=" + javaScriptResult_ + " page=" + newPage_ + "]"; + return "ScriptResult[result=" + javaScriptResult_ + "]"; } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-08-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -1150,7 +1150,7 @@ if (scriptResult == null) { return clickPage; } - return (P) scriptResult.getNewPage(); + return (P) getPage().getWebClient().getCurrentWindow().getEnclosedPage(); } /** @@ -1359,7 +1359,7 @@ currentPage = page; } else { - currentPage = scriptResult.getNewPage(); + currentPage = page.getWebClient().getCurrentWindow().getEnclosedPage(); } final boolean mouseOver = !MouseEvent.TYPE_MOUSE_OUT.equals(eventType); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2018-08-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -125,13 +125,14 @@ if (scriptResult == null) { return htmlPage; } - return scriptResult.getNewPage(); + return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage(); } } final String action = getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { - return htmlPage.executeJavaScript(action, "Form action", getStartLineNumber()).getNewPage(); + htmlPage.executeJavaScript(action, "Form action", getStartLineNumber()); + return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage(); } } else { @@ -377,7 +378,7 @@ final SgmlPage htmlPage = getPage(); final ScriptResult scriptResult = fireEvent(Event.TYPE_RESET); if (ScriptResult.isFalse(scriptResult)) { - return scriptResult.getNewPage(); + return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage(); } for (final HtmlElement next : getHtmlElementDescendants()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2018-08-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -530,7 +530,7 @@ if (scriptResult != null) { // current window doesn't exist anymore - return scriptResult.getNewPage(); + return page.getWebClient().getCurrentWindow().getEnclosedPage(); } return 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-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -909,7 +909,7 @@ */ public ScriptResult executeJavaScript(String sourceCode, final String sourceName, final int startLine) { if (!getWebClient().getOptions().isJavaScriptEnabled()) { - return new ScriptResult(Undefined.instance, this); + return new ScriptResult(Undefined.instance); } if (StringUtils.startsWithIgnoreCase(sourceCode, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { @@ -920,7 +920,7 @@ } final Object result = getWebClient().getJavaScriptEngine().execute(this, sourceCode, sourceName, startLine); - return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage()); + return new ScriptResult(result); } /** Various possible external JavaScript file loading results. */ @@ -2505,7 +2505,7 @@ public ScriptResult executeJavaScriptFunction(final Object function, final Object thisObject, final Object[] args, final DomNode htmlElementScope) { if (!getWebClient().getOptions().isJavaScriptEnabled()) { - return new ScriptResult(null, this); + return new ScriptResult(null); } return executeJavaScriptFunction((Function) function, (Scriptable) thisObject, args, htmlElementScope); @@ -2517,7 +2517,7 @@ final JavaScriptEngine engine = (JavaScriptEngine) getWebClient().getJavaScriptEngine(); final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope); - return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage()); + return new ScriptResult(result); } private void writeObject(final ObjectOutputStream oos) throws IOException { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2018-08-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -143,7 +143,7 @@ if (changed) { final ScriptResult scriptResult = fireEvent(Event.TYPE_CHANGE); if (scriptResult != null) { - page = scriptResult.getNewPage(); + page = page.getEnclosingWindow().getWebClient().getCurrentWindow().getEnclosedPage(); } } return page; 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-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTarget.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -111,18 +111,7 @@ * @return the result */ public ScriptResult fireEvent(final Event event) { - fireEventImpl(event); - // This is deprecated but there're still a few places using ScriptResult.getNewPage() - return new ScriptResult(null, getWindow().getWebWindow().getWebClient().getCurrentWindow().getEnclosedPage()); - } - - /** - * Fires the event on the node with capturing and bubbling phase. - * @param event the event - */ - private void fireEventImpl(final Event event) { final Window window = getWindow(); - final Object[] args = new Object[] {event}; event.startFire(); final Event previousEvent = window.getCurrentEvent(); @@ -146,7 +135,7 @@ propagationPath.add(parent.getScriptableObject()); } - // The load event has some unnatural behaviour that we need to handle specially + // The load event has some unnatural behavior that we need to handle specially if (Event.TYPE_LOAD.equals(event.getType())) { // The load event for other elements target that element and but path only // up to Document and not Window, so do nothing here @@ -166,9 +155,9 @@ final EventTarget jsNode = propagationPath.get(i); final EventListenersContainer elc = jsNode.eventListenersContainer_; if (elc != null) { - elc.executeCapturingListeners(event, args); + elc.executeCapturingListeners(event, new Object[] {event}); if (event.isPropagationStopped()) { - return; + return new ScriptResult(null); } } } @@ -182,24 +171,13 @@ final EventTarget jsNode = propagationPath.get(0); final EventListenersContainer elc = jsNode.eventListenersContainer_; if (elc != null) { - elc.executeAtTargetListeners(event, args); + elc.executeAtTargetListeners(event, new Object[] {event}); if (event.isPropagationStopped()) { - return; + return new ScriptResult(null); } } } - // 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 @@ -210,14 +188,24 @@ final EventTarget jsNode = propagationPath.get(i); final EventListenersContainer elc = jsNode.eventListenersContainer_; if (elc != null) { - elc.executeBubblingListeners(event, args); + elc.executeBubblingListeners(event, new Object[] {event}); if (event.isPropagationStopped()) { - return; + return new ScriptResult(null); } } } } + HtmlLabel label = null; + if (event.processLabelAfterBubbling()) { + for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) { + if (parent instanceof HtmlLabel) { + label = (HtmlLabel) parent; + break; + } + } + } + if (label != null) { final HtmlElement element = label.getReferencedElement(); if (element != null && element != getDomNodeOrNull()) { @@ -235,6 +223,8 @@ event.endFire(); window.setCurrentEvent(previousEvent); // reset event } + + return new ScriptResult(null); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement2Test.java 2018-08-30 17:34:53 UTC (rev 15558) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement2Test.java 2018-08-30 19:28:16 UTC (rev 15559) @@ -64,8 +64,8 @@ getMockWebConnection().setDefaultResponse(secondContent); final HtmlPage page = loadPageWithAlerts(html); - final HtmlPage secondPage = - (HtmlPage) page.executeJavaScript("document.form1.submit()").getNewPage(); + page.executeJavaScript("document.form1.submit()"); + final HtmlPage secondPage = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); assertEquals("second", secondPage.getTitleText()); } @@ -87,7 +87,8 @@ final List<String> collectedAlerts = new ArrayList<>(); final HtmlPage page1 = loadPage(html, collectedAlerts); - final HtmlPage page2 = (HtmlPage) page1.executeJavaScript("document.form1.submit()").getNewPage(); + page1.executeJavaScript("document.form1.submit()"); + final HtmlPage page2 = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); assertEquals(page1, page2); assertEquals(getExpectedAlerts(), collectedAlerts); @@ -111,7 +112,8 @@ final List<String> collectedAlerts = new ArrayList<>(); final HtmlPage page1 = loadPage(html, collectedAlerts); - final HtmlPage page2 = (HtmlPage) page1.executeJavaScript("document.form1.submit()").getNewPage(); + page1.executeJavaScript("document.form1.submit()"); + final HtmlPage page2 = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); assertEquals(page1, page2); assertEquals(getExpectedAlerts(), collectedAlerts); @@ -135,7 +137,8 @@ final List<String> collectedAlerts = new ArrayList<>(); final HtmlPage page1 = loadPage(html, collectedAlerts); - final HtmlPage page2 = (HtmlPage) page1.executeJavaScript("document.form1.submit()").getNewPage(); + page1.executeJavaScript("document.form1.submit()"); + final HtmlPage page2 = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); assertEquals(page1, page2); assertEquals(getExpectedAlerts(), collectedAlerts); @@ -183,8 +186,9 @@ final HtmlPage page = loadPageWithAlerts(html); - final HtmlPage secondPage - = (HtmlPage) page.executeJavaScript("document.form1.submit()").getNewPage(); + page.executeJavaScript("document.form1.submit()"); + final HtmlPage secondPage = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage(); + assertEquals("second", secondPage.getTitleText()); assertEquals("MyNewWindow", secondPage.getEnclosingWindow().getName()); } |