dom/events/test/test_bug967796.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=967796
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 967796</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=967796">Mozilla Bug 967796</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none">
michael@0 16
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script type="application/javascript">
michael@0 20
michael@0 21 /** Test for Bug 967796 **/
michael@0 22
michael@0 23 SpecialPowers.setBoolPref("dom.w3c_pointer_events.enabled", true); // Enable Pointer Events
michael@0 24
michael@0 25 SimpleTest.waitForExplicitFinish();
michael@0 26 SimpleTest.waitForFocus(runTests);
michael@0 27 var outer;
michael@0 28 var middle;
michael@0 29 var inner;
michael@0 30 var outside;
michael@0 31 var container;
michael@0 32 var file;
michael@0 33 var iframe;
michael@0 34 var checkRelatedTarget = false;
michael@0 35 var expectedRelatedEnter = null;
michael@0 36 var expectedRelatedLeave = null;
michael@0 37 var pointerentercount = 0;
michael@0 38 var pointerleavecount = 0;
michael@0 39 var pointerovercount = 0;
michael@0 40 var pointeroutcount = 0;
michael@0 41
michael@0 42 function sendPointerEvent(t, elem) {
michael@0 43 var r = elem.getBoundingClientRect();
michael@0 44 synthesizePointer(elem, r.width / 2, r.height / 2, {type: t});
michael@0 45 }
michael@0 46
michael@0 47 var expectedPointerEnterTargets = [];
michael@0 48 var expectedPointerLeaveTargets = [];
michael@0 49
michael@0 50 function runTests() {
michael@0 51 outer = document.getElementById("outertest");
michael@0 52 middle = document.getElementById("middletest");
michael@0 53 inner = document.getElementById("innertest");
michael@0 54 outside = document.getElementById("outside");
michael@0 55 container = document.getElementById("container");
michael@0 56 file = document.getElementById("file");
michael@0 57 iframe = document.getElementById("iframe");
michael@0 58
michael@0 59 // Make sure ESM thinks pointer is outside the test elements.
michael@0 60 sendPointerEvent("pointermove", outside);
michael@0 61
michael@0 62 pointerentercount = 0;
michael@0 63 pointerleavecount = 0;
michael@0 64 pointerovercount = 0;
michael@0 65 pointeroutcount = 0;
michael@0 66 checkRelatedTarget = true;
michael@0 67 expectedRelatedEnter = outside;
michael@0 68 expectedRelatedLeave = inner;
michael@0 69 expectedPointerEnterTargets = ["outertest", "middletest", "innertest"];
michael@0 70 sendPointerEvent("pointermove", inner);
michael@0 71 is(pointerentercount, 3, "Unexpected pointerenter event count!");
michael@0 72 is(pointerovercount, 1, "Unexpected pointerover event count!");
michael@0 73 is(pointeroutcount, 0, "Unexpected pointerout event count!");
michael@0 74 is(pointerleavecount, 0, "Unexpected pointerleave event count!");
michael@0 75 expectedRelatedEnter = inner;
michael@0 76 expectedRelatedLeave = outside;
michael@0 77 expectedPointerLeaveTargets = ["innertest", "middletest", "outertest"];
michael@0 78 sendPointerEvent("pointermove", outside);
michael@0 79 is(pointerentercount, 3, "Unexpected pointerenter event count!");
michael@0 80 is(pointerovercount, 1, "Unexpected pointerover event count!");
michael@0 81 is(pointeroutcount, 1, "Unexpected pointerout event count!");
michael@0 82 is(pointerleavecount, 3, "Unexpected pointerleave event count!");
michael@0 83
michael@0 84 // Event handling over native anonymous content.
michael@0 85 var r = file.getBoundingClientRect();
michael@0 86 expectedRelatedEnter = outside;
michael@0 87 expectedRelatedLeave = file;
michael@0 88 synthesizePointer(file, r.width / 6, r.height / 2, {type: "pointermove"});
michael@0 89 is(pointerentercount, 4, "Unexpected pointerenter event count!");
michael@0 90 is(pointerovercount, 2, "Unexpected pointerover event count!");
michael@0 91 is(pointeroutcount, 1, "Unexpected pointerout event count!");
michael@0 92 is(pointerleavecount, 3, "Unexpected pointerleave event count!");
michael@0 93
michael@0 94 // Moving pointer over type="file" shouldn't cause pointerover/out/enter/leave events
michael@0 95 synthesizePointer(file, r.width - (r.width / 6), r.height / 2, {type: "pointermove"});
michael@0 96 is(pointerentercount, 4, "Unexpected pointerenter event count!");
michael@0 97 is(pointerovercount, 2, "Unexpected pointerover event count!");
michael@0 98 is(pointeroutcount, 1, "Unexpected pointerout event count!");
michael@0 99 is(pointerleavecount, 3, "Unexpected pointerleave event count!");
michael@0 100
michael@0 101 expectedRelatedEnter = file;
michael@0 102 expectedRelatedLeave = outside;
michael@0 103 sendPointerEvent("pointermove", outside);
michael@0 104 is(pointerentercount, 4, "Unexpected pointerenter event count!");
michael@0 105 is(pointerovercount, 2, "Unexpected pointerover event count!");
michael@0 106 is(pointeroutcount, 2, "Unexpected pointerout event count!");
michael@0 107 is(pointerleavecount, 4, "Unexpected pointerleave event count!");
michael@0 108
michael@0 109 // Initialize iframe
michael@0 110 iframe.contentDocument.documentElement.style.overflow = "hidden";
michael@0 111 iframe.contentDocument.body.style.margin = "0px";
michael@0 112 iframe.contentDocument.body.style.width = "100%";
michael@0 113 iframe.contentDocument.body.style.height = "100%";
michael@0 114 iframe.contentDocument.body.innerHTML =
michael@0 115 "<div style='width: 100%; height: 50%; border: 1px solid black;'></div>" +
michael@0 116 "<div style='width: 100%; height: 50%; border: 1px solid black;'></div>";
michael@0 117 iframe.contentDocument.body.offsetLeft; // flush
michael@0 118
michael@0 119 iframe.contentDocument.body.firstChild.onpointerenter = penter;
michael@0 120 iframe.contentDocument.body.firstChild.onpointerleave = pleave;
michael@0 121 iframe.contentDocument.body.lastChild.onpointerenter = penter;
michael@0 122 iframe.contentDocument.body.lastChild.onpointerleave = pleave;
michael@0 123 r = iframe.getBoundingClientRect();
michael@0 124 expectedRelatedEnter = outside;
michael@0 125 expectedRelatedLeave = iframe;
michael@0 126 // Move pointer inside the iframe.
michael@0 127 synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "pointermove"},
michael@0 128 iframe.contentWindow);
michael@0 129 synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "pointermove"},
michael@0 130 iframe.contentWindow);
michael@0 131 is(pointerentercount, 7, "Unexpected pointerenter event count!");
michael@0 132 expectedRelatedEnter = iframe;
michael@0 133 expectedRelatedLeave = outside;
michael@0 134 sendPointerEvent("pointermove", outside);
michael@0 135 is(pointerleavecount, 7, "Unexpected pointerleave event count!");
michael@0 136
michael@0 137 // pointerdown must produce pointerenter event
michael@0 138 expectedRelatedEnter = outside;
michael@0 139 expectedRelatedLeave = iframe;
michael@0 140 // Move pointer inside the iframe.
michael@0 141 synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "pointerdown"},
michael@0 142 iframe.contentWindow);
michael@0 143 synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "pointerdown"},
michael@0 144 iframe.contentWindow);
michael@0 145 is(pointerentercount, 10, "Unexpected pointerenter event count!");
michael@0 146
michael@0 147 // pointerdown + pointermove must produce single pointerenter event
michael@0 148 expectedRelatedEnter = outside;
michael@0 149 expectedRelatedLeave = iframe;
michael@0 150 synthesizePointer(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "pointerdown"},
michael@0 151 iframe.contentWindow);
michael@0 152 synthesizePointer(iframe.contentDocument.body, r.width / 2 + 1, r.height / 4 + 1, {type: "pointermove"},
michael@0 153 iframe.contentWindow);
michael@0 154 is(pointerentercount, 11, "Unexpected pointerenter event count!");
michael@0 155
michael@0 156 SpecialPowers.clearUserPref("dom.w3c_pointer_events.enabled"); // Disable Pointer Events
michael@0 157
michael@0 158 SimpleTest.finish();
michael@0 159 }
michael@0 160
michael@0 161 function penter(evt) {
michael@0 162 ++pointerentercount;
michael@0 163 evt.stopPropagation();
michael@0 164 if (expectedPointerEnterTargets.length) {
michael@0 165 var t = expectedPointerEnterTargets.shift();
michael@0 166 is(evt.target.id, t, "Wrong event target!");
michael@0 167 }
michael@0 168 is(evt.bubbles, false, evt.type + " should not bubble!");
michael@0 169 is(evt.cancelable, false, evt.type + " is cancelable!");
michael@0 170 is(evt.target, evt.currentTarget, "Wrong event target!");
michael@0 171 ok(!evt.relatedTarget || evt.target.ownerDocument == evt.relatedTarget.ownerDocument,
michael@0 172 "Leaking nodes to another document?");
michael@0 173 if (checkRelatedTarget && evt.target.ownerDocument == document) {
michael@0 174 is(evt.relatedTarget, expectedRelatedEnter, "Wrong related target (pointerenter)");
michael@0 175 }
michael@0 176 }
michael@0 177
michael@0 178 function pleave(evt) {
michael@0 179 ++pointerleavecount;
michael@0 180 evt.stopPropagation();
michael@0 181 if (expectedPointerLeaveTargets.length) {
michael@0 182 var t = expectedPointerLeaveTargets.shift();
michael@0 183 is(evt.target.id, t, "Wrong event target!");
michael@0 184 }
michael@0 185 is(evt.bubbles, false, evt.type + " should not bubble!");
michael@0 186 is(evt.cancelable, false, evt.type + " is cancelable!");
michael@0 187 is(evt.target, evt.currentTarget, "Wrong event target!");
michael@0 188 ok(!evt.relatedTarget || evt.target.ownerDocument == evt.relatedTarget.ownerDocument,
michael@0 189 "Leaking nodes to another document?");
michael@0 190 if (checkRelatedTarget && evt.target.ownerDocument == document) {
michael@0 191 is(evt.relatedTarget, expectedRelatedLeave, "Wrong related target (pointerleave)");
michael@0 192 }
michael@0 193 }
michael@0 194
michael@0 195 function pover(evt) {
michael@0 196 ++pointerovercount;
michael@0 197 evt.stopPropagation();
michael@0 198 }
michael@0 199
michael@0 200 function pout(evt) {
michael@0 201 ++pointeroutcount;
michael@0 202 evt.stopPropagation();
michael@0 203 }
michael@0 204
michael@0 205 </script>
michael@0 206 </pre>
michael@0 207 <div id="container" onpointerenter="penter(event)" onpointerleave="pleave(event)"
michael@0 208 onpointerout="pout(event)" onpointerover="pover(event)">
michael@0 209 <div id="outside" onpointerout="event.stopPropagation()" onpointerover="event.stopPropagation()">foo</div>
michael@0 210 <div id="outertest" onpointerenter="penter(event)" onpointerleave="pleave(event)"
michael@0 211 onpointerout="pout(event)" onpointerover="pover(event)">
michael@0 212 <div id="middletest" onpointerenter="penter(event)" onpointerleave="pleave(event)"
michael@0 213 onpointerout="pout(event)" onpointerover="pover(event)">
michael@0 214 <div id="innertest" onpointerenter="penter(event)" onpointerleave="pleave(event)"
michael@0 215 onpointerout="pout(event)" onpointerover="pover(event)">foo</div>
michael@0 216 </div>
michael@0 217 </div>
michael@0 218 <input type="file" id="file"
michael@0 219 onpointerenter="penter(event)" onpointerleave="pleave(event)"
michael@0 220 onpointerout="pout(event)" onpointerover="pover(event)">
michael@0 221 <br>
michael@0 222 <iframe id="iframe" width="50px" height="50px"
michael@0 223 onpointerenter="penter(event)" onpointerleave="pleave(event)"
michael@0 224 onpointerout="pout(event)" onpointerover="pover(event)"></iframe>
michael@0 225 </div>
michael@0 226 </body>
michael@0 227 </html>

mercurial