4 https://bugzilla.mozilla.org/show_bug.cgi?id=646641
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"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=646641">Mozilla Bug
646641</a>
15 <div id=
"content" style=
"display: none">
19 <script type=
"application/javascript;version=1.7">
21 /** Test for Bug
646641 **/
24 * In a popup (because navigating the main frame confuses Mochitest), do the
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();
37 // Wrap dump so we can turn debug messages on and off easily.
41 var expectedLoadNum = -
1;
42 function childLoad(n) {
43 if (n == expectedLoadNum) {
44 debug('Got load ' + n);
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);
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);
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);
82 function waitForShow(n) {
83 debug('Waiting for show ' + n);
84 expectedPageshowNum = n;
88 var popup = window.open('data:text/html,' +
89 '
<html><body onload=
"opener.childLoad(1)" ' +
90 '
onpageshow=
"opener.childPageshow(1)">' +
96 popup.history.pushState('', '', '');
98 popup.location = 'data:text/html,
<html><body onload=
"opener.childLoad(2)">Popup
2</body></html>';
102 // Now go back
2. The first page should be retrieved from bfcache.
103 popup.history.go(-
2);
110 // Yield once more so we don't throw a StopIteration exception.