helper_doubletap_zoom_oopif-2.html (4516B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=2100,initial-scale=0.4"/> 6 <title>Tests that double tap to zoom in iframe works regardless whether cross-origin or not</title> 7 <script src="apz_test_native_event_utils.js"></script> 8 <script src="apz_test_utils.js"></script> 9 <script src="/tests/SimpleTest/paint_listener.js"></script> 10 <style> 11 html { 12 /* To avoid bug 1865573 */ 13 scrollbar-width: none; 14 } 15 iframe { 16 position: absolute; 17 top: 100px; 18 left: 100px; 19 border: none; 20 } 21 </style> 22 23 <script> 24 25 async function setupIframe(aURL) { 26 const iframe = document.querySelector("iframe"); 27 const iframeLoadPromise = promiseOneEvent(iframe, "load", null); 28 iframe.src = aURL; 29 await iframeLoadPromise; 30 info(`${aURL} loaded`); 31 32 await SpecialPowers.spawn(iframe, [], async () => { 33 await content.wrappedJSObject.waitUntilApzStable(); 34 await SpecialPowers.contentTransformsReceived(content); 35 }); 36 } 37 38 async function targetElementPosition() { 39 const iframe = document.querySelector("iframe"); 40 return SpecialPowers.spawn(iframe, [], async () => { 41 return content.document.querySelector("#target").getBoundingClientRect(); 42 }); 43 } 44 45 const useTouchpad = (location.search == "?touchpad"); 46 47 async function test(aTestFile) { 48 let iframeURL = SimpleTest.getTestFileURL(aTestFile); 49 50 // Load the test document in the same origin. 51 await setupIframe(iframeURL); 52 53 let resolution = await getResolution(); 54 ok(resolution > 0, 55 "The initial_resolution is " + resolution + ", which is some sane value"); 56 let initial_resolution = resolution; 57 58 let pos = await targetElementPosition(); 59 const iframe = document.querySelector("iframe"); 60 await doubleTapOn(iframe, pos.x + 10, pos.y + 10, useTouchpad); 61 62 let prev_resolution = resolution; 63 resolution = await getResolution(); 64 ok(resolution > prev_resolution, "The first double-tap has increased the resolution to " + resolution); 65 66 let zoomedInState = cloneVisualViewport(); 67 68 await doubleTapOn(iframe, pos.x + 10, pos.y + 10, useTouchpad); 69 prev_resolution = resolution; 70 resolution = await getResolution(); 71 ok(resolution < prev_resolution, "The second double-tap has decreased the resolution to " + resolution); 72 73 let zoomedOutState = cloneVisualViewport(); 74 75 // Reset the scale to the initial one since in the `visible: overflow` case 76 // the second double-tap doesn't restore to the initial scale. 77 SpecialPowers.DOMWindowUtils.setResolutionAndScaleTo(initial_resolution); 78 await promiseApzFlushedRepaints(); 79 80 // Now load the document in an OOP iframe. 81 iframeURL = iframeURL.replace(window.location.origin, "https://example.com"); 82 await setupIframe(iframeURL); 83 84 pos = await targetElementPosition(); 85 await doubleTapOn(iframe, pos.x + 10, pos.y + 10, useTouchpad); 86 87 prev_resolution = resolution; 88 resolution = await getResolution(); 89 ok(resolution > prev_resolution, "The first double-tap has increased the resolution to " + resolution); 90 91 compareVisualViewport(zoomedInState, cloneVisualViewport(), "zoomed-in state"); 92 93 await doubleTapOn(iframe, pos.x + 10, pos.y + 10, useTouchpad); 94 compareVisualViewport(zoomedOutState, cloneVisualViewport(), "zoomed-out state"); 95 } 96 97 async function moveIframe() { 98 const iframe = document.querySelector("iframe"); 99 iframe.style.top = "500vh"; 100 101 // Scroll to the bottom to make the layout scroll offset non-zero. 102 window.scrollTo(0, document.documentElement.scrollHeight); 103 ok(window.scrollY > 0, "The root scroll position should be non-zero"); 104 105 await SpecialPowers.spawn(iframe, [], async () => { 106 await SpecialPowers.contentTransformsReceived(content); 107 }); 108 } 109 110 waitUntilApzStable() 111 .then(async () => test("helper_doubletap_zoom_oopif_subframe-1.html")) 112 // A test case where the layout scroll offset isn't zero. 113 .then(async () => moveIframe()) 114 .then(async () => test("helper_doubletap_zoom_oopif_subframe-1.html")) 115 // A test case where the layout scroll offset in the iframe isn't zero. 116 .then(async () => test("helper_doubletap_zoom_oopif_subframe-2.html#target")) 117 // A test case where the double-tap-to-zoom target element is `overflow: visible`. 118 .then(async () => test("helper_doubletap_zoom_oopif_subframe-3.html#target")) 119 // Similar to above but the target element has positive `margin-top`. 120 .then(async () => test("helper_doubletap_zoom_oopif_subframe-4.html#target")) 121 .then(subtestDone, subtestFailed); 122 123 </script> 124 </head> 125 <body> 126 <iframe width="500" height="500"></iframe> 127 </body> 128 </html>