From: <asa...@us...> - 2012-11-28 05:47:52
|
Revision: 7788 http://sourceforge.net/p/htmlunit/code/7788 Author: asashour Date: 2012-11-28 05:47:47 +0000 (Wed, 28 Nov 2012) Log Message: ----------- JavaScript: fix handling relations of document type comment with <html> element (IE), thanks to jQuery Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTypeTest.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-27 15:06:14 UTC (rev 7787) +++ trunk/htmlunit/src/changes/changes.xml 2012-11-28 05:47:47 UTC (rev 7788) @@ -9,6 +9,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> <action type="fix" dev="asashour"> + JavaScript: fix handling relations of document type comment with <html> element (IE). + </action> + <action type="fix" dev="asashour"> JavaScript: properties of Array.prototype should be defined in standards mode (IE). </action> <action type="fix" dev="asashour"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2012-11-27 15:06:14 UTC (rev 7787) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2012-11-28 05:47:47 UTC (rev 7788) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.html; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.DOCTYPE_IS_COMMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_3; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCONDITIONAL_COMMENTS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIFRAME_IGNORE_SELFCLOSING; @@ -782,7 +783,16 @@ public void startDTD(final String name, final String publicId, final String systemId) { final DomDocumentType type = new DomDocumentType(page_, name, publicId, systemId); page_.setDocumentType(type); - page_.appendChild(type); + + final Node child; + if (page_.getWebClient().getBrowserVersion().hasFeature(DOCTYPE_IS_COMMENT)) { + child = new DomComment(page_, "DOCTYPE " + name + " PUBLIC \"" + + publicId + "\" \"" + systemId + '"'); + } + else { + child = type; + } + page_.appendChild(child); } /** {@inheritDoc} */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2012-11-27 15:06:14 UTC (rev 7787) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2012-11-28 05:47:47 UTC (rev 7788) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.DOCTYPE_IS_COMMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EXECCOMMAND_THROWS_ON_WRONG_COMMAND; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_160; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_161; @@ -84,8 +83,6 @@ import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebWindow; import com.gargoylesoftware.htmlunit.html.BaseFrameElement; -import com.gargoylesoftware.htmlunit.html.DomComment; -import com.gargoylesoftware.htmlunit.html.DomDocumentType; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.FrameWindow; @@ -1911,12 +1908,6 @@ */ @Override public SimpleScriptable makeScriptableFor(final DomNode domNode) { - if (domNode instanceof DomDocumentType && getBrowserVersion().hasFeature(DOCTYPE_IS_COMMENT)) { - final DomDocumentType docType = (DomDocumentType) domNode; - final DomComment comment = new DomComment(getHtmlPage(), "DOCTYPE " + docType.getName() + " PUBLIC \"" - + docType.getPublicId() + "\" \"" + docType.getSystemId() + '"'); - return super.makeScriptableFor(comment); - } return super.makeScriptableFor(domNode); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTypeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTypeTest.java 2012-11-27 15:06:14 UTC (rev 7787) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentTypeTest.java 2012-11-28 05:47:47 UTC (rev 7788) @@ -15,7 +15,6 @@ package com.gargoylesoftware.htmlunit.javascript.host; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF3_6; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import org.junit.Test; import org.junit.runner.RunWith; @@ -129,7 +128,6 @@ @Test @Alerts(IE6 = "string", IE7 = "string", IE8 = "string", FF3_6 = { }, DEFAULT = "undefined") - @NotYetImplemented(IE) public void html_previousSibling() throws Exception { final String html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" @@ -139,7 +137,7 @@ + " <script>\n" + " function test() {\n" + " if (document.body.parentElement) {\n" - + " //.text is defined for Comment in IE" + + " //.text is defined for Comment in IE\n" + " alert(typeof document.body.parentElement.previousSibling.text);\n" + " }\n" + " }\n" @@ -155,10 +153,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE6 = { "[object]", "[object]" }, IE7 = { "[object]", "[object]" }, - IE8 = { "[object]", "[object]" }, + @Alerts(IE6 = { "[object HTMLCommentElement]", "[object HTMLHtmlElement]" }, + IE7 = { "[object HTMLCommentElement]", "[object HTMLHtmlElement]" }, + IE8 = { "[object HTMLCommentElement]", "[object HTMLHtmlElement]" }, DEFAULT = { "[object DocumentType]", "[object HTMLHtmlElement]" }) - @NotYetImplemented(IE) public void document_children() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head>\n" 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-27 15:06:14 UTC (rev 7787) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-11-28 05:47:47 UTC (rev 7788) @@ -3275,7 +3275,6 @@ @Test @Alerts(FF3_6 = "manipulation: text() (0, 5, 5)", FF10 = "manipulation: text(undefined) (0, 1, 1)", CHROME = "manipulation: text() (0, 5, 5)", IE = "manipulation: text() (0, 5, 5)") - @NotYetImplemented(IE) public void test_300() throws Exception { runTest(300); } |