test_bug1121701.html (3636B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1121701 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1121701</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 /** Test for Bug 1121701 */ 14 SimpleTest.waitForExplicitFinish(); 15 16 var testUrl1 = "file_bug1121701_1.html"; 17 var testUrl2 = "file_bug1121701_2.html"; 18 19 var page1LoadCount = 0; 20 let page1Done = {}; 21 page1Done.promise = new Promise(resolve => { 22 page1Done.resolve = resolve; 23 }); 24 let page2Done = {}; 25 page2Done.promise = new Promise(resolve => { 26 page2Done.resolve = resolve; 27 }); 28 29 addLoadEvent(async function() { 30 31 // Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5) 32 // Acquire storage access permission here so that the BroadcastChannel used to 33 // communicate with the opened windows works in xorigin tests. Otherwise, 34 // the iframe containing this page is isolated from first-party storage access, 35 // which isolates BroadcastChannel communication. 36 if (isXOrigin) { 37 await SpecialPowers.pushPrefEnv({ 38 set: [["privacy.partition.always_partition_third_party_non_cookie_storage", false]], 39 }); 40 SpecialPowers.wrap(document).notifyUserGestureActivation(); 41 await SpecialPowers.addPermission("storageAccessAPI", true, window.location.href); 42 await SpecialPowers.wrap(document).requestStorageAccess(); 43 } 44 45 var bc = new BroadcastChannel("file_bug1121701_1"); 46 var bc2 = new BroadcastChannel("file_bug1121701_2"); 47 48 async function scheduleFinish() { 49 await Promise.all([page1Done.promise, page2Done.promise]); 50 bc2.close(); 51 bc.close(); 52 SimpleTest.finish(); 53 } 54 55 bc.onmessage = (msgEvent) => { 56 var msg = msgEvent.data; 57 var command = msg.command; 58 if (command == "child1PageShow") { 59 ++page1LoadCount; 60 var persisted = msg.persisted; 61 var pageHideAsserts = msg.pageHideAsserts; 62 if (pageHideAsserts) { 63 ok(pageHideAsserts.persisted, "onpagehide: test page 1 should get persisted"); 64 is(pageHideAsserts.innerHTML, "modified", "onpagehide: innerHTML text is 'modified'"); 65 } 66 if (page1LoadCount == 1) { 67 SimpleTest.executeSoon(function() { 68 is(persisted, false, "Initial page load shouldn't be persisted."); 69 bc.postMessage({command: "setInnerHTML", testUrl2}); 70 }); 71 } else if (page1LoadCount == 2) { 72 is(persisted, true, "Page load from bfcache should be persisted."); 73 is(msg.innerHTML, "modified", "innerHTML text is 'modified'"); 74 bc.postMessage({command: "close"}); 75 } 76 } else if (command == "closed") { 77 page1Done.resolve(); 78 } 79 } 80 bc2.onmessage = (msgEvent) => { 81 var msg = msgEvent.data; 82 var command = msg.command; 83 if (command == "child2PageShow") { 84 bc2.postMessage({command: "setInnerHTML", location: location.href}); 85 } else if (command == "onmessage") { 86 page2Done.resolve(); 87 } 88 } 89 90 scheduleFinish(); 91 // If Fission is disabled, the pref is no-op. 92 SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => { 93 window.open(testUrl1, "", "noopener"); 94 }); 95 }); 96 97 </script> 98 </head> 99 <body> 100 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1121701">Mozilla Bug 1121701</a> 101 <p id="display"></p> 102 <div id="content" style="display: none"> 103 104 </div> 105 <pre id="test"> 106 </pre> 107 </body> 108 </html>