helper_doubletap_zoom_bug1702464.html (3927B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=2100"/> 6 <title>Check that double tapping internal calculations correctly convert the tap point</title> 7 <script type="application/javascript" src="apz_test_native_event_utils.js"></script> 8 <script type="application/javascript" src="apz_test_utils.js"></script> 9 <script src="/tests/SimpleTest/paint_listener.js"></script> 10 <script type="application/javascript"> 11 12 async function test() { 13 let useTouchpad = (location.search == "?touchpad"); 14 15 const deviceScale = window.devicePixelRatio; 16 let target2 = document.getElementById("target2") 17 18 info("deviceScale " + deviceScale); 19 info("window.innerwh " + window.innerWidth + " " + window.innerHeight); 20 info("vv " + visualViewport.offsetLeft + " " + visualViewport.offsetTop + " " + visualViewport.width + " " + visualViewport.height); 21 22 let resolution = await getResolution(); 23 let vvHeightAtUnitZoom = visualViewport.height * resolution; 24 25 // The max amount of zoom is 10 (as defined in dom/base/nsViewportInfo.h), 26 // but that includes the deviceScale (bug 1700865 is filed about this), so 27 // this is the max amount of zoom that double tap can increase by. 28 let maxPinchZoom = 10/deviceScale; 29 30 // Compute the visual viewport size at that max zoom. 31 let minVVHeight = vvHeightAtUnitZoom / maxPinchZoom; 32 33 // Make the element height to just fit inside the minimum visual viewport 34 // height, minus the margins that get added for the zoom target rect (15 on 35 // each side) and a little wiggle room just in case (rounding, etc). 36 let elementHeight = Math.floor(minVVHeight) - 2*15 - 4; 37 38 ok(elementHeight > 10, "tall enough element"); 39 40 // And then make the element skinnier than the window size so it triggers 41 // the bug. (half the aspect ratio minus 5 just to be sure) 42 let elementWidth = Math.max(12, Math.floor(elementHeight * window.innerWidth / (2 * window.innerHeight)) - 5); 43 44 info("element size " + elementWidth + " " + elementHeight); 45 46 target2.style.width = elementWidth + "px"; 47 target2.style.height = elementHeight + "px"; 48 49 await promiseApzFlushedRepaints(); 50 51 resolution = await getResolution(); 52 ok(resolution > 0, 53 "The initial_resolution is " + resolution + ", which is some sane value"); 54 55 // Check that double-tapping once zooms in 56 await doubleTapOn(document.getElementById("target1"), 10, 10, useTouchpad); 57 var prev_resolution = resolution; 58 resolution = await getResolution(); 59 ok(resolution > prev_resolution, "The first double-tap has increased the resolution to " + resolution); 60 61 // Check that double-tapping the smaller element zooms in more 62 await doubleTapOn(target2, 8, elementHeight-8, useTouchpad); 63 prev_resolution = resolution; 64 resolution = await getResolution(); 65 ok(resolution > prev_resolution, "The second double-tap has increased the resolution to " + resolution); 66 67 let rect = target2.getBoundingClientRect(); 68 info("rect " + rect.x + " " + rect.y + " " + rect.width + " " + rect.height); 69 info("vv " + visualViewport.offsetLeft + " " + visualViewport.offsetTop + " " + visualViewport.width + " " + visualViewport.height); 70 71 ok(visualViewport.offsetLeft < rect.x, "visual viewport contains zoom element left"); 72 ok(visualViewport.offsetTop < rect.y, "visual viewport contains zoom element top"); 73 ok(visualViewport.offsetLeft + visualViewport.width > rect.x + rect.width, "visual viewport contains zoom element right"); 74 ok(visualViewport.offsetTop + visualViewport.height > rect.y + rect.height, "visual viewport contains zoom element bottom"); 75 } 76 77 waitUntilApzStable() 78 .then(test) 79 .then(subtestDone, subtestFailed); 80 81 </script> 82 </head> 83 <body> 84 85 <div id="target1" style="background: blue; width: 50vw; height: 200px; position: absolute; top: 50vh;"> 86 <div id="target2" style="background: green; width: 50px; height: 135px; position: absolute; right: 0;"></div> 87 </div> 88 89 </body> 90 </html>