helper_zoom_prevented.html (2688B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width"> 6 <title>Checking prevent-default for zooming</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 testPreventDefault(aTouchStartToCancel) { 13 var initial_resolution = await getResolution(); 14 ok(initial_resolution > 0, 15 "The initial_resolution is " + initial_resolution + ", which is some sane value"); 16 17 // preventDefault exactly one touchstart based on the value of aTouchStartToCancel 18 var touchStartCount = 0; 19 var canceller = function(e) { 20 dump("touchstart listener hit, count: " + touchStartCount + "\n"); 21 touchStartCount++; 22 if (touchStartCount == aTouchStartToCancel) { 23 dump("calling preventDefault on touchstart\n"); 24 e.preventDefault(); 25 document.documentElement.removeEventListener("touchstart", canceller, {passive: false}); 26 } 27 }; 28 document.documentElement.addEventListener("touchstart", canceller, {passive: false}); 29 30 let touchEndPromise = new Promise(resolve => { 31 document.documentElement.addEventListener("touchend", resolve, {passive: true, once: true}); 32 }); 33 34 // Ensure that APZ gets updated hit-test info 35 await promiseAllPaintsDone(); 36 37 await pinchZoomInTouchSequence(150, 300); 38 await touchEndPromise; // wait for the touchend listener to fire 39 40 // Flush state and get the resolution we're at now 41 await promiseApzFlushedRepaints(); 42 let final_resolution = await getResolution(); 43 is(final_resolution, initial_resolution, "The final resolution (" + final_resolution + ") matches the initial resolution"); 44 } 45 46 function transformFailer() { 47 ok(false, "The test fired an unexpected APZ:TransformEnd"); 48 } 49 50 async function test() { 51 // Register a listener that fails the test if the APZ:TransformEnd event fires, 52 // because this test shouldn't actually be triggering any transforms 53 SpecialPowers.Services.obs.addObserver(transformFailer, "APZ:TransformEnd"); 54 55 await testPreventDefault(1); 56 await testPreventDefault(2); 57 } 58 59 function cleanup() { 60 SpecialPowers.Services.obs.removeObserver(transformFailer, "APZ:TransformEnd"); 61 } 62 63 waitUntilApzStable() 64 .then(test) 65 .finally(cleanup) 66 .then(subtestDone, subtestFailed); 67 68 </script> 69 </head> 70 <body> 71 Here is some text to stare at as the test runs. It serves no functional 72 purpose, but gives you an idea of the zoom level. It's harder to tell what 73 the zoom level is when the page is just solid white. 74 </body> 75 </html>