|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=602256 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 602256</title> |
|
8 </head> |
|
9 <body onload="SimpleTest.executeSoon(run_test)"> |
|
10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=602256">Mozilla Bug 602256</a> |
|
11 <div id="content"> |
|
12 <iframe id="iframe" src="data:text/html,<p%20id='text'>Start</p>"></iframe> |
|
13 </div> |
|
14 <pre id="test"> |
|
15 <script type="application/javascript"> |
|
16 |
|
17 /** Test for Bug 602256 **/ |
|
18 |
|
19 var testWin = window.opener ? window.opener : window.parent; |
|
20 |
|
21 var SimpleTest = testWin.SimpleTest; |
|
22 function is() { testWin.is.apply(testWin, arguments); } |
|
23 |
|
24 var gFrame = null; |
|
25 |
|
26 function gState() { |
|
27 return location.hash.replace(/^#/, ""); |
|
28 } |
|
29 |
|
30 function waitForLoad(aCallback) { |
|
31 function listener() { |
|
32 gFrame.removeEventListener("load", listener, false); |
|
33 SimpleTest.executeSoon(aCallback); |
|
34 } |
|
35 |
|
36 gFrame.addEventListener("load", listener, false); |
|
37 } |
|
38 |
|
39 function loadContent(aURL, aCallback) { |
|
40 waitForLoad(aCallback); |
|
41 |
|
42 gFrame.src = aURL; |
|
43 } |
|
44 |
|
45 function getURL() { |
|
46 return gFrame.contentDocument.documentURI; |
|
47 } |
|
48 |
|
49 function getContent() { |
|
50 return gFrame.contentDocument.getElementById("text").textContent; |
|
51 } |
|
52 |
|
53 var START = "data:text/html,<p%20id='text'>Start</p>"; |
|
54 var URL1 = "data:text/html,<p%20id='text'>Test1</p>"; |
|
55 var URL2 = "data:text/html,<p%20id='text'>Test2</p>"; |
|
56 |
|
57 function run_test() { |
|
58 window.location.hash = "START"; |
|
59 |
|
60 gFrame = document.getElementById("iframe"); |
|
61 |
|
62 test_basic_inner_navigation(); |
|
63 } |
|
64 |
|
65 function end_test() { |
|
66 testWin.done(); |
|
67 } |
|
68 |
|
69 function test_basic_inner_navigation() { |
|
70 // Navigate the inner frame a few times |
|
71 loadContent(URL1, function() { |
|
72 is(getURL(), URL1, "URL should be correct"); |
|
73 is(getContent(), "Test1", "Page should be correct"); |
|
74 |
|
75 loadContent(URL2, function() { |
|
76 is(getURL(), URL2, "URL should be correct"); |
|
77 is(getContent(), "Test2", "Page should be correct"); |
|
78 |
|
79 // Test that history is working |
|
80 waitForLoad(function() { |
|
81 is(getURL(), URL1, "URL should be correct"); |
|
82 is(getContent(), "Test1", "Page should be correct"); |
|
83 |
|
84 waitForLoad(function() { |
|
85 is(getURL(), URL2, "URL should be correct"); |
|
86 is(getContent(), "Test2", "Page should be correct"); |
|
87 |
|
88 test_state_navigation(); |
|
89 }); |
|
90 window.history.forward(); |
|
91 }); |
|
92 window.history.back(); |
|
93 }); |
|
94 }); |
|
95 } |
|
96 |
|
97 function test_state_navigation() { |
|
98 window.location.hash = "STATE1"; |
|
99 |
|
100 is(getURL(), URL2, "URL should be correct"); |
|
101 is(getContent(), "Test2", "Page should be correct"); |
|
102 |
|
103 window.location.hash = "STATE2"; |
|
104 |
|
105 is(getURL(), URL2, "URL should be correct"); |
|
106 is(getContent(), "Test2", "Page should be correct"); |
|
107 |
|
108 window.history.back(); |
|
109 |
|
110 is(gState(), "STATE1", "State should be correct after going back"); |
|
111 is(getURL(), URL2, "URL should be correct"); |
|
112 is(getContent(), "Test2", "Page should be correct"); |
|
113 |
|
114 window.history.forward(); |
|
115 |
|
116 is(gState(), "STATE2", "State should be correct after going forward"); |
|
117 is(getURL(), URL2, "URL should be correct"); |
|
118 is(getContent(), "Test2", "Page should be correct"); |
|
119 |
|
120 window.history.back(); |
|
121 window.history.back(); |
|
122 |
|
123 is(gState(), "START", "State should be correct"); |
|
124 is(getURL(), URL2, "URL should be correct"); |
|
125 is(getContent(), "Test2", "Page should be correct"); |
|
126 |
|
127 waitForLoad(function() { |
|
128 is(getURL(), URL1, "URL should be correct"); |
|
129 is(getContent(), "Test1", "Page should be correct"); |
|
130 |
|
131 waitForLoad(function() { |
|
132 is(gState(), "START", "State should be correct"); |
|
133 is(getURL(), START, "URL should be correct"); |
|
134 is(getContent(), "Start", "Page should be correct"); |
|
135 |
|
136 end_test(); |
|
137 }); |
|
138 |
|
139 window.history.back(); |
|
140 |
|
141 is(gState(), "START", "State should be correct after going back twice"); |
|
142 }); |
|
143 |
|
144 window.history.back(); |
|
145 is(gState(), "START", "State should be correct"); |
|
146 } |
|
147 </script> |
|
148 </pre> |
|
149 </body> |
|
150 </html> |