|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=504220 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 504220</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body onload="run_test();"> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=504220">Mozilla Bug 504220</a> |
|
14 <p id="display"></p> |
|
15 <div id="content"> |
|
16 <iframe id="frame" style="height:100px; width:100px; border:0"></iframe> |
|
17 <div id="status" style="display: none"></div> |
|
18 </div> |
|
19 <pre id="test"> |
|
20 <script type="application/javascript;version=1.7"> |
|
21 |
|
22 /** Test for Bug 504220 **/ |
|
23 |
|
24 function run_test() { |
|
25 ok("onhashchange" in document.body, |
|
26 "document.body should contain 'onhashchange'."); |
|
27 |
|
28 ok("onhashchange" in window, "window should contain 'onhashchange'."); |
|
29 |
|
30 // window.onhashchange should mirror document.body.onhashchange. |
|
31 var func = function() { return 42; }; |
|
32 document.body.onhashchange = func; |
|
33 is(window.onhashchange, func); |
|
34 |
|
35 // Likewise, document.body.hashchange should mirror window.onhashchange |
|
36 numEvents = 0; |
|
37 var func2 = function() { numEvents++; gGen.next() }; |
|
38 window.onhashchange = func2; |
|
39 is(document.body.onhashchange, func2); |
|
40 |
|
41 SimpleTest.waitForExplicitFinish(); |
|
42 |
|
43 function waitForHashchange() { |
|
44 // Change the document's hash. If we've been running this test manually, |
|
45 // the hash might already be "#foo", so we need to check in order to be |
|
46 // sure we trigger a hashchange. |
|
47 if (location.hash != "#foo") |
|
48 location.hash = "#foo"; |
|
49 else |
|
50 location.hash = "#bar"; |
|
51 |
|
52 yield undefined; |
|
53 |
|
54 is(numEvents, 1, "Exactly one hashchange should have been fired."); |
|
55 SimpleTest.finish(); |
|
56 yield undefined; |
|
57 } |
|
58 |
|
59 var gGen = waitForHashchange(); |
|
60 gGen.next(); |
|
61 } |
|
62 |
|
63 </script> |
|
64 </pre> |
|
65 </body> |
|
66 </html> |