From: <rb...@us...> - 2013-11-24 19:35:43
|
Revision: 8806 http://sourceforge.net/p/htmlunit/code/8806 Author: rbri Date: 2013-11-24 19:35:40 +0000 (Sun, 24 Nov 2013) Log Message: ----------- location.hash returns '#' in ie mode if the location url ends with '#'; this fixes some more PageReloadTest's (ie) Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PageReloadTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-11-24 12:04:01 UTC (rev 8805) +++ trunk/htmlunit/src/changes/changes.xml 2013-11-24 19:35:40 UTC (rev 8806) @@ -8,6 +8,10 @@ <body> <release version="2.14" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + JavaScript: location.hash returns '#' in ie mode if the location url ends with '#' + (e.g. http://localhost/something/#). + </action> <action type="fix" dev="asashour"> CSS: correct behavior of setting a style value to null. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-11-24 12:04:01 UTC (rev 8805) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-11-24 19:35:40 UTC (rev 8806) @@ -1031,6 +1031,13 @@ JS_LOCATION_HASH_IS_DECODED, /** + * Property location.hash returns '#' for urls ending with a hash + * sign (e.g. http://localhost/something/#). + */ + @BrowserFeature(@WebBrowser(IE)) + JS_LOCATION_HASH_RETURNS_HASH_FOR_EMPTY_DEFINED, + + /** * Indicates if the String representation of a native function begins and ends with a \n. */ @BrowserFeature(@WebBrowser(value = IE, maxVersion = 9)) Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java 2013-11-24 12:04:01 UTC (rev 8805) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Location.java 2013-11-24 19:35:40 UTC (rev 8806) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.ANCHOR_EMPTY_HREF_NO_FILENAME; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_LOCATION_HASH_IS_DECODED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_LOCATION_HASH_RETURNS_HASH_FOR_EMPTY_DEFINED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.URL_ABOUT_BLANK_HAS_EMPTY_PATH; import java.io.IOException; @@ -273,7 +274,13 @@ hash = decodeHash(hash); } - if (!StringUtils.isEmpty(hash)) { + if (StringUtils.isEmpty(hash)) { + if (getBrowserVersion().hasFeature(JS_LOCATION_HASH_RETURNS_HASH_FOR_EMPTY_DEFINED) + && getHref().endsWith("#")) { + return "#"; + } + } + else { return "#" + hash; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PageReloadTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PageReloadTest.java 2013-11-24 12:04:01 UTC (rev 8805) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/PageReloadTest.java 2013-11-24 19:35:40 UTC (rev 8806) @@ -58,7 +58,6 @@ */ @Test @Alerts(DEFAULT = "", IE = "#") - @NotYetImplemented(Browser.IE) public void link_url_emptyHash() throws Exception { openUrlAndClickById(RELOAD_URL, "linkEmptyHash", 0, PATHNAME, getExpectedAlerts()[0]); } @@ -199,7 +198,6 @@ */ @Test @Alerts(DEFAULT = "", IE = "#") - @NotYetImplemented(Browser.IE) public void javascript_url_emptyHash() throws Exception { openUrlAndClickById(RELOAD_URL, "javascriptEmptyHash", 0, PATHNAME, getExpectedAlerts()[0]); } @@ -651,7 +649,6 @@ */ @Test @Alerts(DEFAULT = "", IE = "#") - @NotYetImplemented(Browser.IE) public void submitPost_url_emptyHash() throws Exception { openUrlAndClickById(RELOAD_URL, "submitPostEmptyHash", 1, PATHNAME, getExpectedAlerts()[0]); } @@ -661,7 +658,6 @@ */ @Test @Alerts(DEFAULT = "", IE = "#") - @NotYetImplemented(Browser.IE) public void submitPostV_url_emptyHash() throws Exception { openUrlAndClickById(RELOAD_URL, "submitPostEmptyHashV", 1, PATHNAME, getExpectedAlerts()[0]); } @@ -1238,7 +1234,6 @@ */ @Test @Alerts(DEFAULT = "", IE = "#") - @NotYetImplemented(Browser.IE) public void jsSubmitPost_url_EmptyHash() throws Exception { openUrlAndClickById(RELOAD_URL, "jsSubmitPostEmptyHash", 1, PATHNAME, getExpectedAlerts()[0]); } @@ -1248,7 +1243,6 @@ */ @Test @Alerts(DEFAULT = "", IE = "#") - @NotYetImplemented(Browser.IE) public void jsSubmitPostV_url_EmptyHash() throws Exception { openUrlAndClickById(RELOAD_URL, "jsSubmitPostEmptyHashV", 1, PATHNAME, getExpectedAlerts()[0]); } @@ -1528,6 +1522,7 @@ private String testPage() { return testPageHeader() + + testPageBody() + testPageAnchorPart() + testPageFormGetPart() + testPageFormPostPart(); @@ -1543,16 +1538,18 @@ + " </head>\n"; } - private String testPageAnchorPart() { + private String testPageBody() { return "<body>\n" + " <div id='locationPathname'></div>\n" + " <div id='locationHash'></div>\n" + " <input type='button' id='updateLocationInfo' value='updateLocationInfo' " + "onclick='document.getElementById(\"locationHash\").innerHTML=location.hash;" - + "document.getElementById(\"locationPathname\").innerHTML=location.pathname;'>\n" + + "document.getElementById(\"locationPathname\").innerHTML=location.pathname;'>\n"; + } - + " <a id='linkEmpty' href=''>linkEmpty</a>\n" + private String testPageAnchorPart() { + return " <a id='linkEmpty' href=''>linkEmpty</a>\n" + " <a id='linkEmptyHash' href='#'>linkEmptyHash</a>\n" + " <a id='linkHash' href='#anchor'>linkHash</a>\n" + " <a id='linkDifferentHash' href='#anchor2'>linkDifferentHash</a>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java 2013-11-24 12:04:01 UTC (rev 8805) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Location2Test.java 2013-11-24 19:35:40 UTC (rev 8806) @@ -211,6 +211,28 @@ @Test @Alerts(DEFAULT = "#<a>foobar</a>") public void hash() throws Exception { + checkHash(getDefaultUrl().toExternalForm() + "?#<a>foobar</a>"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "", IE = "#") + public void emptyHash() throws Exception { + checkHash(getDefaultUrl().toExternalForm() + "#"); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "") + public void noHash() throws Exception { + checkHash(getDefaultUrl().toExternalForm()); + } + + private void checkHash(final String url) throws Exception { final String html = "<html><body onload='test()'>\n" + "<script>\n" + "function test() {\n" @@ -220,7 +242,7 @@ + "</body></html>"; getMockWebConnection().setDefaultResponse(html); - loadPageWithAlerts2(html, new URL(getDefaultUrl().toExternalForm() + "?#<a>foobar</a>")); + loadPageWithAlerts2(html, new URL(url)); } /** |