77 lines
2.6 KiB
HTML
77 lines
2.6 KiB
HTML
<html>
|
|
<head>
|
|
<script>
|
|
|
|
if (!window.sessionStorage) {
|
|
alert("This test needs sessionstorage to run properly");
|
|
location.href = "http://webkit.org/";
|
|
}
|
|
|
|
var targetNumberOfEventsForFirstTest = 8;
|
|
var targetNumberOfEventsForSecondTest = 10;
|
|
|
|
var testNumber = 1;
|
|
if (sessionStorage.totalEventsFired == targetNumberOfEventsForFirstTest)
|
|
testNumber = 2;
|
|
|
|
sessionStorage.clear();
|
|
sessionStorage.totalEventsFired = 0;
|
|
|
|
if (window.testRunner) {
|
|
testRunner.dumpAsText();
|
|
testRunner.waitUntilDone();
|
|
}
|
|
|
|
function startTest()
|
|
{
|
|
if (testNumber == 1) {
|
|
location.hash='#';
|
|
location.hash='#';
|
|
location.hash='#someHash';
|
|
location.hash='#';
|
|
location.hash='#';
|
|
location.hash='#someHash';
|
|
location.hash='#someHash';
|
|
location.hash='#';
|
|
} else if (testNumber == 2) {
|
|
location.hash='#someHash';
|
|
location.hash='#someHash';
|
|
location.hash='#';
|
|
location.hash='#someHash';
|
|
location.hash='#someHash';
|
|
location.hash='#';
|
|
location.hash='#';
|
|
location.hash='#someHash';
|
|
} else
|
|
alert("This shouldn't happen.");
|
|
}
|
|
|
|
var totalEventsFired = 0;
|
|
function hashChanged(eventHandlerName)
|
|
{
|
|
alert("Test number " + testNumber + ".\nhashchange event received by " + eventHandlerName + ".\nA total of " + ++sessionStorage.totalEventsFired + " events have been received.");
|
|
if (testNumber == 1 && sessionStorage.totalEventsFired == targetNumberOfEventsForFirstTest) {
|
|
location.hash="";
|
|
location.href=location.href.substr(0, location.href.length - 1);
|
|
}
|
|
if (testNumber == 2 && sessionStorage.totalEventsFired == targetNumberOfEventsForSecondTest && window.testRunner) {
|
|
testRunner.notifyDone();
|
|
sessionStorage.clear();
|
|
}
|
|
}
|
|
|
|
window.addEventListener("hashchange", function() { hashChanged('window-event-listener'); }, false);
|
|
|
|
</script>
|
|
</head>
|
|
<body onload="setTimeout('startTest();', 0);" onhashchange="hashChanged('body-onhashchange-attribute');">
|
|
This test checks to make sure the hashchange event is fired when the value of location.hash changes.<br>
|
|
This includes testing the transition from no fragment identifier to an empty fragment identifier *not* generating an event, as these cases are equivalent as far as location.hash is concerned.<br>
|
|
Clicking the links below manually should also result in the event being fired when the hash actually changes.<br>
|
|
<a href="#">Go to empty hash</a><br>
|
|
<a href="#someHash">Go to non-empty hash</a><br>
|
|
<a name="#">Empty hash anchor</a><br>
|
|
<a name="#someHash">Non-empty hash anchor</a>
|
|
</body>
|
|
</html>
|