4 function print(message
, color
)
6 var paragraph
= document
.createElement("div");
7 paragraph
.appendChild(document
.createTextNode(message
));
8 paragraph
.style
.fontFamily
= "monospace";
10 paragraph
.style
.color
= color
;
11 document
.getElementById("console").appendChild(paragraph
);
14 function shouldBe(a
, b
)
18 print("PASS: " + a
+ " should be " + b
+ " and is.", "green");
20 print("FAIL: " + a
+ " should be " + b
+ " but instead is " + evalA
+ ".", "red");
29 shouldBe('window.history.length == originalHistoryLength', true);
30 shouldBe('window.location.hash', '');
31 window
.location
.hash
= 'foo';
32 shouldBe('window.location.hash', '#foo');
33 shouldBe("window.location == originalLocation + '#foo'", true);
34 shouldBe('window.history.length == originalHistoryLength + 1', true);
35 // hashchange will jump to the next step.
38 window
.location
.hash
= 'bar';
39 shouldBe('window.location.hash', '#bar');
40 shouldBe("window.location == originalLocation + '#bar'", true);
41 shouldBe('window.history.length == originalHistoryLength + 2', true);
42 // hashchange will jump to the next step.
45 window
.location
.hash
= 'bar';
46 shouldBe('window.location.hash', '#bar');
47 shouldBe("window.location == originalLocation + '#bar'", true);
48 shouldBe('window.history.length == originalHistoryLength + 2', true);
49 step(); // No hashchange.
52 shouldBe('window.location.hash', '#bar');
53 shouldBe("window.location == originalLocation + '#bar'", true);
54 window
.history
.back();
55 // history.back() is asychronous, location should be unchanged
56 shouldBe('window.location.hash', '#bar');
57 shouldBe("window.location == originalLocation + '#bar'", true);
58 // hashchange will jump to the next step.
61 shouldBe('window.location.hash', '#foo');
62 shouldBe("window.location == originalLocation + '#foo'", true);
63 window
.history
.back();
64 // history.back() is asychronous, location should be unchanged
65 shouldBe('window.location.hash', '#foo');
66 shouldBe("window.location == originalLocation + '#foo'", true);
67 // hashchange will jump to the next step.
70 shouldBe('window.location.hash', '');
71 shouldBe("window.location == originalLocation", true);
72 window
.history
.forward();
73 // history.forward() is asychronous, location should be unchanged
74 shouldBe('window.location.hash', '');
75 shouldBe("window.location == originalLocation", true);
76 // hashchange will jump to the next step.
79 shouldBe('window.location.hash', '#foo');
80 shouldBe("window.location == originalLocation + '#foo'", true);
81 window
.location
.hash
= '';
82 shouldBe('window.location.hash', '');
83 shouldBe("window.location == originalLocation + '#'", true);
84 window
.location
.hash
= '#';
85 shouldBe('window.location.hash', '');
86 shouldBe("window.location == originalLocation + '#'", true);
88 print("SUCCESS!", "green")
90 print("FAILURE: one or more tests failed", "red");
92 if (window
.testRunner
)
93 testRunner
.notifyDone();
100 if (window
.testRunner
) {
101 testRunner
.clearBackForwardList();
102 testRunner
.dumpAsText();
103 testRunner
.waitUntilDone();
108 originalLocation
= window
.location
.href
;
109 originalHistoryLength
= window
.history
.length
;
111 window
.onhashchange
= step
;
113 // Location changes need to happen outside the onload handler to generate history entries.
118 <body onload=
"runTests();">
119 <p>This tests that modifying location.hash works as it should
</p>