file_zoom_restore_bfcache.html (3707B)
1 <!doctype html> 2 <script> 3 var bcName = "zoomRestoreBfcache" + window.location.search; 4 var bc = new BroadcastChannel(bcName); 5 if (window.location.search == "?2") { 6 bc.onmessage = (msgEvent) => { 7 var msg = msgEvent.data; 8 var command = msg.command; 9 dump(`Subpage ?2 received command=${command}\n`); 10 switch (command) { 11 case "case2sendData": { 12 bc.postMessage({command: "case2data", devicePixelRatio: window.devicePixelRatio, 13 frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio}); 14 break; 15 } 16 case "case2action": { 17 SpecialPowers.spawnChrome([], () => { 18 const FullZoom = this.browsingContext.embedderElement.ownerGlobal.FullZoom; 19 FullZoom.setZoom(2.0); 20 }); 21 SpecialPowers.setFullZoom(window, 2); 22 window.requestAnimationFrame(() => window.requestAnimationFrame(() => { 23 bc.postMessage({command: "case2dataAnimationFrame", devicePixelRatio: window.devicePixelRatio, 24 frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio }); 25 })); 26 break; 27 } 28 case "case2back": { 29 bc.close(); 30 window.history.back(); 31 break; 32 } 33 } 34 } 35 } else { 36 bc.onmessage = (msgEvent) => { 37 var msg = msgEvent.data; 38 var command = msg.command; 39 dump(`Subpage received command=${command}\n`); 40 switch (command) { 41 case "case1sendData": { 42 bc.postMessage({command: "case1data", devicePixelRatio: window.devicePixelRatio}); 43 break; 44 } 45 case "case1click": { 46 document.querySelector("a").click(); 47 // We are opening file_zoom_restore_bfcache.html?2, so the current 48 // page is going into bfcache 49 break; 50 } 51 case "case3sendData": { 52 // We came back from bfcache 53 SpecialPowers.spawnChrome([], () => { 54 // We use FullZoom to set the zoom level in the parent, but if FullZoom is not 55 // available then that will fail. So we don't wait here for the devicePixelRatio 56 // to change if FullZoom is not available, and test_zoom_restore_bfcache.html 57 // will mark this test as todo. 58 return "FullZoom" in this.browsingContext.embedderElement.ownerGlobal; 59 }).then((hasFullZoom) => { 60 function waitUntilZoomLevelRestored() { 61 // Zoom level is updated asynchronously when bfcache lives in the 62 // parent process. 63 if (!hasFullZoom || window.devicePixelRatio == 2) { 64 bc.postMessage({command: "case3data", devicePixelRatio: window.devicePixelRatio, 65 frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio}); 66 return; 67 } 68 window.requestAnimationFrame(waitUntilZoomLevelRestored); 69 } 70 window.requestAnimationFrame(waitUntilZoomLevelRestored); 71 }); 72 break; 73 } 74 case "close": { 75 SpecialPowers.spawnChrome([], () => { 76 const FullZoom = this.browsingContext.embedderElement.ownerGlobal.FullZoom; 77 FullZoom.setZoom(1.0); 78 }); 79 bc.postMessage({command: "closed"}); 80 bc.close(); 81 window.close(); 82 break; 83 } 84 } 85 } 86 } 87 window.addEventListener("pageshow", function(e) { 88 bc.postMessage({command: "handlePageShow", eventPersisted: e.persisted}); 89 }); 90 </script> 91 <a href="?2">This is a very interesting page</a> 92 <iframe srcdoc="And this is a nested frame"></iframe>