Bumping manifests a=b2g-bump
[gecko.git] / docshell / test / test_bfcache_plus_hash.html
blob30c0b6b50291d671eaa07c3c3df75486895f24b2
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">
17 </div>
18 <pre id="test">
19 <script type="application/javascript;version=1.7">
21 /** Test for Bug 646641 **/
23 /*
24 * In a popup (because navigating the main frame confuses Mochitest), do the
25 * following:
27 * * Call history.pushState().
28 * * Navigate to a new page.
29 * * Go back two history entries.
31 * Check that we go back, we retrieve the document from bfcache.
34 SimpleTest.waitForExplicitFinish();
36 function debug(msg) {
37 // Wrap dump so we can turn debug messages on and off easily.
38 dump(msg + '\n');
41 var expectedLoadNum = -1;
42 function childLoad(n) {
43 if (n == expectedLoadNum) {
44 debug('Got load ' + n);
45 expectedLoadNum = -1;
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.
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);
55 else {
56 debug('Got unexpected load ' + n);
57 ok(false, 'Got unexpected load ' + n);
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);
69 else {
70 debug('Got pageshow ' + n);
73 // Since a pageshow comes along with an onload, don't fail the test if we get
74 // an unexpected pageshow.
77 function waitForLoad(n) {
78 debug('Waiting for load ' + n);
79 expectedLoadNum = n;
82 function waitForShow(n) {
83 debug('Waiting for show ' + n);
84 expectedPageshowNum = n;
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;
96 popup.history.pushState('', '', '');
98 popup.location = 'data:text/html,<html><body onload="opener.childLoad(2)">Popup 2</body></html>';
99 waitForLoad(2);
100 yield undefined;
102 // Now go back 2. The first page should be retrieved from bfcache.
103 popup.history.go(-2);
104 waitForShow(1);
105 yield undefined;
107 popup.close();
108 SimpleTest.finish();
110 // Yield once more so we don't throw a StopIteration exception.
111 yield undefined;
114 var gGen = test();
115 gGen.next();
117 </script>
118 </pre>
119 </body>
120 </html>