@@ -1489,9 +1489,9 @@ public void reloadGetHashChanged() throws Exception {
14891489 @ Test
14901490 @ Alerts (DEFAULT = {"1" , "2" , "3" , "a.html?urlParam=urlVal" ,
14911491 "4" , "http://§§URL§§" , "http://§§URL§§/second/a.html?urlParam=urlVal" , "§§URL§§" },
1492- FF = {"1" , "2" , "2 " , "a.html?urlParam=urlVal" ,
1492+ FF = {"1" , "2" , "3 " , "a.html?urlParam=urlVal" ,
14931493 "4" , "http://§§URL§§" , "http://§§URL§§/" , "§§URL§§" },
1494- FF_ESR = {"1" , "2" , "2 " , "a.html?urlParam=urlVal" ,
1494+ FF_ESR = {"1" , "2" , "3 " , "a.html?urlParam=urlVal" ,
14951495 "4" , "http://§§URL§§" , "http://§§URL§§/" , "§§URL§§" })
14961496 public void reloadPost () throws Exception {
14971497 final String form = DOCTYPE_HTML
@@ -1691,4 +1691,82 @@ public void ownPropertyDescriptor() throws Exception {
16911691 expandExpectedAlertsVariables (URL_FIRST );
16921692 loadPageVerifyTitle2 (html );
16931693 }
1694+
1695+ /**
1696+ * Verifies that modifying <tt>window.location.hash</tt> works, but that it doesn't
1697+ * force the page to reload from the server. This is very important for the Dojo
1698+ * unit tests, which will keep reloading themselves if the page gets reloaded.
1699+ *
1700+ * @throws Exception if the test fails
1701+ */
1702+ @ Test
1703+ @ Alerts ({"" , "#b" })
1704+ public void setHash () throws Exception {
1705+ final String html = DOCTYPE_HTML
1706+ + "<html><head>\n "
1707+ + "<script>\n "
1708+ + LOG_TITLE_FUNCTION
1709+ + "</script>\n "
1710+ + "</head>\n "
1711+ + "<body>\n "
1712+ + "<a id='a' onclick='log(location.hash);location.hash=\" b\" ;log(location.hash);'>go</a>\n "
1713+ + "<h2 id='b'>...</h2>\n "
1714+ + "</body>\n "
1715+ + "</html>" ;
1716+
1717+ final WebDriver driver = loadPage2 (html );
1718+ driver .findElement (By .id ("a" )).click ();
1719+
1720+ verifyTitle2 (driver , getExpectedAlerts ());
1721+
1722+ assertEquals (URL_FIRST , getMockWebConnection ().getLastWebRequest ().getUrl ());
1723+ assertEquals (1 , getMockWebConnection ().getRequestCount ());
1724+ }
1725+
1726+ /**
1727+ * @throws Exception if the test fails
1728+ */
1729+ @ Test
1730+ @ Alerts ("§§URL§§#newHash" )
1731+ public void setHashUpdatesPageUrl () throws Exception {
1732+ final String html = DOCTYPE_HTML
1733+ + "<html><head>\n "
1734+ + "<script>\n "
1735+ + LOG_TITLE_FUNCTION
1736+ + "</script>\n "
1737+ + "</head>\n "
1738+ + "<body>\n "
1739+ + "<a id='a' onclick='location.hash=\" newHash\" '>go</a>'>go</a>\n "
1740+ + "</body>\n "
1741+ + "</html>" ;
1742+
1743+ final WebDriver driver = loadPage2 (html );
1744+ driver .findElement (By .id ("a" )).click ();
1745+
1746+ expandExpectedAlertsVariables (URL_FIRST );
1747+
1748+ assertEquals (getExpectedAlerts ()[0 ], driver .getCurrentUrl ());
1749+ assertEquals (1 , getMockWebConnection ().getRequestCount ());
1750+ }
1751+
1752+ /**
1753+ * @throws Exception if the test fails
1754+ */
1755+ @ Test
1756+ @ Alerts ({"about:blank" , "about:blank#foo" , "about:blank#foo" })
1757+ public void setHashAboutBlank () throws Exception {
1758+ WebDriver driver = getWebDriver ();
1759+ driver .get ("about:blank" );
1760+
1761+ assertEquals (getExpectedAlerts ()[0 ], driver .getCurrentUrl ());
1762+ assertEquals (0 , getMockWebConnection ().getRequestCount ());
1763+
1764+ ((JavascriptExecutor ) driver ).executeScript ("location.hash = 'foo'" );
1765+ assertEquals (getExpectedAlerts ()[1 ], driver .getCurrentUrl ());
1766+ assertEquals (0 , getMockWebConnection ().getRequestCount ());
1767+
1768+ driver .navigate ().refresh ();
1769+ assertEquals (getExpectedAlerts ()[2 ], driver .getCurrentUrl ());
1770+ assertEquals (0 , getMockWebConnection ().getRequestCount ());
1771+ }
16941772}
0 commit comments