|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=646641 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 646641</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=646641">Mozilla Bug 646641</a> |
|
14 <p id="display"></p> |
|
15 <div id="content" style="display: none"> |
|
16 |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script type="application/javascript;version=1.7"> |
|
20 |
|
21 /** Test for Bug 646641 **/ |
|
22 |
|
23 /* |
|
24 * In a popup (because navigating the main frame confuses Mochitest), do the |
|
25 * following: |
|
26 * |
|
27 * * Call history.pushState(). |
|
28 * * Navigate to a new page. |
|
29 * * Go back two history entries. |
|
30 * |
|
31 * Check that we go back, we retrieve the document from bfcache. |
|
32 */ |
|
33 |
|
34 SimpleTest.waitForExplicitFinish(); |
|
35 |
|
36 function debug(msg) { |
|
37 // Wrap dump so we can turn debug messages on and off easily. |
|
38 dump(msg + '\n'); |
|
39 } |
|
40 |
|
41 var expectedLoadNum = -1; |
|
42 function childLoad(n) { |
|
43 if (n == expectedLoadNum) { |
|
44 debug('Got load ' + n); |
|
45 expectedLoadNum = -1; |
|
46 |
|
47 // Spin the event loop before calling gGen.next() so the generator runs |
|
48 // outside the onload handler. This prevents us from encountering all |
|
49 // sorts of docshell quirks. |
|
50 // |
|
51 // (I don't know why I need to wrap gGen.next() in a function, but it |
|
52 // throws an error otherwise.) |
|
53 setTimeout(function() { gGen.next() }, 0); |
|
54 } |
|
55 else { |
|
56 debug('Got unexpected load ' + n); |
|
57 ok(false, 'Got unexpected load ' + n); |
|
58 } |
|
59 } |
|
60 |
|
61 var expectedPageshowNum = -1; |
|
62 function childPageshow(n) { |
|
63 if (n == expectedPageshowNum) { |
|
64 debug('Got expected pageshow ' + n); |
|
65 expectedPageshowNum = -1; |
|
66 ok(true, 'Got expected pageshow ' + n); |
|
67 setTimeout(function() { gGen.next() }, 0); |
|
68 } |
|
69 else { |
|
70 debug('Got pageshow ' + n); |
|
71 } |
|
72 |
|
73 // Since a pageshow comes along with an onload, don't fail the test if we get |
|
74 // an unexpected pageshow. |
|
75 } |
|
76 |
|
77 function waitForLoad(n) { |
|
78 debug('Waiting for load ' + n); |
|
79 expectedLoadNum = n; |
|
80 } |
|
81 |
|
82 function waitForShow(n) { |
|
83 debug('Waiting for show ' + n); |
|
84 expectedPageshowNum = n; |
|
85 } |
|
86 |
|
87 function test() { |
|
88 var popup = window.open('data:text/html,' + |
|
89 '<html><body onload="opener.childLoad(1)" ' + |
|
90 'onpageshow="opener.childPageshow(1)">' + |
|
91 'Popup 1' + |
|
92 '</body></html>'); |
|
93 waitForLoad(1); |
|
94 yield undefined; |
|
95 |
|
96 popup.history.pushState('', '', ''); |
|
97 |
|
98 popup.location = 'data:text/html,<html><body onload="opener.childLoad(2)">Popup 2</body></html>'; |
|
99 waitForLoad(2); |
|
100 yield undefined; |
|
101 |
|
102 // Now go back 2. The first page should be retrieved from bfcache. |
|
103 popup.history.go(-2); |
|
104 waitForShow(1); |
|
105 yield undefined; |
|
106 |
|
107 popup.close(); |
|
108 SimpleTest.finish(); |
|
109 |
|
110 // Yield once more so we don't throw a StopIteration exception. |
|
111 yield undefined; |
|
112 } |
|
113 |
|
114 var gGen = test(); |
|
115 gGen.next(); |
|
116 |
|
117 </script> |
|
118 </pre> |
|
119 </body> |
|
120 </html> |