test_bug607529.html (3326B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=607529 5 --> 6 <head> 7 <title>Test for Bug 607529</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> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=607529">Mozilla Bug 607529</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 SimpleTest.waitForExplicitFinish(); 20 21 /* General idea: Open a new window (needed because we don't bfcache 22 subframes) that uses requestAnimationFrame, navigate it, navigate it 23 back, and verify that the animations are still running. */ 24 25 function executeTest() { 26 /** Test for Bug 607529 */ 27 var doneOneLoad = false; 28 var done = false; 29 var bc = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug607529"); 30 var bc_1 = SpecialPowers.wrap(BroadcastChannel).unpartitionedTestingChannel("bug607529_1"); 31 bc.onmessage = (msgEvent) => { 32 var msg = msgEvent.data; 33 isnot(msg, "notcached", "Should never end up not being cached"); 34 if (msg == "loaded") { 35 if (!doneOneLoad) { 36 doneOneLoad = true; 37 bc.postMessage("navigateToPage"); 38 } else { 39 // This is unexpected, but it can happen on Android, probably when 40 // bfcache gets purged due to memory pressure. Hence, "soft fail" there. 41 var message = "onload handler shouldn't fire on restore from bfcache"; 42 if (navigator.appVersion.includes("Android")) { 43 todo(false, message); 44 } else { 45 ok(false, message); 46 } 47 // In any case, more messages aren't coming, so finish up. 48 closeWindowAndFinish(); 49 } 50 } 51 else if (msg == "revived") { 52 bc.postMessage("report"); 53 } 54 else if (msg == "callbackHappened") { 55 // We might get this message more than once, if the other page queues up 56 // more than one callbackHappened message before we manage to close it. 57 // Protect against calling SimpleTest.finish() more than once. 58 if (!done) { 59 closeWindowAndFinish(); 60 done = true; 61 } 62 } else if (msg == "closed") { 63 bc.close(); 64 bc_1.close(); 65 SimpleTest.finish(); 66 } else { 67 try { 68 var jsonMsg = JSON.parse(msg); 69 } catch (ex) { 70 // In case JSON.parse throws, we pause to print the string that it 71 // choked on, and then resume throwing the exception. 72 ok(false, "JSON.parse threw, when passed string '" + jsonMsg + "'"); 73 throw ex; 74 } 75 if (jsonMsg.error) { 76 window.onerror(jsonMsg.msg, jsonMsg.url, jsonMsg.line); 77 } 78 } 79 } 80 bc_1.onmessage = (msgEvent) => { 81 if (msgEvent.data == "goback") { 82 bc_1.postMessage("navigateBack"); 83 } 84 } 85 function closeWindowAndFinish() { 86 bc.postMessage("close"); 87 } 88 89 // If Fission is disabled, the pref is no-op. 90 SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => { 91 window.open("file_bug607529.html", "", "noopener"); 92 }); 93 } 94 95 96 executeTest(); 97 98 99 </script> 100 </pre> 101 </body> 102 </html>