test_bug1420589_2.html (4278B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1420589 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1420589</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1420589">Mozilla Bug 1420589</a> 15 <p id="display"></p> 16 <div id="div1" style="width: 50px; height: 50px; background: green"></div> 17 <iframe id="iframe1" src="./bug_1420589_iframe1.html"> 18 </iframe> 19 <script type="text/javascript"> 20 /* 21 Test for Bug 1420589. This test synthesizes touch events with two points. One 22 hits the div element on the document and the other hits the iframe element. 23 24 We dispatch all touch events to the same document. If we find any target that 25 is not in the same document of the existed target, we try to find the ancestor 26 document of the new target which is in the same as the existing target and 27 dispatch touch events to it. We check the points of the touch event in reverse 28 order. That means we only dispatch touch events to the document which contains 29 the div element in this test and expect the div element and iframe element 30 receive touch events. 31 32 We dispatch pointer events to the hit targets even when there aren't in the 33 same document. This test expects that pointer events are dispatched to the div 34 element and the iframe document. 35 */ 36 SimpleTest.waitForExplicitFinish(); 37 38 var rx = 1; 39 var ry = 1; 40 var angle = 0; 41 var force = 1; 42 var modifiers = 0; 43 var test1PointerId = 1; 44 var test2PointerId = 2; 45 46 function withoutImplicitlyPointerCaptureForTouch() { 47 let expectedEvents = [ 48 // messages from the document of iframe1 49 "iframe1 pointerdown", 50 "iframe1 pointermove", 51 "iframe1 pointerup", 52 53 // messages from the parent document 54 "iframe touchstart", 55 "iframe touchmove", 56 "iframe touchend", 57 "div1 pointerdown", 58 "div1 pointermove", 59 "div1 pointerup", 60 "div1 touchstart", 61 "div1 touchmove", 62 "div1 touchend", 63 ]; 64 65 window.addEventListener('message',function(e) { 66 ok(expectedEvents.includes(e.data), " don't expect " + e.data); 67 expectedEvents = expectedEvents.filter(item => item !== e.data); 68 if (e.data == "div1 touchend") { 69 ok(!expectedEvents.length, " expect " + expectedEvents); 70 SimpleTest.finish(); 71 } 72 }) 73 74 let iframe1 = document.getElementById('iframe1'); 75 let div1 = document.getElementById('div1'); 76 77 let events = ["touchstart", "touchmove", "touchend", "pointerdown", "pointermove", "pointerup"]; 78 events.forEach((event) => { 79 div1.addEventListener(event, (e) => { 80 postMessage("div1 " + e.type, "*"); 81 }, { once: true }); 82 iframe1.addEventListener(event, (e) => { 83 postMessage("iframe " + e.type, "*"); 84 }, { once: true }); 85 }); 86 87 let rect1 = iframe1.getBoundingClientRect(); 88 let rect2 = div1.getBoundingClientRect(); 89 90 let left1 = rect1.left + 5; 91 let left2 = rect2.left + 5; 92 93 let top1 = rect1.top + 5; 94 let top2 = rect2.top + 5; 95 96 var utils = SpecialPowers.getDOMWindowUtils(window); 97 utils.sendTouchEvent('touchstart', [test1PointerId, test2PointerId], 98 [left1, left2], [top1, top2], [rx, rx], [ry, ry], 99 [angle, angle], [force, force], [0, 0], [0, 0], 100 [0, 0], modifiers); 101 102 // Move the touch pointers so that we dispatch all of them to content. 103 left1++; 104 left2++; 105 utils.sendTouchEvent('touchmove', [test1PointerId, test2PointerId], 106 [left1, left2], [top1, top2], [rx, rx], [ry, ry], 107 [angle, angle], [force, force], [0, 0], [0, 0], 108 [0, 0], modifiers); 109 utils.sendTouchEvent('touchend', [test1PointerId, test2PointerId], 110 [left1, left2], [top1, top2], [rx, rx], [ry, ry], 111 [angle, angle], [force, force], [0, 0], [0, 0], 112 [0, 0], modifiers); 113 } 114 115 SimpleTest.waitForFocus(() => { 116 SpecialPowers.pushPrefEnv({"set": [["dom.w3c_pointer_events.implicit_capture", false]]}, 117 withoutImplicitlyPointerCaptureForTouch); 118 }); 119 120 </script> 121 </body> 122 </html>