helper_doubletap_zoom_horizontal_center.html (2305B)
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 an element that doesn't fill the width of the viewport as maximum zoom centers it</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 var resolution = await getResolution(); 16 ok(resolution > 0, 17 "The initial_resolution is " + resolution + ", which is some sane value"); 18 19 // Check that double-tapping once zooms in 20 await doubleTapOn(document.getElementById("target"), 10, 10, useTouchpad); 21 var prev_resolution = resolution; 22 resolution = await getResolution(); 23 ok(resolution > 2*prev_resolution, "The first double-tap has increased the resolution to " + resolution); 24 25 info("window.innerWidth " + window.innerWidth); // value when writing this test: 1280 26 info("visualViewport.offsetLeft " + visualViewport.offsetLeft); //value when writing this test: 625 with bug, 537 with fix 27 info("visualViewport.width " + visualViewport.width); // value when writing this test: 253 28 // the left hand edge of the div is at window.innerWidth/2 29 // we want approximately half of the visual viewport width to be to the left of that point. 30 // we have to remove the 50 pixels for the width of the div from that first though. 31 // we multiply that by 80% to factor in the 15 pixel margin we give the zoomed-to element 32 // (we don't hard code 15 though since we might want to tweak that) 33 ok(visualViewport.offsetLeft < window.innerWidth/2 - 0.8*(visualViewport.width-50)/2, "moved over far enough"); 34 // and then have a sanity check that it's not too small. 35 // using the same 20% factor as before but in the other direction. 36 ok(visualViewport.offsetLeft > window.innerWidth/2 - 1.2*(visualViewport.width-50)/2, "but not too far"); 37 } 38 39 waitUntilApzStable() 40 .then(test) 41 .then(subtestDone, subtestFailed); 42 43 </script> 44 </head> 45 <body> 46 47 <div id="target" style="background: blue; width: 50px; height: 50px; position: absolute; left: 50vw;"></div> 48 49 </body> 50 </html>