helper_basic_pan.html (3090B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width; initial-scale=1.0"> 6 <title>Sanity panning test</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 src="/tests/SimpleTest/EventUtils.js"></script> 11 <script type="application/javascript"> 12 13 async function test() { 14 let scrEvt = new EventCounter(window, "scroll"); 15 let visScrEvt = new EventCounter(window.visualViewport, "scroll"); 16 // Our internal visual viewport events aren't restricted to the visual view- 17 // port itself, so we can listen on the window itself, however the event 18 // listener needs to be in the system group. 19 let visScrEvtInternal = new EventCounter(window, "mozvisualscroll", 20 { mozSystemGroup: true }); 21 22 // This listener will trigger the test to continue once APZ is done with 23 // processing the scroll. 24 let transformEndPromise = promiseTransformEnd(); 25 26 await synthesizeNativeTouchDrag(document.body, 10, 100, 0, -50); 27 dump("Finished native drag, waiting for transform-end observer...\n"); 28 29 // Wait for the APZ:TransformEnd to be fired after touch events are processed. 30 await transformEndPromise; 31 32 // Flush state. 33 await promiseApzFlushedRepaints(); 34 35 is(window.scrollY, 50, "check that the window scrolled"); 36 37 // Check we've got the expected events. 38 // This page is using "width=device-width; initial-scale=1.0" and we haven't 39 // pinch-zoomed any further, so layout and visual viewports have the same 40 // size and will scroll together. Therefore we should be getting layout 41 // viewport "scroll" events as well. 42 scrEvt.unregister(); 43 ok(scrEvt.count > 0, "Got some layout viewport scroll events"); 44 // This one is a bit tricky: Visual viewport "scroll" events are supposed to 45 // fire only when the relative offset between layout and visual viewport 46 // changes. Even when they're both scrolling together, we may update their 47 // positions independently, though, leading to some jitter in the offset and 48 // triggering the event after all. 49 // At least for the case here, where both viewports are the same size and we 50 // have a freshly loaded page, we should however be able to keep the offset at 51 // a constant zero and therefore not cause any visual viewport scroll events 52 // to fire. 53 visScrEvt.unregister(); 54 is(visScrEvt.count, 0, "Got no visual viewport scroll events"); 55 visScrEvtInternal.unregister(); 56 // Our internal visual viewport scroll event on the other hand only cares 57 // about the absolute offset of the visual viewport and should therefore 58 // definitively fire. 59 ok(visScrEvtInternal.count > 0, "Got some mozvisualscroll events"); 60 } 61 62 waitUntilApzStable() 63 .then(test) 64 .then(subtestDone, subtestFailed); 65 66 </script> 67 </head> 68 <body> 69 <div style="height: 5000px; background-color: lightgreen;"> 70 This div makes the page scrollable. 71 </div> 72 </body> 73 </html>