From: <asa...@us...> - 2017-05-06 12:41:08
|
Revision: 14388 http://sourceforge.net/p/htmlunit/code/14388 Author: asashour Date: 2017-05-06 12:41:05 +0000 (Sat, 06 May 2017) Log Message: ----------- Document.xml properties Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlPage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-05-06 12:27:15 UTC (rev 14387) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-05-06 12:41:05 UTC (rev 14388) @@ -415,20 +415,18 @@ /** * {@inheritDoc} - * Not yet implemented. */ @Override public String getXmlEncoding() { - throw new UnsupportedOperationException("HtmlPage.getXmlEncoding is not yet implemented."); + return null; } /** * {@inheritDoc} - * Not yet implemented. */ @Override public boolean getXmlStandalone() { - throw new UnsupportedOperationException("HtmlPage.getXmlStandalone is not yet implemented."); + return false; } /** @@ -442,11 +440,10 @@ /** * {@inheritDoc} - * Not yet implemented. */ @Override public String getXmlVersion() { - throw new UnsupportedOperationException("HtmlPage.getXmlVersion is not yet implemented."); + return null; } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-05-06 12:27:15 UTC (rev 14387) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-05-06 12:41:05 UTC (rev 14388) @@ -1096,6 +1096,15 @@ } /** + * Returns the value of the {@code documentURI} property. + * @return the value of the {@code documentURI} property + */ + @JsxGetter({CHROME, FF}) + public String getDocumentURI() { + return getURL(); + } + + /** * Returns the value of the {@code URLUnencoded} property. * @return the value of the {@code URLUnencoded} property */ @@ -2205,4 +2214,38 @@ return getPage().getFirstChild().getScriptableObject(); } + /** + * Returns the {@code xmlEncoding} property. + * @return the {@code xmlEncoding} property + */ + @JsxGetter({CHROME, IE}) + public String getXmlEncoding() { + String encoding = getPage().getXmlEncoding(); + if (encoding == null && getBrowserVersion().hasFeature(HTMLDOCUMENT_CHARSET_LOWERCASE)) { + encoding = ""; + } + return encoding; + } + + /** + * Returns the {@code xmlStandalone} property. + * @return the {@code xmlStandalone} property + */ + @JsxGetter({CHROME, IE}) + public boolean isXmlStandalone() { + return getPage().getXmlStandalone(); + } + + /** + * Returns the {@code xmlVersion} property. + * @return the {@code xmlVersion} property + */ + @JsxGetter({CHROME, IE}) + public String getXmlVersion() { + String version = getPage().getXmlVersion(); + if (version == null && getBrowserVersion().hasFeature(HTMLDOCUMENT_CHARSET_LOWERCASE)) { + version = ""; + } + return version; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlPage.java 2017-05-06 12:27:15 UTC (rev 14387) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/xml/XmlPage.java 2017-05-06 12:41:05 UTC (rev 14388) @@ -279,29 +279,26 @@ /** * {@inheritDoc} - * Not yet implemented. */ @Override public String getXmlEncoding() { - throw new UnsupportedOperationException("XmlPage.getXmlEncoding is not yet implemented."); + return null; } /** * {@inheritDoc} - * Not yet implemented. */ @Override public boolean getXmlStandalone() { - throw new UnsupportedOperationException("XmlPage.getXmlStandalone is not yet implemented."); + return false; } /** * {@inheritDoc} - * Not yet implemented. */ @Override public String getXmlVersion() { - throw new UnsupportedOperationException("XmlPage.getXmlVersion is not yet implemented."); + return "1.0"; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentTest.java 2017-05-06 12:27:15 UTC (rev 14387) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentTest.java 2017-05-06 12:41:05 UTC (rev 14388) @@ -2414,11 +2414,78 @@ + "<body onload='test()'></body>\n" + "</html>"; - final URL url = new URL(URL_FIRST, "abc%20def"); - expandExpectedAlertsVariables(url); + loadPageWithAlerts2(html); + } - final WebDriver driver = loadPage2(html, url); - verifyAlerts(driver, getExpectedAlerts()); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"null", "null"}, + IE = {"", ""}, + FF = {"undefined", "undefined"}) + public void xmlEncoding() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var xmlDocument = document.implementation.createDocument('', '', null);\n" + + " alert(xmlDocument.xmlEncoding);\n" + + " alert(document.xmlEncoding);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"false", "false"}, + FF = {"undefined", "undefined"}) + public void xmlStandalone() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var xmlDocument = document.implementation.createDocument('', '', null);\n" + + " alert(xmlDocument.xmlStandalone);\n" + + " alert(document.xmlStandalone);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"1.0", "null"}, + FF = {"undefined", "undefined"}, + IE = {"1.0", ""}) + public void xmlVersion() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var xmlDocument = document.implementation.createDocument('', '', null);\n" + + " alert(xmlDocument.xmlVersion);\n" + + " alert(document.xmlVersion);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + } |