From: <rb...@us...> - 2018-01-27 12:48:19
|
Revision: 15094 http://sourceforge.net/p/htmlunit/code/15094 Author: rbri Date: 2018-01-27 12:48:16 +0000 (Sat, 27 Jan 2018) Log Message: ----------- chrome 64 and ff52 refresh 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 2018-01-25 18:37:05 UTC (rev 15093) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-01-27 12:48:16 UTC (rev 15094) @@ -153,7 +153,7 @@ // FF52 FIREFOX_52.applicationVersion_ = "5.0 (Windows)"; FIREFOX_52.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0"; - FIREFOX_52.buildId_ = "20171226003912"; + FIREFOX_52.buildId_ = "20180118122319"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { HttpHeader.HOST, @@ -211,8 +211,8 @@ EDGE.scriptAcceptHeader_ = "application/javascript, */*;q=0.8"; // CHROME - CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36"; - CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36"; + CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"; + CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36"; CHROME.applicationCodeName_ = "Mozilla"; CHROME.vendor_ = "Google Inc."; @@ -354,19 +354,19 @@ // flush plugin (windows version) PluginConfiguration flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 28.0 r0", "28.0.0.126", "NPSWF32_28_0_0_126.dll"); + "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF32_28_0_0_137.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_45.plugins_.add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 28.0 r0", "28.0.0.126", "NPSWF64_28_0_0_126.dll"); + "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF64_28_0_0_137.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_52.plugins_.add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 28.0 r0", "28.0.0.126", "Flash32_28_0_0_126.ocx"); + "Shockwave Flash 28.0 r0", "28.0.0.137", "Flash32_28_0_0_137.ocx"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); INTERNET_EXPLORER.plugins_.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 2018-01-25 18:37:05 UTC (rev 15093) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2018-01-27 12:48:16 UTC (rev 15094) @@ -216,10 +216,10 @@ * @throws Exception on test failure */ @Test - @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.126", "NPSWF32_28_0_0_126.dll"}, - FF52 = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.126", "NPSWF64_28_0_0_126.dll"}, + @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF32_28_0_0_137.dll"}, + FF52 = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF64_28_0_0_137.dll"}, CHROME = "Shockwave Flash not available", - IE = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.126", "Flash32_28_0_0_126.ocx"}, + IE = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.137", "Flash32_28_0_0_137.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" @@ -387,7 +387,7 @@ @Test @Alerts(DEFAULT = "undefined", FF45 = "20170411115307", - FF52 = "20171226003912") + FF52 = "20180118122319") public void buildID() throws Exception { final String html = "<html><head><title>First</title>\n" |
From: <rb...@us...> - 2018-01-27 14:10:43
|
Revision: 15095 http://sourceforge.net/p/htmlunit/code/15095 Author: rbri Date: 2018-01-27 14:10:40 +0000 (Sat, 27 Jan 2018) Log Message: ----------- chrome 64 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-01-27 12:48:16 UTC (rev 15094) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-01-27 14:10:40 UTC (rev 15095) @@ -448,10 +448,6 @@ @BrowserFeature(CHROME) HTMLLINK_CHECK_TYPE_FOR_STYLESHEET, - /** */ - @BrowserFeature({FF, IE}) - HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN, - /** If the single select has exact one option, this options gets never deselected. */ @BrowserFeature(FF45) HTMLOPTION_EXACT_ONE_OPTION_GETS_NERVER_DESELECTED, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java 2018-01-27 12:48:16 UTC (rev 15094) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java 2018-01-27 14:10:40 UTC (rev 15095) @@ -22,7 +22,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEOVER_NEVER_FOR_SELECT_OPTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_EXACT_ONE_OPTION_GETS_NERVER_DESELECTED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_PREVENT_DISABLED; @@ -391,8 +390,7 @@ * @param text the text */ public void setText(final String text) { - if ((text == null || text.isEmpty()) - && hasFeature(HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN)) { + if (text == null || text.isEmpty()) { removeAllChildren(); } else { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2018-01-27 12:48:16 UTC (rev 15094) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2018-01-27 14:10:40 UTC (rev 15095) @@ -850,9 +850,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = {"[object Text]", "[object Text]", "null"}, - CHROME = {"null", "[object Text]", "[object Text]"}, - IE = {"null", "[object Text]", "null"}) + @Alerts(DEFAULT = {"null", "[object Text]", "null"}, + FF = {"[object Text]", "[object Text]", "null"}) public void setText() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ |
From: <rb...@us...> - 2018-01-27 14:26:58
|
Revision: 15096 http://sourceforge.net/p/htmlunit/code/15096 Author: rbri Date: 2018-01-27 14:26:56 +0000 (Sat, 27 Jan 2018) Log Message: ----------- chrome 64 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-01-27 14:10:40 UTC (rev 15095) +++ trunk/htmlunit/src/changes/changes.xml 2018-01-27 14:26:56 UTC (rev 15096) @@ -7,7 +7,7 @@ </properties> <body> - <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators"> + <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> <action type="fix" dev="rbri" due-to="Frank Danek"> Fix some problem to be able to run our test suite with edge. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java 2018-01-27 14:10:40 UTC (rev 15095) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java 2018-01-27 14:26:56 UTC (rev 15096) @@ -2728,8 +2728,8 @@ TEXT_DECORATION_OVERLINE("textDecorationOverline", "text-decoration-overline", ie("false").setIteratable(false)), - /** The style property {@code textDecorationSkip}. */ - TEXT_DECORATION_SKIP("textDecorationSkip", "text-decoration-sskip", chrome("objects")), + /** The style property {@code textDecorationSkipInk}. */ + TEXT_DECORATION_SKIP("textDecorationSkipInk", "text-decoration-skip-ink", chrome("auto")), /** The style property {@code textDecorationStyle}. */ TEXT_DECORATION_STYLE("textDecorationStyle", "text-decoration-style", chrome("solid"), ff("solid")), @@ -2831,6 +2831,9 @@ /** The style property {@code transform}. */ TRANSFORM("transform", "transform", ff("none"), ie("none"), chrome("none")), + /** The style property {@code transformBox}. */ + TRANSFORM_BOX("transformBox", "transform-box", chrome("view-box")), + /** The style property {@code transformOrigin}. */ TRANSFORM_ORIGIN("transformOrigin", "transform-origin", ffBelow52("705px 172.5px"), ff52up("625px 172.5px"), ie("620px 163.2px"), chrome("456.5px 161px")), @@ -3046,8 +3049,7 @@ ff52up("visible")), /** The style property {@code webkitBackgroundClip}. */ - WEBKIT_BACKGROUND_CLIP("webkitBackgroundClip", "webkit-background-clip", - chrome("border-box"), ff52up("border-box")), + WEBKIT_BACKGROUND_CLIP("webkitBackgroundClip", "webkit-background-clip", ff52up("border-box")), /** The style property {@code WebkitBackgroundClip}. */ WEBKIT_BACKGROUND_CLIP_("WebkitBackgroundClip", "webkit-background-clip", @@ -3058,8 +3060,7 @@ ff52up("border-box")), /** The style property {@code webkitBackgroundOrigin}. */ - WEBKIT_BACKGROUND_ORIGIN("webkitBackgroundOrigin", "webkit-background-origin", - chrome("padding-box"), ff52up("padding-box")), + WEBKIT_BACKGROUND_ORIGIN("webkitBackgroundOrigin", "webkit-background-origin", ff52up("padding-box")), /** The style property {@code WebkitBackgroundOrigin}. */ WEBKIT_BACKGROUND_ORIGIN_("WebkitBackgroundOrigin", "webkit-background-origin", Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt 2018-01-27 14:10:40 UTC (rev 15095) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties.Chrome.txt 2018-01-27 14:26:56 UTC (rev 15096) @@ -263,7 +263,7 @@ textDecoration textDecorationColor textDecorationLine -textDecorationSkip +textDecorationSkipInk textDecorationStyle textIndent textOrientation @@ -276,6 +276,7 @@ top touchAction transform +transformBox transformOrigin transformStyle transition @@ -292,8 +293,6 @@ visibility webkitAppRegion webkitAppearance -webkitBackgroundClip -webkitBackgroundOrigin webkitBorderAfter webkitBorderAfterColor webkitBorderAfterStyle Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt 2018-01-27 14:10:40 UTC (rev 15095) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.properties2.Chrome.txt 2018-01-27 14:26:56 UTC (rev 15096) @@ -262,7 +262,7 @@ textDecoration textDecorationColor textDecorationLine -textDecorationSkip +textDecorationSkipInk textDecorationStyle textIndent textOrientation @@ -275,6 +275,7 @@ top touchAction transform +transformBox transformOrigin transformStyle transition @@ -291,8 +292,6 @@ visibility webkitAppRegion webkitAppearance -webkitBackgroundClip -webkitBackgroundOrigin webkitBorderAfter webkitBorderAfterColor webkitBorderAfterStyle Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt 2018-01-27 14:10:40 UTC (rev 15095) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.Chrome.txt 2018-01-27 14:26:56 UTC (rev 15096) @@ -262,7 +262,7 @@ textDecoration=:none solid rgb(0, 0, 0) textDecorationColor=:rgb(0, 0, 0) textDecorationLine=:none -textDecorationSkip=:objects +textDecorationSkipInk=:auto textDecorationStyle=:solid textIndent=:0px textOrientation=:mixed @@ -275,6 +275,7 @@ top=:auto touchAction=:auto transform=:none +transformBox=:view-box transformOrigin=:456.5px 161px transformStyle=:flat transition=:all 0s ease 0s @@ -291,8 +292,6 @@ visibility=:visible webkitAppRegion=:no-drag webkitAppearance=:none -webkitBackgroundClip=:border-box -webkitBackgroundOrigin=:padding-box webkitBorderAfter=:0px none rgb(0, 0, 0) webkitBorderAfterColor=:rgb(0, 0, 0) webkitBorderAfterStyle=:none Modified: trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt =================================================================== --- trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt 2018-01-27 14:10:40 UTC (rev 15095) +++ trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.properties.notAttached.Chrome.txt 2018-01-27 14:26:56 UTC (rev 15096) @@ -262,7 +262,7 @@ textDecoration=: textDecorationColor=: textDecorationLine=: -textDecorationSkip=: +textDecorationSkipInk=: textDecorationStyle=: textIndent=: textOrientation=: @@ -275,6 +275,7 @@ top=: touchAction=: transform=: +transformBox=: transformOrigin=: transformStyle=: transition=: @@ -291,8 +292,6 @@ visibility=: webkitAppRegion=: webkitAppearance=: -webkitBackgroundClip=: -webkitBackgroundOrigin=: webkitBorderAfter=: webkitBorderAfterColor=: webkitBorderAfterStyle=: |
From: <rb...@us...> - 2018-01-27 18:32:37
|
Revision: 15098 http://sourceforge.net/p/htmlunit/code/15098 Author: rbri Date: 2018-01-27 18:32:34 +0000 (Sat, 27 Jan 2018) Log Message: ----------- chrome 64 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributesIterableTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java 2018-01-27 14:57:26 UTC (rev 15097) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributes.java 2018-01-27 18:32:34 UTC (rev 15098) @@ -3052,23 +3052,19 @@ WEBKIT_BACKGROUND_CLIP("webkitBackgroundClip", "webkit-background-clip", ff52up("border-box")), /** The style property {@code WebkitBackgroundClip}. */ - WEBKIT_BACKGROUND_CLIP_("WebkitBackgroundClip", "webkit-background-clip", - ff52up("border-box")), + WEBKIT_BACKGROUND_CLIP_("WebkitBackgroundClip", "webkit-background-clip", ff52up("border-box")), /** The style property {@code -webkit-background-clip}. */ - WEBKIT_BACKGROUND_CLIP__("-webkit-background-clip", "webkit-background-clip", - ff52up("border-box")), + WEBKIT_BACKGROUND_CLIP__("-webkit-background-clip", "webkit-background-clip", ff52up("border-box")), /** The style property {@code webkitBackgroundOrigin}. */ WEBKIT_BACKGROUND_ORIGIN("webkitBackgroundOrigin", "webkit-background-origin", ff52up("padding-box")), /** The style property {@code WebkitBackgroundOrigin}. */ - WEBKIT_BACKGROUND_ORIGIN_("WebkitBackgroundOrigin", "webkit-background-origin", - ff52up("padding-box")), + WEBKIT_BACKGROUND_ORIGIN_("WebkitBackgroundOrigin", "webkit-background-origin", ff52up("padding-box")), /** The style property {@code -webkit-background-origin}. */ - WEBKIT_BACKGROUND_ORIGIN__("-webkit-background-origin", "webkit-background-origin", - ff52up("padding-box")), + WEBKIT_BACKGROUND_ORIGIN__("-webkit-background-origin", "webkit-background-origin", ff52up("padding-box")), /** The style property {@code webkitBackgroundSize}. */ WEBKIT_BACKGROUND_SIZE("webkitBackgroundSize", "webkit-background-size", ff52up("auto auto")), Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributesIterableTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributesIterableTest.java 2018-01-27 14:57:26 UTC (rev 15097) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleAttributesIterableTest.java 2018-01-27 18:32:34 UTC (rev 15098) @@ -76,13 +76,13 @@ "<html><head><script>\n" + " function test() {\n" + " var e = document.getElementById('myDiv');\n" - + " var found = false;\n" + " for (var i in e.style) {\n" + " if (i == '" + propertyName + "') {\n" - + " found = true;\n" + + " alert('true');\n" + + " return;\n" + " }\n" + " }\n" - + " alert(found);\n" + + " alert('false');\n" + " }\n" + "</script></head><body onload='test()'>\n" + " <div id='myDiv'></div>\n" @@ -105,9 +105,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "true", - IE = "false", - FF45 = "false") + @Alerts(DEFAULT = "false", + FF52 = "true") public void _WEBKIT_BACKGROUND_CLIP() throws Exception { test("webkitBackgroundClip"); } @@ -116,9 +115,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "true", - IE = "false", - FF45 = "false") + @Alerts(DEFAULT = "false", + FF52 = "true") public void _WEBKIT_BACKGROUND_ORIGIN() throws Exception { test("webkitBackgroundOrigin"); } |
From: <rb...@us...> - 2018-01-28 10:17:39
|
Revision: 15100 http://sourceforge.net/p/htmlunit/code/15100 Author: rbri Date: 2018-01-28 10:17:36 +0000 (Sun, 28 Jan 2018) Log Message: ----------- chrome 64 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2018-01-27 18:33:07 UTC (rev 15099) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2018-01-28 10:17:36 UTC (rev 15100) @@ -152,8 +152,9 @@ CHROME_FORMATS_.put("be", yyyyDash); CHROME_FORMATS_.put("en-CA", yyyyDash); - CHROME_FORMATS_.put("en-IE", mmSlash); - CHROME_FORMATS_.put("en-MT", mmSlash); + CHROME_FORMATS_.put("en-IE", ddSlash); + CHROME_FORMATS_.put("en-MT", ddSlash); + CHROME_FORMATS_.put("en-PH", ddSlash); CHROME_FORMATS_.put("es-US", ddSlash); CHROME_FORMATS_.put("fr", ddSlash); CHROME_FORMATS_.put("fr-CH", ddDot); @@ -164,10 +165,11 @@ CHROME_FORMATS_.put("iw", ddDot); CHROME_FORMATS_.put("ja-JP-u-ca-japanese", "平成yy/MM/dd"); CHROME_FORMATS_.put("lv", yyyyDotDot); + CHROME_FORMATS_.put("mk", yyyyDash); + CHROME_FORMATS_.put("nl-BE", ddSlash); CHROME_FORMATS_.put("sk", ddDotBlank); CHROME_FORMATS_.put("sq", yyyyDash); CHROME_FORMATS_.put("sr", ddDotDot); - CHROME_FORMATS_.put("mk", yyyyDash); IE_FORMATS_.put("ar", rightToLeft); IE_FORMATS_.put("ar-AE", rightToLeft); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java 2018-01-27 18:33:07 UTC (rev 15099) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormatTest.java 2018-01-28 10:17:36 UTC (rev 15100) @@ -692,8 +692,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "12/20/2012", - FF = "20/12/2012", + @Alerts(DEFAULT = "20/12/2012", IE = "\u200E20\u200E/\u200E12\u200E/\u200E2012") public void format_en_ie() throws Exception { test("new Intl.DateTimeFormat('en-IE').format(date)"); @@ -713,8 +712,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "12/20/2012", - FF = "20/12/2012", + @Alerts(DEFAULT = "20/12/2012", IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") public void format_en_mt() throws Exception { test("new Intl.DateTimeFormat('en-MT').format(date)"); @@ -734,8 +732,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "12/20/2012", - FF = "20/12/2012", + @Alerts(DEFAULT = "20/12/2012", IE = "\u200E12\u200E/\u200E20\u200E/\u200E2012") public void format_en_ph() throws Exception { test("new Intl.DateTimeFormat('en-PH').format(date)"); @@ -1409,8 +1406,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "20-12-2012", - FF52 = "20/12/2012", + @Alerts(DEFAULT = "20/12/2012", + FF45 = "20-12-2012", IE = "\u200E20\u200E/\u200E12\u200E/\u200E2012") public void format_nl_be() throws Exception { test("new Intl.DateTimeFormat('nl-BE').format(date)"); |
From: <rb...@us...> - 2018-02-02 18:36:43
|
Revision: 15109 http://sourceforge.net/p/htmlunit/code/15109 Author: rbri Date: 2018-02-02 18:36:40 +0000 (Fri, 02 Feb 2018) Log Message: ----------- Handling of invalid processing instructions fixed in neko Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-02-01 20:17:02 UTC (rev 15108) +++ trunk/htmlunit/src/changes/changes.xml 2018-02-02 18:36:40 UTC (rev 15109) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="1682" dev="rbri"> + Handling of invalid processing instructions fixed in neko. + </action> <action type="fix" dev="rbri" due-to="Frank Danek"> Fix some problem to be able to run our test suite with edge. </action> Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2018-02-01 20:17:02 UTC (rev 15108) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2018-02-02 18:36:40 UTC (rev 15109) @@ -176,7 +176,6 @@ */ @Test @Alerts("BackCompat") - @NotYetImplemented public void compatMode_question() throws Exception { compatMode("<?DOCTYPE html>"); } |
From: <rb...@us...> - 2018-02-09 18:22:03
|
Revision: 15128 http://sourceforge.net/p/htmlunit/code/15128 Author: rbri Date: 2018-02-09 18:22:00 +0000 (Fri, 09 Feb 2018) Log Message: ----------- RegExp: fix processing of /[]/ and /[^]/ Issue 1949 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverterTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-02-07 20:38:23 UTC (rev 15127) +++ trunk/htmlunit/src/changes/changes.xml 2018-02-09 18:22:00 UTC (rev 15128) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1949" due-to="Atsushi Nakagawa"> + RegExp: fix processing of /[]/ and /[^]/. + </action> <action type="1682" dev="rbri"> Handling of invalid processing instructions fixed in neko. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java 2018-02-07 20:38:23 UTC (rev 15127) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java 2018-02-09 18:22:00 UTC (rev 15128) @@ -30,6 +30,7 @@ * * @author Ronald Brill * @author Leszek Hoppe + * @author Atsushi Nakagawa */ public class RegExpJsToJavaConverter { @@ -106,6 +107,14 @@ } /** + * Removes number of chars from the given string. + * @param count the number of chars to remove + */ + public void remove(final int count) { + tape_.delete(currentPos_, currentPos_ + count); + } + + /** * Read the whole tape content. * * @return tape content @@ -221,17 +230,28 @@ next = tape_.read(); if (']' == next) { tape_.move(-3); - tape_.replace(""); - tape_.replace(""); + tape_.remove(2); tape_.replace("."); insideCharClass_ = false; } } } + else if (']' == next) { + // [^] + tape_.move(-3); + tape_.remove(2); + tape_.replace("."); + } else { tape_.move(-1); } } + else if (']' == next) { + // [] + tape_.move(-2); + tape_.remove(1); + tape_.replace("(?!)"); + } else { tape_.move(-1); } @@ -338,7 +358,7 @@ if ("ACEFGHIJKLMNOPQRTUVXYZaeghijklmpqyz".indexOf(escapeSequence) > -1) { // no need to escape this chars tape_.move(-2); - tape_.replace(""); + tape_.remove(1); tape_.move(1); return; } @@ -414,7 +434,7 @@ // drop back reference for (int i = tmpInsertPos; i <= 0; i++) { tape_.move(-1); - tape_.replace(""); + tape_.remove(1); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java 2018-02-07 20:38:23 UTC (rev 15127) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java 2018-02-09 18:22:00 UTC (rev 15128) @@ -33,6 +33,7 @@ * @author Ronald Brill * @author Carsten Steurl * @author Leszek Hoppe + * @author Atsushi Nakagawa */ @RunWith(BrowserRunner.class) public class HtmlUnitRegExpProxyTest extends WebDriverTestCase { @@ -1049,4 +1050,74 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("abc") + public void specialBrackets1() throws Exception { + // [] matches no character in JS + testEvaluate("'abc'.replace(/[]/, 'x')"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("") + public void specialBrackets2() throws Exception { + // [] matches no character in JS + testEvaluate("'abc'.match(/[]*/)[0]"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("xaxbxcx") + public void specialBrackets3() throws Exception { + // [] matches no character in JS + testEvaluate("'abc'.replace(/[]*/g, 'x')"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("xaxbxxcx*xdx") + public void specialBrackets4() throws Exception { + // [] matches no character in JS + testEvaluate("'ab]c*d'.replace(/[]*]*/g, 'x')"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("xxx") + public void specialBrackets5() throws Exception { + // [^] matches any character in JS + testEvaluate("'abc'.replace(/[^]/g, 'x')"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("abc") + public void specialBrackets6() throws Exception { + // [^] matches any character in JS + testEvaluate("'abc'.match(/[^]*/)[0]"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("axcd") + public void specialBrackets7() throws Exception { + // [^] matches any character in JS + testEvaluate("'ab]cd'.replace(/[^]]/g, 'x')"); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverterTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverterTest.java 2018-02-07 20:38:23 UTC (rev 15127) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/RegExpJsToJavaConverterTest.java 2018-02-09 18:22:00 UTC (rev 15128) @@ -462,4 +462,17 @@ assertEquals("[!\\^()\\[\\]]", regExpJsToJavaConverter.convert("[!\\^()\\[\\]]")); } + /** + * Verifies that square braces can be used non escaped in JS regexp. + */ + @Test + public void squareBracket() { + final RegExpJsToJavaConverter regExpJsToJavaConverter = new RegExpJsToJavaConverter(); + + assertEquals("(?!)", regExpJsToJavaConverter.convert("[]")); + assertEquals("x(?!)y", regExpJsToJavaConverter.convert("x[]y")); + + assertEquals(".", regExpJsToJavaConverter.convert("[^]")); + assertEquals("x.y", regExpJsToJavaConverter.convert("x[^]y")); + } } |
From: <rb...@us...> - 2018-02-16 19:04:23
|
Revision: 15131 http://sourceforge.net/p/htmlunit/code/15131 Author: rbri Date: 2018-02-16 19:04:17 +0000 (Fri, 16 Feb 2018) Log Message: ----------- Fix incorrect encoding of consecutive '%' characters in url's Issue 1951 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-02-12 12:37:11 UTC (rev 15130) +++ trunk/htmlunit/src/changes/changes.xml 2018-02-16 19:04:17 UTC (rev 15131) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1951" due-to="Hartmut Arlt"> + Fix incorrect encoding of consecutive '%' characters in url's + </action> <action type="fix" dev="rbri" issue="1949" due-to="Atsushi Nakagawa"> RegExp: fix processing of /[]/ and /[^]/. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-02-12 12:37:11 UTC (rev 15130) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-02-16 19:04:17 UTC (rev 15131) @@ -40,6 +40,7 @@ * @author Ahmed Ashour * @author Ronald Brill * @author Joerg Werner + * @author Hartmut Arlt */ public final class UrlUtils { private static final BitSet PATH_ALLOWED_CHARS = new BitSet(256); @@ -323,7 +324,7 @@ int offset = 0; for (int i = 0; i < input.length; i++) { final byte b = input[i]; - if (b == '%') { + if (state == 0 && b == '%') { state = 1; } else if (state == 1 || state == 2) { @@ -339,7 +340,7 @@ final int st = i - state + offset; result.replace(st, st + 1, "%25"); offset = offset + 2; - state = 0; + state = b == '%' ? 1 : 0; } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java 2018-02-12 12:37:11 UTC (rev 15130) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java 2018-02-16 19:04:17 UTC (rev 15131) @@ -31,6 +31,7 @@ * @author Sudhan Moghe * @author Ahmed Ashour * @author Ronald Brill + * @author Hartmut Arlt */ public class UrlUtilsTest extends SimpleWebTestCase { @@ -317,9 +318,40 @@ } /** + * Tests for #1951. * @throws Exception if the test fails */ @Test + public void percentEncoding2() throws Exception { + URL url = new URL("http://localhost/foo%%20bar.html"); + assertEquals("http://localhost/foo%25%20bar.html", + UrlUtils.encodeUrl(url, false, ISO_8859_1)); + + url = new URL("http://localhost/foo%20bar.html"); + assertEquals("http://localhost/foo%20bar.html", + UrlUtils.encodeUrl(url, false, ISO_8859_1)); + + url = new URL("http://localhost/foo%ar.html"); + assertEquals("http://localhost/foo%25ar.html", + UrlUtils.encodeUrl(url, false, ISO_8859_1)); + + url = new URL("http://localhost/foo%%xyz.html"); + assertEquals("http://localhost/foo%25%25xyz.html", + UrlUtils.encodeUrl(url, false, ISO_8859_1)); + + url = new URL("http://localhost/foo%20%xyz.html"); + assertEquals("http://localhost/foo%20%25xyz.html", + UrlUtils.encodeUrl(url, false, ISO_8859_1)); + + url = new URL("http://localhost/foo%2x%bar.html"); + assertEquals("http://localhost/foo%252x%bar.html", + UrlUtils.encodeUrl(url, false, ISO_8859_1)); + } + + /** + * @throws Exception if the test fails + */ + @Test public void relativeBase() throws Exception { final String baseUrl = "a/a1/a2"; assertEquals("b", UrlUtils.resolveUrl(baseUrl, "../../b")); |
From: <rb...@us...> - 2018-02-24 20:35:53
|
Revision: 15136 http://sourceforge.net/p/htmlunit/code/15136 Author: rbri Date: 2018-02-20 19:16:28 +0000 (Tue, 20 Feb 2018) Log Message: ----------- page cache now takes care of Cache Control headers Issue 1952 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/History.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/HeaderUtils.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-02-19 20:09:12 UTC (rev 15135) +++ trunk/htmlunit/src/changes/changes.xml 2018-02-20 19:16:28 UTC (rev 15136) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="add" dev="rbri" issue="1952" due-to="Anton Demydenko"> + Our page cache now takes care of Cache Control headers. + </action> <action type="fix" dev="rbri" issue="1951" due-to="Hartmut Arlt"> Fix incorrect encoding of consecutive '%' characters in url's </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2018-02-19 20:09:12 UTC (rev 15135) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2018-02-20 19:16:28 UTC (rev 15136) @@ -26,6 +26,7 @@ import org.apache.http.client.utils.DateUtils; import org.w3c.dom.css.CSSStyleSheet; +import com.gargoylesoftware.htmlunit.util.HeaderUtils; import com.gargoylesoftware.htmlunit.util.UrlUtils; /** @@ -36,6 +37,7 @@ * @author Marc Guillemot * @author Daniel Gredler * @author Ahmed Ashour + * @author Anton Demydenko */ public class Cache implements Serializable { @@ -43,7 +45,7 @@ private int maxSize_ = 40; private static final Pattern DATE_HEADER_PATTERN = Pattern.compile("-?\\d+"); - + private static final long DELAY = 10 * org.apache.commons.lang3.time.DateUtils.MILLIS_PER_MINUTE; /** * The map which holds the cached responses. Note that when keying on URLs, we key on the string version * of the URLs, rather than on the URLs themselves. This is done for performance, because a) the @@ -61,12 +63,14 @@ private WebResponse response_; private Object value_; private long lastAccess_; + private long createdAt_; Entry(final String key, final WebResponse response, final Object value) { key_ = key; response_ = response; value_ = value; - lastAccess_ = System.currentTimeMillis(); + createdAt_ = System.currentTimeMillis(); + lastAccess_ = createdAt_; } /** @@ -178,6 +182,8 @@ } /** + * <p>Perform prior validation for 'no-store' directive in Cache-Control header.</p> + * * <p>Tries to guess if the content is dynamic or not.</p> * * <p>"Since origin servers do not always provide explicit expiration times, HTTP caches typically @@ -188,19 +194,23 @@ * <tt>Last-Modified</tt> header with a date older than 10 minutes or with an <tt>Expires</tt> header * specifying expiration in more than 10 minutes.</p> * + * @see @see <a href="https://tools.ietf.org/html/rfc7234">RFC 7234</a> * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html">RFC 2616</a> * @param response the response to examine * @return {@code true} if the response should be considered as cacheable */ protected boolean isCacheableContent(final WebResponse response) { - final Date lastModified = parseDateHeader(response, "Last-Modified"); - final Date expires = parseDateHeader(response, "Expires"); + if (HeaderUtils.containsNoStore(response)) { + return false; + } - final long delay = 10 * org.apache.commons.lang3.time.DateUtils.MILLIS_PER_MINUTE; + final Date lastModified = parseDateHeader(response, HttpHeader.LAST_MODIFIED); + final Date expires = parseDateHeader(response, HttpHeader.EXPIRES); + final long now = getCurrentTimestamp(); - return expires != null && (expires.getTime() - now > delay) - || (expires == null && lastModified != null && now - lastModified.getTime() > delay); + return expires != null && (expires.getTime() - now > DELAY) + || (expires == null && lastModified != null && now - lastModified.getTime() > DELAY); } /** @@ -235,6 +245,9 @@ * Returns the cached response corresponding to the specified request. If there is * no corresponding cached object, this method returns {@code null}. * + * <p>Calculates and check if object still fresh(RFC 7234) otherwise returns {@code null}.</p> + * @see <a href="https://tools.ietf.org/html/rfc7234">RFC 7234</a> + * * @param request the request whose corresponding response is sought * @return the cached response corresponding to the specified request if any */ @@ -250,6 +263,9 @@ * Returns the cached object corresponding to the specified request. If there is * no corresponding cached object, this method returns {@code null}. * + * <p>Calculates and check if object still fresh(RFC 7234) otherwise returns {@code null}.</p> + * @see <a href="https://tools.ietf.org/html/rfc7234">RFC 7234</a> + * * @param request the request whose corresponding cached compiled script is sought * @return the cached object corresponding to the specified request if any */ @@ -274,13 +290,58 @@ if (cachedEntry == null) { return null; } - synchronized (entries_) { - cachedEntry.touch(); + + // check if object still fresh + if (checkFreshness(cachedEntry.response_, cachedEntry.createdAt_)) { + synchronized (entries_) { + cachedEntry.touch(); + } + return cachedEntry; } - return cachedEntry; + else { + entries_.remove(UrlUtils.normalize(url)); + } + return null; } /** + * <p>Check freshness return value if + * a) s-maxage specified + * b) max-age specified + * c) expired specified + * otherwise return {@code null}</p> + * + * @see <a href="https://tools.ietf.org/html/rfc7234">RFC 7234</a> + * + * @param response + * @param createdAt + * @return freshnessLifetime + */ + private boolean checkFreshness(final WebResponse response, final long createdAt) { + final long now = getCurrentTimestamp(); + long freshnessLifetime = 0; + if (!HeaderUtils.containsPrivate(response) && HeaderUtils.containsSMaxage(response)) { + // check s-maxage + freshnessLifetime = HeaderUtils.sMaxage(response); + } + else if (HeaderUtils.containsMaxAge(response)) { + // check max-age + freshnessLifetime = HeaderUtils.maxAge(response); + } + else if (response.getResponseHeaderValue(HttpHeader.EXPIRES) != null) { + final Date expires = parseDateHeader(response, HttpHeader.EXPIRES); + if (expires != null) { + // use the same logic as in isCacheableContent() + return expires.getTime() - now > DELAY; + } + } + else { + return true; + } + return now - createdAt < freshnessLifetime * org.apache.commons.lang3.time.DateUtils.MILLIS_PER_SECOND; + } + + /** * Returns the cached parsed version of the specified CSS snippet. If there is no * corresponding cached stylesheet, this method returns {@code null}. * @@ -344,5 +405,4 @@ entries_.clear(); } } - } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/History.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/History.java 2018-02-19 20:09:12 UTC (rev 15135) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/History.java 2018-02-20 19:16:28 UTC (rev 15136) @@ -25,6 +25,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.PopStateEvent; +import com.gargoylesoftware.htmlunit.util.HeaderUtils; import com.gargoylesoftware.htmlunit.util.UrlUtils; /** @@ -47,8 +48,15 @@ private Object state_; private HistoryEntry(final Page page) { - page_ = new SoftReference<>(page); + // verify cache-control header values before storing + if (HeaderUtils.containsNoStore(page.getWebResponse())) { + page_ = new SoftReference<>(page); + } + else { + page_ = null; + } + final WebRequest request = page.getWebResponse().getWebRequest(); webRequest_ = new WebRequest(request.getUrl(), request.getHttpMethod()); webRequest_.setRequestParameters(request.getRequestParameters()); @@ -257,6 +265,7 @@ if (entries_.size() > cacheLimit) { entries_.get(entries_.size() - cacheLimit - 1).clearPage(); } + return entry; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2018-02-19 20:09:12 UTC (rev 15135) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpHeader.java 2018-02-20 19:16:28 UTC (rev 15136) @@ -18,6 +18,7 @@ * Various constants. * * @author Ronald Brill + * @author Anton Demydenko */ public final class HttpHeader { @@ -34,6 +35,12 @@ /** Cache-Control. */ public static final String CACHE_CONTROL = "Cache-Control"; + /** Last-Modified. */ + public static final String LAST_MODIFIED = "Last-Modified"; + + /** Expires. */ + public static final String EXPIRES = "Expires"; + /** Accept. */ public static final String ACCEPT = "Accept"; /** accept. */ Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/HeaderUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/HeaderUtils.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/HeaderUtils.java 2018-02-20 19:16:28 UTC (rev 15136) @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2002-2018 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.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; + +import com.gargoylesoftware.htmlunit.HttpHeader; +import com.gargoylesoftware.htmlunit.WebResponse; + +/** + * @author Anton Demydenko + */ +public final class HeaderUtils { + + private static final String CACHE_CONTROL_PRIVATE = "private"; + private static final String CACHE_CONTROL_PUBLIC = "public"; + private static final String CACHE_CONTROL_NO_STORE = "no-store"; + private static final String CACHE_CONTROL_NO_CACHE = "no-cache"; + private static final String CACHE_CONTROL_MAX_AGE = "max-age"; + private static final String CACHE_CONTROL_S_MAXAGE = "s-maxage"; + private static final Pattern MAX_AGE_HEADER_PATTERN = Pattern.compile("^.*max-age=([\\d]+).*$"); + private static final Pattern S_MAXAGE_HEADER_PATTERN = Pattern.compile("^.*s-maxage=([\\d]+).*$"); + + private HeaderUtils() { + // utility class + } + + /** + * @param response {@code WebResponse} + * @return if 'Cache-Control' header is present and contains 'private' value + */ + public static boolean containsPrivate(final WebResponse response) { + return containsValue(response, CACHE_CONTROL_PRIVATE); + } + + /** + * @param response {@code WebResponse} + * @return if 'Cache-Control' header is present and contains 'public' value + */ + public static boolean containsPublic(final WebResponse response) { + return containsValue(response, CACHE_CONTROL_PUBLIC); + } + + /** + * @param response {@code WebResponse} + * @return if 'Cache-Control' header is present and contains 'no-store' value + */ + public static boolean containsNoStore(final WebResponse response) { + return containsValue(response, CACHE_CONTROL_NO_STORE); + } + + /** + * @param response {@code WebResponse} + * @return if 'Cache-Control' header is present and contains 'no-cache' value@return + */ + public static boolean containsNoCache(final WebResponse response) { + return containsValue(response, CACHE_CONTROL_NO_CACHE); + } + + /** + * @param response {@code WebResponse} + * @return if 'Cache-Control' header is present and contains 's-maxage' value + */ + public static boolean containsSMaxage(final WebResponse response) { + return containsValue(response, CACHE_CONTROL_S_MAXAGE); + } + + /** + * @param response {@code WebResponse} + * @return if 'Cache-Control' header is present and contains 'max-age' value + */ + public static boolean containsMaxAge(final WebResponse response) { + return containsValue(response, CACHE_CONTROL_MAX_AGE); + } + + /** + * @param response {@code WebResponse} + * @return value of 's-maxage' directive and 0 if it is absent + */ + public static long sMaxage(final WebResponse response) { + if (containsValue(response, CACHE_CONTROL_S_MAXAGE)) { + return directiveValue(response, S_MAXAGE_HEADER_PATTERN); + } + return 0; + } + + /** + * @param response {@code WebResponse} + * @return value of 'max-age' directive and 0 if it is absent + */ + public static long maxAge(final WebResponse response) { + if (containsValue(response, CACHE_CONTROL_MAX_AGE)) { + return directiveValue(response, MAX_AGE_HEADER_PATTERN); + } + + return 0; + } + + private static long directiveValue(final WebResponse response, final Pattern pattern) { + final String value = response.getResponseHeaderValue(HttpHeader.CACHE_CONTROL); + if (value != null) { + final Matcher matcher = pattern.matcher(value); + if (matcher.matches()) { + return Long.valueOf(matcher.group(1)); + } + } + + return 0; + } + + private static boolean containsValue(final WebResponse response, final String value) { + final String cacheControl = response.getResponseHeaderValue(HttpHeader.CACHE_CONTROL); + return StringUtils.contains(cacheControl, value); + } +} Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2018-02-19 20:09:12 UTC (rev 15135) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2018-02-20 19:16:28 UTC (rev 15136) @@ -24,6 +24,7 @@ import java.io.InputStream; import java.net.URL; import java.nio.charset.Charset; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -46,6 +47,7 @@ * @author Marc Guillemot * @author Ahmed Ashour * @author Frank Danek + * @author Anton Demydenko */ @RunWith(BrowserRunner.class) public class CacheTest extends SimpleWebTestCase { @@ -86,6 +88,9 @@ headers.put("Expires", "-1"); assertFalse(cache.isCacheableContent(response)); + + headers.put("Cache-Control", "no-store"); + assertFalse(cache.isCacheableContent(response)); } /** @@ -359,6 +364,154 @@ } /** + * @throws Exception if the test fails + */ + @Test + public void testNoStoreCacheControl() throws Exception { + final String html = "<html><head><title>page 1</title>\n" + + "<link rel='stylesheet' type='text/css' href='foo.css' />\n" + + "</head>\n" + + "<body>x</body>\n" + + "</html>"; + + final WebClient client = getWebClient(); + + final MockWebConnection connection = new MockWebConnection(); + client.setWebConnection(connection); + + final List<NameValuePair> headers = new ArrayList<>(); + headers.add(new NameValuePair("Cache-Control", "some-other-value, no-store")); + + final URL pageUrl = new URL(URL_FIRST, "page1.html"); + connection.setResponse(pageUrl, html, 200, "OK", "text/html;charset=ISO-8859-1", headers); + connection.setResponse(new URL(URL_FIRST, "foo.css"), "", 200, "OK", JAVASCRIPT_MIME_TYPE, headers); + + client.getPage(pageUrl); + assertEquals(0, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + + client.getPage(pageUrl); + assertEquals(0, client.getCache().getSize()); + assertEquals(4, connection.getRequestCount()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void testMaxAgeCacheControl() throws Exception { + final String html = "<html><head><title>page 1</title>\n" + + "<link rel='stylesheet' type='text/css' href='foo.css' />\n" + + "</head>\n" + + "<body>x</body>\n" + + "</html>"; + + final WebClient client = getWebClient(); + + final MockWebConnection connection = new MockWebConnection(); + client.setWebConnection(connection); + + final List<NameValuePair> headers = new ArrayList<>(); + headers.add(new NameValuePair("Last-Modified", "Tue, 20 Feb 2018 10:00:00 GMT")); + headers.add(new NameValuePair("Cache-Control", "some-other-value, max-age=1")); + + final URL pageUrl = new URL(URL_FIRST, "page1.html"); + connection.setResponse(pageUrl, html, 200, "OK", "text/html;charset=ISO-8859-1", headers); + connection.setResponse(new URL(URL_FIRST, "foo.css"), "", 200, "OK", JAVASCRIPT_MIME_TYPE, headers); + + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + // resources should be still in cache + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + // wait for max-age seconds + 1 for recache + Thread.sleep(2 * 1000); + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(4, connection.getRequestCount()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void testSMaxageCacheControl() throws Exception { + final String html = "<html><head><title>page 1</title>\n" + + "<link rel='stylesheet' type='text/css' href='foo.css' />\n" + + "</head>\n" + + "<body>x</body>\n" + + "</html>"; + + final WebClient client = getWebClient(); + + final MockWebConnection connection = new MockWebConnection(); + client.setWebConnection(connection); + + final List<NameValuePair> headers = new ArrayList<>(); + headers.add(new NameValuePair("Last-Modified", "Tue, 20 Feb 2018 10:00:00 GMT")); + headers.add(new NameValuePair("Cache-Control", "public, s-maxage=1, some-other-value, max-age=10")); + + final URL pageUrl = new URL(URL_FIRST, "page1.html"); + connection.setResponse(pageUrl, html, 200, "OK", "text/html;charset=ISO-8859-1", headers); + connection.setResponse(new URL(URL_FIRST, "foo.css"), "", 200, "OK", JAVASCRIPT_MIME_TYPE, headers); + + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + // resources should be still in cache + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + // wait for s-maxage seconds + 1 for recache + Thread.sleep(2 * 1000); + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(4, connection.getRequestCount()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void testExpiresCacheControl() throws Exception { + final String html = "<html><head><title>page 1</title>\n" + + "<link rel='stylesheet' type='text/css' href='foo.css' />\n" + + "</head>\n" + + "<body>x</body>\n" + + "</html>"; + + final WebClient client = getWebClient(); + + final MockWebConnection connection = new MockWebConnection(); + client.setWebConnection(connection); + + final List<NameValuePair> headers = new ArrayList<>(); + headers.add(new NameValuePair("Last-Modified", "Tue, 20 Feb 2018 10:00:00 GMT")); + headers.add(new NameValuePair("Expires", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(new Date( + System.currentTimeMillis() + 2 * 1000 + 10 * org.apache.commons.lang3.time.DateUtils.MILLIS_PER_MINUTE)))); + headers.add(new NameValuePair("Cache-Control", "public, some-other-value")); + + final URL pageUrl = new URL(URL_FIRST, "page1.html"); + connection.setResponse(pageUrl, html, 200, "OK", "text/html;charset=ISO-8859-1", headers); + connection.setResponse(new URL(URL_FIRST, "foo.css"), "", 200, "OK", JAVASCRIPT_MIME_TYPE, headers); + + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + // resources should be still in cache + client.getPage(pageUrl); + assertEquals(2, client.getCache().getSize()); + assertEquals(2, connection.getRequestCount()); + // wait for expires + Thread.sleep(2 * 1000); + client.getPage(pageUrl); + assertEquals(0, client.getCache().getSize()); + assertEquals(4, connection.getRequestCount()); + } + + /** * Ensures {@link WebResponse#cleanUp()} is called for overflow deleted entries. * @throws Exception if the test fails */ @@ -368,8 +521,9 @@ final WebResponse response1 = createMock(WebResponse.class); expect(response1.getWebRequest()).andReturn(request1); expectLastCall().atLeastOnce(); - expect(response1.getResponseHeaderValue("Last-Modified")).andReturn(null); - expect(response1.getResponseHeaderValue("Expires")).andReturn( + expect(response1.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); + expect(response1.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); + expect(response1.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); final WebRequest request2 = new WebRequest(URL_SECOND, HttpMethod.GET); @@ -376,8 +530,9 @@ final WebResponse response2 = createMock(WebResponse.class); expect(response2.getWebRequest()).andReturn(request2); expectLastCall().atLeastOnce(); - expect(response2.getResponseHeaderValue("Last-Modified")).andReturn(null); - expect(response2.getResponseHeaderValue("Expires")).andReturn( + expect(response2.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); + expect(response2.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); + expect(response2.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); response1.cleanUp(); @@ -402,8 +557,9 @@ final WebResponse response1 = createMock(WebResponse.class); expect(response1.getWebRequest()).andReturn(request1); expectLastCall().atLeastOnce(); - expect(response1.getResponseHeaderValue("Last-Modified")).andReturn(null); - expect(response1.getResponseHeaderValue("Expires")).andReturn( + expect(response1.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); + expect(response1.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); + expect(response1.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); response1.cleanUp(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java 2018-02-19 20:09:12 UTC (rev 15135) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/History2Test.java 2018-02-20 19:16:28 UTC (rev 15136) @@ -14,7 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static java.nio.charset.StandardCharsets.ISO_8859_1; + +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,6 +29,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.util.NameValuePair; /** * Tests for {@link History}. @@ -34,6 +39,7 @@ * @author Ronald Brill * @author Adam Afeltowicz * @author Carsten Steul + * @author Anton Demydenko */ @RunWith(BrowserRunner.class) public class History2Test extends WebDriverTestCase { @@ -802,4 +808,42 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + public void testHistoryBackAndForwarWithNoStoreCacheControlHeader() throws Exception { + final String html = "<html><body>" + + "<a id='startButton' href='" + URL_SECOND + "'>Start</a>\n" + + "</body></html>"; + final String secondContent = "<!DOCTYPE html>\n" + + "<html><head></head>\n" + + "<body>\n" + + " <a id='nextButton' href='" + URL_THIRD + "'>Next</a>\n" + + " <a id='forwardButton' onclick='javascript:window.history.forward()'>Forward</a>\n" + + "</body></html>"; + final String thirdContent = "<html><body>" + + "<a id='backButton' onclick='javascript:window.history.back()'>Back</a>\n" + + "</body></html>"; + + final List<NameValuePair> headers = new ArrayList<>(); + headers.add(new NameValuePair("Cache-Control", "some-other-value, no-store")); + getMockWebConnection().setResponse(URL_SECOND, secondContent, 200, "OK", "text/html;charset=ISO-8859-1", + ISO_8859_1, headers); + getMockWebConnection().setResponse(URL_THIRD, thirdContent, 200, "OK", "text/html;charset=ISO-8859-1", + ISO_8859_1, headers); + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("startButton")).click(); + driver.findElement(By.id("nextButton")).click(); + driver.findElement(By.id("backButton")).click(); + + assertEquals(URL_SECOND.toString(), driver.getCurrentUrl()); + assertEquals(4, getMockWebConnection().getRequestCount()); + + driver.findElement(By.id("forwardButton")).click(); + assertEquals(URL_THIRD.toString(), driver.getCurrentUrl()); + assertEquals(5, getMockWebConnection().getRequestCount()); + } } |
From: <rb...@us...> - 2018-03-04 09:34:00
|
Revision: 15147 http://sourceforge.net/p/htmlunit/code/15147 Author: rbri Date: 2018-03-04 09:33:53 +0000 (Sun, 04 Mar 2018) Log Message: ----------- index based css handling Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/StyleElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSImportRuleTest.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/SelectorSpecificity.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/SelectorSpecificity.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/SelectorSpecificity.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/SelectorSpecificity.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2002-2018 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.css; - -import java.io.Serializable; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.gargoylesoftware.css.parser.condition.AttributeCondition; -import com.gargoylesoftware.css.parser.condition.BeginHyphenAttributeCondition; -import com.gargoylesoftware.css.parser.condition.Condition; -import com.gargoylesoftware.css.parser.condition.OneOfAttributeCondition; -import com.gargoylesoftware.css.parser.condition.PrefixAttributeCondition; -import com.gargoylesoftware.css.parser.condition.SubstringAttributeCondition; -import com.gargoylesoftware.css.parser.condition.SuffixAttributeCondition; -import com.gargoylesoftware.css.parser.selector.ChildSelector; -import com.gargoylesoftware.css.parser.selector.DescendantSelector; -import com.gargoylesoftware.css.parser.selector.DirectAdjacentSelector; -import com.gargoylesoftware.css.parser.selector.ElementSelector; -import com.gargoylesoftware.css.parser.selector.GeneralAdjacentSelector; -import com.gargoylesoftware.css.parser.selector.PseudoElementSelector; -import com.gargoylesoftware.css.parser.selector.Selector; - -/** - * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> - * - * Calculates a selector's specificity. - * @see <a href="http://www.w3.org/TR/CSS21/cascade.html#specificity">W3C CSS21</a> - * - * @author Marc Guillemot - * @author Ronald Brill - */ -public class SelectorSpecificity implements Comparable<SelectorSpecificity>, Serializable { - private static final Log LOG = LogFactory.getLog(SelectorSpecificity.class); - - /** - * The specificity for declarations made in the style attributes of an element. - */ - public static final SelectorSpecificity FROM_STYLE_ATTRIBUTE = new SelectorSpecificity(1, 0, 0, 0); - /** - * The specificity for browser defaults. - */ - public static final SelectorSpecificity DEFAULT_STYLE_ATTRIBUTE = new SelectorSpecificity(0, 0, 0, 0); - - private int fieldA_; - private int fieldB_; - private int fieldC_; - private int fieldD_; - - /** - * Ctor. - * @param selector the selector to read from - */ - public SelectorSpecificity(final Selector selector) { - readSelectorSpecificity(selector); - } - - private SelectorSpecificity(final int a, final int b, final int c, final int d) { - fieldA_ = a; - fieldB_ = b; - fieldC_ = c; - fieldD_ = d; - } - - private void readSelectorSpecificity(final Selector selector) { - switch (selector.getSelectorType()) { - case DESCENDANT_SELECTOR: - final DescendantSelector ds = (DescendantSelector) selector; - readSelectorSpecificity(ds.getAncestorSelector()); - readSelectorSpecificity(ds.getSimpleSelector()); - return; - case CHILD_SELECTOR: - final ChildSelector cs = (ChildSelector) selector; - readSelectorSpecificity(cs.getAncestorSelector()); - readSelectorSpecificity(cs.getSimpleSelector()); - return; - case ELEMENT_NODE_SELECTOR: - final ElementSelector es = (ElementSelector) selector; - if (es.getLocalName() != null) { - fieldD_++; - } - if (es.getConditions() != null) { - for (Condition condition : es.getConditions()) { - readSelectorSpecificity(condition); - } - } - return; - case PSEUDO_ELEMENT_SELECTOR: - final PseudoElementSelector pes = (PseudoElementSelector) selector; - final String pesName = pes.getLocalName(); - if (pesName != null) { - fieldD_++; - } - return; - case DIRECT_ADJACENT_SELECTOR: - final DirectAdjacentSelector das = (DirectAdjacentSelector) selector; - readSelectorSpecificity(das.getSelector()); - readSelectorSpecificity(das.getSimpleSelector()); - return; - case GENERAL_ADJACENT_SELECTOR: - final GeneralAdjacentSelector gas = (GeneralAdjacentSelector) selector; - readSelectorSpecificity(gas.getSelector()); - readSelectorSpecificity(gas.getSimpleSelector()); - return; - default: - LOG.warn("Unhandled CSS selector type for specificity computation: '" - + selector.getSelectorType() + "'."); - return; - } - } - - private void readSelectorSpecificity(final Condition condition) { - switch (condition.getConditionType()) { - case ID_CONDITION: - fieldB_++; - return; - case CLASS_CONDITION: - fieldC_++; - return; - case ATTRIBUTE_CONDITION: - if ("id".equalsIgnoreCase(((AttributeCondition) condition).getLocalName())) { - fieldB_++; - } - else { - fieldC_++; - } - return; - case SUBSTRING_ATTRIBUTE_CONDITION: - if ("id".equalsIgnoreCase(((SubstringAttributeCondition) condition).getLocalName())) { - fieldB_++; - } - else { - fieldC_++; - } - return; - case SUFFIX_ATTRIBUTE_CONDITION: - if ("id".equalsIgnoreCase(((SuffixAttributeCondition) condition).getLocalName())) { - fieldB_++; - } - else { - fieldC_++; - } - return; - case PREFIX_ATTRIBUTE_CONDITION: - if ("id".equalsIgnoreCase(((PrefixAttributeCondition) condition).getLocalName())) { - fieldB_++; - } - else { - fieldC_++; - } - return; - case BEGIN_HYPHEN_ATTRIBUTE_CONDITION: - if ("id".equalsIgnoreCase(((BeginHyphenAttributeCondition) condition).getLocalName())) { - fieldB_++; - } - else { - fieldC_++; - } - return; - case ONE_OF_ATTRIBUTE_CONDITION: - if ("id".equalsIgnoreCase(((OneOfAttributeCondition) condition).getLocalName())) { - fieldB_++; - } - else { - fieldC_++; - } - return; - case PSEUDO_CLASS_CONDITION: - fieldD_++; - return; - default: - LOG.warn("Unhandled CSS condition type for specifity computation: '" - + condition.getConditionType() + "'."); - return; - } - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return fieldA_ + "," + fieldB_ + "," + fieldC_ + "," + fieldD_; - } - - /** - * {@inheritDoc} - */ - @Override - public int compareTo(final SelectorSpecificity other) { - if (fieldA_ != other.fieldA_) { - return fieldA_ - other.fieldA_; - } - else if (fieldB_ != other.fieldB_) { - return fieldB_ - other.fieldB_; - } - else if (fieldC_ != other.fieldC_) { - return fieldC_ - other.fieldC_; - } - else if (fieldD_ != other.fieldD_) { - return fieldD_ - other.fieldD_; - } - return 0; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + fieldA_; - result = prime * result + fieldB_; - result = prime * result + fieldC_; - result = prime * result + fieldD_; - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final SelectorSpecificity other = (SelectorSpecificity) obj; - if (fieldA_ != other.fieldA_) { - return false; - } - if (fieldB_ != other.fieldB_) { - return false; - } - if (fieldC_ != other.fieldC_) { - return false; - } - if (fieldD_ != other.fieldD_) { - return false; - } - return true; - } -} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/StyleElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/StyleElement.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/css/StyleElement.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -16,6 +16,8 @@ import java.io.Serializable; +import com.gargoylesoftware.css.parser.selector.SelectorSpecificity; + /** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -46,12 +46,12 @@ import com.gargoylesoftware.css.parser.CSSException; import com.gargoylesoftware.css.parser.selector.Selector; import com.gargoylesoftware.css.parser.selector.SelectorList; +import com.gargoylesoftware.css.parser.selector.SelectorSpecificity; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.css.SelectorSpecificity; import com.gargoylesoftware.htmlunit.css.StyleElement; import com.gargoylesoftware.htmlunit.javascript.AbstractJavaScriptEngine; import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -238,22 +238,29 @@ */ public void modifyIfNecessary(final ComputedCSSStyleDeclaration style, final Element element, final String pseudoElement) { - final CSSRuleList rules = getWrappedSheet().getCssRules(); - modifyIfNecessary(style, element, pseudoElement, rules, new HashSet<String>()); +// final CSSRuleList ruleList = getWrappedSheet().getCssRules(); +// modifyIfNecessary(style, element, pseudoElement, ruleList, new HashSet<String>()); + + final BrowserVersion browser = getBrowserVersion(); + final DomElement e = element.getDomNodeOrDie(); + final List<CSSStyleSheetImpl.SelectorEntry> matchingRules = + selects(getRuleIndex(), this, browser, e, pseudoElement, false); + for (CSSStyleSheetImpl.SelectorEntry entry : matchingRules) { + final org.w3c.dom.css.CSSStyleDeclaration dec = entry.getRule().getStyle(); + style.applyStyleFromSelector(dec, entry.getSelector()); + } } private void modifyIfNecessary(final ComputedCSSStyleDeclaration style, final Element element, - final String pseudoElement, final CSSRuleList rules, final Set<String> alreadyProcessing) { - if (rules == null) { + final String pseudoElement, final CSSRuleList ruleList, final Set<String> alreadyProcessing) { + if (ruleList == null) { return; } final BrowserVersion browser = getBrowserVersion(); final DomElement e = element.getDomNodeOrDie(); - final int rulesLength = rules.getLength(); - for (int i = 0; i < rulesLength; i++) { - final CSSRule rule = rules.item(i); - + final List<org.w3c.dom.css.CSSRule> rules = ((CSSRuleListImpl) ruleList).getRules(); + for (CSSRule rule : rules) { final short ruleType = rule.getType(); if (CSSRule.STYLE_RULE == ruleType) { final CSSStyleRuleImpl styleRule = (CSSStyleRuleImpl) rule; @@ -281,9 +288,9 @@ } if (!alreadyProcessing.contains(sheet.getUri())) { - final CSSRuleList sheetRules = sheet.getWrappedSheet().getCssRules(); + final CSSRuleList sheetRuleList = sheet.getWrappedSheet().getCssRules(); alreadyProcessing.add(getUri()); - sheet.modifyIfNecessary(style, element, pseudoElement, sheetRules, alreadyProcessing); + sheet.modifyIfNecessary(style, element, pseudoElement, sheetRuleList, alreadyProcessing); } } } @@ -308,7 +315,7 @@ public static CSSStyleSheet loadStylesheet(final HTMLElement element, final HtmlLink link, final String url) { CSSStyleSheet sheet; final HtmlPage page = (HtmlPage) element.getDomNodeOrDie().getPage(); - String uri = page.getUrl().toExternalForm(); // fallback uri for exceptions + String uri = page.getUrl().toExternalForm(); try { // Retrieve the associated content and respect client settings regarding failing HTTP status codes. final WebRequest request; @@ -335,8 +342,7 @@ // Use href. final String accept = client.getBrowserVersion().getCssAcceptHeader(); request = new WebRequest(new URL(url), accept); - final String referer = page.getUrl().toExternalForm(); - request.setAdditionalHeader(HttpHeader.REFERER, referer); + request.setAdditionalHeader(HttpHeader.REFERER, uri); // our cache is a bit strange; // loadWebResponse check the cache for the web response @@ -1113,11 +1119,10 @@ cssRules_.clearRules(); cssRulesIndexFix_.clear(); - final CSSRuleList ruleList = getWrappedSheet().getCssRules(); - final List<org.w3c.dom.css.CSSRule> rules = ((CSSRuleListImpl) ruleList).getRules(); + final CSSRuleListImpl ruleList = (CSSRuleListImpl) getWrappedSheet().getCssRules(); + final List<org.w3c.dom.css.CSSRule> rules = ruleList.getRules(); int pos = 0; - for (Iterator<CSSRule> it = rules.iterator(); it.hasNext();) { - final org.w3c.dom.css.CSSRule rule = it.next(); + for (CSSRule rule : rules) { if (rule instanceof org.w3c.dom.css.CSSCharsetRule) { cssRulesIndexFix_.add(pos); continue; @@ -1133,6 +1138,9 @@ } pos++; } + + // reset our index also + ((CSSStyleSheetImpl) getWrappedSheet()).resetRuleIndex(); } private int fixIndex(int index) { @@ -1551,4 +1559,104 @@ refreshCssRules(); } } + + private CSSStyleSheetImpl.CSSStyleSheetRuleIndex getRuleIndex() { + final CSSStyleSheetImpl styleSheet = (CSSStyleSheetImpl) getWrappedSheet(); + CSSStyleSheetImpl.CSSStyleSheetRuleIndex index = styleSheet.getRuleIndex(); + + if (index == null) { + index = new CSSStyleSheetImpl.CSSStyleSheetRuleIndex(); + final CSSRuleListImpl ruleList = (CSSRuleListImpl) styleSheet.getCssRules(); + index(index, ruleList, new HashSet<String>()); + + styleSheet.setRuleIndex(index); + } + return index; + } + + private void index(final CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, final CSSRuleListImpl ruleList, + final Set<String> alreadyProcessing) { + + for (CSSRule rule : ruleList.getRules()) { + final short ruleType = rule.getType(); + if (CSSRule.STYLE_RULE == ruleType) { + final CSSStyleRuleImpl styleRule = (CSSStyleRuleImpl) rule; + final SelectorList selectors = styleRule.getSelectors(); + for (Selector selector : selectors) { + final SimpleSelector simpleSel = selector.getSimpleSelector(); + if (SelectorType.ELEMENT_NODE_SELECTOR == simpleSel.getSelectorType()) { + final ElementSelector es = (ElementSelector) simpleSel; + index.addElementSelector(es.getElementName(), selector, styleRule); + } + else { + index.addOtherSelector(selector, styleRule); + } + } + } + else if (CSSRule.IMPORT_RULE == ruleType) { + final CSSImportRuleImpl importRule = (CSSImportRuleImpl) rule; + final MediaList mediaList = importRule.getMedia(); + + CSSStyleSheet sheet = imports_.get(importRule); + if (sheet == null) { + final String href = importRule.getHref(); + final String url = UrlUtils.resolveUrl(getUri(), href); + sheet = loadStylesheet(ownerNode_, null, url); + imports_.put(importRule, sheet); + } + + if (!alreadyProcessing.contains(sheet.getUri())) { + final CSSRuleList sheetRuleList = sheet.getWrappedSheet().getCssRules(); + alreadyProcessing.add(sheet.getUri()); + + if (mediaList.getLength() == 0 && index.getMediaList().getLength() == 0) { + index(index, (CSSRuleListImpl) sheetRuleList, alreadyProcessing); + } + else { + index(index.addMedia(mediaList), (CSSRuleListImpl) sheetRuleList, alreadyProcessing); + } + } + } + else if (CSSRule.MEDIA_RULE == ruleType) { + final CSSMediaRuleImpl mediaRule = (CSSMediaRuleImpl) rule; + final MediaList mediaList = mediaRule.getMedia(); + if (mediaList.getLength() == 0 && index.getMediaList().getLength() == 0) { + index(index, (CSSRuleListImpl) mediaRule.getCssRules(), alreadyProcessing); + } + else { + index(index.addMedia(mediaList), (CSSRuleListImpl) mediaRule.getCssRules(), alreadyProcessing); + } + } + } + } + + private List<CSSStyleSheetImpl.SelectorEntry> selects( + final CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, + final SimpleScriptable scriptable, + final BrowserVersion browserVersion, final DomElement element, + final String pseudoElement, final boolean fromQuerySelectorAll) { + + final List<CSSStyleSheetImpl.SelectorEntry> matchingRules = new ArrayList<>(); + + if (CSSStyleSheet.isActive(scriptable, index.getMediaList())) { + final String elementName = element.getLocalName(); + final Iterator<CSSStyleSheetImpl.SelectorEntry> iter = index.getSelectorEntriesIteratorFor(elementName); + + CSSStyleSheetImpl.SelectorEntry entry = iter.next(); + while (null != entry) { + if (CSSStyleSheet.selects(browserVersion, entry.getSelector(), + element, pseudoElement, fromQuerySelectorAll)) { + matchingRules.add(entry); + } + entry = iter.next(); + } + + for (CSSStyleSheetImpl.CSSStyleSheetRuleIndex child : index.getChildren()) { + matchingRules.addAll(selects(child, scriptable, browserVersion, + element, pseudoElement, fromQuerySelectorAll)); + } + } + + return matchingRules; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -95,9 +95,9 @@ import org.apache.commons.lang3.StringUtils; import com.gargoylesoftware.css.parser.selector.Selector; +import com.gargoylesoftware.css.parser.selector.SelectorSpecificity; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; -import com.gargoylesoftware.htmlunit.css.SelectorSpecificity; import com.gargoylesoftware.htmlunit.css.StyleElement; import com.gargoylesoftware.htmlunit.html.BaseFrameElement; import com.gargoylesoftware.htmlunit.html.DomElement; @@ -261,7 +261,7 @@ */ public void applyStyleFromSelector(final org.w3c.dom.css.CSSStyleDeclaration declaration, final Selector selector) { final BrowserVersion browserVersion = getBrowserVersion(); - final SelectorSpecificity specificity = new SelectorSpecificity(selector); + final SelectorSpecificity specificity = selector.getSelectorSpecificity(); for (int i = 0; i < declaration.getLength(); i++) { final String name = declaration.item(i); if (!browserVersion.hasFeature(CSS_COMPUTED_NO_Z_INDEX) || !"z-index".equals(name)) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSImportRuleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSImportRuleTest.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSImportRuleTest.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -254,6 +254,6 @@ getMockWebConnection().setResponse(URL_SECOND, screenCss, "text/css"); getMockWebConnection().setResponse(URL_THIRD, printCss, "text/css"); - loadPageWithAlerts2(html); + loadPageWithAlerts2(html, 70000); } } Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java 2018-03-04 09:31:50 UTC (rev 15146) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/SelectorSpecificityTest.java 2018-03-04 09:33:53 UTC (rev 15147) @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2002-2018 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.css; - -import java.io.StringReader; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.gargoylesoftware.css.parser.InputSource; -import com.gargoylesoftware.css.parser.selector.Selector; -import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.SimpleWebTestCase; -import com.gargoylesoftware.htmlunit.css.SelectorSpecificity; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlStyle; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLStyleElement; - -/** - * Tests for {@link SelectorSpecificity}. - * - * @author Marc Guillemot - */ -@RunWith(BrowserRunner.class) -public class SelectorSpecificityTest extends SimpleWebTestCase { - - /** - * @throws Exception if the test fails - */ - @Test - public void selectorSpecifity() throws Exception { - final SelectorSpecificity specificy0 = selectorSpecifity("*", "0,0,0,0"); - final SelectorSpecificity specificy1 = selectorSpecifity("li", "0,0,0,1"); - final SelectorSpecificity specificy2a = selectorSpecifity("li:first-line", "0,0,0,2"); - final SelectorSpecificity specificy2b = selectorSpecifity("ul li", "0,0,0,2"); - final SelectorSpecificity specificy2c = selectorSpecifity("body > p", "0,0,0,2"); - final SelectorSpecificity specificy3 = selectorSpecifity("ul ol+li", "0,0,0,3"); - final SelectorSpecificity specificy11 = selectorSpecifity("h1 + *[rel=up]", "0,0,1,1"); - final SelectorSpecificity specificy13 = selectorSpecifity("ul ol li.red", "0,0,1,3"); - final SelectorSpecificity specificy21 = selectorSpecifity("li.red.level", "0,0,2,1"); - final SelectorSpecificity specificy100 = selectorSpecifity("#x34y", "0,1,0,0"); - - selectorSpecifity("test#x34y", "0,1,0,1"); - - assertEquals(0, specificy0.compareTo(specificy0)); - assertTrue(specificy0.compareTo(specificy1) < 0); - assertTrue(specificy0.compareTo(specificy2a) < 0); - assertTrue(specificy0.compareTo(specificy13) < 0); - - assertEquals(0, specificy1.compareTo(specificy1)); - assertTrue(specificy1.compareTo(specificy0) > 0); - assertTrue(specificy1.compareTo(specificy2a) < 0); - assertTrue(specificy1.compareTo(specificy13) < 0); - - assertEquals(0, specificy2a.compareTo(specificy2b)); - assertEquals(0, specificy2a.compareTo(specificy2c)); - assertTrue(specificy2a.compareTo(specificy0) > 0); - assertTrue(specificy2a.compareTo(specificy3) < 0); - assertTrue(specificy2a.compareTo(specificy11) < 0); - assertTrue(specificy2a.compareTo(specificy13) < 0); - assertTrue(specificy2a.compareTo(specificy100) < 0); - - assertEquals(0, specificy11.compareTo(specificy11)); - assertTrue(specificy11.compareTo(specificy0) > 0); - assertTrue(specificy11.compareTo(specificy13) < 0); - assertTrue(specificy11.compareTo(specificy21) < 0); - assertTrue(specificy11.compareTo(specificy100) < 0); - } - - /** - * @throws Exception if the test fails - */ - @Test - public void selectorSpecifitySiblingCombinator() throws Exception { - selectorSpecifity(".cls ~ p", "0,0,1,1"); - } - - private SelectorSpecificity selectorSpecifity(final String selector, final String expectedSpecificity) - throws Exception { - final String html = - "<html><body id='b'><style></style>\n" - + "<div id='d' class='foo bar'><span>x</span><span id='s'>a</span>b</div>\n" - + "</body></html>"; - final HtmlPage page = loadPage(html); - final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0); - final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject(); - final CSSStyleSheet sheet = host.getSheet(); - - final Selector selectorObject = parseSelector(sheet, selector); - final SelectorSpecificity specificity = new SelectorSpecificity(selectorObject); - assertEquals(expectedSpecificity, specificity.toString()); - return specificity; - } - - private static Selector parseSelector(final CSSStyleSheet sheet, final String rule) { - return sheet.parseSelectors(new InputSource(new StringReader(rule))).get(0); - } -} |
From: <rb...@us...> - 2018-03-07 11:14:20
|
Revision: 15162 http://sourceforge.net/p/htmlunit/code/15162 Author: rbri Date: 2018-03-07 11:14:09 +0000 (Wed, 07 Mar 2018) Log Message: ----------- Use the correct content type when guessing from the '.js' file extension Issue 1954 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-07 07:50:58 UTC (rev 15161) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-07 11:14:09 UTC (rev 15162) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="add" dev="rbri" issue="1954"> + Use the correct content type when guessing from the '.js' file extension. + </action> <action type="change" dev="rbri"> Major refactoring of the css handling (selector processing). Every style sheet now has a selector index to speed up style processing. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-07 07:50:58 UTC (rev 15161) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-07 11:14:09 UTC (rev 15162) @@ -1243,7 +1243,7 @@ // Java's mime type map does not know these in JDK8. if (fileName.endsWith(".js")) { - return "text/javascript"; + return "application/javascript"; } if (fileName.toLowerCase(Locale.ROOT).endsWith(".css")) { return "text/css"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2018-03-07 07:50:58 UTC (rev 15161) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2018-03-07 11:14:09 UTC (rev 15162) @@ -1428,7 +1428,7 @@ assertEquals("empty.png", "image/png", c.guessContentType(getTestFile("empty.png"))); assertEquals("empty.jpg", "image/jpeg", c.guessContentType(getTestFile("empty.jpg"))); assertEquals("empty.gif", "image/gif", c.guessContentType(getTestFile("empty.gif"))); - assertEquals("empty.js", "text/javascript", c.guessContentType(getTestFile("empty.js"))); + assertEquals("empty.js", "application/javascript", c.guessContentType(getTestFile("empty.js"))); assertEquals("empty.css", "text/css", c.guessContentType(getTestFile("empty.css"))); // test real files with bad file suffix |
From: <rb...@us...> - 2018-03-14 11:51:29
|
Revision: 15166 http://sourceforge.net/p/htmlunit/code/15166 Author: rbri Date: 2018-03-14 11:51:27 +0000 (Wed, 14 Mar 2018) Log Message: ----------- Redirect of head requests should be head requests also Issue 1957 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-12 20:00:37 UTC (rev 15165) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-14 11:51:27 UTC (rev 15166) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1957"> + Redirect of head requests should be head requests also. + </action> <action type="add" dev="rbri" issue="1954"> Use the correct content type when guessing from the '.js' file extension. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-12 20:00:37 UTC (rev 15165) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-14 11:51:27 UTC (rev 15166) @@ -1449,6 +1449,9 @@ || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_SEE_OTHER) { final WebRequest wrs = new WebRequest(newUrl, HttpMethod.GET); + if (HttpMethod.HEAD == webRequest.getHttpMethod()) { + wrs.setHttpMethod(HttpMethod.HEAD); + } for (final Map.Entry<String, String> entry : webRequest.getAdditionalHeaders().entrySet()) { wrs.setAdditionalHeader(entry.getKey(), entry.getValue()); } |
From: <rb...@us...> - 2018-03-14 19:02:39
|
Revision: 15167 http://sourceforge.net/p/htmlunit/code/15167 Author: rbri Date: 2018-03-14 19:02:36 +0000 (Wed, 14 Mar 2018) Log Message: ----------- use latest cssparser changes, some tests for the new index Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2018-03-14 11:51:27 UTC (rev 15166) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2018-03-14 19:02:36 UTC (rev 15167) @@ -365,7 +365,7 @@ switch (selector.getSelectorType()) { case ELEMENT_NODE_SELECTOR: final ElementSelector es = (ElementSelector) selector; - final String name = es.getLocalName(); + final String name = es.getLocalNameLowerCase(); if (name == null || name.equals(element.getLowercaseName())) { final List<Condition> conditions = es.getConditions(); if (conditions != null) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java 2018-03-14 11:51:27 UTC (rev 15166) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheetTest.java 2018-03-14 19:02:36 UTC (rev 15167) @@ -1415,4 +1415,235 @@ webDriver.get(URL_FIRST + "#anchor"); assertTrue(webDriver.findElement(By.id("anchor")).isDisplayed()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexLowercaseElement() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " div { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercaseElement() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " div { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <DIV id='di'>\n" + + " <p>Content</p>\n" + + " </DIV>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercaseRule() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " DIV { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexLowercaseClass() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " .cls { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di' class='cls'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercaseElementClass() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " .cls { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di' class='CLS'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertTrue(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercaseRuleClass() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " .CLS { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di' class='cls'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertTrue(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercaseClass() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " .CLS { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di' class='CLS'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexLowercase2Class() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " div.cls { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di' class='cls'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercase2ElementClass() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " div.cls { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <DIV id='di' class='CLS'>\n" + + " <p>Content</p>\n" + + " </DIV>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertTrue(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercase2RuleClass() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " div.CLS { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <diV id='di' class='cls'>\n" + + " <p>Content</p>\n" + + " </diV>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertTrue(webDriver.findElement(By.id("di")).isDisplayed()); + } + + /** + * @throws Exception if the test fails + */ + @Test + public void indexUppercase2Class() throws Exception { + final String html = "<!DOCTYPE html>\n" + + "<head>\n" + + "<style>\n" + + " DiV.CLS { display: none; }\n" + + "</style>" + + "</head>\n" + + "<body>\n" + + " <div id='di' class='CLS'>\n" + + " <p>Content</p>\n" + + " </div>\n" + + "</body></html>"; + + final WebDriver webDriver = loadPage2(html); + assertFalse(webDriver.findElement(By.id("di")).isDisplayed()); + } } |
From: <rb...@us...> - 2018-03-14 19:32:29
|
Revision: 15168 http://sourceforge.net/p/htmlunit/code/15168 Author: rbri Date: 2018-03-14 19:32:27 +0000 (Wed, 14 Mar 2018) Log Message: ----------- setters for window.innerWidth/Height and window.outerWidth/Height added Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-14 19:02:36 UTC (rev 15167) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-14 19:32:27 UTC (rev 15168) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="add" dev="rbri"> + Setters for window.innerWidth/Height and window.outerWidth/Height added. + </action> <action type="fix" dev="rbri" issue="1957"> Redirect of head requests should be head requests also. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-03-14 19:02:36 UTC (rev 15167) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-03-14 19:32:27 UTC (rev 15168) @@ -1553,6 +1553,15 @@ } /** + * Sets the {@code innerWidth}. + * @param width the {@code innerWidth} + */ + @JsxSetter + public void setInnerWidth(final int width) { + getWebWindow().setInnerWidth(width); + } + + /** * Returns the {@code outerWidth}. * @return the {@code outerWidth} * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref79.html">Mozilla doc</a> @@ -1563,6 +1572,15 @@ } /** + * Sets the {@code outerWidth}. + * @param width the {@code outerWidth} + */ + @JsxSetter + public void setOuterWidth(final int width) { + getWebWindow().setOuterWidth(width); + } + + /** * Returns the {@code innerHeight}. * @return the {@code innerHeight} * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref27.html">Mozilla doc</a> @@ -1573,6 +1591,15 @@ } /** + * Sets the {@code innerHeight}. + * @param height the {@code innerHeight} + */ + @JsxSetter + public void setInneHeight(final int height) { + getWebWindow().setInnerHeight(height); + } + + /** * Returns the {@code outerHeight}. * @return the {@code outerHeight} * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref78.html">Mozilla doc</a> @@ -1583,6 +1610,15 @@ } /** + * Sets the {@code outerHeight}. + * @param height the {@code outerHeight} + */ + @JsxSetter + public void setOuterHeight(final int height) { + getWebWindow().setOuterHeight(height); + } + + /** * Prints the current page. The current implementation does nothing. * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref85.html"> * Mozilla documentation</a> 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 2018-03-14 19:02:36 UTC (rev 15167) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2018-03-14 19:32:27 UTC (rev 15168) @@ -676,6 +676,78 @@ } /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"true", "1234"}) + public void setInnerWidth() throws Exception { + final String html + = "<html><body onload='test()'><script>\n" + + "function test() {\n" + + " alert(window.innerWidth > 0);\n" + + " window.innerWidth = 1234;\n" + + " alert(window.innerWidth);\n" + + "}\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"true", "1234"}) + public void setInnerHeight() throws Exception { + final String html + = "<html><body onload='test()'><script>\n" + + "function test() {\n" + + " alert(window.innerHeight > 0);\n" + + " window.innerHeight = 1234;\n" + + " alert(window.innerHeight);\n" + + "}\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"true", "1234"}) + public void setOuterWidth() throws Exception { + final String html + = "<html><body onload='test()'><script>\n" + + "function test() {\n" + + " alert(window.outerWidth > 0);\n" + + " window.outerWidth = 1234;\n" + + " alert(window.outerWidth);\n" + + "}\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"true", "1234"}) + public void setOuterHeight() throws Exception { + final String html + = "<html><body onload='test()'><script>\n" + + "function test() {\n" + + " alert(window.outerHeight > 0);\n" + + " window.outerHeight = 1234;\n" + + " alert(window.outerHeight);\n" + + "}\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } + + /** * Regression test for bug 2944261. * @throws Exception if the test fails */ |
From: <rb...@us...> - 2018-03-17 17:41:18
|
Revision: 15170 http://sourceforge.net/p/htmlunit/code/15170 Author: rbri Date: 2018-03-17 17:41:07 +0000 (Sat, 17 Mar 2018) Log Message: ----------- setting the Map size property is now ignored (or throws a Type error in strict mode) Issue 1956 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/css/CSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-17 17:41:07 UTC (rev 15170) @@ -8,6 +8,12 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1956"> + Setting the Map size property is now ignored (or throws a Type error in strict mode). + </action> + <action type="fix" dev="rbri" issue="1956"> + Setting the CSSStyleDeclaration length property is now ignored (or throws a Type error in strict mode). + </action> <action type="add" dev="rbri"> Setters for window.innerWidth/Height and window.outerWidth/Height added. </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 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -22,6 +22,8 @@ import java.util.LinkedHashMap; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnly; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnlyStatus; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; @@ -145,6 +147,7 @@ * @return the size */ @JsxGetter + @CanSetReadOnly(CanSetReadOnlyStatus.IGNORE) public int getSize() { return map_.size(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -132,6 +132,8 @@ import com.gargoylesoftware.htmlunit.css.StyleElement; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnly; +import com.gargoylesoftware.htmlunit.javascript.configuration.CanSetReadOnlyStatus; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; @@ -1410,6 +1412,7 @@ * @return the {@code length} property */ @JsxGetter + @CanSetReadOnly(CanSetReadOnlyStatus.IGNORE) public int getLength() { return getStyleMap().size(); } 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 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/MapTest.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -473,4 +473,55 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "0"}) + public void setSize() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " var map = new Map();\n" + + " try {\n" + + " alert(map.size);\n" + + " map.size = 100;\n" + + " alert(map.size);\n" + + " } catch(e) { alert(e); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "Type error"}) + public void setSizeStrictMode() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " 'use strict';\n" + + " var map = new Map();\n" + + " try {\n" + + " alert(map.size);\n" + + " map.size = 100;\n" + + " alert(map.size);\n" + + " } catch(e) { alert('Type error'); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java 2018-03-15 16:42:58 UTC (rev 15169) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration2Test.java 2018-03-17 17:41:07 UTC (rev 15170) @@ -284,7 +284,7 @@ final String html = "<html>\n" - + "<head><title>Tester</title>\n" + + "<head>\n" + "<script>\n" + "function test() {\n" + " var style = document.getElementById('myDiv').style;\n" @@ -309,4 +309,55 @@ actual = StringUtils.replace(actual, "\r\n", "\n"); assertEquals(expected, actual); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "0"}) + public void setLength() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " var style = document.body.style;\n" + + " try {\n" + + " alert(style.length);\n" + + " style.length = 100;\n" + + " alert(style.length);\n" + + " } catch(e) { alert(e); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "Type error"}) + public void setLengthStrictMode() throws Exception { + final String html + = "<html>\n" + + "<head>\n" + + "<script>\n" + + "function test() {\n" + + " 'use strict';\n" + + " var style = document.body.style;\n" + + " try {\n" + + " alert(style.length);\n" + + " style.length = 100;\n" + + " alert(style.length);\n" + + " } catch(e) { alert('Type error'); }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-03-21 17:49:04
|
Revision: 15173 http://sourceforge.net/p/htmlunit/code/15173 Author: rbri Date: 2018-03-21 17:49:01 +0000 (Wed, 21 Mar 2018) Log Message: ----------- working on update for latest chrome (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java 2018-03-21 07:56:30 UTC (rev 15172) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAnchorElement.java 2018-03-21 17:49:01 UTC (rev 15173) @@ -747,7 +747,7 @@ * Returns the {@code relList} attribute. * @return the {@code relList} attribute */ - @JsxGetter(FF) + @JsxGetter({CHROME, FF}) public DOMTokenList getRelList() { throw Context.throwAsScriptRuntimeEx(new UnsupportedOperationException()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-03-21 07:56:30 UTC (rev 15172) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementPropertiesTest.java 2018-03-21 17:49:01 UTC (rev 15173) @@ -856,14 +856,11 @@ */ @Test @Alerts(DEFAULT = "charset,coords,download,hash,host,hostname,href,hreflang,name,origin,password,pathname,ping," - + "port,protocol,referrerPolicy,rel,rev,search,shape,target,text,type," + + "port,protocol,referrerPolicy,rel,relList,rev,search,shape,target,text,type," + "username", FF45 = "charset,coords,download,hash,host,hostname,href,hreflang,name,origin,password,pathname,ping," + "port,protocol,rel,relList,rev,search,shape,target,text,type," + "username", - FF52 = "charset,coords,download,hash,host,hostname,href,hreflang,name,origin,password,pathname,ping," - + "port,protocol,referrerPolicy,rel,relList,rev,search,shape,target,text,type," - + "username", IE = "charset,coords,hash,host,hostname,href,hreflang,Methods,mimeType,name,nameProp,pathname,port," + "protocol,protocolLong,rel,rev,search,shape,target,text,type," + "urn", @@ -912,11 +909,9 @@ */ @Test @Alerts(DEFAULT = "alt,coords,download,hash,host,hostname,href,noHref,origin,password,pathname,ping,port," - + "protocol,referrerPolicy,rel,search,shape,target,username", + + "protocol,referrerPolicy,rel,relList,search,shape,target,username", FF45 = "alt,coords,download,hash,host,hostname,href,noHref,origin,password,pathname,ping,port,protocol," + "rel,relList,search,shape,target,username", - FF52 = "alt,coords,download,hash,host,hostname,href,noHref,origin,password,pathname,ping,port,protocol," - + "referrerPolicy,rel,relList,search,shape,target,username", IE = "alt,coords,hash,host,hostname,href,noHref,pathname,port,protocol,rel,search,shape,target", EDGE = "alt,coords,hash,host,hostname,href,noHref,pathname,port,protocol,rel,search,shape,target") @NotYetImplemented @@ -1703,7 +1698,7 @@ FF52 = "align,alt,border,complete,crossOrigin,currentSrc,height,hspace,isMap,longDesc,lowsrc,name," + "naturalHeight,naturalWidth,referrerPolicy,sizes,src,srcset,useMap,vspace,width,x," + "y", - CHROME = "align,alt,border,complete,crossOrigin,currentSrc,decode()," + CHROME = "align,alt,border,complete,crossOrigin,currentSrc,decode(),decoding," + "height,hspace,isMap,longDesc,lowsrc,name," + "naturalHeight,naturalWidth,referrerPolicy,sizes,src,srcset,useMap,vspace,width,x," + "y", @@ -2991,7 +2986,7 @@ */ @Test @Alerts(DEFAULT = "-", - CHROME = "assignedNodes(),name") + CHROME = "assignedElements(),assignedNodes(),name") @NotYetImplemented(CHROME) public void slot() throws Exception { test("slot"); @@ -3003,7 +2998,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "alinkColor,all,bgColor,captureEvents(),clear(),fgColor,linkColor,releaseEvents(),vlinkColor", + @Alerts(DEFAULT = "-", FF45 = "alinkColor,all,anchors,applets,bgColor,body,captureEvents(),clear(),close(),cookie,designMode," + "domain," + "embeds,execCommand(),fgColor,forms,getElementsByName(),getItems(),getSelection(),head,images," @@ -3015,8 +3010,7 @@ + "embeds,execCommand(),fgColor,forms,getElementsByName(),getSelection(),head,images," + "linkColor,links," + "open(),plugins,queryCommandEnabled(),queryCommandIndeterm(),queryCommandState()," - + "queryCommandSupported(),queryCommandValue(),releaseEvents(),scripts,vlinkColor,write(),writeln()", - IE = "-") + + "queryCommandSupported(),queryCommandValue(),releaseEvents(),scripts,vlinkColor,write(),writeln()") @NotYetImplemented public void htmlDocument() throws Exception { testString("document, xmlDocument"); |
From: <rb...@us...> - 2018-03-21 18:44:07
|
Revision: 15174 http://sourceforge.net/p/htmlunit/code/15174 Author: rbri Date: 2018-03-21 18:44:05 +0000 (Wed, 21 Mar 2018) Log Message: ----------- working on update for latest chrome (wip) 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 2018-03-21 17:49:01 UTC (rev 15173) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-03-21 18:44:05 UTC (rev 15174) @@ -153,7 +153,7 @@ // FF52 FIREFOX_52.applicationVersion_ = "5.0 (Windows)"; FIREFOX_52.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0"; - FIREFOX_52.buildId_ = "20180118122319"; + FIREFOX_52.buildId_ = "20180315163333"; FIREFOX_52.productSub_ = "20100101"; FIREFOX_52.headerNamesOrdered_ = new String[] { HttpHeader.HOST, @@ -211,8 +211,8 @@ EDGE.scriptAcceptHeader_ = "application/javascript, */*;q=0.8"; // CHROME - CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"; - CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"; + CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"; + CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"; CHROME.applicationCodeName_ = "Mozilla"; CHROME.vendor_ = "Google Inc."; @@ -354,19 +354,19 @@ // flush plugin (windows version) PluginConfiguration flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF32_28_0_0_137.dll"); + "Shockwave Flash 29.0 r0", "29.0.0.113", "NPSWF32_29_0_0_113.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_45.plugins_.add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF64_28_0_0_137.dll"); + "Shockwave Flash 29.0 r0", "29.0.0.113", "NPSWF64_29_0_0_113.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_52.plugins_.add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 28.0 r0", "28.0.0.137", "Flash32_28_0_0_137.ocx"); + "Shockwave Flash 29.0 r0", "29.0.0.113", "Flash32_29_0_0_113.ocx"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); INTERNET_EXPLORER.plugins_.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 2018-03-21 17:49:01 UTC (rev 15173) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2018-03-21 18:44:05 UTC (rev 15174) @@ -216,10 +216,10 @@ * @throws Exception on test failure */ @Test - @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF32_28_0_0_137.dll"}, - FF52 = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.137", "NPSWF64_28_0_0_137.dll"}, + @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 29.0 r0", "29.0.0.113", "NPSWF32_29_0_0_113.dll"}, + FF52 = {"Shockwave Flash", "Shockwave Flash 29.0 r0", "29.0.0.113", "NPSWF64_29_0_0_113.dll"}, CHROME = "Shockwave Flash not available", - IE = {"Shockwave Flash", "Shockwave Flash 28.0 r0", "28.0.0.137", "Flash32_28_0_0_137.ocx"}, + IE = {"Shockwave Flash", "Shockwave Flash 29.0 r0", "29.0.0.113", "Flash32_29_0_0_113.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" @@ -387,7 +387,7 @@ @Test @Alerts(DEFAULT = "undefined", FF45 = "20170411115307", - FF52 = "20180118122319") + FF52 = "20180315163333") public void buildID() throws Exception { final String html = "<html><head><title>First</title>\n" |
From: <rb...@us...> - 2018-03-22 19:35:48
|
Revision: 15180 http://sourceforge.net/p/htmlunit/code/15180 Author: rbri Date: 2018-03-22 19:35:43 +0000 (Thu, 22 Mar 2018) Log Message: ----------- Improved clone implementation to take care of references Issue 1959 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-22 19:35:43 UTC (rev 15180) @@ -8,6 +8,9 @@ <body> <release version="2.30" date="xx, 2018" description="Bugfixes, URLSearchParams implemented, start adding support of user defined iterators, CHROME 64"> + <action type="fix" dev="rbri" issue="1959"> + Improved clone implementation to take care of references. + </action> <action type="fix" dev="rbri" issue="1956"> Setting the Map size property is now ignored (or throws a Type error in strict mode). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -33,6 +33,7 @@ * @author Ahmed Ashour * @author Sudhan Moghe * @author Philip Graf + * @author Ronald Brill */ public class DomText extends DomCharacterData implements Text { @@ -215,4 +216,15 @@ return (c < '\uE000' || c > '\uF8FF') && (c == ' ' || !Character.isWhitespace(c)); } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final DomText newnode = (DomText) super.cloneNode(deep); + selectionDelegate_ = new SimpleSelectionDelegate(); + doTypeProcessor_ = new DoTypeProcessor(this); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -28,12 +28,13 @@ * Wrapper for the HTML element "input" where type is "email". * * @author Ahmed Ashour + * @author Ronald Brill */ public class HtmlEmailInput extends HtmlInput implements SelectableTextInput { private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); /** * Creates an instance. @@ -154,4 +155,14 @@ } } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlEmailInput newnode = (HtmlEmailInput) super.cloneNode(deep); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -30,10 +30,9 @@ */ public class HtmlNumberInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -203,4 +202,16 @@ // ignore } } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlNumberInput newnode = (HtmlNumberInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -35,10 +35,9 @@ */ public class HtmlPasswordInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -192,4 +191,16 @@ final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); setDefaultValue(defaultValue, modifyValue); } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlPasswordInput newnode = (HtmlPasswordInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -24,13 +24,13 @@ * Wrapper for the HTML element "input" where type is "tel". * * @author Ahmed Ashour + * @author Ronald Brill */ public class HtmlTelInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -139,4 +139,15 @@ } } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlTelInput newnode = (HtmlTelInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -61,10 +61,9 @@ private String originalName_; private Collection<String> newNames_ = Collections.emptySet(); - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -626,4 +625,17 @@ protected boolean isRequiredSupported() { return true; } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlTextArea newnode = (HtmlTextArea) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + newnode.newNames_ = new HashSet<>(newNames_); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -36,10 +36,9 @@ */ public class HtmlTextInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -193,4 +192,16 @@ final boolean modifyValue = getValueAttribute().equals(getDefaultValue()); setDefaultValue(defaultValue, modifyValue); } + + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlTextInput newnode = (HtmlTextInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -28,13 +28,13 @@ * Wrapper for the HTML element "input" where type is "url". * * @author Ahmed Ashour + * @author Ronald Brill */ public class HtmlUrlInput extends HtmlInput implements SelectableTextInput { - private final SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private SelectableTextSelectionDelegate selectionDelegate_ = new SelectableTextSelectionDelegate(this); + private DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - private final DoTypeProcessor doTypeProcessor_ = new DoTypeProcessor(this); - /** * Creates an instance. * @@ -154,4 +154,15 @@ } } + /** + * {@inheritDoc} + */ + @Override + public DomNode cloneNode(final boolean deep) { + final HtmlUrlInput newnode = (HtmlUrlInput) super.cloneNode(deep); + newnode.selectionDelegate_ = new SelectableTextSelectionDelegate(newnode); + newnode.doTypeProcessor_ = new DoTypeProcessor(newnode); + + return newnode; + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -32,7 +32,7 @@ * @throws Exception if the test fails */ @Test - public void typing() throws Exception { + public void typingAndClone() throws Exception { final String htmlContent = "<html>\n" + "<head></head>\n" @@ -39,27 +39,14 @@ + "<body>\n" + "<form id='form1'>\n" + " <input type='email' id='foo'>\n" - + " <input type='email' id='foo2' value='x...@em...' >\n" + "</form>\n" + "</body></html>"; final HtmlPage page = loadPage(htmlContent); - HtmlEmailInput emailInput = (HtmlEmailInput) page.getElementById("foo"); - emailInput.focus(); - emailInput.type("my...@em..."); - - emailInput = (HtmlEmailInput) page.getElementById("foo2"); - emailInput.focus(); - emailInput.type("abc"); - assertEquals("ab...@em...", emailInput.getValueAttribute()); - - emailInput.setSelectionStart(4); - emailInput.type("xx"); - assertEquals("ab...@em...", emailInput.getValueAttribute()); - - emailInput.setSelectionStart(1); - emailInput.type("y"); - assertEquals("ay...@em...", emailInput.getValueAttribute()); + HtmlEmailInput input = (HtmlEmailInput) page.getElementById("foo"); + input = (HtmlEmailInput) input.cloneNode(true); + input.type("ab...@em..."); + assertEquals("ab...@em...", input.getValueAttribute()); } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2018 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 com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.SimpleWebTestCase; + +/** + * Tests for {@link HtmlNumberInput}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlNumberInput2Test extends SimpleWebTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndClone() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='number' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlNumberInput input = (HtmlNumberInput) page.getElementById("foo"); + input = (HtmlNumberInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput2Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java 2018-03-21 20:35:01 UTC (rev 15179) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -85,4 +85,26 @@ t.type(KeyboardEvent.DOM_VK_DELETE); assertEquals("tt", t.getValueAttribute()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndClone() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='password' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlPasswordInput input = (HtmlPasswordInput) page.getElementById("foo"); + input = (HtmlPasswordInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2018 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 com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.SimpleWebTestCase; + +/** + * Tests for {@link HtmlTelInput}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlTelInput2Test extends SimpleWebTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndClone() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='tel' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlTelInput input = (HtmlTelInput) page.getElementById("foo"); + input = (HtmlTelInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput2Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java 2018-03-22 19:35:43 UTC (rev 15180) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2018 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 com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.SimpleWebTestCase; + +/** + * Tests for {@link HtmlUrlInput}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlUrlInput2Test extends SimpleWebTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + public void typingAndClone() throws Exception { + final String htmlContent + = "<html>\n" + + "<head></head>\n" + + "<body>\n" + + "<form id='form1'>\n" + + " <input type='url' id='foo'>\n" + + "</form>\n" + + "</body></html>"; + + final HtmlPage page = loadPage(htmlContent); + + HtmlUrlInput input = (HtmlUrlInput) page.getElementById("foo"); + input = (HtmlUrlInput) input.cloneNode(true); + input.type("4711"); + assertEquals("4711", input.getValueAttribute()); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput2Test.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |
From: <rb...@us...> - 2018-03-30 08:55:19
|
Revision: 15215 http://sourceforge.net/p/htmlunit/code/15215 Author: rbri Date: 2018-03-30 08:55:15 +0000 (Fri, 30 Mar 2018) Log Message: ----------- GAE support is history Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/gae/ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/gae/ Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-30 08:55:15 UTC (rev 15215) @@ -7,6 +7,13 @@ </properties> <body> + <release version="2.31" date="xx, 2018" description="Bugfixes, special GAE handlings removed"> + <action type="update" dev="rbri"> + Special handling of the GAE environment is no longer required, the JDK8 at GAE has no longer + any restrictions. + </action> + </release> + <release version="2.30" date="March 25, 2018" description="Bugfixes, using or own CSSParser for improved performance, URLSearchParams implemented, start adding support of user defined iterators, CHROME 66"> <action type="fix" dev="rbri" issue="1959"> Improved clone implementation to take care of references. @@ -26,18 +33,18 @@ <action type="add" dev="rbri" issue="1954"> Use the correct content type when guessing from the '.js' file extension. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> Major refactoring of the css handling (selector processing). Every style sheet now has a selector index to speed up style processing. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> We have now our own cssparser (a cleaned up version of the cssparser we have used so far) to be able to change the model classes to better support our use cases. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> getArttibute is optimized for speed in some special cases. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> Local files are now cached using the same rules as server requests (cacheable if date-modified is more than ten minutes in the past) </action> @@ -74,7 +81,7 @@ <action type="add" dev="rbri"> JavaScript: Array.from() now supports user defined iterators also. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> Samples on page Get Started updated. </action> <action type="fix" dev="rbri" issue="1946"> @@ -244,7 +251,7 @@ INCOMPATIBLE CHANGE: BrowserVersion is final now and all constructors are removed. The only way to create new customized Browser versions is by using the BrowserVersionBuilder. </action> - <action type="change" dev="rbri" issue="1890"> + <action type="update" dev="rbri" issue="1890"> BrowserVersion setter methods are fluent now. </action> <action type="fix" dev="asashour" issue="1905"> @@ -733,7 +740,7 @@ <action type="fix" dev="rbri" issue="1803" due-to="Carsten Steul"> IllegalStateException adding an option to a select. </action> - <action type="change" dev="rbri" issue="1620"> + <action type="update" dev="rbri" issue="1620"> New class DefaultJavaScriptErrorListener added. This listener will be always used of no specific listener is defined. The logging of js errors was moved to this class. If you like to have the logging and your own JavaScriptErrorListener than subclass or decorate this. Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2002-2018 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.http.client.utils.URLEncodedUtils; - -import com.gargoylesoftware.htmlunit.util.Cookie; -import com.gargoylesoftware.htmlunit.util.NameValuePair; - -/** - * An implementation of {@link WebConnection}, compatible with Google App Engine. - * <p> - * Note: this class is experimental and not mature like {@link HttpWebConnection}. - * It doesn't currently support multipart POST. - * </p> - * <p>This might not use all headers because the JDK ignores/censors some headers (at lease Origin). - * You can disable this censorship by setting 'sun.net.http.allowRestrictedHeaders' to true - * </p> - * - * @author Amit Manjhi - * @author Marc Guillemot - * @author Pieter Herroelen - * @author Ronald Brill - * - * @since HtmlUnit 2.8 - * @see "http://code.google.com/p/googleappengine/issues/detail?id=3379" - */ -public class UrlFetchWebConnection implements WebConnection { - - /** Logging support. */ - private static final Log LOG = LogFactory.getLog(UrlFetchWebConnection.class); - - private static final String[] GAE_URL_HACKS = {"http://gaeHack_javascript/", "http://gaeHack_data/", - "http://gaeHack_about/"}; - - private final WebClient webClient_; - - /** - * Creates a new web connection instance. - * @param webClient the WebClient that is using this connection - */ - public UrlFetchWebConnection(final WebClient webClient) { - webClient_ = webClient; - } - - /** - * {@inheritDoc} - */ - @Override - public WebResponse getResponse(final WebRequest webRequest) throws IOException { - final long startTime = System.currentTimeMillis(); - final URL url = webRequest.getUrl(); - if (LOG.isTraceEnabled()) { - LOG.trace("about to fetch URL " + url); - } - - // hack for JS, about, and data URLs. - final WebResponse response = produceWebResponseForGAEProcolHack(url); - if (response != null) { - return response; - } - - // this is a "normal" URL - try { - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); -// connection.setUseCaches(false); - connection.setConnectTimeout(webClient_.getOptions().getTimeout()); - - connection.addRequestProperty(HttpHeader.USER_AGENT, webClient_.getBrowserVersion().getUserAgent()); - connection.setInstanceFollowRedirects(false); - - // copy the headers from WebRequestSettings - // this might not copy all headers because the JDK ignores/censors some headers - // you can disable this by setting sun.net.http.allowRestrictedHeaders to true - // see UrlFetchWebConnectionTest for some links - for (final Entry<String, String> header : webRequest.getAdditionalHeaders().entrySet()) { - connection.addRequestProperty(header.getKey(), header.getValue()); - } - addCookies(connection); - - final HttpMethod httpMethod = webRequest.getHttpMethod(); - connection.setRequestMethod(httpMethod.name()); - if (HttpMethod.POST == httpMethod || HttpMethod.PUT == httpMethod || HttpMethod.PATCH == httpMethod) { - connection.setDoOutput(true); - final Charset charset = webRequest.getCharset(); - connection.addRequestProperty(HttpHeader.CONTENT_TYPE, FormEncodingType.URL_ENCODED.getName()); - - try (OutputStream outputStream = connection.getOutputStream()) { - final List<NameValuePair> pairs = webRequest.getRequestParameters(); - final org.apache.http.NameValuePair[] httpClientPairs = NameValuePair.toHttpClient(pairs); - final String query = URLEncodedUtils.format(Arrays.asList(httpClientPairs), charset); - outputStream.write(query.getBytes(charset)); - if (webRequest.getRequestBody() != null) { - IOUtils.write(webRequest.getRequestBody().getBytes(charset), outputStream); - } - } - } - - final int responseCode = connection.getResponseCode(); - if (LOG.isTraceEnabled()) { - LOG.trace("fetched URL " + url); - } - - final List<NameValuePair> headers = new ArrayList<>(); - for (final Map.Entry<String, List<String>> headerEntry : connection.getHeaderFields().entrySet()) { - final String headerKey = headerEntry.getKey(); - if (headerKey != null) { // map contains entry like (null: "HTTP/1.1 200 OK") - final StringBuilder sb = new StringBuilder(); - for (final String headerValue : headerEntry.getValue()) { - if (sb.length() != 0) { - sb.append(", "); - } - sb.append(headerValue); - } - headers.add(new NameValuePair(headerKey, sb.toString())); - } - } - - final byte[] byteArray; - try (InputStream is = responseCode < 400 - ? connection.getInputStream() : connection.getErrorStream()) { - byteArray = IOUtils.toByteArray(is); - } - - final long duration = System.currentTimeMillis() - startTime; - final WebResponseData responseData = new WebResponseData(byteArray, responseCode, - connection.getResponseMessage(), headers); - saveCookies(url.getHost(), headers); - return new WebResponse(responseData, webRequest, duration); - } - catch (final IOException e) { - LOG.error("Exception while tyring to fetch " + url, e); - throw new RuntimeException(e); - } - } - - private void addCookies(final HttpURLConnection connection) { - final StringBuilder cookieHeader = new StringBuilder(); - boolean isFirst = true; - for (Cookie cookie : webClient_.getCookies(connection.getURL())) { - if (isFirst) { - isFirst = false; - } - else { - cookieHeader.append("; "); - } - - cookieHeader.append(cookie.getName()).append('=').append(cookie.getValue()); - } - if (!isFirst) { - connection.setRequestProperty(HttpHeader.COOKIE, cookieHeader.toString()); - } - } - - private void saveCookies(final String domain, final List<NameValuePair> headers) { - for (final NameValuePair nvp : headers) { - if ("Set-Cookie".equalsIgnoreCase(nvp.getName())) { - final Set<Cookie> cookies = parseCookies(domain, nvp.getValue()); - for (Cookie cookie : cookies) { - webClient_.getCookieManager().addCookie(cookie); - } - } - } - } - - private static WebResponse produceWebResponseForGAEProcolHack(final URL url) { - final String externalForm = url.toExternalForm(); - for (String pattern : GAE_URL_HACKS) { - final int index = externalForm.indexOf(pattern); - if (index == 0) { - String contentString = externalForm.substring(pattern.length()); - if (contentString.startsWith("'") && contentString.endsWith("'")) { - contentString = contentString.substring(1, contentString.length() - 1); - } - if (LOG.isDebugEnabled()) { - LOG.debug("special handling of URL, returning (" + contentString + ") for URL " + url); - } - return new StringWebResponse(contentString, url); - } - } - return null; - } - - /** - * Parses the given string into cookies. - * Very limited implementation. - * All created cookies apply to all paths, never expire and are not secure. - * Will not work when there's a comma in the cookie value (because there's a bug in the Url Fetch Service) - * @see "http://code.google.com/p/googleappengine/issues/detail?id=3379" - * @param cookieHeaderString The cookie string to parse - * @param domain the domain of the current request - * @return The parsed cookies - */ - static Set<Cookie> parseCookies(final String domain, final String cookieHeaderString) { - final Set<Cookie> cookies = new HashSet<>(); - final String[] cookieStrings = cookieHeaderString.split(","); - for (int i = 0; i < cookieStrings.length; i++) { - final String[] nameAndValue = cookieStrings[i].split(";")[0].split("="); - if (nameAndValue.length > 1) { - cookies.add(new Cookie(domain, nameAndValue[0], nameAndValue[1])); - } - } - return cookies; - } - - /** - * {@inheritDoc} - */ - @Override - public void close() throws Exception { - } -} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -70,7 +70,6 @@ import com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLActiveXObjectFactory; import com.gargoylesoftware.htmlunit.attachment.Attachment; import com.gargoylesoftware.htmlunit.attachment.AttachmentHandler; -import com.gargoylesoftware.htmlunit.gae.GAEUtils; import com.gargoylesoftware.htmlunit.html.BaseFrameElement; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; @@ -245,7 +244,7 @@ getOptions().setProxyConfig(new ProxyConfig(proxyHost, proxyPort)); } - webConnection_ = createWebConnection(); // this has to be done after the browser version was set + webConnection_ = new HttpWebConnection(this); // this has to be done after the browser version was set scriptEngine_ = new JavaScriptEngine(this); loadQueue_ = new ArrayList<>(); @@ -2050,7 +2049,7 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); - webConnection_ = createWebConnection(); + webConnection_ = new HttpWebConnection(this); scriptEngine_ = new JavaScriptEngine(this); jobManagers_ = Collections.synchronizedList(new ArrayList<WeakReference<JavaScriptJobManager>>()); loadQueue_ = new ArrayList<>(); @@ -2060,14 +2059,6 @@ } } - private WebConnection createWebConnection() { - if (GAEUtils.isGaeMode()) { - return new UrlFetchWebConnection(this); - } - - return new HttpWebConnection(this); - } - private static class LoadJob { private final WebWindow requestingWindow_; private final String target_; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -860,7 +860,6 @@ * @return the page contained in the current window as returned by {@link WebClient#getCurrentWindow()} * @exception IOException if an IO error occurs */ - @SuppressWarnings("unchecked") public <P extends Page> P click() throws IOException { return click(false, false, false); } @@ -1102,7 +1101,6 @@ * @return the page that occupies this element's window after the element has been double-clicked * @exception IOException if an IO error occurs */ - @SuppressWarnings("unchecked") public <P extends Page> P dblClick() throws IOException { return dblClick(false, false, false); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -671,19 +671,6 @@ } /** - * Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty. - * No use in non-GAE mode (see {@link com.gargoylesoftware.htmlunit.gae.GAEUtils#isGaeMode}. - * @param timeoutMillis the timeout in milliseconds - * @return the number of jobs executed - */ - public int pumpEventLoop(final long timeoutMillis) { - if (javaScriptExecutor_ == null) { - return 0; - } - return javaScriptExecutor_.pumpEventLoop(timeoutMillis); - } - - /** * Shutdown the JavaScriptEngine. */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -120,17 +120,6 @@ return javaScriptJobManager; } - /** - * Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty. - * No use in non-GAE mode. - * @param timeoutMillis the timeout in milliseconds - * @return the number of jobs executed - */ - @Override - public int pumpEventLoop(final long timeoutMillis) { - return 0; - } - /** Runs the eventLoop. */ @Override public void run() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -37,12 +37,4 @@ * Notes that this thread has been shutdown. */ void shutdown(); - - /** - * Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty. - * No use in non-GAE mode. - * @param timeoutMillis the timeout in milliseconds - * @return the number of jobs executed - */ - int pumpEventLoop(long timeoutMillis); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -21,7 +21,6 @@ /** * Interface to the rendering context used by * {@link com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D}. - * We have this abstraction to support GAE also. * * @author Ronald Brill */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -19,7 +19,7 @@ import java.io.Serializable; /** - * Interface redirection to support GAE also. + * Helper to support various matrix transform operations. * * @author Ronald Brill */ Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2002-2018 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.util; - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLStreamHandler; -import java.util.Locale; - -import org.apache.commons.lang3.StringUtils; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.gae.GAEUtils; -import com.gargoylesoftware.htmlunit.protocol.AnyHandler; -import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection; - -/** - * Responsible for URL creation. - * @author Marc Guillemot - */ -abstract class URLCreator { - abstract URL toUrlUnsafeClassic(String url) throws MalformedURLException; - abstract String getProtocol(URL url); - - protected URL toNormalUrl(final String url) throws MalformedURLException { - final URL response = new URL(url); - if (response.getProtocol().startsWith("http") && StringUtils.isEmpty(response.getHost())) { - throw new MalformedURLException("Missing host name in url: " + url); - } - return response; - } - - /** - * Gets the instance responsible for URL creating, detecting if we are running on GoogleAppEngine - * where custom URLStreamHandler is prohibited. - */ - static URLCreator getCreator() { - if (!GAEUtils.isGaeMode()) { - return new URLCreatorStandard(); - } - return new URLCreatorGAE(); - } - - /** - * For the normal case. - */ - static class URLCreatorStandard extends URLCreator { - private static final URLStreamHandler JS_HANDLER - = new com.gargoylesoftware.htmlunit.protocol.javascript.Handler(); - private static final URLStreamHandler ABOUT_HANDLER - = new com.gargoylesoftware.htmlunit.protocol.about.Handler(); - private static final URLStreamHandler DATA_HANDLER = new com.gargoylesoftware.htmlunit.protocol.data.Handler(); - - @Override - URL toUrlUnsafeClassic(final String url) throws MalformedURLException { - final String protocol = StringUtils.substringBefore(url, ":") - .toLowerCase(Locale.ROOT); - - if (protocol.isEmpty() || UrlUtils.isNormalUrlProtocol(protocol)) { - return toNormalUrl(url); - } - else if (JavaScriptURLConnection.JAVASCRIPT_PREFIX.equals(protocol + ":")) { - return new URL(null, url, JS_HANDLER); - } - else if ("about".equals(protocol)) { - if (WebClient.URL_ABOUT_BLANK != null - && StringUtils.equalsIgnoreCase(WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) { - return WebClient.URL_ABOUT_BLANK; - } - return new URL(null, url, ABOUT_HANDLER); - } - else if ("data".equals(protocol)) { - return new URL(null, url, DATA_HANDLER); - } - else { - return new URL(null, url, AnyHandler.INSTANCE); - } - } - - @Override - String getProtocol(final URL url) { - return url.getProtocol(); - } - } - - /** - * For working on GoogleAppEngine. The URL hack will require special handling from a dedicated WebConnection. - */ - static class URLCreatorGAE extends URLCreator { - private static final String PREFIX = "http://gaeHack_"; - - @Override - URL toUrlUnsafeClassic(final String url) throws MalformedURLException { - if (WebClient.URL_ABOUT_BLANK != null - && StringUtils.equalsIgnoreCase(WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) { - return WebClient.URL_ABOUT_BLANK; - } - else if (StringUtils.startsWithIgnoreCase(url, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { - return new URL(PREFIX + url.replaceFirst(":", "/")); - } - else if (StringUtils.startsWithIgnoreCase(url, WebClient.ABOUT_SCHEME)) { - return new URL(PREFIX + url.replaceFirst(":", "/")); - } - else if (StringUtils.startsWithIgnoreCase(url, "data:")) { - return new URL(PREFIX + url.replaceFirst(":", "/")); - } - else { - return toNormalUrl(url); - } - } - - @Override - String getProtocol(final URL url) { - final String stringUrl = url.toString(); - if (stringUrl.startsWith(PREFIX)) { - final int begin = PREFIX.length(); - final int end = stringUrl.indexOf('/', begin); - return stringUrl.substring(begin, end); - } - - return url.getProtocol(); - } - } -} - Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -21,13 +21,18 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLStreamHandler; import java.nio.charset.Charset; import java.util.BitSet; +import java.util.Locale; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.net.URLCodec; import com.gargoylesoftware.htmlunit.WebAssert; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.protocol.AnyHandler; +import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection; /** * URL utilities class that makes it easy to create new URLs based off of old URLs @@ -43,11 +48,14 @@ * @author Hartmut Arlt */ public final class UrlUtils { + private static final URLStreamHandler JS_HANDLER = new com.gargoylesoftware.htmlunit.protocol.javascript.Handler(); + private static final URLStreamHandler ABOUT_HANDLER = new com.gargoylesoftware.htmlunit.protocol.about.Handler(); + private static final URLStreamHandler DATA_HANDLER = new com.gargoylesoftware.htmlunit.protocol.data.Handler(); + private static final BitSet PATH_ALLOWED_CHARS = new BitSet(256); private static final BitSet QUERY_ALLOWED_CHARS = new BitSet(256); private static final BitSet ANCHOR_ALLOWED_CHARS = new BitSet(256); private static final BitSet HASH_ALLOWED_CHARS = new BitSet(256); - private static final URLCreator URL_CREATOR = URLCreator.getCreator(); /** * URI allowed char initialization; based on HttpClient 3.1's URI bit sets. @@ -203,7 +211,36 @@ */ public static URL toUrlUnsafe(final String url) throws MalformedURLException { WebAssert.notNull("url", url); - return URL_CREATOR.toUrlUnsafeClassic(url); + + final String protocol = org.apache.commons.lang3.StringUtils.substringBefore(url, ":").toLowerCase(Locale.ROOT); + + if (protocol.isEmpty() || UrlUtils.isNormalUrlProtocol(protocol)) { + final URL response = new URL(url); + if (response.getProtocol().startsWith("http") + && org.apache.commons.lang3.StringUtils.isEmpty(response.getHost())) { + throw new MalformedURLException("Missing host name in url: " + url); + } + return response; + } + + if (JavaScriptURLConnection.JAVASCRIPT_PREFIX.equals(protocol + ":")) { + return new URL(null, url, JS_HANDLER); + } + + if ("about".equals(protocol)) { + if (WebClient.URL_ABOUT_BLANK != null + && org.apache.commons.lang3.StringUtils. + equalsIgnoreCase(WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) { + return WebClient.URL_ABOUT_BLANK; + } + return new URL(null, url, ABOUT_HANDLER); + } + + if ("data".equals(protocol)) { + return new URL(null, url, DATA_HANDLER); + } + + return new URL(null, url, AnyHandler.INSTANCE); } /** @@ -218,7 +255,7 @@ * @return the encoded URL */ public static URL encodeUrl(final URL url, final boolean minimalQueryEncoding, final Charset charset) { - if (!isNormalUrlProtocol(URL_CREATOR.getProtocol(url))) { + if (!isNormalUrlProtocol(url.getProtocol())) { return url; // javascript:, about:, data: and anything not supported like foo: } Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2002-2018 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; - -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Unit tests for {@link UrlFetchWebConnection}. - * - * @author Marc Guillemot - * @author Pieter Herroelen - */ -@RunWith(BrowserRunner.class) -public class UrlFetchWebConnection2Test extends SimpleWebTestCase { - - /** - * Test a HEAD request with additional headers. - * @throws Exception if the test fails - */ - @Test - public void head() throws Exception { - final WebRequest referenceRequest = getHeadRequest(); - - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - final WebRequest newRequest = getHeadRequest(); - - // compare the two requests - UrlFetchWebConnectionTest.compareRequests(referenceRequest, newRequest); - } - - private WebRequest getHeadRequest() throws Exception { - final String html = "<html><head><script>\n" - + " function test() {\n" - + " var request = new XMLHttpRequest();\n" - + " request.open('HEAD', 'second.html', false);\n" - + " request.setRequestHeader('X-Foo', '123456');\n" - + " request.send('');\n" - + " }\n" - + "</script></head><body onload='test()'></body></html>"; - - getMockWebConnection().setDefaultResponse(""); - loadPage(html); - - return getMockWebConnection().getLastWebRequest(); - } - -} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2002-2018 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; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.util.Cookie; -import com.gargoylesoftware.htmlunit.util.NameValuePair; - -/** - * Unit tests for {@link UrlFetchWebConnection}. - * - * @author Marc Guillemot - * @author Pieter Herroelen - * @author Ronald Brill - */ -@RunWith(BrowserRunner.class) -public class UrlFetchWebConnectionTest extends WebServerTestCase { - - private static final String allowRestrictedHeaders = System.getProperty("sun.net.http.allowRestrictedHeaders"); - - /** - * Setup jdk / HttpURLConnection - * to support all headers (Origin in this case). - * - * see https://stackoverflow.com/questions/8335501/does-httpurlconnection-censor-some-headers-notably-origin - * see https://stackoverflow.com/questions/13255051/ - * setting-origin-and-access-control-request-method-headers-with-jersey-client - */ - @BeforeClass - public static void beforeClass() { - System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); - } - - /** - * Saves HTML and PNG files. - * - * @throws IOException if an error occurs - */ - @AfterClass - public static void saveAll() throws IOException { - if (allowRestrictedHeaders == null) { - System.setProperty("sun.net.http.allowRestrictedHeaders", "false"); - } - else { - System.setProperty("sun.net.http.allowRestrictedHeaders", allowRestrictedHeaders); - } - } - - /** - * Tests a simple GET. - * @throws Exception if the test fails - */ - @Test - public void get() throws Exception { - doGetTest(URL_FIRST); - } - - /** - * GET with query parameters. - * @throws Exception if the test fails - */ - @Test - public void get_withQueryParameters() throws Exception { - final URL url = new URL(URL_FIRST, "?a=b&c=d&e=f"); - doGetTest(url); - } - - private void doGetTest(final URL url) throws Exception { - // get with default WebConnection - getMockWebConnection().setDefaultResponse(""); - loadPage("", url); - final WebRequest referenceRequest = getMockWebConnection().getLastWebRequest(); - - // get with UrlFetchWebConnection - final WebClient wc = getWebClient(); - wc.setWebConnection(new UrlFetchWebConnection(wc)); - wc.getPage(url); - final WebRequest newRequest = getMockWebConnection().getLastWebRequest(); - - // compare the two requests - compareRequests(referenceRequest, newRequest); - } - - /** - * Simple POST url-encoded. - * @throws Exception if the test fails - */ - @Test - public void post() throws Exception { - final WebRequest referenceRequest = getPostRequest(FormEncodingType.URL_ENCODED); - - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - final WebRequest newRequest = getPostRequest(FormEncodingType.URL_ENCODED); - - // compare the two requests - compareRequests(referenceRequest, newRequest); - } - - private WebRequest getPostRequest(final FormEncodingType encoding) throws Exception { - final String html = "<html><body><form action='foo' method='post' enctype='" + encoding.getName() + "'>\n" - + "<input name='text1' value='me &amp; you'>\n" - + "<textarea name='text2'>Hello\nworld!</textarea>\n" - + "<input type='submit' id='submit'>\n" - + "</form></body></html>"; - - getMockWebConnection().setDefaultResponse(""); - final HtmlPage page = loadPage(html, URL_FIRST); - page.getHtmlElementById("submit").click(); - return getMockWebConnection().getLastWebRequest(); - } - - /** - * Simple POST multipart. - * This doesn't work currently and the test should be reworked as the boundary for the body varies. - * @throws Exception if the test fails - */ - @NotYetImplemented - @Test - public void post_multipart() throws Exception { - final WebRequest referenceRequest = getPostRequest(FormEncodingType.MULTIPART); - - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - final WebRequest newRequest = getPostRequest(FormEncodingType.MULTIPART); - - // compare the two requests - compareRequests(referenceRequest, newRequest); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("my_key=Hello") - public void cookie() throws Exception { - final List<NameValuePair> responseHeader = new ArrayList<>(); - responseHeader.add(new NameValuePair("Set-Cookie", "my_key=Hello")); - getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE, - 200, "OK", "text/html", responseHeader); - - // verify expectations with "normal" HTMLUnit - loadPageWithAlerts(URL_FIRST); - - getWebClient().getCookieManager().clearCookies(); - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - loadPageWithAlerts(URL_FIRST); - } - - static void compareRequests(final WebRequest referenceRequest, final WebRequest newRequest) { - assertEquals(referenceRequest.getRequestBody(), newRequest.getRequestBody()); - assertEquals(referenceRequest.getCharset(), newRequest.getCharset()); - assertEquals(referenceRequest.getProxyHost(), newRequest.getProxyHost()); - assertEquals(referenceRequest.getUrl(), newRequest.getUrl()); - assertEquals(referenceRequest.getEncodingType(), newRequest.getEncodingType()); - assertEquals(referenceRequest.getHttpMethod(), newRequest.getHttpMethod()); - assertEquals(referenceRequest.getProxyPort(), newRequest.getProxyPort()); - assertEquals(referenceRequest.getRequestParameters().toString(), newRequest.getRequestParameters().toString()); - - // java U - // https://stackoverflow.com/questions/8335501/does-httpurlconnection-censor-some-headers-notably-origin - assertEquals(headersToString(referenceRequest), headersToString(newRequest)); - } - - private static String headersToString(final WebRequest request) { - final Set<String> caseInsensitiveHeaders = new HashSet<>(Arrays.asList(HttpHeader.CONNECTION)); - - final StringBuilder sb = new StringBuilder(); - // ensure ordering for comparison - final Map<String, String> headers = new TreeMap<>(request.getAdditionalHeaders()); - for (final Entry<String, String> headerEntry : headers.entrySet()) { - sb.append(headerEntry.getKey()); - sb.append(": "); - if (caseInsensitiveHeaders.contains(headerEntry.getKey())) { - sb.append(headerEntry.getValue().toLowerCase(Locale.ROOT)); - } - else { - sb.append(headerEntry.getValue()); - } - sb.append("\n"); - } - return sb.toString(); - } - - /** - * Tests that an empty string is parsed into zero cookies. - */ - @Test - public void emptyStringHasNoCookies() { - assertTrue(UrlFetchWebConnection.parseCookies("www.foo.com", "").isEmpty()); - } - - /** - * Tests that a string with one cookie is parsed into one cookie with the right name and value. - */ - @Test - public void oneCookieStringHasOneCookie() { - final String cookieHeader = "Name=Value; expires=Fri, 18-Nov-2011 21:13:50 GMT"; - final Set<Cookie> cookies = UrlFetchWebConnection.parseCookies("www.foo.com", cookieHeader); - final Cookie cookie = cookies.iterator().next(); - assertEquals(1, cookies.size()); - assertEquals("Name", cookie.getName()); - assertEquals("Value", cookie.getValue()); - } - - /** - * Tests that a string with three cookies is parsed into three cookies. - */ - @Test - public void threeCookiesStringHasThreeCookies() { - final String cookieHeader = ".ASPXANONYMOUS=sl7T9zamzAEkAAAAY2RmY2U1MWEtMzllYy00MDk1LThmNDMtM2U0MzBiMmEyMTFi0;" - + " expires=Fri, 18-Nov-2011 21:13:50 GMT; path=/; HttpOnly, ASP.NET_SessionId=dqsvrc45gpj51f45n0c1q4qa;" - + " path=/; HttpOnly, language=en-US; path=/; HttpOnly"; - assertEquals(3, UrlFetchWebConnection.parseCookies("www.foo.com", cookieHeader).size()); - } - - /** - * Test that redirects are handled by the WebClient and not by the UrlFetchWebConnection (issue #3557486). - * @throws Exception if the test fails. - */ - @Test - public void redirect() throws Exception { - final String html = "<html></html>"; - - // get with default WebConnection - final List<NameValuePair> headers = Collections.singletonList( - new NameValuePair("Location", URL_SECOND.toString())); - final MockWebConnection conn = getMockWebConnection(); - conn.setResponse(URL_FIRST, "", 302, "Some error", "text/html", headers); - conn.setResponse(URL_SECOND, html); - - Page page = loadPageWithAlerts(URL_FIRST); - assertEquals(URL_SECOND, page.getUrl()); - - // get with UrlFetchWebConnection - final WebClient wc = getWebClient(); - wc.setWebConnection(new UrlFetchWebConnection(wc)); - - page = loadPageWithAlerts(URL_FIRST); - assertEquals(URL_SECOND, page.getUrl()); - } -} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2002-2018 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.background; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.lang3.mutable.MutableInt; -import org.easymock.EasyMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.gargoylesoftware.htmlunit.Page; -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.WebWindow; -import com.gargoylesoftware.htmlunit.gae.GAETestRunner; - -/** - * Minimal tests for {@link JavaScriptJobManagerImpl} on GoogleAppEngine. - * - * @author Amit Manjhi - */ -@Ignore -@RunWith(GAETestRunner.class) -public class JavaScriptJobManagerGaeMinimalTest { - - private WebClient client_; - private WebWindow window_; - private Page page_; - private JavaScriptJobManagerImpl manager_; - private DefaultJavaScriptExecutor eventLoop_; - enum WaitingMode { - WAIT_STARTING_BEFORE, WAIT_TIMELIMIT, - } - - /** - * Initializes variables required by the unit tests. - */ - @Before - public void before() { - // set the GAE mode - client_ = new WebClient(); - window_ = EasyMock.createNiceMock(WebWindow.class); - page_ = EasyMock.createNiceMock(Page.class); - manager_ = new JavaScriptJobManagerImpl(window_); - EasyMock.expect(window_.getEnclosedPage()).andReturn(page_).anyTimes(); - EasyMock.expect(window_.getJobManager()).andReturn(manager_).anyTimes(); - EasyMock.replay(window_, page_); - eventLoop_ = new GAEJavaScriptExecutor(client_); - eventLoop_.addWindow(window_); - } - - /** - * Shuts down the event loop. - */ - @After - public void after() { - if (eventLoop_ != null) { - eventLoop_.shutdown(); - } - if (client_ != null) { - client_.close(); - } - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void addJob_singleExecution() throws Exception { - final MutableInt count = new MutableInt(0); - final JavaScriptJob job = new BasicJavaScriptJob(5, null) { - @Override - public void run() { - count.increment(); - } - }; - manager_.addJob(job, page_); - assertEquals(1, manager_.getJobCount()); - final int executedJobs = eventLoop_.pumpEventLoop(10_000); - assertEquals(1, executedJobs); - assertEquals(1, count.intValue()); - assertEquals(0, manager_.getJobCount()); - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void addJob_multipleExecution_removeJob() throws Exception { - final MutableInt id = new MutableInt(); - final MutableInt count = new MutableInt(0); - final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) { - @Override - public void run() { - count.increment(); - if (count.intValue() >= 5) { - manager_.removeJob(id.intValue()); - } - } - }; - id.setValue(manager_.addJob(job, page_)); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(5, executedJobs); - assertEquals(5, count.intValue()); - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void addJob_multipleExecution_removeAllJobs() throws Exception { - final MutableInt count = new MutableInt(0); - final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) { - @Override - public void run() { - count.increment(); - if (count.intValue() >= 5) { - manager_.removeAllJobs(); - } - } - }; - manager_.addJob(job, page_); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(5, executedJobs); - assertEquals(5, count.intValue()); - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void getJobCount() throws Exception { - final MutableInt count = new MutableInt(); - final JavaScriptJob job = new BasicJavaScriptJob(50, null) { - @Override - public void run() { - count.setValue(manager_.getJobCount()); - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job, page_); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(1, executedJobs); - assertEquals(1, count.intValue()); - assertEquals(0, manager_.getJobCount()); - } - - /** - * Tests waiting for the current job. - */ - @Test - public void waitForCurrentLongJob() { - final JavaScriptJob job = new BasicJavaScriptJob(50, null) { - // Long job - @Override - public void run() { - try { - Thread.sleep(500); - } - catch (final InterruptedException e) { - // ignore - } - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job, page_); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(1, executedJobs); - assertEquals(0, manager_.getJobCount()); - } - - /** - * Tests if waiting for simple jobs works. - */ - @Test - public void waitForSimpleJobs() { - final JavaScriptJob job1 = new BasicJavaScriptJob(50, null) { - @Override - public void run() { - // Empty. - } - }; - final JavaScriptJob job2 = new BasicJavaScriptJob(1000, null) { - @Override - public void run() { - // Empty. - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job1, page_); - manager_.addJob(job2, page_); - final int executedJobs = eventLoop_.pumpEventLoop(200); - assertEquals(1, executedJobs); - assertEquals(1, manager_.getJobCount()); - } - - /** - * Tests if waiting for complex jobs work. - */ - @Test - public void waitForComplexJobs() { - final JavaScriptJob job1 = new BasicJavaScriptJob(50, null) { - // This job takes 30ms to complete. - @Override - public void run() { - try { - Thread.sleep(30); - } - catch (final InterruptedException e) { - // ignore - } - } - }; - final JavaScriptJob job2 = new BasicJavaScriptJob(60, null) { - @Override - public void run() { - // Empty. - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job1, page_); - manager_.addJob(job2, page_); - final int executedJobs = eventLoop_.pumpEventLoop(70); - assertEquals(1, executedJobs); - assertEquals(1, manager_.getJobCount()); - } -} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2018 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.util; - -import static org.junit.Assert.assertEquals; - -import java.net.URL; - -import org.junit.Test; - -import com.gargoylesoftware.htmlunit.util.URLCreator.URLCreatorGAE; - -/** - * Tests for {@link URLCreator}. - * - * @author Marc Guillemot - */ -public class UrlCreatorTest { - - /** - * @throws Exception if the test fails - */ - @Test - public void gaeGetProtocol() throws Exception { - final URLCreatorGAE creator = new URLCreator.URLCreatorGAE(); - - final URL url = creator.toUrlUnsafeClassic("data:text/javascript,d1%20%3D%20'one'%3B"); - assertEquals("http://gaeHack_data/text/javascript,d1%20%3D%20'one'%3B", url.toString()); - assertEquals("data", creator.getProtocol(url)); - } -} |
From: <rb...@us...> - 2018-03-30 13:05:09
|
Revision: 15219 http://sourceforge.net/p/htmlunit/code/15219 Author: rbri Date: 2018-03-30 13:05:06 +0000 (Fri, 30 Mar 2018) Log Message: ----------- code cleanup Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -1507,19 +1507,19 @@ final HtmlElement element = getHtmlElementByAccessKey(accessKey); if (element != null) { element.focus(); - final Page newPage; - if (element instanceof HtmlAnchor || element instanceof HtmlArea || element instanceof HtmlButton - || element instanceof HtmlInput || element instanceof HtmlLabel || element instanceof HtmlLegend - || element instanceof HtmlTextArea || element instanceof HtmlArea) { - newPage = element.click(); - } - else { - newPage = this; - } + if (element instanceof HtmlAnchor + || element instanceof HtmlArea + || element instanceof HtmlButton + || element instanceof HtmlInput + || element instanceof HtmlLabel + || element instanceof HtmlLegend + || element instanceof HtmlTextArea) { + final Page newPage = element.click(); - if (newPage != this && getFocusedElement() == element) { - // The page was reloaded therefore no element on this page will have the focus. - getFocusedElement().blur(); + if (newPage != this && getFocusedElement() == element) { + // The page was reloaded therefore no element on this page will have the focus. + getFocusedElement().blur(); + } } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/StringUtils.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -21,8 +21,6 @@ import org.apache.http.client.utils.DateUtils; -import com.gargoylesoftware.htmlunit.WebAssert; - /** * String utilities class for utility functions not covered by third party libraries. * @@ -149,63 +147,26 @@ final int tmpRed = Integer.parseInt(tmpHex.substring(0, 2), 16); final int tmpGreen = Integer.parseInt(tmpHex.substring(2, 4), 16); final int tmpBlue = Integer.parseInt(tmpHex.substring(4, 6), 16); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; + return new Color(tmpRed, tmpGreen, tmpBlue); } final int tmpRed = Integer.parseInt(tmpHex.substring(0, 1) + tmpHex.substring(0, 1), 16); final int tmpGreen = Integer.parseInt(tmpHex.substring(1, 2) + tmpHex.substring(1, 2), 16); final int tmpBlue = Integer.parseInt(tmpHex.substring(2, 3) + tmpHex.substring(2, 3), 16); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; + return new Color(tmpRed, tmpGreen, tmpBlue); } /** - * Returns true if the specified token is in RGB notation. - * @param token the token to check - * @return whether the token is a color in RGB notation or not - */ - public static boolean isColorRGB(final String token) { - if (token == null) { - return false; - } - return RGB_COLOR.matcher(token.trim()).matches(); - } - - /** * Returns a Color parsed from the given rgb notation. * @param token the token to parse * @return a Color whether the token is a color in RGB notation; otherwise null */ - public static Color asColorRGB(final String token) { - if (token == null) { - return null; - } - final Matcher tmpMatcher = RGB_COLOR.matcher(token); - final boolean tmpFound = tmpMatcher.matches(); - if (!tmpFound) { - return null; - } - - final int tmpRed = Integer.parseInt(tmpMatcher.group(1)); - final int tmpGreen = Integer.parseInt(tmpMatcher.group(2)); - final int tmpBlue = Integer.parseInt(tmpMatcher.group(3)); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; - } - - /** - * Returns a Color parsed from the given rgb notation. - * @param token the token to parse - * @return a Color whether the token is a color in RGB notation; otherwise null - */ public static Color findColorRGB(final String token) { if (token == null) { return null; } final Matcher tmpMatcher = RGB_COLOR.matcher(token); - final boolean tmpFound = tmpMatcher.find(); - if (!tmpFound) { + if (!tmpMatcher.find()) { return null; } @@ -212,8 +173,7 @@ final int tmpRed = Integer.parseInt(tmpMatcher.group(1)); final int tmpGreen = Integer.parseInt(tmpMatcher.group(2)); final int tmpBlue = Integer.parseInt(tmpMatcher.group(3)); - final Color tmpColor = new Color(tmpRed, tmpGreen, tmpBlue); - return tmpColor; + return new Color(tmpRed, tmpGreen, tmpBlue); } /** @@ -227,17 +187,6 @@ } /** - * Formats the specified date according to RFC 1123. - * - * @param date the date to format - * @return the specified date, formatted according to RFC 1123 - */ - public static String formatHttpDate(final Date date) { - WebAssert.notNull("date", date); - return DateUtils.formatDate(date); - } - - /** * Sanitize a string for use in Matcher.appendReplacement. * Replaces all \ with \\ and $ as \$ because they are used as control * characters in appendReplacement. @@ -246,9 +195,8 @@ * @return sanitized version of the given string */ public static String sanitizeForAppendReplacement(final String toSanitize) { - final String toReplace = org.apache.commons.lang3.StringUtils.replaceEach(toSanitize, - new String[] {"\\", "$"}, new String[]{"\\\\", "\\$"}); - return toReplace; + return org.apache.commons.lang3.StringUtils.replaceEach(toSanitize, + new String[] {"\\", "$"}, new String[]{"\\\\", "\\$"}); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -510,8 +510,7 @@ s.append(ref); } - final URL url = new URL(s.toString()); - return url; + return new URL(s.toString()); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/AbstractPageTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit; +import static org.apache.http.client.utils.DateUtils.formatDate; + import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -23,7 +25,6 @@ import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Tests for {@link AbstractPage}. @@ -43,7 +44,7 @@ webClient.getOptions().setMaxInMemory(3); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Expires", StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1)))); + headers.add(new NameValuePair("Expires", formatDate(DateUtils.addHours(new Date(), 1)))); getMockWebConnection().setDefaultResponse("something", 200, "Ok", "unknown_type", headers); startWebServer(getMockWebConnection()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -14,7 +14,7 @@ */ package com.gargoylesoftware.htmlunit; -import static com.gargoylesoftware.htmlunit.util.StringUtils.formatHttpDate; +import static org.apache.http.client.utils.DateUtils.formatDate; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expectLastCall; @@ -39,7 +39,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Tests for {@link Cache}. @@ -71,13 +70,13 @@ headers.put("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT"); assertTrue(cache.isCacheableContent(response)); - headers.put("Last-Modified", formatHttpDate(DateUtils.addMinutes(new Date(), -5))); + headers.put("Last-Modified", formatDate(DateUtils.addMinutes(new Date(), -5))); assertFalse(cache.isCacheableContent(response)); - headers.put("Expires", formatHttpDate(DateUtils.addMinutes(new Date(), 5))); + headers.put("Expires", formatDate(DateUtils.addMinutes(new Date(), 5))); assertFalse(cache.isCacheableContent(response)); - headers.put("Expires", formatHttpDate(DateUtils.addHours(new Date(), 1))); + headers.put("Expires", formatDate(DateUtils.addHours(new Date(), 1))); assertTrue(cache.isCacheableContent(response)); headers.remove("Last-Modified"); @@ -524,7 +523,7 @@ expect(response1.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( - StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); + formatDate(DateUtils.addHours(new Date(), 1))); final WebRequest request2 = new WebRequest(URL_SECOND, HttpMethod.GET); final WebResponse response2 = createMock(WebResponse.class); @@ -533,7 +532,7 @@ expect(response2.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); expect(response2.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); expect(response2.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( - StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); + formatDate(DateUtils.addHours(new Date(), 1))); response1.cleanUp(); @@ -560,7 +559,7 @@ expect(response1.getResponseHeaderValue(HttpHeader.CACHE_CONTROL)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.LAST_MODIFIED)).andReturn(null); expect(response1.getResponseHeaderValue(HttpHeader.EXPIRES)).andReturn( - StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1))); + formatDate(DateUtils.addHours(new Date(), 1))); response1.cleanUp(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -31,7 +31,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Unit tests for {@link CookieManager}. @@ -282,7 +281,7 @@ final List<NameValuePair> responseHeader1 = new ArrayList<>(); responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Fri, 02-Jan-1970 00:00:00 GMT")); responseHeader1.add(new NameValuePair("Set-Cookie", - "second=2;expires=" + StringUtils.formatHttpDate(aBitLater))); + "second=2;expires=" + DateUtils.formatDate(aBitLater))); responseHeader1.add(new NameValuePair("Set-Cookie", "visit=fo; expires=\"Sat, 07-Apr-2002 13:11:33 GMT\";")); responseHeader1.add(new NameValuePair("Set-Cookie", "visitor=f2; expires=\"Sat, 07-Apr-2092 13:11:33 GMT\";")); getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", "text/html", responseHeader1); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/SgmlPageTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit; +import static org.apache.http.client.utils.DateUtils.formatDate; + import java.util.ArrayList; import java.util.Date; import java.util.Iterator; @@ -31,7 +33,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlDivision; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.util.StringUtils; /** * Tests for {@link SgmlPage}. @@ -51,7 +52,7 @@ webClient.getOptions().setMaxInMemory(3); final List<NameValuePair> headers = new ArrayList<>(); - headers.add(new NameValuePair("Expires", StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1)))); + headers.add(new NameValuePair("Expires", formatDate(DateUtils.addHours(new Date(), 1)))); getMockWebConnection().setDefaultResponse("something", 200, "Ok", "text/html", headers); startWebServer(getMockWebConnection()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java 2018-03-30 12:40:08 UTC (rev 15218) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/StringUtilsTest.java 2018-03-30 13:05:06 UTC (rev 15219) @@ -45,35 +45,6 @@ * @throws Exception if the test fails */ @Test - public void isColorRGB() throws Exception { - assertFalse(StringUtils.isColorRGB(null)); - assertFalse(StringUtils.isColorRGB("")); - assertFalse(StringUtils.isColorRGB(" ")); - - assertFalse(StringUtils.isColorRGB("#a1")); - assertTrue(StringUtils.isColorRGB("rgb(1,12,13)")); - assertTrue(StringUtils.isColorRGB(" rgb(1,12,13) ")); - assertTrue(StringUtils.isColorRGB("rgb ( 1, 12, 13 )")); - assertFalse(StringUtils.isColorRGB("rgb(a1,12,13)")); - } - - /** - * @throws Exception if the test fails - */ - @Test - public void asColorRGB() throws Exception { - assertNull(StringUtils.asColorRGB(null)); - assertNull(StringUtils.asColorRGB("")); - assertNull(StringUtils.asColorRGB(" ")); - - assertNull(StringUtils.asColorRGB("#a1")); - assertEquals(new Color(1, 12, 13), StringUtils.asColorRGB("rgb(1,12,13)")); - } - - /** - * @throws Exception if the test fails - */ - @Test public void findColorRGB() throws Exception { assertNull(StringUtils.findColorRGB(null)); assertNull(StringUtils.findColorRGB("")); |
From: <rb...@us...> - 2018-04-02 13:42:24
|
Revision: 15222 http://sourceforge.net/p/htmlunit/code/15222 Author: rbri Date: 2018-04-02 13:42:22 +0000 (Mon, 02 Apr 2018) Log Message: ----------- fix doNotTrack Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -1076,6 +1076,10 @@ @BrowserFeature(IE) JS_MENU_TYPE_EMPTY, + /** Navigator.doNotTrack returns unspecified if not set. */ + @BrowserFeature(FF) + JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED, + /** Indicates if the String representation of a native function is without newline. */ @BrowserFeature({CHROME, EDGE}) JS_NATIVE_FUNCTION_TOSTRING_COMPACT, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Navigator.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED; 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; @@ -20,6 +21,7 @@ import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE; import com.gargoylesoftware.htmlunit.PluginConfiguration; +import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -300,12 +302,16 @@ * Returns the {@code doNotTrack} property. * @return the {@code doNotTrack} property */ - @JsxGetter(FF) - public String getDoNotTrack() { - if (getWindow().getWebWindow().getWebClient().getOptions().isDoNotTrackEnabled()) { - return "yes"; + @JsxGetter({CHROME, FF}) + public Object getDoNotTrack() { + final WebClient client = getWindow().getWebWindow().getWebClient(); + if (client.getOptions().isDoNotTrackEnabled()) { + return 1; } - return "unspecified"; + if (client.getBrowserVersion().hasFeature(JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED)) { + return "unspecified"; + } + return null; } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -4483,6 +4483,18 @@ setEventHandler("selectstart", selectstart); } + /** + * Returns the {@code doNotTrack} property. + * @return the {@code doNotTrack} property + */ + @JsxGetter(IE) + public Object getDoNotTrack() { + final WebClient client = getWindow().getWebWindow().getWebClient(); + if (client.getOptions().isDoNotTrackEnabled()) { + return 1; + } + return null; + } } class HTMLCollectionFrames extends HTMLCollection { @@ -4545,5 +4557,4 @@ } } } - } 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 2018-03-30 18:32:00 UTC (rev 15221) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2018-04-02 13:42:22 UTC (rev 15222) @@ -466,4 +466,27 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = {"unspecified", "undefined", "undefined"}, + CHROME = {"null", "undefined", "undefined"}, + IE = {"undefined", "undefined", "null"}) + public void doNotTrack() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " alert(navigator.doNotTrack);\n" + + " alert(navigator.msDoNotTrack);\n" + + " alert(window.doNotTrack);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2018-04-02 13:51:58
|
Revision: 15223 http://sourceforge.net/p/htmlunit/code/15223 Author: rbri Date: 2018-04-02 13:51:55 +0000 (Mon, 02 Apr 2018) Log Message: ----------- deprecate FIREFOX_45 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-04-02 13:42:22 UTC (rev 15222) +++ trunk/htmlunit/src/changes/changes.xml 2018-04-02 13:51:55 UTC (rev 15223) @@ -7,8 +7,14 @@ </properties> <body> - <release version="2.31" date="xx, 2018" description="Bugfixes, special GAE handlings removed"> + <release version="2.31" date="xx, 2018" description="Bugfixes, FIREFOX_45 is deprecated, special GAE handlings removed"> <action type="update" dev="rbri"> + BrowserVersion: deprecate FIREFOX_45. + </action> + <action type="fix" dev="rbri"> + Navigator.doNotTrack fixed, property is available in Chrome too, Window.doNotTrack added for is available for IE. + </action> + <action type="update" dev="rbri"> Special handling of the GAE environment is no longer required, the JDK8 at GAE has no longer any restrictions. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-04-02 13:42:22 UTC (rev 15222) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2018-04-02 13:51:55 UTC (rev 15223) @@ -95,7 +95,9 @@ /** * Firefox 45 ESR. * @since 2.21 + * @deprecated starting with version 2.31 */ + @Deprecated public static final BrowserVersion FIREFOX_45 = new BrowserVersion(45, "FF45"); /** |
From: <rb...@us...> - 2018-04-13 18:25:10
|
Revision: 15231 http://sourceforge.net/p/htmlunit/code/15231 Author: rbri Date: 2018-04-13 18:25:05 +0000 (Fri, 13 Apr 2018) Log Message: ----------- use the symbol implementation from rhino (and other es6 features) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.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/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/ScriptableObjectTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -267,6 +267,7 @@ @Override protected Context makeContext() { final TimeoutContext cx = new TimeoutContext(this); + cx.setLanguageVersion(Context.VERSION_ES6); // Use pure interpreter mode to get observeInstructionCount() callbacks. cx.setOptimizationLevel(-1); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -69,7 +69,6 @@ import com.gargoylesoftware.htmlunit.javascript.host.SimpleArray; import com.gargoylesoftware.htmlunit.javascript.host.Storage; import com.gargoylesoftware.htmlunit.javascript.host.StorageManager; -import com.gargoylesoftware.htmlunit.javascript.host.Symbol; import com.gargoylesoftware.htmlunit.javascript.host.TextDecoder; import com.gargoylesoftware.htmlunit.javascript.host.TextEncoder; import com.gargoylesoftware.htmlunit.javascript.host.Touch; @@ -593,7 +592,7 @@ SVGSymbolElement.class, SVGTextContentElement.class, SVGTextElement.class, SVGTextPathElement.class, SVGTextPositioningElement.class, SVGTitleElement.class, SVGTransform.class, SVGTransformList.class, SVGTSpanElement.class, SVGUnitTypes.class, SVGUseElement.class, SVGViewElement.class, - SVGZoomEvent.class, Symbol.class, SyncManager.class, Text.class, TextDecoder.class, + SVGZoomEvent.class, SyncManager.class, Text.class, TextDecoder.class, TextEncoder.class, TextEvent.class, TextMetrics.class, TextRange.class, TextTrack.class, TextTrackCue.class, TextTrackCueList.class, TextTrackList.class, TimeEvent.class, TimeRanges.class, Touch.class, TouchEvent.class, TouchList.class, TrackEvent.class, TransitionEvent.class, TreeWalker.class, 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 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Iterator.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -26,6 +26,8 @@ import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; +import net.sourceforge.htmlunit.corejs.javascript.SymbolKey; +import net.sourceforge.htmlunit.corejs.javascript.SymbolScriptable; import net.sourceforge.htmlunit.corejs.javascript.Undefined; /** @@ -113,7 +115,10 @@ final Scriptable thisObj, final Scriptable scriptable, final Consumer<Object> processor) { - final Object iterator = scriptable.get(Symbol.ITERATOR_STRING, scriptable); + if (!(scriptable instanceof SymbolScriptable)) { + return false; + } + final Object iterator = ((SymbolScriptable) scriptable).get(SymbolKey.ITERATOR, scriptable); if (iterator == Scriptable.NOT_FOUND) { return false; } 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 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Map.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -36,6 +36,9 @@ import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; +import net.sourceforge.htmlunit.corejs.javascript.Symbol; +import net.sourceforge.htmlunit.corejs.javascript.SymbolKey; +import net.sourceforge.htmlunit.corejs.javascript.SymbolScriptable; import net.sourceforge.htmlunit.corejs.javascript.Undefined; /** @@ -45,7 +48,7 @@ * @author Ronald Brill */ @JsxClass -public class Map extends SimpleScriptable { +public class Map extends SimpleScriptable implements SymbolScriptable { private static final String MAP_ITERATOR_NAME = "Map Iterator"; private static Iterator ITERATOR_PROTOTYPE_; @@ -214,18 +217,6 @@ } /** - * {@inheritDoc} - */ - @Override - 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 ScriptableObject.getProperty(start, "entries"); - } - return super.get(name, start); - } - - /** * Returns a new {@code Iterator} object that contains the {@code [key, value]} pairs for each element in the * Map object in insertion order. * @return a new {@code Iterator} object @@ -295,4 +286,26 @@ new Object[] {entry.getValue(), entry.getKey(), this}); } } + + /** + * {@inheritDoc} + */ + @Override + public Object get(final Symbol key, final Scriptable start) { + if (SymbolKey.ITERATOR.equals(key)) { + return ScriptableObject.getProperty(start, "entries"); + } + return super.get(key, start); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean has(final Symbol key, final Scriptable start) { + if (SymbolKey.ITERATOR.equals(key)) { + return true; + } + return super.has(key, 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 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Set.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -35,6 +35,9 @@ import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; +import net.sourceforge.htmlunit.corejs.javascript.Symbol; +import net.sourceforge.htmlunit.corejs.javascript.SymbolKey; +import net.sourceforge.htmlunit.corejs.javascript.SymbolScriptable; import net.sourceforge.htmlunit.corejs.javascript.Undefined; /** @@ -44,7 +47,7 @@ * @author Ronald Brill */ @JsxClass -public class Set extends SimpleScriptable { +public class Set extends SimpleScriptable implements SymbolScriptable { private static final String SET_ITERATOR_NAME = "Set Iterator"; private static Iterator ITERATOR_PROTOTYPE_; @@ -184,18 +187,6 @@ } /** - * {@inheritDoc} - */ - @Override - 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 ScriptableObject.getProperty(start, "values"); - } - return super.get(name, start); - } - - /** * Returns a new {@code Iterator} object that contains the values for each element in the Set object * in insertion order. * @return a new {@code Iterator} object @@ -238,4 +229,26 @@ new Object[] {object, object, this}); } } + + /** + * {@inheritDoc} + */ + @Override + public Object get(final Symbol key, final Scriptable start) { + if (SymbolKey.ITERATOR.equals(key)) { + return ScriptableObject.getProperty(start, "values"); + } + return super.get(key, start); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean has(final Symbol key, final Scriptable start) { + if (SymbolKey.ITERATOR.equals(key)) { + return true; + } + return super.has(key, start); + } } Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2002-2018 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 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.FF52; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import com.gargoylesoftware.htmlunit.BrowserVersion; -import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; -import com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration; -import com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration; -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.JsxStaticFunction; -import com.gargoylesoftware.htmlunit.javascript.configuration.JsxStaticGetter; - -import net.sourceforge.htmlunit.corejs.javascript.Context; -import net.sourceforge.htmlunit.corejs.javascript.Function; -import net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime; -import net.sourceforge.htmlunit.corejs.javascript.Scriptable; -import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; - -/** - * A JavaScript object for {@code Symbol}. - * - * @author Ahmed Ashour - * @author Ronald Brill - */ -@JsxClass({CHROME, FF, EDGE}) -public class Symbol extends SimpleScriptable { - - static final String ITERATOR_STRING = "Symbol(Symbol.iterator)"; - private static Map<String, Map<String, Symbol>> SYMBOL_MAP_ = new HashMap<>(); - - private Object name_; - - /** - * Default constructor. - */ - public Symbol() { - } - - /** - * Creates an instance. - * @param name the name - */ - @JsxConstructor - public Symbol(final Object name) { - name_ = name; - for (final StackTraceElement stackElement : new Throwable().getStackTrace()) { - if (stackElement.getClassName().contains("BaseFunction") - && "construct".equals(stackElement.getMethodName())) { - throw ScriptRuntime.typeError("Symbol is not a constructor"); - } - } - } - - /** - * Returns the {@code iterator} static property. - * @param thisObj the scriptable - * @return the {@code iterator} static property - */ - @JsxStaticGetter - public static Symbol getIterator(final Scriptable thisObj) { - return getSymbol(thisObj, "iterator"); - } - - private static Symbol getSymbol(final Scriptable thisObj, final String name) { - final SimpleScriptable scope = (SimpleScriptable) thisObj.getParentScope(); - final BrowserVersion browserVersion = scope.getBrowserVersion(); - - Map<String, Symbol> map = SYMBOL_MAP_.get(browserVersion.getNickname()); - if (map == null) { - map = new HashMap<>(); - SYMBOL_MAP_.put(browserVersion.getNickname(), map); - } - - return map.computeIfAbsent(name, - k -> { - final Symbol sym = new Symbol(); - sym.name_ = k; - sym.setParentScope(scope); - sym.setPrototype(scope.getPrototype(sym.getClass())); - return sym; - }); - } - - /** - * Returns the {@code unscopables} static property. - * @param thisObj the scriptable - * @return the {@code unscopables} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getUnscopables(final Scriptable thisObj) { - return getSymbol(thisObj, "unscopables"); - } - - /** - * Returns the {@code isConcatSpreadable} static property. - * @param thisObj the scriptable - * @return the {@code isConcatSpreadable} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getIsConcatSpreadable(final Scriptable thisObj) { - return getSymbol(thisObj, "isConcatSpreadable"); - } - - /** - * Returns the {@code toPrimitive} static property. - * @param thisObj the scriptable - * @return the {@code toPrimitive} static property - */ - @JsxStaticGetter({CHROME, FF}) - public static Symbol getToPrimitive(final Scriptable thisObj) { - return getSymbol(thisObj, "toPrimitive"); - } - - /** - * Returns the {@code toStringTag} static property. - * @param thisObj the scriptable - * @return the {@code toStringTag} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getToStringTag(final Scriptable thisObj) { - return getSymbol(thisObj, "toStringTag"); - } - - /** - * Returns the {@code match} static property. - * @param thisObj the scriptable - * @return the {@code match} static property - */ - @JsxStaticGetter({CHROME, FF}) - public static Symbol getMatch(final Scriptable thisObj) { - return getSymbol(thisObj, "match"); - } - - /** - * Returns the {@code hasInstance} static property. - * @param thisObj the scriptable - * @return the {@code hasInstance} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getHasInstance(final Scriptable thisObj) { - return getSymbol(thisObj, "hasInstance"); - } - - /** - * Returns the {@code replace} static property. - * @param thisObj the scriptable - * @return the {@code replace} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getReplace(final Scriptable thisObj) { - return getSymbol(thisObj, "replace"); - } - - /** - * Returns the {@code search} static property. - * @param thisObj the scriptable - * @return the {@code search} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getSearch(final Scriptable thisObj) { - return getSymbol(thisObj, "search"); - } - - /** - * Returns the {@code split} static property. - * @param thisObj the scriptable - * @return the {@code split} static property - */ - @JsxStaticGetter({CHROME, FF52}) - public static Symbol getSplit(final Scriptable thisObj) { - return getSymbol(thisObj, "split"); - } - - /** - * Returns the {@code species} static property. - * @param thisObj the scriptable - * @return the {@code species} static property - */ - @JsxStaticGetter({CHROME, FF}) - public static Symbol getSpecies(final Scriptable thisObj) { - return getSymbol(thisObj, "species"); - } - - /** - * Searches for existing symbols in a runtime-wide symbol registry with the given key and returns it if found. - * Otherwise a new symbol gets created in the global symbol registry with this key. - * @param context the context - * @param thisObj this object - * @param args the arguments - * @param function the function - * @return the symbol - */ - @JsxStaticFunction(functionName = "for") - public static Symbol forFunction(final Context context, final Scriptable thisObj, final Object[] args, - final Function function) { - final String key = Context.toString(args.length != 0 ? args[0] : Undefined.instance); - - Symbol symbol = (Symbol) ((ScriptableObject) thisObj).get(key); - if (symbol == null) { - final SimpleScriptable parentScope = (SimpleScriptable) thisObj.getParentScope(); - - symbol = new Symbol(); - symbol.name_ = key; - symbol.setParentScope(parentScope); - symbol.setPrototype(parentScope.getPrototype(symbol.getClass())); - thisObj.put(key, thisObj, symbol); - } - return symbol; - } - - /** - * {@inheritDoc} - */ - @Override - public String getTypeOf() { - return "symbol"; - } - - /** - * {@inheritDoc} - */ - @Override - @JsxFunction - public String toString() { - if (name_ == Undefined.instance) { - return "Symbol()"; - } - - final ClassConfiguration config = AbstractJavaScriptConfiguration - .getClassConfiguration(getClass(), getBrowserVersion()); - - final String name = Context.toString(name_); - for (final Entry<String, ClassConfiguration.PropertyInfo> propertyEntry : config.getStaticPropertyEntries()) { - if (propertyEntry.getKey().equals(name)) { - return "Symbol(Symbol." + name + ')'; - } - } - return "Symbol(" + name + ')'; - } - - /** - * {@inheritDoc} - */ - @Override - public Object getDefaultValue(final Class<?> hint) { - if (String.class.equals(hint) || hint == null) { - return toString(); - } - return super.getDefaultValue(hint); - } - - /** - * Removes all cached symbols, which have the specified {@code window} as their parent scope. - * @param window the window - */ - public static void remove(final Window window) { - for (final Map<String, Symbol> symbols : SYMBOL_MAP_.values()) { - for (final java.util.Iterator<Symbol> it = symbols.values().iterator(); it.hasNext();) { - if (it.next().getParentScope() == window) { - it.remove(); - } - } - } - } -} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -2347,7 +2347,6 @@ */ @Override public void close() { - Symbol.remove(this); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/ScriptableObjectTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/ScriptableObjectTest.java 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/ScriptableObjectTest.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -14,15 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; - 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; /** @@ -70,7 +66,6 @@ @Test @Alerts(DEFAULT = {"2", "symbol", "symbol", "1", "c"}, IE = "not defined") - @NotYetImplemented({CHROME, FF}) public void getOwnPropertySymbols() throws Exception { final String html = "<html><body>\n" + "<script>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java 2018-04-09 19:17:19 UTC (rev 15230) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java 2018-04-13 18:25:05 UTC (rev 15231) @@ -14,15 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; - 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; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -178,7 +174,6 @@ @Alerts(DEFAULT = {"Symbol()", "Symbol(foo)", "Symbol(Symbol.iterator)", "exception"}, FF45 = {"Symbol()", "Symbol(foo)", "Symbol(Symbol.iterator)", "undefined"}, IE = "not supported") - @NotYetImplemented({CHROME, FF52}) public void string() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ |
From: <rb...@us...> - 2018-04-14 17:32:41
|
Revision: 15237 http://sourceforge.net/p/htmlunit/code/15237 Author: rbri Date: 2018-04-14 17:32:36 +0000 (Sat, 14 Apr 2018) Log Message: ----------- use a different rhino language level for the IE we have removed a HtmlUnit feature from our Rhino fork, because this is no longer required Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeObjectTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java 2018-04-14 11:46:24 UTC (rev 15236) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java 2018-04-14 17:32:36 UTC (rev 15237) @@ -19,8 +19,8 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ENUM_NUMBERS_FIRST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ERROR_STACK; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FUNCTION_DECLARED_FORWARD_IN_BLOCK; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GET_PROTOTYPE_OF_STRING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IGNORES_LAST_LINE_CONTAINING_UNCOMMENTED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_PRE_WIDTH_STRING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_PROPERTY_DESCRIPTOR_NAME; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_PROPERTY_DESCRIPTOR_NEW_LINE; @@ -267,7 +267,12 @@ @Override protected Context makeContext() { final TimeoutContext cx = new TimeoutContext(this); - cx.setLanguageVersion(Context.VERSION_ES6); + if (browserVersion_.hasFeature(JS_PRE_WIDTH_STRING)) { + cx.setLanguageVersion(Context.VERSION_1_8); + } + else { + cx.setLanguageVersion(Context.VERSION_ES6); + } // Use pure interpreter mode to get observeInstructionCount() callbacks. cx.setOptimizationLevel(-1); @@ -344,8 +349,6 @@ return browserVersion_.hasFeature(JS_FUNCTION_DECLARED_FORWARD_IN_BLOCK); case Context.FEATURE_HTMLUNIT_ENUM_NUMBERS_FIRST: return browserVersion_.hasFeature(JS_ENUM_NUMBERS_FIRST); - case Context.FEATURE_HTMLUNIT_GET_PROTOTYPE_OF_STRING: - return browserVersion_.hasFeature(JS_GET_PROTOTYPE_OF_STRING); case Context.FEATURE_HTMLUNIT_MEMBERBOX_NAME: return browserVersion_.hasFeature(JS_PROPERTY_DESCRIPTOR_NAME); case Context.FEATURE_HTMLUNIT_MEMBERBOX_NEWLINE: Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeObjectTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeObjectTest.java 2018-04-14 11:46:24 UTC (rev 15236) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeObjectTest.java 2018-04-14 17:32:36 UTC (rev 15237) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; @@ -239,15 +238,15 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "", + @Alerts(DEFAULT = "true", IE = "exception") - public void getPrototypeOf() throws Exception { + public void getPrototypeOfString() throws Exception { final String html = "" + "<html><head>\n" + "<script>\n" + " function test() {\n" + " try {\n" - + " alert(Object.getPrototypeOf(''));\n" + + " alert(String.prototype === Object.getPrototypeOf(''));\n" + " } catch(e) {alert('exception')}\n" + " }\n" + "</script>\n" @@ -262,7 +261,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "0", + @Alerts(DEFAULT = "true", IE = "exception") public void getPrototypeOfNumber() throws Exception { final String html = "" @@ -270,7 +269,7 @@ + "<script>\n" + " function test() {\n" + " try {\n" - + " alert(Object.getPrototypeOf(1));\n" + + " alert(Number.prototype === Object.getPrototypeOf(1));\n" + " } catch(e) {alert('exception')}\n" + " }\n" + "</script>\n" @@ -285,9 +284,31 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "true", + IE = "exception") + public void getPrototypeOfBoolean() throws Exception { + final String html = "" + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " try {\n" + + " alert(Boolean.prototype === Object.getPrototypeOf(true));\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = "object", IE = "exception") - @NotYetImplemented({CHROME, FF}) public void getTypeOfPrototypeOfNumber() throws Exception { final String html = "" + "<html><head>\n" |
From: <rb...@us...> - 2018-04-15 11:33:44
|
Revision: 15239 http://sourceforge.net/p/htmlunit/code/15239 Author: rbri Date: 2018-04-15 11:33:32 +0000 (Sun, 15 Apr 2018) Log Message: ----------- test fails with chrome also Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-04-14 18:31:36 UTC (rev 15238) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2018-04-15 11:33:32 UTC (rev 15239) @@ -1071,6 +1071,7 @@ /** Type property of menu has always '' as value. */ @BrowserFeature(IE) JS_MENU_TYPE_EMPTY, + /** Indicates if the String representation of a native function is without newline. */ @BrowserFeature({CHROME, EDGE}) JS_NATIVE_FUNCTION_TOSTRING_COMPACT, 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 2018-04-14 18:31:36 UTC (rev 15238) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2018-04-15 11:33:32 UTC (rev 15239) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.xml; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; @@ -37,10 +38,10 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.BrowserRunner.Tries; +import com.gargoylesoftware.htmlunit.HttpHeader; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -1594,7 +1595,7 @@ "\nfunction onreadystatechange() {\n [native code]\n}\n", "\nfunction onreadystatechange() {\n [native code]\n}\n", "true", "true"}) - @NotYetImplemented(FF52) + @NotYetImplemented({CHROME, FF52}) public void getOwnPropertyDescriptor() throws Exception { final String html = "<html>\n" |