dom/events/test/test_bug432698.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=432698
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 432698</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=432698">Mozilla Bug 432698</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 432698 **/
michael@0 22 SimpleTest.waitForExplicitFinish();
michael@0 23 SimpleTest.waitForFocus(runTests);
michael@0 24 var outer;
michael@0 25 var middle;
michael@0 26 var inner;
michael@0 27 var outside;
michael@0 28 var container;
michael@0 29 var file;
michael@0 30 var iframe;
michael@0 31 var checkRelatedTarget = false;
michael@0 32 var expectedRelatedEnter = null;
michael@0 33 var expectedRelatedLeave = null;
michael@0 34 var mouseentercount = 0;
michael@0 35 var mouseleavecount = 0;
michael@0 36 var mouseovercount = 0;
michael@0 37 var mouseoutcount = 0;
michael@0 38
michael@0 39 function sendMouseEvent(t, elem) {
michael@0 40 var r = elem.getBoundingClientRect();
michael@0 41 synthesizeMouse(elem, r.width / 2, r.height / 2, {type: t});
michael@0 42 }
michael@0 43
michael@0 44 var expectedMouseEnterTargets = [];
michael@0 45 var expectedMouseLeaveTargets = [];
michael@0 46
michael@0 47 function runTests() {
michael@0 48 outer = document.getElementById("outertest");
michael@0 49 middle = document.getElementById("middletest");
michael@0 50 inner = document.getElementById("innertest");
michael@0 51 outside = document.getElementById("outside");
michael@0 52 container = document.getElementById("container");
michael@0 53 file = document.getElementById("file");
michael@0 54 iframe = document.getElementById("iframe");
michael@0 55
michael@0 56 // Make sure ESM thinks mouse is outside the test elements.
michael@0 57 sendMouseEvent("mousemove", outside);
michael@0 58
michael@0 59 mouseentercount = 0;
michael@0 60 mouseleavecount = 0;
michael@0 61 mouseovercount = 0;
michael@0 62 mouseoutcount = 0;
michael@0 63 checkRelatedTarget = true;
michael@0 64 expectedRelatedEnter = outside;
michael@0 65 expectedRelatedLeave = inner;
michael@0 66 expectedMouseEnterTargets = ["outertest", "middletest", "innertest"];
michael@0 67 sendMouseEvent("mousemove", inner);
michael@0 68 is(mouseentercount, 3, "Unexpected mouseenter event count!");
michael@0 69 is(mouseovercount, 1, "Unexpected mouseover event count!");
michael@0 70 is(mouseoutcount, 0, "Unexpected mouseout event count!");
michael@0 71 is(mouseleavecount, 0, "Unexpected mouseleave event count!");
michael@0 72 expectedRelatedEnter = inner;
michael@0 73 expectedRelatedLeave = outside;
michael@0 74 expectedMouseLeaveTargets = ["innertest", "middletest", "outertest"];
michael@0 75 sendMouseEvent("mousemove", outside);
michael@0 76 is(mouseentercount, 3, "Unexpected mouseenter event count!");
michael@0 77 is(mouseovercount, 1, "Unexpected mouseover event count!");
michael@0 78 is(mouseoutcount, 1, "Unexpected mouseout event count!");
michael@0 79 is(mouseleavecount, 3, "Unexpected mouseleave event count!");
michael@0 80
michael@0 81 // Event handling over native anonymous content.
michael@0 82 var r = file.getBoundingClientRect();
michael@0 83 expectedRelatedEnter = outside;
michael@0 84 expectedRelatedLeave = file;
michael@0 85 synthesizeMouse(file, r.width / 6, r.height / 2, {type: "mousemove"});
michael@0 86 is(mouseentercount, 4, "Unexpected mouseenter event count!");
michael@0 87 is(mouseovercount, 2, "Unexpected mouseover event count!");
michael@0 88 is(mouseoutcount, 1, "Unexpected mouseout event count!");
michael@0 89 is(mouseleavecount, 3, "Unexpected mouseleave event count!");
michael@0 90
michael@0 91 // Moving mouse over type="file" shouldn't cause mouseover/out/enter/leave events
michael@0 92 synthesizeMouse(file, r.width - (r.width / 6), r.height / 2, {type: "mousemove"});
michael@0 93 is(mouseentercount, 4, "Unexpected mouseenter event count!");
michael@0 94 is(mouseovercount, 2, "Unexpected mouseover event count!");
michael@0 95 is(mouseoutcount, 1, "Unexpected mouseout event count!");
michael@0 96 is(mouseleavecount, 3, "Unexpected mouseleave event count!");
michael@0 97
michael@0 98 expectedRelatedEnter = file;
michael@0 99 expectedRelatedLeave = outside;
michael@0 100 sendMouseEvent("mousemove", outside);
michael@0 101 is(mouseentercount, 4, "Unexpected mouseenter event count!");
michael@0 102 is(mouseovercount, 2, "Unexpected mouseover event count!");
michael@0 103 is(mouseoutcount, 2, "Unexpected mouseout event count!");
michael@0 104 is(mouseleavecount, 4, "Unexpected mouseleave event count!");
michael@0 105
michael@0 106 // Initialize iframe
michael@0 107 iframe.contentDocument.documentElement.style.overflow = "hidden";
michael@0 108 iframe.contentDocument.body.style.margin = "0px";
michael@0 109 iframe.contentDocument.body.style.width = "100%";
michael@0 110 iframe.contentDocument.body.style.height = "100%";
michael@0 111 iframe.contentDocument.body.innerHTML =
michael@0 112 "<div style='width: 100%; height: 50%; border: 1px solid black;'></div>" +
michael@0 113 "<div style='width: 100%; height: 50%; border: 1px solid black;'></div>";
michael@0 114 iframe.contentDocument.body.offsetLeft; // flush
michael@0 115
michael@0 116 iframe.contentDocument.body.firstChild.onmouseenter = menter;
michael@0 117 iframe.contentDocument.body.firstChild.onmouseleave = mleave;
michael@0 118 iframe.contentDocument.body.lastChild.onmouseenter = menter;
michael@0 119 iframe.contentDocument.body.lastChild.onmouseleave = mleave;
michael@0 120 r = iframe.getBoundingClientRect();
michael@0 121 expectedRelatedEnter = outside;
michael@0 122 expectedRelatedLeave = iframe;
michael@0 123 // Move mouse inside the iframe.
michael@0 124 synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height / 4, {type: "mousemove"},
michael@0 125 iframe.contentWindow);
michael@0 126 synthesizeMouse(iframe.contentDocument.body, r.width / 2, r.height - (r.height / 4), {type: "mousemove"},
michael@0 127 iframe.contentWindow);
michael@0 128 is(mouseentercount, 7, "Unexpected mouseenter event count!");
michael@0 129 expectedRelatedEnter = iframe;
michael@0 130 expectedRelatedLeave = outside;
michael@0 131 sendMouseEvent("mousemove", outside);
michael@0 132 is(mouseleavecount, 7, "Unexpected mouseleave event count!");
michael@0 133
michael@0 134 checkRelatedTarget = false;
michael@0 135
michael@0 136 iframe.contentDocument.body.firstChild.onmouseenter = null;
michael@0 137 iframe.contentDocument.body.firstChild.onmouseleave = null;
michael@0 138 iframe.contentDocument.body.lastChild.onmouseenter = null;
michael@0 139 iframe.contentDocument.body.lastChild.onmouseleave = null;
michael@0 140
michael@0 141 container.onmouseenter = null;
michael@0 142 container.onmouseleave = null;
michael@0 143 container.onmouseout = null;
michael@0 144 container.onmouseover = null;
michael@0 145
michael@0 146 var children = container.getElementsByTagName('*');
michael@0 147 for (var i=0;i<children.length;i++) {
michael@0 148 children[i].onmouseenter = null;
michael@0 149 children[i].onmouseleave = null;
michael@0 150 children[i].onmouseout = null;
michael@0 151 children[i].onmouseover = null;
michael@0 152 }
michael@0 153
michael@0 154 SimpleTest.finish();
michael@0 155 }
michael@0 156
michael@0 157 function menter(evt) {
michael@0 158 ++mouseentercount;
michael@0 159 evt.stopPropagation();
michael@0 160 if (expectedMouseEnterTargets.length) {
michael@0 161 var t = expectedMouseEnterTargets.shift();
michael@0 162 is(evt.target.id, t, "Wrong event target!");
michael@0 163 }
michael@0 164 is(evt.bubbles, false, evt.type + " should not bubble!");
michael@0 165 is(evt.cancelable, false, evt.type + " is not cancelable!");
michael@0 166 is(evt.target, evt.currentTarget, "Wrong event target!");
michael@0 167 ok(!evt.relatedTarget || evt.target.ownerDocument == evt.relatedTarget.ownerDocument,
michael@0 168 "Leaking nodes to another document?");
michael@0 169 if (checkRelatedTarget && evt.target.ownerDocument == document) {
michael@0 170 is(evt.relatedTarget, expectedRelatedEnter, "Wrong related target (mouseenter)");
michael@0 171 }
michael@0 172 }
michael@0 173
michael@0 174 function mleave(evt) {
michael@0 175 ++mouseleavecount;
michael@0 176 evt.stopPropagation();
michael@0 177 if (expectedMouseLeaveTargets.length) {
michael@0 178 var t = expectedMouseLeaveTargets.shift();
michael@0 179 is(evt.target.id, t, "Wrong event target!");
michael@0 180 }
michael@0 181 is(evt.bubbles, false, evt.type + " should not bubble!");
michael@0 182 is(evt.cancelable, false, evt.type + " is not cancelable!");
michael@0 183 is(evt.target, evt.currentTarget, "Wrong event target!");
michael@0 184 ok(!evt.relatedTarget || evt.target.ownerDocument == evt.relatedTarget.ownerDocument,
michael@0 185 "Leaking nodes to another document?");
michael@0 186 if (checkRelatedTarget && evt.target.ownerDocument == document) {
michael@0 187 is(evt.relatedTarget, expectedRelatedLeave, "Wrong related target (mouseleave)");
michael@0 188 }
michael@0 189 }
michael@0 190
michael@0 191 function mover(evt) {
michael@0 192 ++mouseovercount;
michael@0 193 evt.stopPropagation();
michael@0 194 }
michael@0 195
michael@0 196 function mout(evt) {
michael@0 197 ++mouseoutcount;
michael@0 198 evt.stopPropagation();
michael@0 199 }
michael@0 200
michael@0 201 </script>
michael@0 202 </pre>
michael@0 203 <div id="container" onmouseenter="menter(event)" onmouseleave="mleave(event)"
michael@0 204 onmouseout="mout(event)" onmouseover="mover(event)">
michael@0 205 <div id="outside" onmouseout="event.stopPropagation()" onmouseover="event.stopPropagation()">foo</div>
michael@0 206 <div id="outertest" onmouseenter="menter(event)" onmouseleave="mleave(event)"
michael@0 207 onmouseout="mout(event)" onmouseover="mover(event)">
michael@0 208 <div id="middletest" onmouseenter="menter(event)" onmouseleave="mleave(event)"
michael@0 209 onmouseout="mout(event)" onmouseover="mover(event)">
michael@0 210 <div id="innertest" onmouseenter="menter(event)" onmouseleave="mleave(event)"
michael@0 211 onmouseout="mout(event)" onmouseover="mover(event)">foo</div>
michael@0 212 </div>
michael@0 213 </div>
michael@0 214 <input type="file" id="file"
michael@0 215 onmouseenter="menter(event)" onmouseleave="mleave(event)"
michael@0 216 onmouseout="mout(event)" onmouseover="mover(event)">
michael@0 217 <br>
michael@0 218 <iframe id="iframe" width="50px" height="50px"
michael@0 219 onmouseenter="menter(event)" onmouseleave="mleave(event)"
michael@0 220 onmouseout="mout(event)" onmouseover="mover(event)"></iframe>
michael@0 221 </div>
michael@0 222 </body>
michael@0 223 </html>

mercurial