helper_bug1637113_main_thread_hit_test.html (2531B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1637113 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 9 <title>Test for Bug 1637113</title> 10 <script src="/tests/SimpleTest/paint_listener.js"></script> 11 <script src="/tests/SimpleTest/EventUtils.js"></script> 12 <script type="application/javascript" src="apz_test_native_event_utils.js"></script> 13 <script type="application/javascript" src="apz_test_utils.js"></script> 14 <style> 15 iframe { 16 margin-top: 1000px; 17 } 18 </style> 19 </head> 20 <body> 21 <iframe id="subframe" srcdoc="<div id='target' style='width:100px;height:100px;'>" width="100px" height="100px"></iframe> 22 <script type="application/javascript"> 23 24 async function test() { 25 let utils = SpecialPowers.getDOMWindowUtils(window); 26 27 // Reproducing the bug requires three ingredients: 28 // 1. A large layout viewport offset. 29 // 2. A large visual viewport offset relative to the layout viewport. 30 // 3. An event that's dispatched in the iframe's document. 31 // We make the first two happen by doing a large visual scroll that will 32 // also drag the layout viewport with it part of the way. 33 let visualScrollPromise = new Promise(resolve => { 34 window.visualViewport.addEventListener("scroll", resolve, { once: true }); 35 }); 36 utils.scrollToVisual(0, 900, utils.UPDATE_TYPE_MAIN_THREAD, 37 utils.SCROLL_MODE_INSTANT); 38 await visualScrollPromise; 39 await promiseApzFlushedRepaints(); 40 41 let target = subframe.contentWindow.document.getElementById("target"); 42 // To get an event that's dispatched in the iframe's document, 43 // synthesize a native tap. This will synthesize three events: 44 // a mouse-move, a mouse-down, and a mouse-up. The mouse-move 45 // and mouse-down are dispatched in the root content document. 46 // The mouse-down causes the iframe to "capture" the mouse, which 47 // leads the mouse-up to be dispatched in the iframe's document 48 // instead. We listen for the mouse-up. 49 let mouseUpEvent = null; 50 let mouseUpPromise = new Promise(resolve => { 51 target.addEventListener("mouseup", function(e) { 52 mouseUpEvent = e; 53 resolve(); 54 }); 55 }); 56 57 await synthesizeNativeTap(target, 10, 10); 58 await mouseUpPromise; 59 60 is(mouseUpEvent.target, target, "mouseup event targeted the correct element"); 61 } 62 63 SpecialPowers.getDOMWindowUtils(window).setResolutionAndScaleTo(2.0); 64 waitUntilApzStable() 65 .then(test) 66 .then(subtestDone, subtestFailed); 67 68 </script> 69 </body> 70 </html>