docshell/test/test_bfcache_plus_hash.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial