From: <asa...@us...> - 2012-11-26 12:38:22
|
Revision: 7778 http://sourceforge.net/p/htmlunit/code/7778 Author: asashour Date: 2012-11-26 12:38:16 +0000 (Mon, 26 Nov 2012) Log Message: ----------- JavaScript: correctly process null function handlers, thanks to jQuery Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-11-26 10:41:57 UTC (rev 7777) +++ trunk/htmlunit/src/changes/changes.xml 2012-11-26 12:38:16 UTC (rev 7778) @@ -9,6 +9,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> <action type="fix" dev="asashour"> + JavaScript: correctly process null function handlers. + </action> + <action type="fix" dev="asashour"> JavaScript: correct select.value after enclosing form.reset(). </action> <action type="fix" dev="asashour"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-11-26 10:41:57 UTC (rev 7777) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-11-26 12:38:16 UTC (rev 7778) @@ -278,10 +278,6 @@ /** Was originally .isIE(). */ @BrowserFeature(@WebBrowser(IE)) - GENERATED_129, - - /** Was originally .isIE(). */ - @BrowserFeature(@WebBrowser(IE)) GENERATED_13, /** Was originally .isIE(). */ @@ -889,6 +885,10 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) JS_GET_ELEMENT_BY_ID_CASE_SENSITIVE, + /** Indicates that not defined function handler should be 'undefined', or 'null'. */ + @BrowserFeature(@WebBrowser(value = FF, maxVersion = 3.6f)) + JS_HANDLER_UNDEFINED, + /** Indicates that objects with prototype property available in window scope; Firefox does this. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) JS_HAS_OBJECT_WITH_PROTOTYPE_PROPERTY_IN_WINDOW_SCOPE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2012-11-26 10:41:57 UTC (rev 7777) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2012-11-26 12:38:16 UTC (rev 7778) @@ -14,9 +14,9 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_129; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_133; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_EVENT_HANDLER_AS_PROPERTY_DONT_RECEIVE_EVENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HANDLER_UNDEFINED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_CHANGE_OPENER_NOT_ALLOWED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FRAMES_ACCESSIBLE_BY_ID; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_IS_NOT_A_FUNCTION; @@ -1241,14 +1241,14 @@ private Object getHandlerForJavaScript(final String eventName) { Object handler = getEventListenersContainer().getEventHandlerProp(eventName); - if (handler == null && !getBrowserVersion().hasFeature(GENERATED_129)) { + if (handler == null && getBrowserVersion().hasFeature(JS_HANDLER_UNDEFINED)) { handler = Scriptable.NOT_FOUND; } return handler; } private void setHandlerForJavaScript(final String eventName, final Object handler) { - if (handler instanceof Function) { + if (handler instanceof Function || handler == null) { getEventListenersContainer().setEventHandlerProp(eventName, handler); } // Otherwise, fail silently. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2012-11-26 10:41:57 UTC (rev 7777) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2012-11-26 12:38:16 UTC (rev 7778) @@ -884,4 +884,30 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "null", "function", "null" }, FF3_6 = { "undefined", "function", "null" }) + @NotYetImplemented(FF3_6) + public void onbeforeunload() throws Exception { + final String html = + "<html><head><title>First</title>\n" + + "<script>\n" + + "function test() {\n" + + " alert(window.onbeforeunload);\n" + + " var handle = function () {};\n" + + " window.onbeforeunload = handle;\n" + + " alert(typeof window.onbeforeunload);\n" + + " window.onbeforeunload = null;\n" + + " alert(window.onbeforeunload);\n" + + " \n" + + "}\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElementTest.java 2012-11-26 10:41:57 UTC (rev 7777) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLSelectElementTest.java 2012-11-26 12:38:16 UTC (rev 7778) @@ -1180,11 +1180,12 @@ + "<body onload='test()'>\n" + "<form id='myForm' name='myForm'>\n" + " <select id='mySelect'>\n" - + " <option>One</option>\n" - + " <option>Two</option>\n" + + " <option value='One'>One</option>\n" + + " <option value='Two'>Two</option>\n" + " </select>\n" + "</form>\n" + "</body></html>"; + loadPageWithAlerts2(html); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-11-26 10:41:57 UTC (rev 7777) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-11-26 12:38:16 UTC (rev 7778) @@ -2364,7 +2364,6 @@ + "(0, 3, 3)", IE = "event: on(beforeunload) creates/deletes window property instead of adding/removing event listener " + "(0, 3, 3)") - @NotYetImplemented public void test_217() throws Exception { runTest(217); } |