test_remove_frame_when_got_pointer_capture.html (4583B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test for triggering popup by pointer events</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <script src="/tests/SimpleTest/EventUtils.js"></script> 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 9 </head> 10 <body> 11 <p id="content"> 12 </p> 13 <script> 14 15 SimpleTest.waitForExplicitFinish(); 16 17 function startTest() { 18 let content = document.getElementById('content'); 19 let iframe = document.createElement('iframe'); 20 iframe.width = 200; 21 iframe.height = 200; 22 content.appendChild(iframe); 23 iframe.contentDocument.body.innerHTML = 24 "<div id='div1' style='width: 50px; height: 50px; background: green'></div>" + 25 "<div id='div2' style='width: 50px; height: 50px; background: red'></div>"; 26 27 let div1 = iframe.contentDocument.getElementById("div1"); 28 let div2 = iframe.contentDocument.getElementById("div2"); 29 let divEvents = [ 30 "pointerdown", 31 "gotpointercapture", 32 "pointermove", 33 "pointerup", 34 "lostpointercapture", 35 "mousedown", 36 "mousemove", 37 "mouseup", 38 ]; 39 40 let documentEvents = [ 41 "pointerdown", 42 "pointermove", 43 "pointerup", 44 "mousedown", 45 "mousemove", 46 "mouseup", 47 ]; 48 49 divEvents.forEach((event) => { 50 div1.addEventListener(event, (e) => { 51 ok(divEvents.includes(e.type), " don't expect " + e.type); 52 divEvents = divEvents.filter(item => item !== e.type); 53 }, { once: true }); 54 }); 55 56 documentEvents.forEach((event) => { 57 iframe.contentDocument.addEventListener(event, (e) => { 58 is(e.target, div1, e.type + " should be dispatched to div1"); 59 }, { once: true }); 60 }); 61 62 div1.addEventListener("pointerdown", (e) => { 63 div1.setPointerCapture(e.pointerId); 64 }); 65 66 div1.addEventListener("gotpointercapture", (e) => { 67 div1.style.display = "none"; 68 }); 69 70 info("Tests for mouseup"); 71 synthesizeMouseAtCenter(div1, {type: "mousedown"}, iframe.contentWindow); 72 synthesizeMouseAtCenter(div2, {type: "mousemove"}, iframe.contentWindow); 73 synthesizeMouseAtCenter(div2, {type: "mouseup"}, iframe.contentWindow); 74 75 ok(!divEvents.length, " expect " + divEvents); 76 77 divEvents = [ 78 "pointerdown", 79 "gotpointercapture", 80 "pointermove", 81 "pointerup", 82 "lostpointercapture", 83 "touchstart", 84 "touchmove", 85 "touchend", 86 ]; 87 88 documentEvents = [ 89 "pointerdown", 90 "pointermove", 91 "pointerup", 92 "touchstart", 93 "touchmove", 94 "touchend", 95 ]; 96 divEvents.forEach((event) => { 97 div1.addEventListener(event, (e) => { 98 ok(divEvents.includes(e.type), " don't expect " + e.type); 99 divEvents = divEvents.filter(item => item !== e.type); 100 }, { once: true }); 101 }); 102 103 documentEvents.forEach((event) => { 104 iframe.contentDocument.addEventListener(event, (e) => { 105 is(e.target, div1, e.type + " should be dispatched to div1"); 106 }, { once: true }); 107 }); 108 109 info("Tests for touchend"); 110 div1.style.display = "block"; 111 synthesizeMouseAtCenter(div1, {type: "mousemove"}, iframe.contentWindow); 112 synthesizeTouch(div1, 5, 5, { type: "touchstart" }, iframe.contentWindow); 113 synthesizeTouch(div2, 5, 5, { type: "touchmove" }, iframe.contentWindow); 114 synthesizeTouch(div2, 5, 5, { type: "touchend" }, iframe.contentWindow); 115 116 ok(!divEvents.length, " expect " + divEvents); 117 118 divEvents = [ 119 "pointerdown", 120 "gotpointercapture", 121 "pointermove", 122 "pointercancel", 123 "lostpointercapture", 124 "touchstart", 125 "touchmove", 126 "touchcancel", 127 ]; 128 129 documentEvents = [ 130 "pointerdown", 131 "pointermove", 132 "pointercancel", 133 "touchstart", 134 "touchmove", 135 "touchcancel", 136 ]; 137 divEvents.forEach((event) => { 138 div1.addEventListener(event, (e) => { 139 ok(divEvents.includes(e.type), " don't expect " + e.type); 140 divEvents = divEvents.filter(item => item !== e.type); 141 }, { once: true }); 142 }); 143 144 documentEvents.forEach((event) => { 145 iframe.contentDocument.addEventListener(event, (e) => { 146 is(e.target, div1, e.type + " should be dispatched to div1"); 147 }, { once: true }); 148 }); 149 150 info("Tests for touchcancel"); 151 div1.style.display = "block"; 152 synthesizeMouseAtCenter(div1, {type: "mousemove"}, iframe.contentWindow); 153 synthesizeTouch(div1, 5, 5, { type: "touchstart" }, iframe.contentWindow); 154 synthesizeTouch(div2, 5, 5, { type: "touchmove" }, iframe.contentWindow); 155 synthesizeTouch(div2, 5, 5, { type: "touchcancel" }, iframe.contentWindow); 156 157 ok(!divEvents.length, " expect " + divEvents); 158 159 SimpleTest.finish(); 160 } 161 162 SimpleTest.waitForFocus(startTest); 163 164 </script> 165 </body> 166 </html>