test_bfcache_plus_hash.html (3684B)
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 src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script 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"> 20 21 /** Test for Bug 646641 */ 22 23 /** 24 * Steps: 25 * - Main page (this one) opens file_bfcache_plus_hash_1.html (subpage 1) 26 * - subpage 1 sends msg { "childLoad", 1 } 27 * - subpage 1 sends msg { "childPageshow", 1 } 28 * - main page sends message "pushState" 29 * - subpage 1 does pushState() 30 * - subpage 1 navigates to file_bfcache_plus_hash_2.html (subpage 2) 31 * - subpage 2 sends msg { "childLoad", 2 } 32 * - subpage 2 sends msg { "childPageshow", 2 } 33 * - main page sends msg "go-2" 34 * - subpage 2 goes back two history entries 35 * - subpage 1 sends msg { "childPageshow", 1 } 36 * - Receiving only this msg shows we have retrieved the document from bfcache 37 * - main page sends msg "close" 38 * - subpage 1 sends msg "closed" 39 */ 40 SimpleTest.waitForExplicitFinish(); 41 42 function debug(msg) { 43 // Wrap dump so we can turn debug messages on and off easily. 44 dump(msg + "\n"); 45 } 46 47 var expectedLoadNum = -1; 48 var expectedPageshowNum = -1; 49 50 function waitForLoad(n) { 51 debug("Waiting for load " + n); 52 expectedLoadNum = n; 53 } 54 55 function waitForShow(n) { 56 debug("Waiting for show " + n); 57 expectedPageshowNum = n; 58 } 59 60 61 62 function executeTest() { 63 function* test() { 64 window.open("file_bfcache_plus_hash_1.html", "", "noopener"); 65 waitForLoad(1); 66 waitForShow(1); 67 yield undefined; 68 yield undefined; 69 70 bc1.postMessage("pushState"); 71 72 waitForLoad(2); 73 waitForShow(2); 74 yield undefined; 75 yield undefined; 76 77 // Now go back 2. The first page should be retrieved from bfcache. 78 bc2.postMessage("go-2"); 79 waitForShow(1); 80 yield undefined; 81 82 bc1.postMessage("close"); 83 } 84 85 var bc1 = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug646641_1"); 86 var bc2 = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug646641_2"); 87 bc1.onmessage = (msgEvent) => { 88 var msg = msgEvent.data.message; 89 var n = msgEvent.data.num; 90 if (msg == "childLoad") { 91 if (n == expectedLoadNum) { 92 debug("Got load " + n); 93 expectedLoadNum = -1; 94 95 // Spin the event loop before calling gGen.next() so the generator runs 96 // outside the onload handler. This prevents us from encountering all 97 // sorts of docshell quirks. 98 setTimeout(function() { gGen.next(); }, 0); 99 } else { 100 debug("Got unexpected load " + n); 101 ok(false, "Got unexpected load " + n); 102 } 103 } else if (msg == "childPageshow") { 104 if (n == expectedPageshowNum) { 105 debug("Got expected pageshow " + n); 106 expectedPageshowNum = -1; 107 ok(true, "Got expected pageshow " + n); 108 setTimeout(function() { gGen.next(); }, 0); 109 } else { 110 debug("Got unexpected pageshow " + n); 111 ok(false, "Got unexpected pageshow " + n); 112 } 113 } else if (msg == "closed") { 114 bc1.close(); 115 bc2.close(); 116 SimpleTest.finish(); 117 } 118 } 119 120 bc2.onmessage = bc1.onmessage; 121 122 var gGen = test(); 123 124 // If Fission is disabled, the pref is no-op. 125 SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => { 126 gGen.next(); 127 }); 128 } 129 130 executeTest(); 131 132 133 </script> 134 </pre> 135 </body> 136 </html>