From: <asa...@us...> - 2017-05-23 11:40:53
|
Revision: 14471 http://sourceforge.net/p/htmlunit/code/14471 Author: asashour Date: 2017-05-23 11:40:50 +0000 (Tue, 23 May 2017) Log Message: ----------- JavaScript: fix Set/Map with undefined value. Issue 1886 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-05-23 11:31:10 UTC (rev 14470) +++ trunk/htmlunit/src/changes/changes.xml 2017-05-23 11:40:50 UTC (rev 14471) @@ -8,6 +8,9 @@ <body> <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> + <action type="fix" dev="asashour" issue="1886"> + JavaScript: fix Set/Map with undefined value. + </action> <action type="fix" dev="asashour" issue="1606"> Stack property was not set when new Error() was called from js. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2017-05-23 11:31:10 UTC (rev 14470) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2017-05-23 11:40:50 UTC (rev 14471) @@ -145,6 +145,9 @@ if (key instanceof Delegator) { key = ((Delegator) key).getDelegee(); } + if (key == NOT_FOUND) { + key = Undefined.instance; + } map_.put(key, value); return this; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java 2017-05-23 11:31:10 UTC (rev 14470) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java 2017-05-23 11:40:50 UTC (rev 14471) @@ -124,6 +124,9 @@ if (value instanceof Delegator) { value = ((Delegator) value).getDelegee(); } + if (value == NOT_FOUND) { + value = Undefined.instance; + } set_.add(value); return this; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java 2017-05-23 11:31:10 UTC (rev 14470) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java 2017-05-23 11:40:50 UTC (rev 14471) @@ -385,4 +385,32 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"value1", "undefined", "[object Map]", "[object Window]", + "[object Object]", "key2", "[object Map]", "[object Window]"}, + IE = {}) + public void forEach_withElision() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function logElement(value, key, m) {\n" + + " alert(value);\n" + + " alert(key);\n" + + " alert(m);\n" + + " alert(this);\n" + + "}\n" + + "function test() {\n" + + "try {" + + " var myMap = new Map([[, 'value1'], ['key2', {}]]);\n" + + " myMap.forEach(logElement);\n" + + "}catch(e){alert(e)}" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java 2017-05-23 11:31:10 UTC (rev 14470) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SetTest.java 2017-05-23 11:40:50 UTC (rev 14471) @@ -302,4 +302,27 @@ loadPageWithAlerts2(html); } + /** + * Test case for Bug #1886. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"undefined", "0"}, + IE = {}) + public void forEach_withElision() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function logElement(value) {\n" + + " alert(value);\n" + + "}\n" + + "function test() {\n" + + " var mySet = new Set([, 0]);\n" + + " mySet.forEach(logElement);\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2017-05-24 18:15:42
|
Revision: 14473 http://sourceforge.net/p/htmlunit/code/14473 Author: rbri Date: 2017-05-24 18:15:39 +0000 (Wed, 24 May 2017) Log Message: ----------- fix build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-24 15:48:26 UTC (rev 14472) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-24 18:15:39 UTC (rev 14473) @@ -314,7 +314,7 @@ CHROME.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 25.0 r0", "25.0.0.148", "NPSWF32_25_0_0_148.dll"); + "Shockwave Flash 25.0 r0", "25.0.0.171", "NPSWF32_25_0_0_171.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_45.getPlugins().add(flash); @@ -326,7 +326,7 @@ FIREFOX_52.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 25.0 r0", "25.0.0.148", "Flash32_25_0_0_148.ocx"); + "Shockwave Flash 25.0 r0", "25.0.0.171", "Flash32_25_0_0_171.ocx"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); INTERNET_EXPLORER.getPlugins().add(flash); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-05-24 15:48:26 UTC (rev 14472) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-05-24 18:15:39 UTC (rev 14473) @@ -212,7 +212,7 @@ @Test @Alerts(FF = {"Shockwave Flash", "Shockwave Flash 25.0 r0", "25.0.0.171", "NPSWF32_25_0_0_171.dll"}, CHROME = {"Shockwave Flash", "Shockwave Flash 24.0 r0", "undefined", "internal-not-yet-present"}, - IE = {"Shockwave Flash", "Shockwave Flash 25.0 r0", "25.0.0.148", "Flash32_25_0_0_148.ocx"}, + IE = {"Shockwave Flash", "Shockwave Flash 25.0 r0", "25.0.0.171", "Flash32_25_0_0_171.ocx"}, EDGE = {"Shockwave Flash", "Shockwave Flash 18.0 r0", "18.0.0.232", "Flash.ocx"}) public void pluginsShockwaveFlash() throws Exception { final String html = "<html>\n" |
From: <rb...@us...> - 2017-05-26 18:18:00
|
Revision: 14476 http://sourceforge.net/p/htmlunit/code/14476 Author: rbri Date: 2017-05-26 18:17:57 +0000 (Fri, 26 May 2017) Log Message: ----------- simulated system time zone is now configurable Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/changes/changes.xml 2017-05-26 18:17:57 UTC (rev 14476) @@ -8,6 +8,9 @@ <body> <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> + <action type="fix" dev="rbri" issue="1827"> + Simulated system time zone is now configurable (BrowserVersion.setSystemTimezone(String)). + </action> <action type="fix" dev="asashour" issue="1886"> JavaScript: fix Set/Map with undefined value. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-26 18:17:57 UTC (rev 14476) @@ -107,6 +107,11 @@ private static final String LANGUAGE_ENGLISH_US = "en-US"; /** + * United States . + */ + private static final String TIMEZONE_NEW_YORK = "America/New_York"; + + /** * The X86 CPU class. */ private static final String CPU_CLASS_X86 = "x86"; @@ -349,6 +354,7 @@ private boolean onLine_ = true; private String platform_ = PLATFORM_WIN32; private String systemLanguage_ = LANGUAGE_ENGLISH_US; + private String systemTimezone_ = TIMEZONE_NEW_YORK; private String userAgent_; private String userLanguage_ = LANGUAGE_ENGLISH_US; private int browserVersionNumeric_; @@ -614,6 +620,15 @@ } /** + * Returns the system timezone, for example "America/New_York". + * Default value is {@link #TIMEZONE_NEW_YORK} if not explicitly configured. + * @return the system timezone + */ + public String getSystemTimezone() { + return systemTimezone_; + } + + /** * Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)". * @return the user agent string */ @@ -746,6 +761,13 @@ } /** + * @param systemTimezone the systemTimezone to set + */ + public void setSystemTimezone(final String systemTimezone) { + systemTimezone_ = systemTimezone; + } + + /** * @param userAgent the userAgent to set */ public void setUserAgent(final String userAgent) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java 2017-05-26 18:17:57 UTC (rev 14476) @@ -23,6 +23,7 @@ import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import org.apache.commons.lang3.time.FastDateFormat; @@ -73,13 +74,14 @@ final Date date = new Date(getLastModified()); final BrowserVersion browser = getBrowserVersion(); final Locale locale = new Locale(browser.getSystemLanguage()); + final TimeZone timezone = TimeZone.getTimeZone(browser.getSystemTimezone()); if (browser.hasFeature(JS_FILE_SHORT_DATE_FORMAT)) { - final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT_FF, locale); + final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT_FF, timezone, locale); return format.format(date); } - final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT, locale); + final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT, timezone, locale); return format.format(date); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java 2017-05-26 18:17:57 UTC (rev 14476) @@ -42,14 +42,14 @@ */ @Test @Alerts(CHROME = {"1", "ScriptExceptionTest1.txt", - "Sun Jul 26 2015 16:21:47 GMT+0200 (Central European Summer Time)", + "Sun Jul 26 2015 10:21:47 GMT-0400 (Eastern Daylight Time)", "1437920507000", "", "14", "text/plain"}, - FF45 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200", + FF45 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 10:21:47 GMT-0400", "1437920507000", "undefined", "14", "text/plain"}, - FF52 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200", + FF52 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 10:21:47 GMT-0400", "1437920507000", "", "14", "text/plain"}, IE = {"1", "ScriptExceptionTest1.txt", - "Sun Jul 26 2015 16:21:47 GMT+0200 (Central European Summer Time)", + "Sun Jul 26 2015 10:21:47 GMT-0400 (Eastern Daylight Time)", "undefined", "undefined", "14", "text/plain"}) public void properties() throws Exception { final String html |
From: <rb...@us...> - 2017-05-28 15:42:05
|
Revision: 14477 http://sourceforge.net/p/htmlunit/code/14477 Author: rbri Date: 2017-05-28 15:42:01 +0000 (Sun, 28 May 2017) Log Message: ----------- outerHtml fixes Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-05-26 18:17:57 UTC (rev 14476) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-05-28 15:42:01 UTC (rev 14477) @@ -440,6 +440,10 @@ @BrowserFeature(CHROME) HTMLLINK_CHECK_TYPE_FOR_STYLESHEET, + /** No end tag for menu item. */ + @BrowserFeature(CHROME) + HTMLMENUITEM_END_TAG_FORBIDDEN, + /** */ @BrowserFeature({FF, IE}) HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java 2017-05-26 18:17:57 UTC (rev 14476) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java 2017-05-28 15:42:01 UTC (rev 14477) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLMENUITEM_END_TAG_FORBIDDEN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_HYPHEN_ELEMENT_CLASS_NAME; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_RUBY_ELEMENT_CLASS_NAME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; @@ -100,7 +101,9 @@ */ @Override protected boolean isEndTagForbidden() { - if ("IMAGE".equals(getNodeName())) { + if ("BGSOUND".equals(getNodeName()) + || (getBrowserVersion().hasFeature(HTMLMENUITEM_END_TAG_FORBIDDEN) + && "MENUITEM".equals(getNodeName()))) { return true; } return super.isEndTagForbidden(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java 2017-05-26 18:17:57 UTC (rev 14476) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java 2017-05-28 15:42:01 UTC (rev 14477) @@ -14,14 +14,11 @@ */ package com.gargoylesoftware.htmlunit.general; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; - 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; /** @@ -135,7 +132,6 @@ */ @Test @Alerts("<bgsound>") - @NotYetImplemented(CHROME) public void bgsound() throws Exception { loadPageWithAlerts2(test("bgsound")); } @@ -633,7 +629,6 @@ @Test @Alerts(DEFAULT = "<image></image>", IE = "<img>") - @NotYetImplemented(CHROME) public void image() throws Exception { loadPageWithAlerts2(test("image")); } @@ -798,7 +793,6 @@ @Test @Alerts(DEFAULT = "<menuitem></menuitem>", CHROME = "<menuitem>") - @NotYetImplemented(CHROME) public void menuitem() throws Exception { loadPageWithAlerts2(test("menuitem")); } |
From: <rb...@us...> - 2017-05-29 15:25:59
|
Revision: 14484 http://sourceforge.net/p/htmlunit/code/14484 Author: rbri Date: 2017-05-29 15:25:56 +0000 (Mon, 29 May 2017) Log Message: ----------- the svg elemnet is now an ordinary html element Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -92,6 +92,7 @@ HtmlSource.TAG_NAME, HtmlSpan.TAG_NAME, HtmlStrike.TAG_NAME, HtmlStrong.TAG_NAME, HtmlStyle.TAG_NAME, HtmlSubscript.TAG_NAME, HtmlSummary.TAG_NAME, HtmlSuperscript.TAG_NAME, + HtmlSvg.TAG_NAME, HtmlTable.TAG_NAME, HtmlTableColumn.TAG_NAME, HtmlTableColumnGroup.TAG_NAME, HtmlTableBody.TAG_NAME, HtmlTableDataCell.TAG_NAME, HtmlTableHeaderCell.TAG_NAME, HtmlTableRow.TAG_NAME, HtmlTextArea.TAG_NAME, HtmlTableFooter.TAG_NAME, @@ -646,6 +647,10 @@ element = new HtmlSuperscript(qualifiedName, page, attributeMap); break; + case HtmlSvg.TAG_NAME: + element = new HtmlSvg(qualifiedName, page, attributeMap); + break; + case HtmlTable.TAG_NAME: element = new HtmlTable(qualifiedName, page, attributeMap); break; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -352,16 +352,15 @@ * @param namespaceURI the namespace URI * @param qualifiedName the qualified name * @param insideHtml is the node inside HTML or not + * @param insideSvg is the node inside an SVG node or not * @return the pre-registered element factory corresponding to the specified tag, or an UnknownElementFactory */ static ElementFactory getElementFactory(final SgmlPage page, final String namespaceURI, - final String qualifiedName, final boolean insideHtml) { - final String qualifiedNameLower = qualifiedName.toLowerCase(Locale.ROOT); - if (SVG_NAMESPACE.equals(namespaceURI) - || (SVG_FACTORY.isSupported(qualifiedNameLower)) - && !ELEMENT_FACTORIES.containsKey(qualifiedNameLower)) { + final String qualifiedName, final boolean insideHtml, final boolean insideSvg) { + if (insideSvg) { return SVG_FACTORY; } + if (namespaceURI == null || namespaceURI.isEmpty() || !qualifiedName.contains(":") || namespaceURI.equals(XHTML_NAMESPACE)) { @@ -406,6 +405,8 @@ private HtmlElement body_; private boolean lastTagWasSynthesized_; private HtmlForm formWaitingForLostChildren_; + private boolean insideSvg_; + private static final String FEATURE_AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations"; private static final String FEATURE_PARSE_NOSCRIPT = "http://cyberneko.org/html/features/parse-noscript-content"; @@ -555,7 +556,7 @@ } // add a head if none was there else if (headParsed_ == HeadParsed.NO && ("body".equals(tagLower) || "frameset".equals(tagLower))) { - final ElementFactory factory = getElementFactory(page_, namespaceURI, "head", true); + final ElementFactory factory = getElementFactory(page_, namespaceURI, "head", true, insideSvg_); final DomElement newElement = factory.createElement(page_, "head", null); currentNode_.appendChild(newElement); headParsed_ = HeadParsed.SYNTHESIZED; @@ -584,7 +585,8 @@ tagLower = "select"; qName = "select"; } - final ElementFactory factory = getElementFactory(page_, namespaceURI, qName, isInsideHtml()); + + final ElementFactory factory = getElementFactory(page_, namespaceURI, qName, isInsideHtml(), insideSvg_); if (factory == SVG_FACTORY) { namespaceURI = SVG_NAMESPACE; } @@ -594,6 +596,10 @@ // parse can't replace everything as it does not buffer elements while parsing addNodeToRightParent(currentNode_, newElement); + if ("svg".equals(tagLower)) { + insideSvg_ = true; + } + // If we had an old synthetic body and we just added a real body element, quietly // remove the old body and move its children to the real body element we just added. if (oldBody != null) { @@ -767,6 +773,10 @@ } } + if ("svg".equals(tagLower)) { + insideSvg_ = false; + } + // Need to reset this at each closing form tag because a valid form could start afterwards. if ("form".equals(tagLower)) { formWaitingForLostChildren_ = null; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -156,7 +156,20 @@ */ protected HtmlElement(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { - super(HTMLParser.XHTML_NAMESPACE, qualifiedName, page, attributes); + this(HTMLParser.XHTML_NAMESPACE, qualifiedName, page, attributes); + } + /** + * Creates an instance of a DOM element that can have a namespace. + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name of the element type to instantiate + * @param page the page that contains this element + * @param attributes a map ready initialized with the attributes for this element, or + * {@code null}. The map will be stored as is, not copied. + */ + protected HtmlElement(final String namespaceURI, final String qualifiedName, final SgmlPage page, + final Map<String, DomAttr> attributes) { + super(namespaceURI, qualifiedName, page, attributes); attributeListeners_ = new LinkedHashSet<>(); } 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-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -565,7 +565,7 @@ */ @Override public DomElement createElementNS(final String namespaceURI, final String qualifiedName) { - return HTMLParser.getElementFactory(this, namespaceURI, qualifiedName, true) + return HTMLParser.getElementFactory(this, namespaceURI, qualifiedName, true, false) .createElementNS(this, namespaceURI, qualifiedName, null, true); } Copied: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java (from rev 14479, trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java) =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSvg.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002-2017 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.html; + +import java.util.Map; + +import com.gargoylesoftware.htmlunit.SgmlPage; + +/** + * Wrapper for the SVG element {@code svg}. + * + * @author Ahmed Ashour + * @author Ronald Brill + */ +public class HtmlSvg extends HtmlElement { + + /** The tag represented by this element. */ + public static final String TAG_NAME = "svg"; + + /** + * Creates a new instance. + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name of the element type to instantiate + * @param page the page that contains this element + * @param attributes the initial attributes + */ + HtmlSvg(final String qualifiedName, final SgmlPage page, + final Map<String, DomAttr> attributes) { + super(HTMLParser.SVG_NAMESPACE, qualifiedName, page, attributes); + } +} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptObject.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -51,6 +51,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlTextArea; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import com.gargoylesoftware.htmlunit.html.HtmlTitle; +import com.gargoylesoftware.htmlunit.html.HtmlSvg; import com.gargoylesoftware.htmlunit.javascript.host.Element2; import com.gargoylesoftware.htmlunit.javascript.host.Window2; import com.gargoylesoftware.htmlunit.javascript.host.dom.Attr2; @@ -80,7 +81,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTitleElement2; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLUnknownElement2; import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGSVGElement2; -import com.gargoylesoftware.htmlunit.svg.SvgSvg; import com.gargoylesoftware.js.nashorn.internal.objects.Global; import com.gargoylesoftware.js.nashorn.internal.runtime.ScriptObject; @@ -295,7 +295,7 @@ host = HTMLStyleElement2.constructor(true, global); host.setDomNode(domNode); } - else if (domNode instanceof SvgSvg) { + else if (domNode instanceof HtmlSvg) { host = SVGSVGElement2.constructor(true, global); host.setDomNode(domNode); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -18,11 +18,11 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; +import com.gargoylesoftware.htmlunit.html.HtmlSvg; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; -import com.gargoylesoftware.htmlunit.svg.SvgSvg; /** * A JavaScript object for {@code SVGSVGElement}. @@ -29,7 +29,7 @@ * * @author Ahmed Ashour */ -@JsxClass(domClass = SvgSvg.class) +@JsxClass(domClass = HtmlSvg.class) public class SVGSVGElement extends SVGGraphicsElement { /** The constant {@code SVG_ZOOMANDPAN_UNKNOWN}. */ Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/svg/SvgSvg.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2002-2017 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.svg; - -import java.util.Map; - -import com.gargoylesoftware.htmlunit.SgmlPage; -import com.gargoylesoftware.htmlunit.html.DomAttr; - -/** - * Wrapper for the SVG element {@code svg}. - * - * @author Ahmed Ashour - */ -public class SvgSvg extends SvgElement { - - /** The tag represented by this element. */ - public static final String TAG_NAME = "svg"; - - /** - * Creates a new instance. - * - * @param namespaceURI the URI that identifies an XML namespace - * @param qualifiedName the qualified name of the element type to instantiate - * @param page the page that contains this element - * @param attributes the initial attributes - */ - SvgSvg(final String namespaceURI, final String qualifiedName, final SgmlPage page, - final Map<String, DomAttr> attributes) { - super(namespaceURI, qualifiedName, page, attributes); - } -} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementChildNodesTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1330,6 +1330,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSuperscript}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts({"3", "2", "2", "3", "2", "2"}) + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementClosesItselfTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1393,6 +1393,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSuperscript}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts("1") + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/AttributesTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -110,6 +110,7 @@ "HtmlSource", "HtmlSpan", "HtmlStrike", "HtmlStrong", "HtmlStyle", "HtmlSubscript", "HtmlSummary", "HtmlSuperscript", + "HtmlSvg", "HtmlTable", "HtmlTableColumn", "HtmlTableColumnGroup", "HtmlTableBody", "HtmlTableDataCell", "HtmlTableHeaderCell", "HtmlTableRow", "HtmlTextArea", "HtmlTableFooter", Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -28,7 +28,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -388,6 +387,36 @@ * @throws Exception if the test fails */ @Test + @Alerts({"[object SVGSVGElement]", "http://www.w3.org/2000/svg", + "[object SVGRectElement]", "http://www.w3.org/2000/svg"}) + public void htmlPageEmbeddedSvgWithoutNamespace() throws Exception { + final String content + = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + + "<head>\n" + + "<title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('mySvg'));\n" + + " alert(document.getElementById('mySvg').namespaceURI);\n" + + " alert(document.getElementById('myRect'));\n" + + " alert(document.getElementById('myRect').namespaceURI);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <svg id='mySvg'>\n" + + " <rect id='myRect' />\n" + + " </svg>\n" + + "</body>\n" + + "</html>"; + + loadPageWithAlerts2(content); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts("HTML") public void htmlPage() throws Exception { final String content @@ -414,7 +443,6 @@ */ @Test @Alerts("[object HTMLHtmlElement]") - @NotYetImplemented public void htmlSvgPage() throws Exception { final String content = "<html xmlns=\"http://www.w3.org/2000/svg\">\n" Copied: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java (from rev 14479, trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java) =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSvgTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2002-2017 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.html; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link HtmlSvg}. + * + * @author Ahmed Ashour + * @author Frank Danek + */ +@RunWith(BrowserRunner.class) +public class HtmlSvgTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("[object SVGSVGElement]") + public void simpleScriptable() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('myId'));\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "</body></html>"; + + final WebDriver driver = loadPageWithAlerts2(html); + if (driver instanceof HtmlUnitDriver) { + final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage(); + assertTrue(HtmlSvg.class.isInstance(page.getElementById("myId"))); + } + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("false") + public void style() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " alert(document.getElementById('myId').style == undefined);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"function", "function"}) + public void functions() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + " alert(typeof svg.getScreenCTM);\n" + + " alert(typeof svg.createSVGMatrix);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("[object SVGMatrix]") + public void getScreenCTM() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + " var svg = document.getElementById('myId');\n" + + " try {\n" + + " alert(svg.getScreenCTM());\n" + + " } catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java 2017-05-29 14:12:25 UTC (rev 14483) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgSvgTest.java 2017-05-29 15:25:56 UTC (rev 14484) @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2002-2017 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.svg; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.htmlunit.HtmlUnitDriver; - -import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.WebDriverTestCase; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlPageTest; - -/** - * Tests for {@link SvgSvg}. - * - * @author Ahmed Ashour - * @author Frank Danek - */ -@RunWith(BrowserRunner.class) -public class SvgSvgTest extends WebDriverTestCase { - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("[object SVGSVGElement]") - public void simpleScriptable() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><head>\n" - + "<script>\n" - + " function test() {\n" - + " alert(document.getElementById('myId'));\n" - + " }\n" - + "</script>\n" - + "</head><body onload='test()'>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "</body></html>"; - - final WebDriver driver = loadPageWithAlerts2(html); - if (driver instanceof HtmlUnitDriver) { - final HtmlPage page = (HtmlPage) getWebWindowOf((HtmlUnitDriver) driver).getEnclosedPage(); - assertTrue(SvgSvg.class.isInstance(page.getElementById("myId"))); - } - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("false") - public void style() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><body>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "<script>\n" - + " alert(document.getElementById('myId').style == undefined);\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts({"function", "function"}) - public void functions() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><body>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "<script>\n" - + " var svg = document.getElementById('myId');\n" - + " alert(typeof svg.getScreenCTM);\n" - + " alert(typeof svg.createSVGMatrix);\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("[object SVGMatrix]") - public void getScreenCTM() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "<html><body>\n" - + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" - + " </svg>\n" - + "<script>\n" - + " var svg = document.getElementById('myId');\n" - + " try {\n" - + " alert(svg.getScreenCTM());\n" - + " } catch(e) { alert('exception'); }\n" - + "</script>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); - } -} |
From: <rb...@us...> - 2017-05-29 16:27:56
|
Revision: 14485 http://sourceforge.net/p/htmlunit/code/14485 Author: rbri Date: 2017-05-29 16:27:53 +0000 (Mon, 29 May 2017) Log Message: ----------- missing tests for the new svg element Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementCreationTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementDefaultStyleDisplayTest.java 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-29 15:25:56 UTC (rev 14484) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-05-29 16:27:53 UTC (rev 14485) @@ -91,6 +91,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlRp; import com.gargoylesoftware.htmlunit.html.HtmlRt; import com.gargoylesoftware.htmlunit.html.HtmlScript; +import com.gargoylesoftware.htmlunit.html.HtmlSvg; import com.gargoylesoftware.htmlunit.html.HtmlUnknownElement; import com.gargoylesoftware.htmlunit.html.impl.SimpleRange; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; @@ -664,7 +665,7 @@ } final SgmlPage page = getPage(); - final org.w3c.dom.Node element = page.createElement(tagName); + org.w3c.dom.Node element = page.createElement(tagName); if (element instanceof BaseFrameElement) { ((BaseFrameElement) element).markAsCreatedByJavascript(); @@ -687,6 +688,9 @@ else if (element instanceof HtmlUnknownElement) { ((HtmlUnknownElement) element).markAsCreatedByJavascript(); } + else if (element instanceof HtmlSvg) { + element = page.createElement("unknown"); + } final Object jsElement = getScriptableFor(element); if (jsElement == NOT_FOUND) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementCreationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementCreationTest.java 2017-05-29 15:25:56 UTC (rev 14484) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementCreationTest.java 2017-05-29 16:27:53 UTC (rev 14485) @@ -1327,6 +1327,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSuperscript}. + * + * @throws Exception if an error occurs + */ + @Test + @Alerts("[object HTMLUnknownElement]") + public void svg() throws Exception { + test("svg"); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if an error occurs Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementDefaultStyleDisplayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementDefaultStyleDisplayTest.java 2017-05-29 15:25:56 UTC (rev 14484) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementDefaultStyleDisplayTest.java 2017-05-29 16:27:53 UTC (rev 14485) @@ -1501,6 +1501,19 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSuperscript}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"", "inline"}, + FF = {"block", "inline"}, + IE = {"inline", "inline"}) + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails |
From: <rb...@us...> - 2017-05-29 17:22:41
|
Revision: 14487 http://sourceforge.net/p/htmlunit/code/14487 Author: rbri Date: 2017-05-29 17:22:37 +0000 (Mon, 29 May 2017) Log Message: ----------- missing tests for the new svg element Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java 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-29 17:12:30 UTC (rev 14486) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-05-29 17:22:37 UTC (rev 14487) @@ -93,6 +93,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlScript; import com.gargoylesoftware.htmlunit.html.HtmlSvg; import com.gargoylesoftware.htmlunit.html.HtmlUnknownElement; +import com.gargoylesoftware.htmlunit.html.UnknownElementFactory; import com.gargoylesoftware.htmlunit.html.impl.SimpleRange; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnly; @@ -689,7 +690,8 @@ ((HtmlUnknownElement) element).markAsCreatedByJavascript(); } else if (element instanceof HtmlSvg) { - element = page.createElement("unknown"); + element = UnknownElementFactory.instance.createElementNS(page, "", "svg", null); + ((HtmlUnknownElement) element).markAsCreatedByJavascript(); } final Object jsElement = getScriptableFor(element); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java 2017-05-29 17:12:30 UTC (rev 14486) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java 2017-05-29 17:22:37 UTC (rev 14487) @@ -1117,6 +1117,15 @@ * @throws Exception if the test fails */ @Test + @Alerts("<svg></svg>") + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts("<table></table>") public void table() throws Exception { loadPageWithAlerts2(test("table")); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2017-05-29 17:12:30 UTC (rev 14486) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2017-05-29 17:22:37 UTC (rev 14487) @@ -2395,6 +2395,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSvg}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts("-") + public void svg() throws Exception { + test("svg"); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java 2017-05-29 17:12:30 UTC (rev 14486) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementClientWidthTest.java 2017-05-29 17:22:37 UTC (rev 14487) @@ -1460,6 +1460,19 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSvg}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "300", + FF = "0") + @NotYetImplemented + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java 2017-05-29 17:12:30 UTC (rev 14486) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/property/ElementOffsetWidthTest.java 2017-05-29 17:22:37 UTC (rev 14487) @@ -1461,6 +1461,17 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.html.HtmlSvg}. + * + * @throws Exception if the test fails + */ + @Test + @Alerts("NaN") + public void svg() throws Exception { + loadPageWithAlerts2(test("svg")); + } + + /** * Test {@link com.gargoylesoftware.htmlunit.html.HtmlTable}. * * @throws Exception if the test fails |
From: <asa...@us...> - 2017-05-31 08:43:20
|
Revision: 14505 http://sourceforge.net/p/htmlunit/code/14505 Author: asashour Date: 2017-05-31 08:43:17 +0000 (Wed, 31 May 2017) Log Message: ----------- JsxClass: add extendedClass() as a parameter Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JsxClass.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/performance/Performance.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfigurationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java 2017-05-31 08:04:04 UTC (rev 14504) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java 2017-05-31 08:43:17 UTC (rev 14505) @@ -128,6 +128,16 @@ boolean isJsObject = false; String className = null; + String extendedClassName = ""; + + final Class<?> superClass = klass.getSuperclass(); + if (superClass != SimpleScriptable.class) { + extendedClassName = superClass.getSimpleName(); + } + else { + extendedClassName = ""; + } + for (int i = 0; i < jsxClassValues.length; i++) { final JsxClass jsxClass = jsxClassValues[i]; @@ -139,12 +149,16 @@ if (!jsxClass.className().isEmpty()) { className = jsxClass.className(); } + if (jsxClass.extendedClass() != Object.class) { + extendedClassName = jsxClass.extendedClass().getSimpleName(); + } + break; } } final ClassConfiguration classConfiguration = new ClassConfiguration(klass, domClasses.toArray(new Class<?>[0]), isJsObject, - className); + className, extendedClassName); process(classConfiguration, hostClassName, expectedBrowser); return classConfiguration; @@ -163,9 +177,22 @@ if (className.isEmpty()) { className = null; } + String extendedClassName = ""; + + final Class<?> superClass = klass.getSuperclass(); + if (superClass != SimpleScriptable.class) { + extendedClassName = superClass.getSimpleName(); + } + else { + extendedClassName = ""; + } + if (jsxClass.extendedClass() != Object.class) { + extendedClassName = jsxClass.extendedClass().getSimpleName(); + } + final ClassConfiguration classConfiguration = new ClassConfiguration(klass, domClasses.toArray(new Class<?>[0]), jsxClass.isJSObject(), - className); + className, extendedClassName); process(classConfiguration, hostClassName, expectedBrowser); return classConfiguration; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java 2017-05-31 08:04:04 UTC (rev 14504) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java 2017-05-31 08:43:17 UTC (rev 14505) @@ -24,7 +24,6 @@ import java.util.Set; import com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable; -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; @@ -64,14 +63,7 @@ * @param className the class name, can be null */ public ClassConfiguration(final Class<? extends HtmlUnitScriptable> hostClass, final Class<?>[] domClasses, - final boolean jsObject, final String className) { - final Class<?> superClass = hostClass.getSuperclass(); - if (superClass != SimpleScriptable.class) { - extendedClassName_ = superClass.getSimpleName(); - } - else { - extendedClassName_ = ""; - } + final boolean jsObject, final String className, final String extendedClassName) { hostClass_ = hostClass; hostClassSimpleName_ = hostClass_.getSimpleName(); jsObject_ = jsObject; @@ -82,6 +74,7 @@ else { className_ = className; } + extendedClassName_ = extendedClassName; } void setJSConstructor(final Member jsConstructor) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JsxClass.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JsxClass.java 2017-05-31 08:04:04 UTC (rev 14504) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JsxClass.java 2017-05-31 08:43:17 UTC (rev 14505) @@ -54,6 +54,12 @@ String className() default ""; /** + * The extended (super) class. + * @return the extended (super) class + */ + Class<?> extendedClass() default Object.class; + + /** * The {@link SupportedBrowser}s supported by this constant. * @return the {@link SupportedBrowser}s */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/performance/Performance.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/performance/Performance.java 2017-05-31 08:04:04 UTC (rev 14504) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/performance/Performance.java 2017-05-31 08:43:17 UTC (rev 14505) @@ -17,7 +17,9 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; +import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE; +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; @@ -30,7 +32,8 @@ * @author Ahmed Ashour * @author Ronald Brill */ -@JsxClass +@JsxClass({CHROME, FF}) +@JsxClass(value = IE, extendedClass = SimpleScriptable.class) public class Performance extends EventTarget { private PerformanceTiming timing_; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfigurationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfigurationTest.java 2017-05-31 08:04:04 UTC (rev 14504) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfigurationTest.java 2017-05-31 08:43:17 UTC (rev 14505) @@ -32,7 +32,7 @@ */ @Test public void forJSFlagTrue() throws Exception { - final ClassConfiguration config1 = new ClassConfiguration(ConfigTestClass.class, null, true, null); + final ClassConfiguration config1 = new ClassConfiguration(ConfigTestClass.class, null, true, null, ""); assertTrue("JSObject Flag should have been set", config1.isJsObject()); } @@ -41,7 +41,7 @@ */ @Test public void forJSFlagFalse() throws Exception { - final ClassConfiguration config1 = new ClassConfiguration(ConfigTestClass.class, null, false, null); + final ClassConfiguration config1 = new ClassConfiguration(ConfigTestClass.class, null, false, null, ""); assertFalse("JSObject Flag should not have been set", config1.isJsObject()); } |
From: <asa...@us...> - 2017-05-31 09:14:55
|
Revision: 14506 http://sourceforge.net/p/htmlunit/code/14506 Author: asashour Date: 2017-05-31 09:14:52 +0000 (Wed, 31 May 2017) Log Message: ----------- DocumentFragment fix Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentFragment.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentFragment.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentFragment.java 2017-05-31 08:43:17 UTC (rev 14505) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentFragment.java 2017-05-31 09:14:52 UTC (rev 14506) @@ -17,7 +17,6 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; -import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE; import org.w3c.css.sac.CSSException; @@ -26,7 +25,6 @@ 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.host.html.HTMLDocument; import net.sourceforge.htmlunit.corejs.javascript.Context; @@ -42,8 +40,6 @@ @JsxClass(domClass = DomDocumentFragment.class) public class DocumentFragment extends Node { - //TODO: seems that in IE, DocumentFragment extends HTMLDocument - /** * Creates an instance. */ @@ -52,55 +48,6 @@ } /** - * Creates a new HTML attribute with the specified name. - * - * @param attributeName the name of the attribute to create - * @return an attribute with the specified name - */ - @JsxFunction(IE) - public Object createAttribute(final String attributeName) { - return getDocument().createAttribute(attributeName); - } - - /** - * Returns HTML document. - * @return HTML document - */ - protected HTMLDocument getDocument() { - return (HTMLDocument) getDomNodeOrDie().getPage().getScriptableObject(); - } - - /** - * Creates a new Comment. - * @param comment the comment text - * @return the new Comment - */ - @JsxFunction(IE) - public Object createComment(final String comment) { - return getDocument().createComment(comment); - } - - /** - * Creates a new document fragment. - * @return a newly created document fragment - */ - @JsxFunction(IE) - public Object createDocumentFragment() { - return getDocument().createDocumentFragment(); - } - - /** - * Create a new DOM text node with the given data. - * - * @param newData the string value for the text node - * @return the new text node or NOT_FOUND if there is an error - */ - @JsxFunction(IE) - public Object createTextNode(final String newData) { - return getDocument().createTextNode(newData); - } - - /** * Retrieves all element nodes from descendants of the starting element node that match any selector * within the supplied selector strings. * The NodeList object returned by the querySelectorAll() method must be static, not live. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2017-05-31 08:43:17 UTC (rev 14505) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2017-05-31 09:14:52 UTC (rev 14506) @@ -3178,4 +3178,45 @@ testString("document.createRange(), window.performance"); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "append(),appendChild(),ATTRIBUTE_NODE,baseURI,CDATA_SECTION_NODE,childElementCount,childNodes," + + "children,cloneNode(),COMMENT_NODE,compareDocumentPosition(),contains(),DOCUMENT_FRAGMENT_NODE," + + "DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS," + + "DOCUMENT_POSITION_DISCONNECTED,DOCUMENT_POSITION_FOLLOWING," + + "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,DOCUMENT_POSITION_PRECEDING,DOCUMENT_TYPE_NODE," + + "ELEMENT_NODE,ENTITY_NODE,ENTITY_REFERENCE_NODE,firstChild,firstElementChild,getElementById()," + + "getRootNode(),hasChildNodes(),insertBefore(),isConnected,isDefaultNamespace(),isEqualNode()," + + "isSameNode(),lastChild,lastElementChild,lookupNamespaceURI(),lookupPrefix(),nextSibling,nodeName," + + "nodeType,nodeValue,normalize(),NOTATION_NODE,ownerDocument,parentElement,parentNode,prepend()," + + "previousSibling,PROCESSING_INSTRUCTION_NODE,querySelector(),querySelectorAll(),removeChild()," + + "replaceChild(),TEXT_NODE,textContent", + FF = "addEventListener(),append(),appendChild(),ATTRIBUTE_NODE,baseURI,CDATA_SECTION_NODE," + + "childElementCount,childNodes,children,cloneNode(),COMMENT_NODE,compareDocumentPosition(),contains()," + + "dispatchEvent(),DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE,DOCUMENT_POSITION_CONTAINED_BY," + + "DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_DISCONNECTED,DOCUMENT_POSITION_FOLLOWING," + + "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,DOCUMENT_POSITION_PRECEDING,DOCUMENT_TYPE_NODE," + + "ELEMENT_NODE,ENTITY_NODE,ENTITY_REFERENCE_NODE,firstChild,firstElementChild,getElementById()," + + "hasChildNodes(),insertBefore(),isConnected,isDefaultNamespace(),isEqualNode(),isSameNode()," + + "lastChild,lastElementChild,lookupNamespaceURI(),lookupPrefix(),nextSibling,nodeName,nodeType," + + "nodeValue,normalize(),NOTATION_NODE,ownerDocument,parentElement,parentNode,prepend()," + + "previousSibling,PROCESSING_INSTRUCTION_NODE,querySelector(),querySelectorAll(),removeChild()," + + "removeEventListener(),replaceChild(),TEXT_NODE,textContent", + IE = "addEventListener(),appendChild(),ATTRIBUTE_NODE,attributes,CDATA_SECTION_NODE,childNodes,cloneNode()," + + "COMMENT_NODE,compareDocumentPosition(),dispatchEvent(),DOCUMENT_FRAGMENT_NODE,DOCUMENT_NODE," + + "DOCUMENT_POSITION_CONTAINED_BY,DOCUMENT_POSITION_CONTAINS,DOCUMENT_POSITION_DISCONNECTED," + + "DOCUMENT_POSITION_FOLLOWING,DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,DOCUMENT_POSITION_PRECEDING," + + "DOCUMENT_TYPE_NODE,ELEMENT_NODE,ENTITY_NODE,ENTITY_REFERENCE_NODE,firstChild,hasAttributes()," + + "hasChildNodes(),insertBefore(),isDefaultNamespace(),isEqualNode(),isSameNode(),isSupported()," + + "lastChild,localName,lookupNamespaceURI(),lookupPrefix(),namespaceURI,nextSibling,nodeName,nodeType," + + "nodeValue,normalize(),NOTATION_NODE,ownerDocument,parentNode,prefix,previousSibling," + + "PROCESSING_INSTRUCTION_NODE,querySelector(),querySelectorAll(),removeChild(),removeEventListener()," + + "removeNode(),replaceChild(),replaceNode(),swapNode(),TEXT_NODE,textContent") + @NotYetImplemented + public void documentFragment() throws Exception { + testString("document.createDocumentFragment(), window.performance"); + } + } |
From: <asa...@us...> - 2017-05-31 10:37:33
|
Revision: 14509 http://sourceforge.net/p/htmlunit/code/14509 Author: asashour Date: 2017-05-31 10:37:30 +0000 (Wed, 31 May 2017) Log Message: ----------- - Fix Element.remove() - Test missing FF45 expectations Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 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 2017-05-31 09:25:00 UTC (rev 14508) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2017-05-31 10:37:30 UTC (rev 14509) @@ -1970,4 +1970,13 @@ setEventHandler("pointerup", onpointerup); } + /** + * {@inheritDoc} + */ + @Override + @JsxFunction({CHROME, FF, EDGE}) + public void remove() { + super.remove(); + } + } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java 2017-05-31 09:25:00 UTC (rev 14508) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java 2017-05-31 10:37:30 UTC (rev 14509) @@ -177,4 +177,13 @@ return null; } + /** + * {@inheritDoc} + */ + @Override + @JsxFunction({CHROME, FF, EDGE}) + public void remove() { + super.remove(); + } + } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java 2017-05-31 09:25:00 UTC (rev 14508) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java 2017-05-31 10:37:30 UTC (rev 14509) @@ -28,6 +28,7 @@ import com.gargoylesoftware.htmlunit.html.DomDocumentType; 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.Undefined; @@ -160,4 +161,13 @@ return super.getNamespaceURI(); } + /** + * {@inheritDoc} + */ + @Override + @JsxFunction({CHROME, FF, EDGE}) + public void remove() { + super.remove(); + } + } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java 2017-05-31 09:25:00 UTC (rev 14508) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java 2017-05-31 10:37:30 UTC (rev 14509) @@ -372,8 +372,7 @@ * Removes the DOM node from its parent. * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove">MDN documentation</a> */ - @JsxFunction({CHROME, FF, EDGE}) - public void remove() { + protected void remove() { getDomNodeOrDie().remove(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2017-05-31 09:25:00 UTC (rev 14508) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2017-05-31 10:37:30 UTC (rev 14509) @@ -557,9 +557,57 @@ } /** + * Test {@link com.gargoylesoftware.htmlunit.javascript.host.Element}. + * * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "after(),animate(),assignedSlot,attachShadow(),attributes,before(),classList,className," + + "clientHeight,clientLeft,clientTop,clientWidth,closest(),createShadowRoot(),getAttribute()," + + "getAttributeNode(),getAttributeNodeNS(),getAttributeNS(),getBoundingClientRect(),getClientRects()," + + "getDestinationInsertionPoints(),getElementsByClassName(),getElementsByTagName()," + + "getElementsByTagNameNS(),hasAttribute(),hasAttributeNS(),hasAttributes(),hasPointerCapture(),id," + + "innerHTML,insertAdjacentElement(),insertAdjacentHTML(),insertAdjacentText(),localName,matches()," + + "namespaceURI,nextElementSibling,onbeforecopy,onbeforecut,onbeforepaste,oncopy,oncut,onpaste," + + "onsearch,onselectstart,onwebkitfullscreenchange,onwebkitfullscreenerror,onwheel,outerHTML,prefix," + + "previousElementSibling,releasePointerCapture(),remove(),removeAttribute(),removeAttributeNode()," + + "removeAttributeNS(),replaceWith(),requestPointerLock(),scrollHeight,scrollIntoView()," + + "scrollIntoViewIfNeeded(),scrollLeft,scrollTop,scrollWidth,setAttribute(),setAttributeNode()," + + "setAttributeNodeNS(),setAttributeNS(),setPointerCapture(),shadowRoot,slot,tagName," + + "webkitMatchesSelector(),webkitRequestFullScreen(),webkitRequestFullscreen()", + FF52 = "after(),animate(),attributes,before(),classList,className,clientHeight,clientLeft,clientTop," + + "clientWidth,closest(),getAttribute(),getAttributeNames(),getAttributeNode(),getAttributeNodeNS()," + + "getAttributeNS(),getBoundingClientRect(),getClientRects(),getElementsByClassName()," + + "getElementsByTagName(),getElementsByTagNameNS(),hasAttribute(),hasAttributeNS(),hasAttributes(),id," + + "innerHTML,insertAdjacentElement(),insertAdjacentHTML(),insertAdjacentText(),localName,matches()," + + "mozMatchesSelector(),mozRequestFullScreen(),namespaceURI,nextElementSibling,onwheel,outerHTML," + + "prefix,previousElementSibling,releaseCapture(),remove(),removeAttribute(),removeAttributeNode()," + + "removeAttributeNS(),replaceWith(),requestPointerLock(),scroll(),scrollBy(),scrollHeight," + + "scrollIntoView(),scrollLeft,scrollLeftMax,scrollTo(),scrollTop,scrollTopMax,scrollWidth," + + "setAttribute(),setAttributeNode(),setAttributeNodeNS(),setAttributeNS(),setCapture(),tagName," + + "webkitMatchesSelector()", + IE = "childElementCount,clientHeight,clientLeft,clientTop,clientWidth,firstElementChild,getAttribute()," + + "getAttributeNode(),getAttributeNodeNS(),getAttributeNS(),getBoundingClientRect(),getClientRects()," + + "getElementsByTagName(),getElementsByTagNameNS(),hasAttribute(),hasAttributeNS(),lastElementChild," + + "msContentZoomFactor,msGetRegionContent(),msGetUntransformedBounds(),msMatchesSelector()," + + "msRegionOverflow,msReleasePointerCapture(),msRequestFullscreen(),msSetPointerCapture()," + + "nextElementSibling,ongotpointercapture,onlostpointercapture,onmsgesturechange,onmsgesturedoubletap," + + "onmsgestureend,onmsgesturehold,onmsgesturestart,onmsgesturetap,onmsgotpointercapture," + + "onmsinertiastart,onmslostpointercapture,onmspointercancel,onmspointerdown,onmspointerenter," + + "onmspointerleave,onmspointermove,onmspointerout,onmspointerover,onmspointerup,onpointercancel," + + "onpointerdown,onpointerenter,onpointerleave,onpointermove,onpointerout,onpointerover,onpointerup," + + "previousElementSibling,releasePointerCapture(),removeAttribute(),removeAttributeNode()," + + "removeAttributeNS(),scrollHeight,scrollLeft,scrollTop,scrollWidth,setAttribute(),setAttributeNode()," + + "setAttributeNodeNS(),setAttributeNS(),setPointerCapture(),tagName") + @NotYetImplemented + public void element2() throws Exception { + testString("element, document.createDocumentFragment()"); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = "-", IE = "blockDirection,clipBottom,clipLeft,clipRight,clipTop,hasLayout") @NotYetImplemented(IE) |
From: <asa...@us...> - 2017-05-31 10:46:44
|
Revision: 14510 http://sourceforge.net/p/htmlunit/code/14510 Author: asashour Date: 2017-05-31 10:46:40 +0000 (Wed, 31 May 2017) Log Message: ----------- TextArea.minLength Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2017-05-31 10:37:30 UTC (rev 14509) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2017-05-31 10:46:40 UTC (rev 14510) @@ -313,11 +313,46 @@ } catch (final NumberFormatException e) { getDomNodeOrDie().setAttribute("maxLength", "0"); - return; } } /** + * Returns the minimum number of characters in this text area. + * @return the minimum number of characters in this text area + */ + @JsxGetter({CHROME, FF}) + public Object getMinLength() { + final String minLength = getDomNodeOrDie().getAttribute("minLength"); + + try { + return Integer.parseInt(minLength); + } + catch (final NumberFormatException e) { + return -1; + } + } + + /** + * Sets minimum number of characters in this text area. + * @param minLength minimum number of characters in this text area. + */ + @JsxSetter({CHROME, FF}) + public void setMinLength(final String minLength) { + try { + final int i = Integer.parseInt(minLength); + + if (i < 0 ) { + throw Context.throwAsScriptRuntimeEx( + new NumberFormatException("New value for minLength '" + minLength + "' is smaller than zero.")); + } + getDomNodeOrDie().setAttribute("minLength", minLength); + } + catch (final NumberFormatException e) { + getDomNodeOrDie().setAttribute("minLength", "0"); + } + } + + /** * Returns the {@code placeholder} attribute. * @return the {@code placeholder} attribute */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java 2017-05-31 10:37:30 UTC (rev 14509) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java 2017-05-31 10:46:40 UTC (rev 14510) @@ -602,7 +602,7 @@ @Test @Alerts(DEFAULT = {"-1", "null", "32", "32", "-1", "ms"}, IE = {"2147483647", "null", "32", "32", "2147483647", "ms"}) - public void getMaxLength() throws Exception { + public void maxLength() throws Exception { final String html = "<html>\n" + "<head><title>foo</title>\n" @@ -618,7 +618,7 @@ + " </script>\n" + "</head>\n" + "<body onload='test()'>\n" - + " <form name='form1' method='post' >\n" + + " <form name='form1' method='post'>\n" + " <textarea name='textarea1'></textarea>\n" + " <textarea name='textarea2' maxLength='32'></textarea>\n" + " <textarea name='textarea3' maxLength='ms'></textarea>\n" @@ -632,6 +632,38 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = {"-1", "null", "32", "32", "-1", "ms"}, + IE = {"undefined", "null", "undefined", "32", "undefined", "ms"}) + public void minLength() throws Exception { + final String html + = "<html>\n" + + "<head><title>foo</title>\n" + + " <script>\n" + + " function test() {\n" + + " alert(document.form1.textarea1.minLength);\n" + + " alert(document.form1.textarea1.getAttribute('minLength'));\n" + + " alert(document.form1.textarea2.minLength);\n" + + " alert(document.form1.textarea2.getAttribute('minLength'));\n" + + " alert(document.form1.textarea3.minLength);\n" + + " alert(document.form1.textarea3.getAttribute('minLength'));\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <form name='form1' method='post'>\n" + + " <textarea name='textarea1'></textarea>\n" + + " <textarea name='textarea2' minLength='32'></textarea>\n" + + " <textarea name='textarea3' minLength='ms'></textarea>\n" + + " </form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = {"10", "10", "error", "10", "10", "0", "0"}, IE = {"10", "10", "-1", "-1", "0", "0"}) public void setMaxLength() throws Exception { |
From: <asa...@us...> - 2017-05-31 11:07:56
|
Revision: 14511 http://sourceforge.net/p/htmlunit/code/14511 Author: asashour Date: 2017-05-31 11:07:54 +0000 (Wed, 31 May 2017) Log Message: ----------- Use TimeZone for BrowserVersion.set/getSystemTimezone() Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-05-31 10:46:40 UTC (rev 14510) +++ trunk/htmlunit/src/changes/changes.xml 2017-05-31 11:07:54 UTC (rev 14511) @@ -9,7 +9,7 @@ <body> <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> <action type="fix" dev="rbri" issue="1827"> - Simulated system time zone is now configurable (BrowserVersion.setSystemTimezone(String)). + Simulated system time zone is now configurable (BrowserVersion.setSystemTimezone()). </action> <action type="fix" dev="asashour" issue="1886"> JavaScript: fix Set/Map with undefined value. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-31 10:46:40 UTC (rev 14510) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-31 11:07:54 UTC (rev 14511) @@ -24,6 +24,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TimeZone; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -107,7 +108,7 @@ private static final String LANGUAGE_ENGLISH_US = "en-US"; /** - * United States . + * United States. */ private static final String TIMEZONE_NEW_YORK = "America/New_York"; @@ -354,7 +355,7 @@ private boolean onLine_ = true; private String platform_ = PLATFORM_WIN32; private String systemLanguage_ = LANGUAGE_ENGLISH_US; - private String systemTimezone_ = TIMEZONE_NEW_YORK; + private TimeZone systemTimezone_ = TimeZone.getTimeZone(TIMEZONE_NEW_YORK); private String userAgent_; private String userLanguage_ = LANGUAGE_ENGLISH_US; private int browserVersionNumeric_; @@ -620,11 +621,11 @@ } /** - * Returns the system timezone, for example "America/New_York". - * Default value is {@link #TIMEZONE_NEW_YORK} if not explicitly configured. - * @return the system timezone + * Returns the system {@link TimeZone}. + * Default value is {@code America/New_York} if not explicitly configured. + * @return the system {@link TimeZone} */ - public String getSystemTimezone() { + public TimeZone getSystemTimezone() { return systemTimezone_; } @@ -763,7 +764,7 @@ /** * @param systemTimezone the systemTimezone to set */ - public void setSystemTimezone(final String systemTimezone) { + public void setSystemTimezone(final TimeZone systemTimezone) { systemTimezone_ = systemTimezone; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java 2017-05-31 10:46:40 UTC (rev 14510) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java 2017-05-31 11:07:54 UTC (rev 14511) @@ -74,7 +74,7 @@ final Date date = new Date(getLastModified()); final BrowserVersion browser = getBrowserVersion(); final Locale locale = new Locale(browser.getSystemLanguage()); - final TimeZone timezone = TimeZone.getTimeZone(browser.getSystemTimezone()); + final TimeZone timezone = browser.getSystemTimezone(); if (browser.hasFeature(JS_FILE_SHORT_DATE_FORMAT)) { final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT_FF, timezone, locale); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2017-05-31 10:46:40 UTC (rev 14510) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2017-05-31 11:07:54 UTC (rev 14511) @@ -337,7 +337,7 @@ } else { final int st = i - state + offset; - result .replace(st, st + 1, "%25"); + result.replace(st, st + 1, "%25"); offset = offset + 2; state = 0; } @@ -345,7 +345,7 @@ } if (state == 1 || state == 2) { final int st = input.length - state + offset; - result .replace(st, st + 1, "%25"); + result.replace(st, st + 1, "%25"); } return result.toString(); } |
From: <asa...@us...> - 2017-05-31 21:12:04
|
Revision: 14519 http://sourceforge.net/p/htmlunit/code/14519 Author: asashour Date: 2017-05-31 21:12:01 +0000 (Wed, 31 May 2017) Log Message: ----------- JavaScript: implement .before(), .after() and .replaceWith() Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/SeleniumTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/changes/changes.xml 2017-05-31 21:12:01 UTC (rev 14519) @@ -8,6 +8,9 @@ <body> <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> + <action type="add" dev="asashour"> + JavaScript: implement .before(), .after() and .replaceWith(). + </action> <action type="fix" dev="rbri" issue="1827"> Simulated system time zone is now configurable (BrowserVersion.setSystemTimezone()). </action> 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 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -1955,4 +1955,44 @@ super.remove(); } + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just before this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void before(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.before(context, thisObj, args, function); + } + + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just after this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void after(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.after(context, thisObj, args, function); + } + + /** + * Replaces the node wit a set of Node or DOMString objects. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void replaceWith(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.replaceWith(context, thisObj, args, function); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/CharacterData.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -29,6 +29,8 @@ import com.gargoylesoftware.htmlunit.javascript.host.Element; import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.Function; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; /** * A JavaScript object for {@code CharacterData}. @@ -186,4 +188,44 @@ super.remove(); } + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just before this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void before(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.before(context, thisObj, args, function); + } + + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just after this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void after(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.after(context, thisObj, args, function); + } + + /** + * Replaces the node wit a set of Node or DOMString objects. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void replaceWith(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.replaceWith(context, thisObj, args, function); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DocumentType.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -31,6 +31,9 @@ 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.Function; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.Undefined; /** @@ -170,4 +173,44 @@ super.remove(); } + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just before this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void before(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.before(context, thisObj, args, function); + } + + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just after this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void after(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.after(context, thisObj, args, function); + } + + /** + * Replaces the node wit a set of Node or DOMString objects. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + @JsxFunction({CHROME, FF}) + public static void replaceWith(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + Node.replaceWith(context, thisObj, args, function); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Node.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -42,6 +42,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.Element; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLHtmlElement; import net.sourceforge.htmlunit.corejs.javascript.Context; @@ -795,4 +796,83 @@ }; return collection; } + + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just after this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + protected static void after(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + final DomNode thisDomNode = ((Node) thisObj).getDomNodeOrDie(); + final DomNode parentNode = thisDomNode.getParentNode(); + final DomNode nextSibling = thisDomNode.getNextSibling(); + for (Object arg : args) { + final Node node = toNodeOrTextNode((Node) thisObj, arg); + final DomNode newNode = node.getDomNodeOrDie(); + if (nextSibling != null) { + nextSibling.insertBefore(newNode); + } + else { + parentNode.appendChild(newNode); + } + } + } + + private static Node toNodeOrTextNode(final Node thisObj, final Object obj) { + if (obj instanceof Node) { + return (Node) obj; + } + return (Node) + ((HTMLDocument) thisObj.getOwnerDocument()).createTextNode(Context.toString(obj)); + } + + /** + * Inserts a set of Node or DOMString objects in the children list of this ChildNode's parent, + * just before this ChildNode. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + protected static void before(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + for (Object arg : args) { + final Node node = toNodeOrTextNode((Node) thisObj, arg); + ((Node) thisObj).getDomNodeOrDie().insertBefore(node.getDomNodeOrDie()); + } + } + + /** + * Replaces this ChildNode in the children list of its parent with a set of Node or DOMString objects. + * @param context the context + * @param thisObj this object + * @param args the arguments + * @param function the function + */ + protected static void replaceWith(final Context context, final Scriptable thisObj, final Object[] args, + final Function function) { + final DomNode thisDomNode = ((Node) thisObj).getDomNodeOrDie(); + final DomNode parentNode = thisDomNode.getParentNode(); + final DomNode nextSibling = thisDomNode.getNextSibling(); + boolean isFirst = true; + for (Object arg : args) { + final DomNode newNode = toNodeOrTextNode((Node) thisObj, arg).getDomNodeOrDie(); + if (isFirst) { + isFirst = false; + thisDomNode.replace(newNode); + } + else { + if (nextSibling != null) { + nextSibling.insertBefore(newNode); + } + else { + parentNode.appendChild(newNode); + } + } + } + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -1089,7 +1089,7 @@ * This should be always 0, if {@link #isWebClientCached()} is {@code false}. */ @Before - public void before() { + public void beforeTest() { if (!isWebClientCached()) { assertTrue(getJavaScriptThreads().isEmpty()); } 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 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/NodeTest.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -1185,4 +1185,88 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "<div><span></span>nullundefinedhello<p></p></div>", + IE = "<div><p></p></div>") + public void before() throws Exception { + final String html = + "<html><head>\n" + + " <script>\n" + + " function test() {\n" + + " var parent = document.createElement('div');\n" + + " var child = document.createElement('p');\n" + + " parent.appendChild(child);\n" + + " var span = document.createElement('span');\n" + + " if (child.before) {" + + " child.before(span, null, undefined, 'hello');\n" + + " }\n" + + " alert(parent.outerHTML);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "<div><p></p><span></span>nullundefinedhello</div>", + IE = "<div><p></p></div>") + public void after() throws Exception { + final String html = + "<html><head>\n" + + " <script>\n" + + " function test() {\n" + + " var parent = document.createElement('div');\n" + + " var child = document.createElement('p');\n" + + " parent.appendChild(child);\n" + + " var span = document.createElement('span');\n" + + " if (child.after) {" + + " child.after(span, null, undefined, 'hello');\n" + + " }\n" + + " alert(parent.outerHTML);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "<div><span></span>nullundefinedhello</div>", + IE = "<div><p></p></div>") + public void replaceWith() throws Exception { + final String html = + "<html><head>\n" + + " <script>\n" + + " function test() {\n" + + " var parent = document.createElement('div');\n" + + " var child = document.createElement('p');\n" + + " parent.appendChild(child);\n" + + " var span = document.createElement('span');\n" + + " if (child.replaceWith) {" + + " child.replaceWith(span, null, undefined, 'hello');\n" + + " }\n" + + " alert(parent.outerHTML);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'></body>\n" + + "</html>"; + + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/SeleniumTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/SeleniumTest.java 2017-05-31 19:32:05 UTC (rev 14518) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/selenium/SeleniumTest.java 2017-05-31 21:12:01 UTC (rev 14519) @@ -31,7 +31,7 @@ */ @Override @Before - public void before() { + public void beforeTest() { try { startWebServer("src/test/resources/selenium", null, null); } |
From: <asa...@us...> - 2017-06-01 07:28:58
|
Revision: 14520 http://sourceforge.net/p/htmlunit/code/14520 Author: asashour Date: 2017-06-01 07:28:54 +0000 (Thu, 01 Jun 2017) Log Message: ----------- JavaScript: implement Element.matches() Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/changes/changes.xml 2017-06-01 07:28:54 UTC (rev 14520) @@ -9,6 +9,9 @@ <body> <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> <action type="add" dev="asashour"> + JavaScript: implement Element.matches(). + </action> + <action type="add" dev="asashour"> JavaScript: implement .before(), .after() and .replaceWith(). </action> <action type="fix" dev="rbri" issue="1827"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-06-01 07:28:54 UTC (rev 14520) @@ -36,6 +36,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.css.sac.CSSException; +import org.w3c.css.sac.Selector; +import org.w3c.css.sac.SelectorList; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; import org.w3c.dom.Element; @@ -43,6 +46,7 @@ import org.w3c.dom.Node; import org.w3c.dom.TypeInfo; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.SgmlPage; @@ -54,6 +58,7 @@ import com.gargoylesoftware.htmlunit.javascript.NashornJavaScriptEngine; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptObject; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.Event2; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; @@ -1599,6 +1604,30 @@ return false; } + /** + * Returns true if the element would be selected by the specified selector string; otherwise, returns false. + * @param selectorString the selector to test + * @return true if the element would be selected by the specified selector string; otherwise, returns false. + */ + public boolean matches(final String selectorString) { + try { + final BrowserVersion browserVersion = getPage().getWebClient().getBrowserVersion(); + final SelectorList selectorList = getSelectorList(selectorString, browserVersion); + + if (selectorList != null) { + for (int i = 0; i < selectorList.getLength(); i++) { + final Selector selector = selectorList.item(i); + if (CSSStyleSheet.selects(browserVersion, selector, this, null, true)) { + return true; + } + } + } + return false; + } + catch (final IOException e) { + throw new CSSException("Error parsing CSS selectors from '" + selectorString + "': " + e.getMessage()); + } + } } /** @@ -1830,4 +1859,5 @@ public Collection<DomAttr> values() { return map_.values(); } + } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2017-06-01 07:28:54 UTC (rev 14520) @@ -1898,29 +1898,11 @@ */ public DomNodeList<DomNode> querySelectorAll(final String selectors) { try { - final WebClient webClient = getPage().getWebClient(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); - final CheckErrorHandler errorHandler = new CheckErrorHandler(); - parser.setErrorHandler(errorHandler); + final BrowserVersion browserVersion = getPage().getWebClient().getBrowserVersion(); + final SelectorList selectorList = getSelectorList(selectors, browserVersion); - final SelectorList selectorList = parser.parseSelectors(new InputSource(new StringReader(selectors))); - // in case of error parseSelectors returns null - if (errorHandler.errorDetected()) { - throw new CSSException("Invalid selectors: " + selectors); - } - final List<DomNode> elements = new ArrayList<>(); if (selectorList != null) { - final BrowserVersion browserVersion = webClient.getBrowserVersion(); - int documentMode = 9; - if (browserVersion.hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS)) { - final Object sobj = getPage().getScriptableObject(); - if (sobj instanceof HTMLDocument) { - documentMode = ((HTMLDocument) sobj).getDocumentMode(); - } - } - CSSStyleSheet.validateSelectors(selectorList, documentMode, this); - for (final DomElement child : getDomElementDescendants()) { for (int i = 0; i < selectorList.getLength(); i++) { final Selector selector = selectorList.item(i); @@ -1939,6 +1921,39 @@ } /** + * Returns the {@link SelectorList}. + * @param selectors the selectors + * @param browserVersion the {@link BrowserVersion} + * @return the {@link SelectorList} + * @throws IOException if an error occurs + */ + protected SelectorList getSelectorList(final String selectors, final BrowserVersion browserVersion) + throws IOException { + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); + final CheckErrorHandler errorHandler = new CheckErrorHandler(); + parser.setErrorHandler(errorHandler); + + final SelectorList selectorList = parser.parseSelectors(new InputSource(new StringReader(selectors))); + // in case of error parseSelectors returns null + if (errorHandler.errorDetected()) { + throw new CSSException("Invalid selectors: " + selectors); + } + + if (selectorList != null) { + int documentMode = 9; + if (browserVersion.hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS)) { + final Object sobj = getPage().getScriptableObject(); + if (sobj instanceof HTMLDocument) { + documentMode = ((HTMLDocument) sobj).getDocumentMode(); + } + } + CSSStyleSheet.validateSelectors(selectorList, documentMode, this); + + } + return selectorList; + } + + /** * Returns the first element within the document that matches the specified group of selectors. * @param selectors one or more CSS selectors separated by commas * @param <N> the node type Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/ClassConfiguration.java 2017-06-01 07:28:54 UTC (rev 14520) @@ -61,6 +61,7 @@ * @param domClasses the DOM classes that this object supports * @param jsObject boolean flag for if this object is a JavaScript object * @param className the class name, can be null + * @param extendedClassName the extended class name */ public ClassConfiguration(final Class<? extends HtmlUnitScriptable> hostClass, final Class<?>[] domClasses, final boolean jsObject, final String className, final String extendedClassName) { 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 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2017-06-01 07:28:54 UTC (rev 14520) @@ -1995,4 +1995,44 @@ final Function function) { Node.replaceWith(context, thisObj, args, function); } + + /** + * Returns true if the element would be selected by the specified selector string; otherwise, returns false. + * @param selectorString the selector to test + * @return the value + */ + @JsxFunction({CHROME, FF}) + public boolean matches(final String selectorString) { + return getDomNodeOrDie().matches(selectorString); + } + + /** + * Returns true if the element would be selected by the specified selector string; otherwise, returns false. + * @param selectorString the selector to test + * @return the value + */ + @JsxFunction(FF) + public boolean mozMatchesSelector(final String selectorString) { + return matches(selectorString); + } + + /** + * Returns true if the element would be selected by the specified selector string; otherwise, returns false. + * @param selectorString the selector to test + * @return the value + */ + @JsxFunction({CHROME, FF}) + public boolean webkitMatchesSelector(final String selectorString) { + return matches(selectorString); + } + + /** + * Returns true if the element would be selected by the specified selector string; otherwise, returns false. + * @param selectorString the selector to test + * @return the value + */ + @JsxFunction(IE) + public boolean msMatchesSelector(final String selectorString) { + return matches(selectorString); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2017-06-01 07:28:54 UTC (rev 14520) @@ -341,7 +341,7 @@ try { final int i = Integer.parseInt(minLength); - if (i < 0 ) { + if (i < 0) { throw Context.throwAsScriptRuntimeEx( new NumberFormatException("New value for minLength '" + minLength + "' is smaller than zero.")); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2017-05-31 21:12:01 UTC (rev 14519) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2017-06-01 07:28:54 UTC (rev 14520) @@ -1265,4 +1265,39 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "Philippine eagle", + IE = "not found") + public void matches() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " var birds = document.getElementsByTagName('li');\n" + + " var found = false;" + + " for (var i = 0; i < birds.length; i++) {\n" + + " if (birds[i].matches && birds[i].matches('.endangered')) {\n" + + " alert(birds[i].textContent);\n" + + " found = true;" + + " }\n" + + " }\n" + + " if (!found) {\n" + + " alert('not found');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <ul id='birds'>\n" + + " <li>Orange-winged parrot</li>\n" + + " <li class='endangered'>Philippine eagle</li>\n" + + " <li>Great white pelican</li>\n" + + " </ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <asa...@us...> - 2017-06-02 15:01:45
|
Revision: 14531 http://sourceforge.net/p/htmlunit/code/14531 Author: asashour Date: 2017-06-02 15:01:42 +0000 (Fri, 02 Jun 2017) Log Message: ----------- Add regression test detected by WebDriver Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-06-02 06:14:24 UTC (rev 14530) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-06-02 15:01:42 UTC (rev 14531) @@ -1308,7 +1308,6 @@ final boolean altKey, final int button) { final SgmlPage page = getPage(); - final ScriptResult scriptResult; final Event event; if (MouseEvent.TYPE_CONTEXT_MENU.equals(eventType) Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-06-02 06:14:24 UTC (rev 14530) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-06-02 15:01:42 UTC (rev 14531) @@ -2488,7 +2488,7 @@ * @return a ScriptResult which will contain both the current page (which may be different than * the previous page and a JavaScript result object. */ - public ScriptResult executeJavaScriptFunction(Object function, final Object thisObject, + public ScriptResult executeJavaScriptFunction(final Object function, final Object thisObject, final Object[] args, final DomNode htmlElementScope) { if (!getWebClient().getOptions().isJavaScriptEnabled()) { return new ScriptResult(null, this); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-06-02 06:14:24 UTC (rev 14530) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-06-02 15:01:42 UTC (rev 14531) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.html; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; +import static java.nio.charset.StandardCharsets.ISO_8859_1; import java.util.List; @@ -456,4 +457,34 @@ loadPageWithAlerts2(content); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "error", + CHROME = "Something") + public void shouldBeAbleToFindElementByXPathInXmlDocument() throws Exception { + final String html = "<?xml version='1.0' encoding='UTF-8'?>\n" + + "<html xmlns='http://www.w3.org/1999/xhtml'\n" + + " xmlns:svg='http://www.w3.org/2000/svg'\n" + + " xmlns:xlink='http://www.w3.org/1999/xlink'>\n" + + "<body>\n" + + " <svg:svg id='chart_container' height='220' width='400'>\n" + + " <svg:text y='16' x='200' text-anchor='middle'>Something</svg:text>\n" + + " </svg:svg>\n" + + "</body>\n" + + "</html>\n"; + + final WebDriver driver = loadPage2(html, URL_FIRST, "application/xhtml+xml", ISO_8859_1, null); + String actual; + try { + WebElement element = driver.findElement(By.xpath("//svg:svg//svg:text")); + actual = element.getText(); + } + catch (final Exception e) { + actual = "error"; + } + assertEquals(getExpectedAlerts()[0], actual); + } } |
From: <rb...@us...> - 2017-06-02 18:08:18
|
Revision: 14534 http://sourceforge.net/p/htmlunit/code/14534 Author: rbri Date: 2017-06-02 18:08:15 +0000 (Fri, 02 Jun 2017) Log Message: ----------- one more svg fix Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-06-02 16:35:59 UTC (rev 14533) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2017-06-02 18:08:15 UTC (rev 14534) @@ -362,7 +362,9 @@ } if (namespaceURI == null || namespaceURI.isEmpty() - || !qualifiedName.contains(":") || namespaceURI.equals(XHTML_NAMESPACE)) { + || !qualifiedName.contains(":") + || namespaceURI.equals(XHTML_NAMESPACE) + || namespaceURI.equals(SVG_NAMESPACE)) { String tagName = qualifiedName; final int index = tagName.indexOf(':'); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-06-02 16:35:59 UTC (rev 14533) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2017-06-02 18:08:15 UTC (rev 14534) @@ -14,8 +14,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -32,7 +30,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -468,7 +465,6 @@ @Test @Alerts(DEFAULT = "Something", IE = "error") - @NotYetImplemented({CHROME, FF}) public void shouldBeAbleToFindElementByXPathInXmlDocument() throws Exception { final String html = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<html xmlns='http://www.w3.org/1999/xhtml'\n" |
From: <asa...@us...> - 2017-06-03 09:29:52
|
Revision: 14538 http://sourceforge.net/p/htmlunit/code/14538 Author: asashour Date: 2017-06-03 09:29:49 +0000 (Sat, 03 Jun 2017) Log Message: ----------- JavaScript: implement Array.from() Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-06-03 06:31:32 UTC (rev 14537) +++ trunk/htmlunit/src/changes/changes.xml 2017-06-03 09:29:49 UTC (rev 14538) @@ -7,7 +7,10 @@ </properties> <body> - <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> + <release version="2.27" date="???" description="FF52, Bugfixes"> + <action type="add" dev="asashour" issue="44336828" system="stackoverflow"> + JavaScript: implement Array.from(). + </action> <action type="update" dev="rbri"> CSS: cssparser updated to 0.9.23. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-06-03 06:31:32 UTC (rev 14537) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-06-03 09:29:49 UTC (rev 14538) @@ -57,6 +57,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo; import com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration; import com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject; +import com.gargoylesoftware.htmlunit.javascript.host.ArrayCustom; import com.gargoylesoftware.htmlunit.javascript.host.DateCustom; import com.gargoylesoftware.htmlunit.javascript.host.ObjectCustom; import com.gargoylesoftware.htmlunit.javascript.host.Reflect; @@ -493,6 +494,10 @@ if (browserVersion.hasFeature(STRING_INCLUDES)) { ((ScriptableObject) objectPrototype).defineFunctionProperties(new String[] {"getOwnPropertySymbols"}, ObjectCustom.class, ScriptableObject.DONTENUM); + + final ScriptableObject arrayPrototype = (ScriptableObject) ScriptRuntime.name(context, window, "Array"); + ((ScriptableObject) arrayPrototype).defineFunctionProperties(new String[] {"from"}, + ArrayCustom.class, ScriptableObject.DONTENUM); } window.setPrototypes(prototypes, prototypesPerJSName); Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java 2017-06-03 09:29:49 UTC (rev 14538) @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2002-2017 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; + +import java.util.ArrayList; +import java.util.List; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; + +import net.sourceforge.htmlunit.corejs.javascript.Context; +import net.sourceforge.htmlunit.corejs.javascript.Function; +import net.sourceforge.htmlunit.corejs.javascript.FunctionObject; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import net.sourceforge.htmlunit.corejs.javascript.Undefined; + +/** + * Contains some missing features of Rhino NativeArray. + * + * @author Ahmed Ashour + */ +public final class ArrayCustom { + + private ArrayCustom() { } + + /** + * Creates a new Array instance from an array-like or iterable object. + * @param context the JavaScript context + * @param thisObj the scriptable + * @param args the arguments passed into the method + * @param function the function + * @return converted string + */ + public static Scriptable from( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + final Object arrayLike = args[0]; + Object[] array = null; + if (arrayLike instanceof Scriptable) { + final Scriptable scriptable = (Scriptable) arrayLike; + final Object length = scriptable.get("length", scriptable); + if (length != Scriptable.NOT_FOUND) { + int size = (int) length; + array = new Object[(int) size]; + for (int i = 0; i < size; i++) { + array[i] = scriptable.get(i, scriptable); + } + } + final Object iterator = scriptable.get(Symbol.ITERATOR_STRING, scriptable); + if (iterator != Scriptable.NOT_FOUND) { + final List<Object> list = new ArrayList<>(); + final Iterator it = (Iterator) ((FunctionObject) iterator) + .call(context, thisObj.getParentScope(), scriptable, new Object[0]); + SimpleScriptable next = it.next(); + boolean done = (boolean) next.get("done"); + Object value = next.get("value"); + while (!done) { + if (value != Undefined.instance) { + list.add(value); + } + next = it.next(); + done = (boolean) next.get("done"); + value = next.get("value"); + } + array = list.toArray(); + } + } + else if (arrayLike instanceof String) { + final String string = (String) arrayLike; + array = new Object[string.length()]; + for (int i = 0; i < array.length; i++) { + array[i] = string.charAt(i); + } + } + if (array == null) { + array = new Object[0]; + } + return context.newArray(thisObj, array); + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ArrayCustom.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java 2017-06-03 06:31:32 UTC (rev 14537) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java 2017-06-03 09:29:49 UTC (rev 14538) @@ -63,7 +63,7 @@ * Returns the next object. * @return the next object */ - public Object next() { + public SimpleScriptable next() { final SimpleScriptable object = new SimpleScriptable(); object.setParentScope(getParentScope()); final Object value; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2017-06-03 06:31:32 UTC (rev 14537) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2017-06-03 09:29:49 UTC (rev 14538) @@ -187,7 +187,7 @@ public Object get(final String name, final Scriptable start) { // A hack to handle Rhino not supporting "get(Object object, Scriptable start)" if (name.equals(Symbol.ITERATOR_STRING)) { - return super.get("entries", start); + return ScriptableObject.getProperty(start, "entries"); } return super.get(name, start); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java 2017-06-03 06:31:32 UTC (rev 14537) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java 2017-06-03 09:29:49 UTC (rev 14538) @@ -166,7 +166,7 @@ public Object get(final String name, final Scriptable start) { // A hack to handle Rhino not supporting "get(Object object, Scriptable start)" if (name.equals(Symbol.ITERATOR_STRING)) { - return super.get("values", start); + return ScriptableObject.getProperty(start, "values"); } return super.get(name, start); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-06-03 06:31:32 UTC (rev 14537) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-06-03 09:29:49 UTC (rev 14538) @@ -35,6 +35,7 @@ * * @author Marc Guillemot * @author Frank Danek + * @author Ahmed Ashour */ @RunWith(BrowserRunner.class) public class NativeArrayTest extends WebDriverTestCase { @@ -266,4 +267,90 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"3", "a", "b", "c"}, + IE = "not supported") + public void from() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + " if (Array.from) {\n" + + " var arr = Array.from('abc');\n" + + " alert(arr.length);\n" + + " for (var i = 0; i < arr.length; i++) {\n" + + " alert(arr[i]);\n" + + " }\n" + + " } else {\n" + + " alert('not supported');\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"2", "abc", "[object Window]"}, + IE = "not supported") + public void fromSet() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + " if (Array.from) {\n" + + " var s = new Set(['abc', window]);\n" + + " var arr = Array.from(s);\n" + + " alert(arr.length);\n" + + " for (var i = 0; i < arr.length; i++) {\n" + + " alert(arr[i]);\n" + + " }\n" + + " } else {\n" + + " alert('not supported');\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"3", "1,2", "3,4", "5,6"}, + IE = "not supported") + public void fromMap() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + " if (Array.from) {\n" + + " var m = new Map([[1, 2], [3, 4], [5, 6]]);\n" + + " var arr = Array.from(m);\n" + + " alert(arr.length);\n" + + " for (var i = 0; i < arr.length; i++) {\n" + + " alert(arr[i]);\n" + + " }\n" + + " } else {\n" + + " alert('not supported');\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <asa...@us...> - 2017-06-03 10:19:34
|
Revision: 14539 http://sourceforge.net/p/htmlunit/code/14539 Author: asashour Date: 2017-06-03 10:19:31 +0000 (Sat, 03 Jun 2017) Log Message: ----------- Fix exception type Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 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 2017-06-03 09:29:49 UTC (rev 14538) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2017-06-03 10:19:31 UTC (rev 14539) @@ -75,6 +75,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.FunctionObject; +import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; /** @@ -2008,7 +2009,8 @@ return domNode != null && ((DomElement) domNode).matches(selectorString); } catch (final CSSException e) { - throw Context.reportRuntimeError("An invalid or illegal selector was specified (selector: '" + throw ScriptRuntime.constructError("SyntaxError", + "An invalid or illegal selector was specified (selector: '" + selectorString + "' error: " + e.getMessage() + ")."); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2017-06-03 09:29:49 UTC (rev 14538) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2017-06-03 10:19:31 UTC (rev 14539) @@ -1305,7 +1305,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"exception", "done"}, + @Alerts(DEFAULT = {"SyntaxError", "done"}, IE = "done") public void matchesInvalidSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ @@ -1319,7 +1319,7 @@ + " alert(birds[i].textContent);\n" + " }\n" + " }\n" - + " } catch (e) { alert('exception'); }\n" + + " } catch (e) { alert(e.name); }\n" + " alert('done');\n" + " }\n" + "</script>\n" @@ -1332,4 +1332,5 @@ loadPageWithAlerts2(html); } + } |
From: <asa...@us...> - 2017-06-03 12:51:57
|
Revision: 14541 http://sourceforge.net/p/htmlunit/code/14541 Author: asashour Date: 2017-06-03 12:51:54 +0000 (Sat, 03 Jun 2017) Log Message: ----------- Fix build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 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 2017-06-03 10:37:26 UTC (rev 14540) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Element.java 2017-06-03 12:51:54 UTC (rev 14541) @@ -2003,9 +2003,14 @@ * @return the value */ @JsxFunction({CHROME, FF}) - public boolean matches(final String selectorString) { + public static boolean matches( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + final String selectorString = (String) args[0]; + if (!(thisObj instanceof Element)) { + throw ScriptRuntime.typeError("Illegal invocation"); + } try { - final DomNode domNode = getDomNodeOrNull(); + final DomNode domNode = ((Element) thisObj).getDomNodeOrNull(); return domNode != null && ((DomElement) domNode).matches(selectorString); } catch (final CSSException e) { @@ -2021,8 +2026,9 @@ * @return the value */ @JsxFunction(FF) - public boolean mozMatchesSelector(final String selectorString) { - return matches(selectorString); + public static boolean mozMatchesSelector( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + return matches(context, thisObj, args, function); } /** @@ -2031,8 +2037,9 @@ * @return the value */ @JsxFunction({CHROME, FF}) - public boolean webkitMatchesSelector(final String selectorString) { - return matches(selectorString); + public static boolean webkitMatchesSelector( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + return matches(context, thisObj, args, function); } /** @@ -2041,7 +2048,8 @@ * @return the value */ @JsxFunction(IE) - public boolean msMatchesSelector(final String selectorString) { - return matches(selectorString); + public static boolean msMatchesSelector( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + return matches(context, thisObj, args, function); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2017-06-03 10:37:26 UTC (rev 14540) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2017-06-03 12:51:54 UTC (rev 14541) @@ -1334,13 +1334,11 @@ } /** - * Test is based on a problem we had with jQuery 1.1.2 test suite. * @throws Exception if an error occurs */ @Test @Alerts({"TypeError", "done"}) - @NotYetImplemented - public void matchesJQuery() throws Exception { + public void matchesWindow() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head>\n" + "<script>\n" |
From: <rb...@us...> - 2017-06-04 13:40:42
|
Revision: 14546 http://sourceforge.net/p/htmlunit/code/14546 Author: rbri Date: 2017-06-04 13:40:39 +0000 (Sun, 04 Jun 2017) Log Message: ----------- SVGMatrix operations (flipX, flipY, inverse, multiply, rotate, rotateFromVector, scale, scaleNonUniform, skewX, skewY, translate) implemented Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-06-04 09:58:08 UTC (rev 14545) +++ trunk/htmlunit/src/changes/changes.xml 2017-06-04 13:40:39 UTC (rev 14546) @@ -8,6 +8,10 @@ <body> <release version="2.28" date="???" description="Bugfixes"> + <action type="add" dev="rbri" > + JavaScript: SVGMatrix operations (flipX, flipY, inverse, multiply, rotate, rotateFromVector, + scale, scaleNonUniform, skewX, skewY, translate) implemented. + </action> </release> <release version="2.27" date="June 4, 2017" description="FF52, Bugfixes"> <action type="add" dev="asashour" issue="44336828" system="stackoverflow"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java 2017-06-04 09:58:08 UTC (rev 14545) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGMatrix.java 2017-06-04 13:40:39 UTC (rev 14546) @@ -18,6 +18,9 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; +import java.awt.geom.AffineTransform; +import java.awt.geom.NoninvertibleTransformException; + import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -26,25 +29,27 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.host.Window; +import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; + /** * A JavaScript object for {@code SVGMatrix}. * @see <a href="https://developer.mozilla.org/en-US/docs/DOM/SVGMatrix">MDN doc</a> * @author Marc Guillemot + * @author Ronald Brill */ @JsxClass public class SVGMatrix extends SimpleScriptable { - private double fieldA_ = 1; - private double fieldB_ = 0; - private double fieldC_ = 0; - private double fieldD_ = 1; - private double fieldE_ = 0; - private double fieldF_ = 0; + private static final AffineTransform FLIP_X_TRANSFORM = new AffineTransform(-1, 0, 0, 1, 0, 0); + private static final AffineTransform FLIP_Y_TRANSFORM = new AffineTransform(1, 0, 0, -1, 0, 0); + private AffineTransform affineTransform_; + /** * Creates an instance. */ @JsxConstructor({CHROME, FF, EDGE}) public SVGMatrix() { + affineTransform_ = new AffineTransform(); } /** @@ -52,6 +57,7 @@ * @param scope the parent scope */ public SVGMatrix(final Window scope) { + this(); setParentScope(scope); setPrototype(getPrototype(getClass())); } @@ -62,7 +68,7 @@ */ @JsxGetter public double getA() { - return fieldA_; + return affineTransform_.getScaleX(); } /** @@ -71,7 +77,7 @@ */ @JsxGetter public double getB() { - return fieldB_; + return affineTransform_.getShearY(); } /** @@ -80,7 +86,7 @@ */ @JsxGetter public double getC() { - return fieldC_; + return affineTransform_.getShearX(); } /** @@ -89,7 +95,7 @@ */ @JsxGetter public double getD() { - return fieldD_; + return affineTransform_.getScaleY(); } /** @@ -98,7 +104,7 @@ */ @JsxGetter public double getE() { - return fieldE_; + return affineTransform_.getTranslateX(); } /** @@ -107,7 +113,7 @@ */ @JsxGetter public double getF() { - return fieldF_; + return affineTransform_.getTranslateY(); } /** @@ -116,7 +122,13 @@ */ @JsxSetter public void setA(final double newValue) { - fieldA_ = newValue; + affineTransform_.setTransform( + newValue, + affineTransform_.getShearY(), + affineTransform_.getShearX(), + affineTransform_.getScaleY(), + affineTransform_.getTranslateX(), + affineTransform_.getTranslateY()); } /** @@ -125,7 +137,13 @@ */ @JsxSetter public void setB(final double newValue) { - fieldB_ = newValue; + affineTransform_.setTransform( + affineTransform_.getScaleX(), + newValue, + affineTransform_.getShearX(), + affineTransform_.getScaleY(), + affineTransform_.getTranslateX(), + affineTransform_.getTranslateY()); } /** @@ -134,7 +152,13 @@ */ @JsxSetter public void setC(final double newValue) { - fieldC_ = newValue; + affineTransform_.setTransform( + affineTransform_.getScaleX(), + affineTransform_.getShearY(), + newValue, + affineTransform_.getScaleY(), + affineTransform_.getTranslateX(), + affineTransform_.getTranslateY()); } /** @@ -143,7 +167,13 @@ */ @JsxSetter public void setD(final double newValue) { - fieldD_ = newValue; + affineTransform_.setTransform( + affineTransform_.getScaleX(), + affineTransform_.getShearY(), + affineTransform_.getShearX(), + newValue, + affineTransform_.getTranslateX(), + affineTransform_.getTranslateY()); } /** @@ -152,7 +182,13 @@ */ @JsxSetter public void setE(final double newValue) { - fieldE_ = newValue; + affineTransform_.setTransform( + affineTransform_.getScaleX(), + affineTransform_.getShearY(), + affineTransform_.getShearX(), + affineTransform_.getScaleY(), + newValue, + affineTransform_.getTranslateY()); } /** @@ -161,7 +197,13 @@ */ @JsxSetter public void setF(final double newValue) { - fieldF_ = newValue; + affineTransform_.setTransform( + affineTransform_.getScaleX(), + affineTransform_.getShearY(), + affineTransform_.getShearX(), + affineTransform_.getScaleY(), + affineTransform_.getTranslateX(), + newValue); } /** @@ -172,12 +214,9 @@ public SVGMatrix flipX() { final SVGMatrix result = new SVGMatrix(getWindow()); - result.setA(fieldA_ * -1); - result.setB(fieldB_ * -1); - result.setC(fieldC_); - result.setD(fieldD_); - result.setE(fieldE_); - result.setF(fieldF_); + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.concatenate(FLIP_X_TRANSFORM); + result.affineTransform_ = tr; return result; } @@ -190,12 +229,9 @@ public SVGMatrix flipY() { final SVGMatrix result = new SVGMatrix(getWindow()); - result.setA(fieldA_); - result.setB(fieldB_); - result.setC(fieldC_ * -1); - result.setD(fieldD_ * -1); - result.setE(fieldE_); - result.setF(fieldF_); + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.concatenate(FLIP_Y_TRANSFORM); + result.affineTransform_ = tr; return result; } @@ -206,7 +242,17 @@ */ @JsxFunction public SVGMatrix inverse() { - return new SVGMatrix(getWindow()); + try { + final SVGMatrix result = new SVGMatrix(getWindow()); + + result.affineTransform_ = affineTransform_.createInverse(); + + return result; + } + catch (final NoninvertibleTransformException e) { + throw ScriptRuntime.constructError("Error", + "Failed to execute 'inverse' on 'SVGMatrix': The matrix is not invertible."); + } } /** @@ -216,7 +262,13 @@ */ @JsxFunction public SVGMatrix multiply(final SVGMatrix by) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.concatenate(by.affineTransform_); + result.affineTransform_ = tr; + + return result; } /** @@ -226,7 +278,13 @@ */ @JsxFunction public SVGMatrix rotate(final double angle) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.rotate(Math.toRadians(angle)); + result.affineTransform_ = tr; + + return result; } /** @@ -237,7 +295,18 @@ */ @JsxFunction public SVGMatrix rotateFromVector(final double x, final double y) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + if (x == 0 || y == 0) { + throw ScriptRuntime.constructError("Error", + "Failed to execute 'rotateFromVector' on 'SVGMatrix': Arguments cannot be zero."); + } + + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.rotate(Math.atan2(y, x)); + result.affineTransform_ = tr; + + return result; } /** @@ -249,12 +318,9 @@ public SVGMatrix scale(final double factor) { final SVGMatrix result = new SVGMatrix(getWindow()); - result.setA(fieldA_ * factor); - result.setB(fieldB_ * factor); - result.setC(fieldC_ * factor); - result.setD(fieldD_ * factor); - result.setE(fieldE_); - result.setF(fieldF_); + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.scale(factor, factor); + result.affineTransform_ = tr; return result; } @@ -267,7 +333,13 @@ */ @JsxFunction public SVGMatrix scaleNonUniform(final double factorX, final double factorY) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.scale(factorX, factorY); + result.affineTransform_ = tr; + + return result; } /** @@ -277,7 +349,13 @@ */ @JsxFunction public SVGMatrix skewX(final double angle) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.concatenate(AffineTransform.getShearInstance(Math.tan(Math.toRadians(angle)), 0)); + result.affineTransform_ = tr; + + return result; } /** @@ -287,7 +365,13 @@ */ @JsxFunction public SVGMatrix skewY(final double angle) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.concatenate(AffineTransform.getShearInstance(0, Math.tan(Math.toRadians(angle)))); + result.affineTransform_ = tr; + + return result; } /** @@ -298,6 +382,12 @@ */ @JsxFunction public SVGMatrix translate(final double x, final double y) { - return new SVGMatrix(getWindow()); // TODO: this is wrong, compute it! + final SVGMatrix result = new SVGMatrix(getWindow()); + + final AffineTransform tr = (AffineTransform) affineTransform_.clone(); + tr.translate(x, y); + result.affineTransform_ = tr; + + return result; } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java 2017-06-04 09:58:08 UTC (rev 14545) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgMatrixTest.java 2017-06-04 13:40:39 UTC (rev 14546) @@ -14,8 +14,15 @@ */ package com.gargoylesoftware.htmlunit.svg; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; @@ -28,6 +35,7 @@ * * @author Marc Guillemot * @author Frank Danek + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class SvgMatrixTest extends WebDriverTestCase { @@ -142,7 +150,6 @@ */ @Test @Alerts("-2, 1, 1.5, -0.5, 1, -2") - @NotYetImplemented public void inverse() throws Exception { transformTest("inverse()"); } @@ -151,11 +158,184 @@ * @throws Exception if the test fails */ @Test + @Alerts("exception") + public void inverseNotPossible() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + "function alertFields(m) {\n" + + " var fields = ['a', 'b', 'c', 'd', 'e', 'f'];\n" + + " for (var i = 0; i < fields.length; i++) {\n" + + " fields[i] = m[fields[i]];\n" + + " }\n" + + " alert(fields.join(', '));\n" + + "}\n" + + "var svg = document.getElementById('myId');\n" + + "try {\n" + + " var m = svg.createSVGMatrix();\n" + + " m.a = 1;\n" + + " m.b = 1;\n" + + " m.c = 1;\n" + + " m.d = 1;\n" + + " m.e = 5;\n" + + " m.f = 6;\n" + + " m = m.inverse();\n" + + " alertFields(m);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("25, 38, 17, 26, 14, 20") + public void multiply() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><body>\n" + + " <svg xmlns='http://www.w3.org/2000/svg' id='myId' version='1.1'>\n" + + " </svg>\n" + + "<script>\n" + + "function alertFields(m) {\n" + + " var fields = ['a', 'b', 'c', 'd', 'e', 'f'];\n" + + " for (var i = 0; i < fields.length; i++) {\n" + + " fields[i] = m[fields[i]];\n" + + " }\n" + + " alert(fields.join(', '));\n" + + "}\n" + + "var svg = document.getElementById('myId');\n" + + "try {\n" + + " var m = svg.createSVGMatrix();\n" + + " m.a = 1;\n" + + " m.b = 2;\n" + + " m.c = 3;\n" + + " m.d = 4;\n" + + " m.e = 5;\n" + + " m.f = 6;\n" + + + " var n = svg.createSVGMatrix();\n" + + " n.a = 7;\n" + + " n.b = 6;\n" + + " n.c = 5;\n" + + " n.d = 4;\n" + + " n.e = 3;\n" + + " n.f = 2;\n" + + " m = m.multiply(n);\n" + + " alertFields(m);\n" + + "} catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "1.2322946786880493, 2.307671070098877, 2.912292957305908, 3.8307511806488037, 5, 6", + CHROME = "1.2322946209166628, 2.307671050377636, 2.912292905471539, 3.8307511434768218, 5, 6", + IE = "1.2322945594787597, 2.307671070098877, 2.912292718887329, 3.8307509422302246, 5, 6") + public void rotate() throws Exception { + transformTest("rotate(4.5)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "3.147735595703125, 4.346245765686035, -0.3029201924800873, -1.0536353588104248, 5, 6", + CHROME = "3.1477355949224934, 4.346245800520598, -0.302920161854466, -1.053635345580751, 5, 6", + IE = "3.147735595703125, 4.346245765686035, -0.30292022228240967, -1.0536353588104248, 5, 6") + public void rotateFromVector() throws Exception { + transformTest("rotateFromVector(17, 74)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "exception", + IE = "3, 4, -1, -2, 5, 6") + @NotYetImplemented(IE) + public void rotateFromVectorZeroX() throws Exception { + transformTest("rotateFromVector(0, 74)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "exception", + IE = "1, 2, 3, 4, 5, 6") + @NotYetImplemented(IE) + public void rotateFromVectorZeroY() throws Exception { + transformTest("rotateFromVector(17, 0)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("exception") + public void rotateFromVectorZeroXY() throws Exception { + transformTest("rotateFromVector(0, 0)"); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts("3, 6, 9, 12, 5, 6") public void scale() throws Exception { transformTest("scale(3)"); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("7, 14, 21, 28, 5, 6") + public void scaleNonUniform() throws Exception { + transformTest("scale(7, 22)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "1, 2, 3.0699267387390137, 4.139853477478027, 5, 6", + CHROME = "1, 2, 3.0699268119435104, 4.139853623887021, 5, 6", + IE = "1, 2, 3.0699267387390136, 4.139853477478027, 5, 6") + public void skewX() throws Exception { + transformTest("skewX(4)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "1.6926045417785645, 2.9234728813171387, 3, 4, 5, 6", + CHROME = "1.6926045733766895, 2.9234727645022525, 3, 4, 5, 6", + IE = "1.6926045417785644, 2.9234728813171386, 3, 4, 5, 6") + public void skewY() throws Exception { + transformTest("skewY(13)"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("1, 2, 3, 4, 69, 100") + public void translate() throws Exception { + transformTest("translate(13 , 17)"); + } + private void transformTest(final String transforamtion) throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><body>\n" @@ -184,6 +364,32 @@ + "</script>\n" + "</body></html>"; - loadPageWithAlerts2(html); + final String[] expectedAlerts = getExpectedAlerts(); + + final WebDriver driver = loadPage2(html, URL_FIRST); + final List<String> actualAlerts = getCollectedAlerts(DEFAULT_WAIT_TIME, driver, expectedAlerts.length); + + assertEquals(expectedAlerts.length, actualAlerts.size()); + if (useRealBrowser()) { + for (int i = expectedAlerts.length - 1; i >= 0; i--) { + assertEquals(expectedAlerts[i], actualAlerts.get(i)); + } + } + else { + for (int i = expectedAlerts.length - 1; i >= 0; i--) { + final String[] expected = StringUtils.split(expectedAlerts[i], ','); + final String[] actual = StringUtils.split(actualAlerts.get(i), ','); + + assertEquals(expected.length, actual.length); + for (int j = expected.length - 1; j >= 0; j--) { + try { + Assert.assertEquals(Double.parseDouble(expected[j]), Double.parseDouble(actual[j]), 0.000001); + } + catch (final NumberFormatException e) { + assertEquals(expected[j], actual[j]); + } + } + } + } } } |
From: <rb...@us...> - 2017-06-06 19:06:34
|
Revision: 14558 http://sourceforge.net/p/htmlunit/code/14558 Author: rbri Date: 2017-06-06 19:06:32 +0000 (Tue, 06 Jun 2017) Log Message: ----------- latest chrome Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-06-06 18:47:17 UTC (rev 14557) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-06-06 19:06:32 UTC (rev 14558) @@ -148,9 +148,9 @@ /** Latest Chrome. */ public static final BrowserVersion CHROME = new BrowserVersion( NETSCAPE, "5.0 (Windows NT 6.1) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", + + " (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36", + + " (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36", 58, "Chrome", null); /** Microsoft Edge. Work In Progress!!! */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2017-06-06 18:47:17 UTC (rev 14557) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2017-06-06 19:06:32 UTC (rev 14558) @@ -41,7 +41,7 @@ */ @Test @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - CHROME = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + CHROME = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", IE = "Accept: text/html, application/xhtml+xml, */*") public void acceptHeaderGetUrl() throws Exception { final String html = "<html><body>Response</body></html>"; @@ -55,7 +55,8 @@ */ @Test @Alerts(DEFAULT = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, - CHROME = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}, + CHROME = {"2", "Accept: text/html,application/xhtml+xml," + + "application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, IE = {"2", "Accept: text/html, application/xhtml+xml, */*"}) public void acceptHeaderWindowOpen() throws Exception { String html = "<html><body>Response</body></html>"; @@ -81,7 +82,8 @@ */ @Test @Alerts(DEFAULT = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, - CHROME = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}, + CHROME = {"2", "Accept: text/html,application/xhtml+xml," + + "application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, IE = {"2", "Accept: text/html, application/xhtml+xml, */*"}) public void acceptHeaderAnchorClick() throws Exception { String html = "<html><body>Response</body></html>"; @@ -103,7 +105,7 @@ */ @Test @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - CHROME = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + CHROME = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", IE = "Accept: text/html, application/xhtml+xml, */*") public void acceptHeaderAnchorClickWithType() throws Exception { String html = "<html><body>Response</body></html>"; @@ -125,7 +127,7 @@ */ @Test @Alerts(DEFAULT = "Accept: image/png,image/*;q=0.8,*/*;q=0.5", - CHROME = "Accept: image/webp,image/*,*/*;q=0.8", + CHROME = "Accept: image/webp,image/apng,image/*,*/*;q=0.8", FF52 = "Accept: */*", IE = "Accept: image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5") public void acceptHeaderImage() throws Exception { @@ -295,7 +297,8 @@ */ @Test @Alerts(DEFAULT = {"2", "Accept: text/css,*/*;q=0.1"}, - CHROME = {"1", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}, + CHROME = {"1", "Accept: text/html,application/xhtml+xml," + + "application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, IE = {"2", "Accept: text/css, */*"}) public void acceptHeaderCssDifferentType() throws Exception { final String html @@ -324,7 +327,8 @@ */ @Test @Alerts(DEFAULT = {"2", "Accept: text/css,*/*;q=0.1"}, - CHROME = {"1", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}, + CHROME = {"1", "Accept: text/html,application/xhtml+xml," + + "application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, IE = {"2", "Accept: text/css, */*"}) public void acceptHeaderCssWrongType() throws Exception { final String html Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-06-06 18:47:17 UTC (rev 14557) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-06-06 19:06:32 UTC (rev 14558) @@ -44,7 +44,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {"Host", "Connection", "Accept", "User-Agent", "Accept-Encoding", "Accept-Language"}, + @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", + "Accept", "Accept-Encoding", "Accept-Language"}, FF = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Connection"}, IE = {"Accept", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection"}) @NotYetImplemented(IE) @@ -84,12 +85,13 @@ * @throws Exception if the test fails */ @Test - @Alerts(CHROME = {"Host", "Connection", "Accept", "User-Agent", "Referer", "Accept-Encoding", "Accept-Language", - "Cookie"}, + @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", + "Accept", "Referer", "Accept-Encoding", "Accept-Language", + "Cookie"}, FF = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", - "Connection"}, + "Connection"}, IE = {"Accept", "Referer", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", - "Cookie"}) + "Cookie"}) @NotYetImplemented(IE) public void headers_cookie_referer() throws Exception { final String htmlResponse = "<a href='2.html'>Click me</a>"; |
From: <asa...@us...> - 2017-06-06 19:12:48
|
Revision: 14563 http://sourceforge.net/p/htmlunit/code/14563 Author: asashour Date: 2017-06-06 19:12:45 +0000 (Tue, 06 Jun 2017) Log Message: ----------- Fix case for IE/Chrome Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java 2017-06-06 19:10:48 UTC (rev 14562) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java 2017-06-06 19:12:45 UTC (rev 14563) @@ -67,12 +67,19 @@ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); - if (thisObj instanceof BaseFunction && s.indexOf("[native code]") > -1) { final String functionName = ((BaseFunction) thisObj).getFunctionName(); return "\nfunction " + functionName + "() {\n [native code]\n}\n"; } - return s; + + final int start = s.indexOf('{') + 1; + final int end = s.lastIndexOf('}'); + String body = s.substring(start, end).trim(); + if (body.endsWith(";")) { + body = body.substring(0, body.length() - 1); + } + + return s.substring(0, start).replace(" ()", "()") + ' ' + body + " }"; } static class NativeFunctionToStringFunctionChrome extends FunctionWrapper { @@ -88,11 +95,13 @@ public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); - if (thisObj instanceof BaseFunction && s.indexOf("[native code]") > -1) { - final String functionName = ((BaseFunction) thisObj).getFunctionName(); - return "function " + functionName + "() { [native code] }"; + final int start = s.indexOf('{') + 1; + final int end = s.lastIndexOf('}'); + String body = s.substring(start, end).trim(); + if (body.endsWith(";")) { + body = body.substring(0, body.length() - 1); } - return s; + return s.substring(0, start) + ' ' + body + " }"; } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-06-06 19:10:48 UTC (rev 14562) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-06-06 19:12:45 UTC (rev 14563) @@ -1638,6 +1638,7 @@ "function() { return !0 }", "\nfunction onreadystatechange() {\n [native code]\n}\n", "true", "true"}) + @NotYetImplemented(FF) public void defineProperty() throws Exception { final String html = "<html>\n" |
From: <asa...@us...> - 2017-06-07 06:31:07
|
Revision: 14566 http://sourceforge.net/p/htmlunit/code/14566 Author: asashour Date: 2017-06-07 06:31:04 +0000 (Wed, 07 Jun 2017) Log Message: ----------- Fix build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java 2017-06-07 06:14:33 UTC (rev 14565) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionToStringFunction.java 2017-06-07 06:31:04 UTC (rev 14566) @@ -72,6 +72,10 @@ return "\nfunction " + functionName + "() {\n [native code]\n}\n"; } + if (s.startsWith("function anonymous()")) { + return s; + } + final int start = s.indexOf('{') + 1; final int end = s.lastIndexOf('}'); String body = s.substring(start, end).trim(); @@ -95,6 +99,9 @@ public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); + if (s.startsWith("function anonymous()")) { + return s; + } final int start = s.indexOf('{') + 1; final int end = s.lastIndexOf('}'); String body = s.substring(start, end).trim(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java 2017-06-07 06:14:33 UTC (rev 14565) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java 2017-06-07 06:31:04 UTC (rev 14566) @@ -109,9 +109,6 @@ } /** - * For the first test of this kind, we take a special case to have - * correct expectations for IE as IE (at least IE6) seems to just return - * the original string. * @throws Exception if the test fails */ @Test |
From: <asa...@us...> - 2017-06-07 06:47:11
|
Revision: 14567 http://sourceforge.net/p/htmlunit/code/14567 Author: asashour Date: 2017-06-07 06:47:08 +0000 (Wed, 07 Jun 2017) Log Message: ----------- Remove old comments Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClientOptions.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/attachment/AttachmentHandler.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.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/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrame2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentWrite2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHtmlElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/mozilla/MozillaTestGenerator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/DebuggingWebConnectionTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -410,7 +410,7 @@ * @param userAgent the user agent string that will be sent to the server * @param javaScriptVersion the version of JavaScript * @param browserVersionNumeric the floating number version of the browser - * @param nickname the short name of the browser (like "FF3", "IE6", ...) + * @param nickname the short name of the browser (like "FF52", "IE", ...) * @param features the browser features */ private BrowserVersion(final String applicationName, final String applicationVersion, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -1526,7 +1526,7 @@ /** * Returns the current refresh handler. - * The default refresh handler is a {@link NiceRefreshHandler NiceRefreshHandler(2)} (since HtmlUnit-2.12). + * The default refresh handler is a {@link NiceRefreshHandler NiceRefreshHandler(2)}. * @return the current RefreshHandler */ public RefreshHandler getRefreshHandler() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClientOptions.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClientOptions.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClientOptions.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -244,10 +244,9 @@ /** * Enables/disables Applet support. By default, this property is disabled.<br> * <p> - * Note: as of HtmlUnit-2.4, Applet support is experimental and minimal + * Note: Applet support is experimental and minimal * </p> * @param enabled {@code true} to enable Applet support - * @since HtmlUnit-2.4 */ public void setAppletEnabled(final boolean enabled) { appletEnabled_ = enabled; @@ -447,7 +446,7 @@ /** * Gets the timeout value for the {@link WebConnection}. - * The default timeout is 90 seconds (it was 0 up to HtmlUnit-2.11). + * The default timeout is 90 seconds. * @return the timeout value in milliseconds * @see WebClientOptions#setTimeout(int) */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/attachment/AttachmentHandler.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/attachment/AttachmentHandler.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/attachment/AttachmentHandler.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -29,8 +29,7 @@ * {@link com.gargoylesoftware.htmlunit.WebClient#setAttachmentHandler(AttachmentHandler)}. When * no attachment handler has been registered with the <tt>WebClient</tt>, the semantics described * above to not apply, and attachments are loaded inline. By default, <tt>AttachmentHandler</tt>s - * are not registered with new <tt>WebClient</tt> instances, in order to maintain backwards - * compatibility with HtmlUnit 2.1 and earlier. This will likely change in the future.</p> + * are not registered with new <tt>WebClient</tt> instances.</p> * * @author Bruce Chapman * @author Sudhan Moghe Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -51,7 +51,7 @@ /** * Creates an instance. - * If no value is specified, it is set to "on" as browsers do (e.g. IE6 and Mozilla 1.7) + * If no value is specified, it is set to "on" as browsers do * even if spec says that it is not allowed * (<a href="http://www.w3.org/TR/REC-html40/interact/forms.html#adef-value-INPUT">W3C</a>). * @@ -61,7 +61,6 @@ */ HtmlCheckBoxInput(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { - // default value for both IE6 and Mozilla 1.7 even if spec says it is unspecified super(qualifiedName, page, addValueIfNeeded(page, attributes)); // fix the default value in case we have set it @@ -167,8 +166,7 @@ } /** - * Both IE and Mozilla will first update the internal state of checkbox - * and then handle "onclick" event. + * First update the internal state of checkbox and then handle "onclick" event. * {@inheritDoc} */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -853,7 +853,7 @@ * * The HTML specification seems to indicate that one accesskey cannot be used * for multiple elements however Internet Explorer does seem to support this. - * It's worth noting that Mozilla does not support multiple elements with one + * It's worth noting that Firefox does not support multiple elements with one * access key so you are making your HTML browser specific if you rely on this * feature.<p> * Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -53,7 +53,7 @@ /** * Creates an instance. - * If no value is specified, it is set to "on" as browsers do (eg IE6 and Mozilla 1.7) + * If no value is specified, it is set to "on" as browsers do * even if spec says that it is not allowed * (<a href="http://www.w3.org/TR/REC-html40/interact/forms.html#adef-value-INPUT">W3C</a>). * @@ -63,7 +63,6 @@ */ HtmlRadioButtonInput(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { - // default value for both IE6 and Mozilla 1.7 even if spec says it is unspecified super(qualifiedName, page, addValueIfNeeded(page, attributes)); // fix the default value in case we have set it 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 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -197,7 +197,6 @@ /** * JavaScript function "write" may accept a variable number of arguments. - * It's not documented by W3C, Mozilla or MSDN but works with Mozilla and IE. * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method @@ -226,7 +225,6 @@ /** * JavaScript function "writeln" may accept a variable number of arguments. - * It's not documented by W3C, Mozilla or MSDN but works with Mozilla and IE. * @param context the JavaScript context * @param thisObj the scriptable * @param args the arguments passed into the method Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -115,8 +115,7 @@ } /** - * Was causing a "java.net.URISyntaxException: Malformed escape pair" - * as of HtmlUnit-2.12-SNAPSHOT on Nov. 29, 2012. + * Was causing a "java.net.URISyntaxException: Malformed escape pair". * HtmlUnit now escapes the "%%" to "%25%25" to build a valid URL but FF doesn't care * and sends the invalid "%%" sequence as it. * This will be quite difficult to simulate FF here as HttpClient's HttpRequestBase @@ -135,8 +134,7 @@ } /** - * Was causing a "java.net.URISyntaxException: Malformed escape pair" - * as of HtmlUnit-2.12-SNAPSHOT on Nov. 29, 2012. + * Was causing a "java.net.URISyntaxException: Malformed escape pair". * This is a simplified version of {@link #escapeRequestQuery2a()} only testing * that no exception is thrown. The request performed is not fully correct. * This test can be removed once {@link #escapeRequestQuery2a()} runs correctly. @@ -402,7 +400,6 @@ /** * Test "deflate" encoding without ZLIB header and checksum fields. - * This was failing as of HtmlUnit-2.10. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser4Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -601,7 +601,6 @@ /** * Test for a case where complete HTML page is set in innerHTML of HTML tag. - * IE8 throws JavaScript error as innerHTML of HTML is read only. * Others replace the current content of the HTML node by the new one. * * @throws Exception failure Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrame2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrame2Test.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFrame2Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -238,7 +238,6 @@ } /** - * Was failing as of HtmlUnit-2.11. * @see <a href="sourceforge.net/p/htmlunit/bugs/1443/">Bug #1443</a> * @throws Exception if the test fails */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine2Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -48,11 +48,7 @@ public class JavaScriptEngine2Test extends WebDriverTestCase { /** - * All browsers except Opera seem to have a single JS execution thread for all windows, - * but it is not the case of HtmlUnit-2.6! - * Tested browsers (21.09.09): - * - single JS thread: FF2, FF3.1, FF3.5, IE6 (and for info: Konqueror 4.2.2, Chrome Linux dev build) - * - multiple JS threads: none of HtmlUnit's simulated browsers (for info Opera 10.00) + * All browsers except Opera seem to have a single JS execution thread for all windows. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -169,9 +169,6 @@ /** * If a reference has been hold on a page and the page is not * anymore the one contained in "its" window, JavaScript should not be executed. - * Up to HtmlUnit-2.10 it could work a little bit without any guarantee but this - * has been removed to fix a problem where background JS tasks were still executed - * once a page has been unloaded * (see {@link com.gargoylesoftware.htmlunit.javascript.host.WindowConcurrencyTest#cleanSetTimeout}). * @throws Exception if the test fails */ @@ -242,9 +239,7 @@ /** * An odd case, if two external scripts are referenced and the <script> element * of the first contain a comment which contain an apostrophe, then the second script - * is ignored. - * https://sourceforge.net/tracker/?func=detail&atid=448266&aid=1990198&group_id=47038 - * This works fine in IE6 and FF 2.0. Remove the apostrophe from "shouldn't" to make it work here. + * is ignored. Bug #632. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeFunctionTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -144,7 +144,7 @@ } /** - * Function properties "arguments" and "caller" were wrongly enumerated as of HtmlUnit-2.11. + * Function properties "arguments" and "caller" were wrongly enumerated. * @throws Exception if the test fails */ @Test 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 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -1130,8 +1130,6 @@ } /** - * This was causing HtmlUnit to hang as of HtmlUnit-2.12 snapshot from 24.01.2013 and probably since a very long - * time. * The reason was that "top" evaluate to WindowProxy and "Object(top)" was setting the top scope as parentScope * of the WindowProxy which was setting it on the Window where it should always be null. * @throws Exception if the test fails @@ -1186,7 +1184,7 @@ } /** - * As of 2.12-SNAPSHOT on 19.02.2013, a task started by setTimeout in an event handler could be executed before + * As of 19.02.2013, a task started by setTimeout in an event handler could be executed before * all events handlers have been executed due to a missing synchronization. * @throws Exception if the test fails */ 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 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window3Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -1065,12 +1065,12 @@ } /** - * Tests Mozilla viewport properties. + * Tests viewport properties. * @throws Exception if the test fails */ @Test @Alerts({"number", "number", "number", "number"}) - public void mozillaViewport() throws Exception { + public void viewport() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head></head>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -1451,7 +1451,7 @@ */ @Test @Alerts({"10", "20", "30", "40"}) - public void mozillaViewportSetters() throws Exception { + public void viewportSetters() throws Exception { final String html = "<html>\n" + "<head></head>\n" + "<body>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event2Test.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/Event2Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -516,7 +516,7 @@ } /** - * Test Mozilla DOMContentLoaded event. + * Test DOMContentLoaded event. * @throws Exception if the test fails */ @Test 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 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -945,7 +945,6 @@ /** * Test that the function open resolves to document.open within a handler defined by an attribute. - * This was wrong (even in unit tests) up to HtmlUnit-2.12. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentWrite2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentWrite2Test.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentWrite2Test.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -337,8 +337,8 @@ } /** - * This was causing a StackOverflowError in HtmlUnit-2.10-SNAPSHOT when simulating IE as of 14.10.2011 - * and probably in release 2.9 as well. + * This was causing a StackOverflowError. + * * @throws Exception if an error occurs */ @Test 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 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -3146,7 +3146,7 @@ + "<script>\n" + "function test() {\n" + " var div1 = document.getElementById('div1');\n" - + " var defined = typeof(div1.filters) != 'undefined';\n" // "unknown" for IE6!!! + + " var defined = typeof(div1.filters) != 'undefined';\n" + " alert(defined ? 'defined' : 'undefined');\n" + "}\n" + "</script></head><body onload='test()'>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -835,7 +835,6 @@ getMockWebConnection().setDefaultResponse(""); final WebDriver driver = loadPageWithAlerts2(html); driver.findElement(By.id("x")).click(); - // caution: IE7 doesn't put a trailing "?" assertEquals(URL_FIRST + expectedFile, driver.getCurrentUrl().replaceAll("\\?", "")); } @@ -1136,7 +1135,6 @@ /** * Ensure that Multipart form text fields are correctly encoded. - * This was a regression introduced in 2.12-SNAPSHOT after upgrading to HttpClient to 4.3. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHtmlElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHtmlElementTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHtmlElementTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -120,7 +120,7 @@ @Alerts({"true", "true", "true", "true"}) public void clientWidth() throws Exception { final String html = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'" - + " 'http://www.w3.org/TR/html4/loose.dtd'>" // important for IE6!!! + + " 'http://www.w3.org/TR/html4/loose.dtd'>" + "<html><head>\n" + "<script>\n" + "function test() {\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -875,7 +875,6 @@ /** * Inputs have properties not only from there own type. - * Works with Mozilla, Firefox and IE... but not with HtmlUnit now. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -108,7 +108,7 @@ } /** - * Tests Mozilla and IE style object creation. + * Tests style object creation. * @throws Exception if the test fails */ @Test Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/mozilla/MozillaTestGenerator.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/mozilla/MozillaTestGenerator.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/mozilla/MozillaTestGenerator.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -23,7 +23,7 @@ import org.apache.commons.io.FileUtils; /** - * Utility for automatically transforming Moalla JavaScript tests to WebDriver test cases. + * Utility for automatically transforming Mozilla JavaScript tests to WebDriver test cases. * * @author Ahmed Ashour */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/DebuggingWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/DebuggingWebConnectionTest.java 2017-06-07 06:31:04 UTC (rev 14566) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/DebuggingWebConnectionTest.java 2017-06-07 06:47:08 UTC (rev 14567) @@ -91,7 +91,7 @@ /** * Ensures that Content-Encoding headers are removed when JavaScript is uncompressed. - * (was causing java.io.IOException: Not in GZIP format as of HtmlUnit-2.10). + * (was causing java.io.IOException: Not in GZIP format). * @throws Exception if the test fails */ @Test |
From: <rb...@us...> - 2017-06-07 09:49:22
|
Revision: 14569 http://sourceforge.net/p/htmlunit/code/14569 Author: rbri Date: 2017-06-07 09:49:19 +0000 (Wed, 07 Jun 2017) Log Message: ----------- header fix (Chrome, FF52) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-06-07 07:09:23 UTC (rev 14568) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-06-07 09:49:19 UTC (rev 14569) @@ -187,7 +187,7 @@ FIREFOX_52.setVendor(""); FIREFOX_52.buildId_ = "20170517122419"; FIREFOX_52.setHeaderNamesOrdered(new String[] { - "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection"}); + "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection", "Upgrade-Insecure-Requests"}); FIREFOX_52.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); FIREFOX_52.setCssAcceptHeader("text/css,*/*;q=0.1"); @@ -213,7 +213,7 @@ CHROME.setPlatform("MacIntel"); CHROME.setCpuClass(null); CHROME.setHeaderNamesOrdered(new String[] { - "Host", "Connection", "Accept", "User-Agent", "Referer", "Accept-Encoding", "Accept-Language", "Cookie"}); + "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", "Referer", "Accept-Encoding", "Accept-Language", "Cookie"}); CHROME.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); CHROME.setImgAcceptHeader("image/webp,image/apng,image/*,*/*;q=0.8"); CHROME.setCssAcceptHeader("text/css,*/*;q=0.1"); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-06-07 07:09:23 UTC (rev 14568) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-06-07 09:49:19 UTC (rev 14569) @@ -521,6 +521,10 @@ @BrowserFeature({CHROME, FF}) HTTP_COOKIE_START_DATE_1970, + /** Browser sends Upgrade-Insecure-Requests header. */ + @BrowserFeature({CHROME, FF52}) + HTTP_HEADER_UPGRADE_INSECURE_REQUEST, + /** Supports redirect via 308 code. */ @BrowserFeature({CHROME, FF}) HTTP_REDIRECT_308, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-06-07 07:09:23 UTC (rev 14568) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-06-07 09:49:19 UTC (rev 14569) @@ -802,6 +802,9 @@ else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) { list.add(new AcceptEncodingHeaderHttpRequestInterceptor(requestHeaders.get(header))); } + else if ("Upgrade-Insecure-Requests".equals(header) && requestHeaders.get(header) != null) { + list.add(new UpgradeInsecureRequestHeaderHttpRequestInterceptor(requestHeaders.get(header))); + } else if ("Referer".equals(header) && requestHeaders.get(header) != null) { list.add(new RefererHeaderHttpRequestInterceptor(requestHeaders.get(header))); } @@ -886,7 +889,19 @@ request.setHeader("Accept-Language", value_); } } + private static final class UpgradeInsecureRequestHeaderHttpRequestInterceptor implements HttpRequestInterceptor { + private String value_; + UpgradeInsecureRequestHeaderHttpRequestInterceptor(final String value) { + value_ = value; + } + + @Override + public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { + request.setHeader("Upgrade-Insecure-Requests", value_); + } + } + private static final class AcceptEncodingHeaderHttpRequestInterceptor implements HttpRequestInterceptor { private String value_; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-06-07 07:09:23 UTC (rev 14568) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-06-07 09:49:19 UTC (rev 14569) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.DIALOGWINDOW_REFERER; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_HEADER_UPGRADE_INSECURE_REQUEST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTTP_REDIRECT_308; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_SUPPORT_VIA_ACTIVEXOBJECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.URL_MINIMAL_QUERY_ENCODING; @@ -1468,6 +1469,10 @@ if (!wrs.isAdditionalHeader("Accept-Language")) { wrs.setAdditionalHeader("Accept-Language", getBrowserVersion().getBrowserLanguage()); } + if (getBrowserVersion().hasFeature(HTTP_HEADER_UPGRADE_INSECURE_REQUEST) + && !wrs.isAdditionalHeader("Upgrade-Insecure-Requests")) { + wrs.setAdditionalHeader("Upgrade-Insecure-Requests", "1"); + } // Add user-specified headers last so that they can override HtmlUnit defaults. wrs.getAdditionalHeaders().putAll(requestHeaders_); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-06-07 07:09:23 UTC (rev 14568) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-06-07 09:49:19 UTC (rev 14569) @@ -34,6 +34,7 @@ * Tests using the {@link PrimitiveWebServer}. * * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class HttpWebConnection3Test extends WebDriverTestCase { @@ -46,7 +47,9 @@ @Test @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", "Accept-Encoding", "Accept-Language"}, - FF = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Connection"}, + FF45 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Connection"}, + FF52 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", + "Connection", "Upgrade-Insecure-Requests"}, IE = {"Accept", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection"}) @NotYetImplemented(IE) public void headers() throws Exception { @@ -88,8 +91,10 @@ @Alerts(CHROME = {"Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", "Referer", "Accept-Encoding", "Accept-Language", "Cookie"}, - FF = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", + FF45 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection"}, + FF52 = {"Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", + "Connection", "Upgrade-Insecure-Requests"}, IE = {"Accept", "Referer", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", "Cookie"}) @NotYetImplemented(IE) |