test_bug1379762.html (2306B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id= 5 --> 6 <head> 7 <title>Test for Bug 1379762</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body onload="runTest()"> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1379762">Mozilla Bug 1379762</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 /** 20 * - This page opens new window 21 * - new window sends 'init' msg 22 * - onload() in new window sends 'increment_loadCount' msg 23 * - onpageshow() in new window sends 'increment_testCount' msg 24 * - This page sends 'forward_back' msg 25 * - onpageshow() in new window 'increment_testCount' 26 * - This page sends 'finish_test' msg 27 * - onpageshow() in new window sends 'finished' msg 28 */ 29 var testCount = 0; // Used by the test files. 30 var loadCount = 0; 31 var goneBack = false; 32 var bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug1379762"); 33 bc.onmessage = (messageEvent) => { 34 let message = messageEvent.data; 35 if (message == "init") { 36 is(testCount, 0, "new window should only be loaded once; otherwise the loadCount variable makes no sense"); 37 } else if (message == "increment_loadCount") { 38 loadCount++; 39 is(loadCount, 1, "Should only get one load") 40 } else if (message == 'increment_testCount') { 41 testCount++; 42 if (testCount == 1) { 43 bc.postMessage("forward_back"); 44 goneBack = true; 45 } else if (testCount == 2) { 46 ok(goneBack, "We had a chance to navigate backwards and forwards in the new window to test BFCache"); 47 bc.postMessage("finish_test"); 48 } 49 } else if (message == "finished") { 50 bc.close(); 51 SimpleTest.finish(); 52 } 53 } 54 55 SimpleTest.waitForExplicitFinish(); 56 57 function runTest() { 58 // If Fission is disabled, the pref is no-op. 59 SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => { 60 window.open("file_bug1379762-1.html", "", "width=360,height=480,noopener"); 61 }); 62 } 63 64 </script> 65 </pre> 66 </body> 67 </html>