From: <asa...@us...> - 2012-11-25 10:54:43
|
Revision: 7766 http://sourceforge.net/p/htmlunit/code/7766 Author: asashour Date: 2012-11-25 10:54:39 +0000 (Sun, 25 Nov 2012) Log Message: ----------- JavaScript: element.set/getAttribute() should fix the name (e.g. "className") only in Quirks mode (IE). 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/Element.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.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-25 09:56:52 UTC (rev 7765) +++ trunk/htmlunit/src/changes/changes.xml 2012-11-25 10:54:39 UTC (rev 7766) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="fix" dev="asashour"> + JavaScript: element.set/getAttribute() should fix the name (e.g. "className") only in Quirks mode (IE). + </action> <action type="fix" dev="mguillem"> Cookies: use 1970 as two digits year start for the expiration date. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-11-25 09:56:52 UTC (rev 7765) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-11-25 10:54:39 UTC (rev 7766) @@ -450,10 +450,6 @@ /** Was originally .isIE(). */ @BrowserFeature(@WebBrowser(IE)) - GENERATED_66, - - /** Was originally .isIE(). */ - @BrowserFeature(@WebBrowser(IE)) GENERATED_69, /** Was originally .isIE(). */ @@ -583,6 +579,13 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) HTMLELEMENT_ALIGN_INVALID, + /** + * Indicates that attribute name should be fixed for get/setAttribute(), specifically "className" and "class", + * only in quirks mode. + */ + @BrowserFeature(@WebBrowser(IE)) + HTMLELEMENT_ATTRIBUTE_FIX_IN_QUIRKS_MODE, + /** */ HTMLELEMENT_TRIM_CLASS_ATTRIBUTE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2012-11-25 09:56:52 UTC (rev 7765) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2012-11-25 10:54:39 UTC (rev 7766) @@ -138,8 +138,8 @@ */ @JsxFunction public Object getAttribute(String attributeName, final Integer flags) { + attributeName = fixAttributeName(attributeName); final boolean supportsFlags = getBrowserVersion().hasFeature(JS_GET_ATTRIBUTE_SUPPORTS_FLAGS); - attributeName = fixAttributeName(attributeName); Object value; if (supportsFlags && flags != null && flags == 2 && "style".equalsIgnoreCase(attributeName)) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2012-11-25 09:56:52 UTC (rev 7765) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2012-11-25 10:54:39 UTC (rev 7766) @@ -16,7 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_167; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_65; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_66; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLELEMENT_ATTRIBUTE_FIX_IN_QUIRKS_MODE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_69; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_70; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_71; @@ -564,7 +564,8 @@ */ @Override protected String fixAttributeName(final String attributeName) { - if (getBrowserVersion().hasFeature(GENERATED_66)) { + if (getBrowserVersion().hasFeature(HTMLELEMENT_ATTRIBUTE_FIX_IN_QUIRKS_MODE) + && ((HtmlPage) getDomNodeOrDie().getPage()).isQuirksMode()) { if ("className".equals(attributeName)) { return "class"; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2012-11-25 09:56:52 UTC (rev 7765) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2012-11-25 10:54:39 UTC (rev 7766) @@ -27,6 +27,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; /** * Tests for {@link HTMLElement}. @@ -2555,14 +2556,13 @@ * @throws Exception on test failure */ @Test - @Alerts("") - @NotYetImplemented(IE) + @Alerts(IE = "t", FF = "") public void setAttribute_className() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test(){\n" + " var div = document.createElement('div');\n" - + " div.setAttribute('className', 't');" + + " div.setAttribute('className', 't');\n" + " alert(div.className);\n" + " }\n" + "</script>\n" @@ -2576,14 +2576,13 @@ * @throws Exception on test failure */ @Test - @Alerts("t") - @NotYetImplemented(IE) + @Alerts(IE = "", FF = "t") public void setAttribute_class() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test(){\n" + " var div = document.createElement('div');\n" - + " div.setAttribute('class', 't');" + + " div.setAttribute('class', 't');\n" + " alert(div.className);\n" + " }\n" + "</script>\n" @@ -2593,4 +2592,44 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception on test failure + */ + @Test + @Alerts("") + public void setAttribute_className_standards() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + + "<script>\n" + + " function test(){\n" + + " var div = document.createElement('div');\n" + + " div.setAttribute('className', 't');\n" + + " alert(div.className);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'></body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception on test failure + */ + @Test + @Alerts("t") + public void setAttribute_class_standards() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + + "<script>\n" + + " function test(){\n" + + " var div = document.createElement('div');\n" + + " div.setAttribute('class', 't');\n" + + " alert(div.className);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'></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-25 09:56:52 UTC (rev 7765) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-11-25 10:54:39 UTC (rev 7766) @@ -1080,7 +1080,6 @@ */ @Test @Alerts("support: A background on the testElement does not cause IE8 to crash (#9823) (0, 1, 1)") - @NotYetImplemented(IE) public void test_106() throws Exception { runTest(106); } @@ -1504,6 +1503,7 @@ FF10 = "attributes: attr(jquery_method) (0, 9, 9)", CHROME = "attributes: attr(jquery_method) (0, 9, 9)", IE = "attributes: attr(String, Object) (0, 81, 81)") + @NotYetImplemented(IE) public void test_143() throws Exception { runTest(143); } @@ -1588,6 +1588,7 @@ FF10 = "attributes: prop(String, Object) (0, 31, 31)", CHROME = "attributes: prop(String, Object) (0, 31, 31)", IE = "attributes: removeAttr(Multi String, variable space width) (0, 8, 8)") + @NotYetImplemented(IE) public void test_150() throws Exception { runTest(150); } |