|
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 var gState = null; |
|
27 |
|
28 window.addEventListener("popstate", function(aEvent) { |
|
29 gState = aEvent.state; |
|
30 }, false); |
|
31 |
|
32 function waitForLoad(aCallback) { |
|
33 function listener() { |
|
34 gFrame.removeEventListener("load", listener, false); |
|
35 SimpleTest.executeSoon(aCallback); |
|
36 } |
|
37 |
|
38 gFrame.addEventListener("load", listener, false); |
|
39 } |
|
40 |
|
41 function loadContent(aURL, aCallback) { |
|
42 waitForLoad(aCallback); |
|
43 |
|
44 gFrame.src = aURL; |
|
45 } |
|
46 |
|
47 function getURL() { |
|
48 return gFrame.contentDocument.documentURI; |
|
49 } |
|
50 |
|
51 function getContent() { |
|
52 return gFrame.contentDocument.getElementById("text").textContent; |
|
53 } |
|
54 |
|
55 var START = "data:text/html,<p%20id='text'>Start</p>"; |
|
56 var URL1 = "data:text/html,<p%20id='text'>Test1</p>"; |
|
57 var URL2 = "data:text/html,<p%20id='text'>Test2</p>"; |
|
58 |
|
59 function run_test() { |
|
60 window.history.pushState("START", window.location); |
|
61 |
|
62 gFrame = document.getElementById("iframe"); |
|
63 |
|
64 test_basic_inner_navigation(); |
|
65 } |
|
66 |
|
67 function end_test() { |
|
68 testWin.done(); |
|
69 } |
|
70 |
|
71 function test_basic_inner_navigation() { |
|
72 // Navigate the inner frame a few times |
|
73 loadContent(URL1, function() { |
|
74 is(getURL(), URL1, "URL should be correct"); |
|
75 is(getContent(), "Test1", "Page should be correct"); |
|
76 |
|
77 loadContent(URL2, function() { |
|
78 is(getURL(), URL2, "URL should be correct"); |
|
79 is(getContent(), "Test2", "Page should be correct"); |
|
80 |
|
81 // Test that history is working |
|
82 waitForLoad(function() { |
|
83 is(getURL(), URL1, "URL should be correct"); |
|
84 is(getContent(), "Test1", "Page should be correct"); |
|
85 |
|
86 waitForLoad(function() { |
|
87 is(getURL(), URL2, "URL should be correct"); |
|
88 is(getContent(), "Test2", "Page should be correct"); |
|
89 |
|
90 test_state_navigation(); |
|
91 }); |
|
92 window.history.forward(); |
|
93 }); |
|
94 window.history.back(); |
|
95 }); |
|
96 }); |
|
97 } |
|
98 |
|
99 function test_state_navigation() { |
|
100 window.history.pushState("STATE1", window.location); |
|
101 |
|
102 is(getURL(), URL2, "URL should be correct"); |
|
103 is(getContent(), "Test2", "Page should be correct"); |
|
104 |
|
105 window.history.pushState("STATE2", window.location); |
|
106 |
|
107 is(getURL(), URL2, "URL should be correct"); |
|
108 is(getContent(), "Test2", "Page should be correct"); |
|
109 |
|
110 window.history.back(); |
|
111 |
|
112 is(gState, "STATE1", "State should be correct"); |
|
113 is(getURL(), URL2, "URL should be correct"); |
|
114 is(getContent(), "Test2", "Page should be correct"); |
|
115 |
|
116 window.history.forward(); |
|
117 |
|
118 is(gState, "STATE2", "State should be correct"); |
|
119 is(getURL(), URL2, "URL should be correct"); |
|
120 is(getContent(), "Test2", "Page should be correct"); |
|
121 |
|
122 window.history.back(); |
|
123 window.history.back(); |
|
124 |
|
125 is(gState, "START", "State should be correct"); |
|
126 is(getURL(), URL2, "URL should be correct"); |
|
127 is(getContent(), "Test2", "Page should be correct"); |
|
128 |
|
129 waitForLoad(function() { |
|
130 is(getURL(), URL1, "URL should be correct"); |
|
131 is(getContent(), "Test1", "Page should be correct"); |
|
132 |
|
133 waitForLoad(function() { |
|
134 is(gState, "START", "State should be correct"); |
|
135 is(getURL(), START, "URL should be correct"); |
|
136 is(getContent(), "Start", "Page should be correct"); |
|
137 |
|
138 end_test(); |
|
139 }); |
|
140 |
|
141 window.history.back(); |
|
142 |
|
143 is(gState, "START", "State should be correct"); |
|
144 }); |
|
145 |
|
146 window.history.back(); |
|
147 is(gState, "START", "State should be correct"); |
|
148 } |
|
149 </script> |
|
150 </pre> |
|
151 </body> |
|
152 </html> |