layout/style/test/chrome/hover_helper.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for :hover</title>
michael@0 5 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 6 <style type="text/css">
michael@0 7
michael@0 8 div#one { height: 10px; width: 10px; }
michael@0 9 div#one:hover { background: #00f; }
michael@0 10 div#one > div { height: 5px; width: 20px; }
michael@0 11 div#one > div:hover { background: #f00; }
michael@0 12
michael@0 13 div#twoparent { overflow: hidden; height: 20px; }
michael@0 14 div#two { width: 10px; height: 10px; }
michael@0 15 div#two:hover { margin-left: 5px; background: #0f0; }
michael@0 16 div#two + iframe { width: 50px; height: 10px; }
michael@0 17 div#two:hover + iframe { width: 100px; }
michael@0 18
michael@0 19 </style>
michael@0 20 </head>
michael@0 21 <!-- need a set timeout because we need things to start after painting suppression ends -->
michael@0 22 <body onload="setTimeout(step1, 0)">
michael@0 23 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 24 <div id="display" style="position: absolute; top: 0; left: 0; width: 300px; height: 300px">
michael@0 25
michael@0 26 <div id="one"><div></div></div>
michael@0 27
michael@0 28 <div id="twoparent">
michael@0 29 <div id="two"></div>
michael@0 30 <iframe id="twoi" src="hover_empty.html"></iframe>
michael@0 31 <div style="width: 5000px; height: 10px;"></div>
michael@0 32 </div>
michael@0 33
michael@0 34 </div>
michael@0 35 <pre id="test">
michael@0 36 <script type="application/javascript">
michael@0 37
michael@0 38 var imports = [ "SimpleTest", "is", "isnot", "ok" ];
michael@0 39 for (var name of imports) {
michael@0 40 window[name] = window.opener.wrappedJSObject[name];
michael@0 41 }
michael@0 42
michael@0 43 var div = document.getElementById("display");
michael@0 44 var divtwo = document.getElementById("two");
michael@0 45 var iframe = document.getElementById("twoi");
michael@0 46 var divtwoparent = document.getElementById("twoparent");
michael@0 47
michael@0 48 iframe.contentDocument.open();
michael@0 49 iframe.contentDocument.write("<style type='text/css'>html, body { margin: 0; padding: 0; }<\/style><body>");
michael@0 50 iframe.contentDocument.close();
michael@0 51
michael@0 52 var moveEvent = { type: "mousemove", clickCount: "0" };
michael@0 53
michael@0 54 function setResize(str) {
michael@0 55 var handler = function() {
michael@0 56 iframe.contentWindow.removeEventListener("resize", arguments.callee, false);
michael@0 57 setTimeout(str, 100);
michael@0 58 };
michael@0 59 iframe.contentWindow.addEventListener("resize", handler, false);
michael@0 60 }
michael@0 61
michael@0 62 function step1() {
michael@0 63 /** test basic hover **/
michael@0 64 var divone = document.getElementById("one");
michael@0 65 synthesizeMouse(divone, 5, 7, moveEvent, window);
michael@0 66 is(getComputedStyle(divone, "").backgroundColor, "rgb(0, 0, 255)",
michael@0 67 ":hover applies");
michael@0 68 is(getComputedStyle(divone.firstChild, "").backgroundColor, "transparent",
michael@0 69 ":hover does not apply");
michael@0 70 synthesizeMouse(divone, 5, 2, moveEvent, window);
michael@0 71 is(getComputedStyle(divone, "").backgroundColor, "rgb(0, 0, 255)",
michael@0 72 ":hover applies hierarchically");
michael@0 73 is(getComputedStyle(divone.firstChild, "").backgroundColor, "rgb(255, 0, 0)",
michael@0 74 ":hover applies");
michael@0 75 synthesizeMouse(divone, 15, 7, moveEvent, window);
michael@0 76 is(getComputedStyle(divone, "").backgroundColor, "transparent",
michael@0 77 ":hover does not apply");
michael@0 78 is(getComputedStyle(divone.firstChild, "").backgroundColor, "transparent",
michael@0 79 ":hover does not apply");
michael@0 80 synthesizeMouse(divone, 15, 2, moveEvent, window);
michael@0 81 is(getComputedStyle(divone, "").backgroundColor, "rgb(0, 0, 255)",
michael@0 82 ":hover applies hierarchically");
michael@0 83 is(getComputedStyle(divone.firstChild, "").backgroundColor, "rgb(255, 0, 0)",
michael@0 84 ":hover applies");
michael@0 85
michael@0 86 /** Test for Bug 302561 **/
michael@0 87 setResize("step2();");
michael@0 88 is(iframe.contentDocument.body.offsetWidth, 50,
michael@0 89 ":hover does not apply (iframe body width)");
michael@0 90 synthesizeMouse(divtwoparent, 7, 5, moveEvent, window);
michael@0 91 is(iframe.contentDocument.body.offsetWidth, 100,
michael@0 92 ":hover applies (iframe body width)");
michael@0 93 }
michael@0 94
michael@0 95 var step2called = false;
michael@0 96 function step2() {
michael@0 97 is(step2called, false, "step2 called only once");
michael@0 98 step2called = true;
michael@0 99 is(getComputedStyle(divtwo, "").backgroundColor, "rgb(0, 255, 0)",
michael@0 100 ":hover applies");
michael@0 101 is(iframe.contentDocument.body.offsetWidth, 100,
michael@0 102 ":hover applies (iframe body width)");
michael@0 103 setResize("step3()");
michael@0 104 synthesizeMouse(divtwoparent, 2, 5, moveEvent, window);
michael@0 105 is(iframe.contentDocument.body.offsetWidth, 50,
michael@0 106 ":hover does not apply (iframe body width)");
michael@0 107 }
michael@0 108
michael@0 109 var step3called = false;
michael@0 110 function step3() {
michael@0 111 is(step3called, false, "step3 called only once");
michael@0 112 step3called = true;
michael@0 113 if (getComputedStyle(iframe, "").width == "100px") {
michael@0 114 // The two resize events may be coalesced into a single one.
michael@0 115 step4();
michael@0 116 return;
michael@0 117 }
michael@0 118 is(getComputedStyle(divtwo, "").backgroundColor, "transparent",
michael@0 119 ":hover does not apply");
michael@0 120 setResize("step4()");
michael@0 121 /* expect to get a second resize from the oscillation */
michael@0 122 }
michael@0 123
michael@0 124 var step4called = false;
michael@0 125 function step4() {
michael@0 126 is(step4called, false, "step4 called only once (more than two cycles of oscillation)");
michael@0 127 if (step4called)
michael@0 128 return;
michael@0 129 step4called = true;
michael@0 130 is(getComputedStyle(divtwo, "").backgroundColor, "rgb(0, 255, 0)",
michael@0 131 ":hover applies");
michael@0 132 setTimeout(step5, 500); // time to detect oscillations if they exist
michael@0 133 }
michael@0 134
michael@0 135 var step5called = false;
michael@0 136 function step5() {
michael@0 137 is(step5called, false, "step5 called only once");
michael@0 138 step5called = true;
michael@0 139 setResize("step6()");
michael@0 140 synthesizeMouse(divtwoparent, 25, 5, moveEvent, window);
michael@0 141 }
michael@0 142
michael@0 143 var step6called = false;
michael@0 144 function step6() {
michael@0 145 is(step6called, false, "step6 called only once");
michael@0 146 step6called = true;
michael@0 147 is(getComputedStyle(divtwo, "").backgroundColor, "transparent",
michael@0 148 ":hover does not apply");
michael@0 149 setResize("step7()");
michael@0 150 synthesizeMouse(divtwoparent, 2, 5, moveEvent, window);
michael@0 151 }
michael@0 152
michael@0 153 var step7called = false;
michael@0 154 function step7() {
michael@0 155 is(step7called, false, "step7 called only once");
michael@0 156 step7called = true;
michael@0 157 if (getComputedStyle(iframe, "").width == "50px") {
michael@0 158 // The two resize events may be coalesced into a single one.
michael@0 159 step8();
michael@0 160 return;
michael@0 161 }
michael@0 162 is(getComputedStyle(divtwo, "").backgroundColor, "rgb(0, 255, 0)",
michael@0 163 ":hover applies");
michael@0 164 setResize("step8()");
michael@0 165 /* expect to get a second resize from the oscillation */
michael@0 166 }
michael@0 167
michael@0 168 var step8called = false;
michael@0 169 function step8() {
michael@0 170 is(step8called, false, "step8 called only once (more than two cycles of oscillation)");
michael@0 171 if (step8called)
michael@0 172 return;
michael@0 173 step8called = true;
michael@0 174 is(getComputedStyle(divtwo, "").backgroundColor, "transparent",
michael@0 175 ":hover does not apply");
michael@0 176 setTimeout(step9, 500); // time to detect oscillations if they exist
michael@0 177 }
michael@0 178
michael@0 179 /* test the same case with scrolltop */
michael@0 180
michael@0 181 var step9called = false;
michael@0 182 function step9() {
michael@0 183 is(step9called, false, "step9 called only once");
michael@0 184 step9called = true;
michael@0 185 iframe.contentDocument.body.removeAttribute("onresize");
michael@0 186 /* move the mouse out of the way */
michael@0 187 synthesizeMouse(divtwoparent, 200, 5, moveEvent, window);
michael@0 188 divtwoparent.scrollLeft = 5;
michael@0 189 setResize("step10()");
michael@0 190 synthesizeMouse(divtwoparent, 2, 5, moveEvent, window);
michael@0 191 /* mouse now over 7, 5 */
michael@0 192 }
michael@0 193
michael@0 194 var step10called = false;
michael@0 195 function step10() {
michael@0 196 is(step10called, false, "step10 called only once");
michael@0 197 step10called = true;
michael@0 198 is(getComputedStyle(divtwo, "").backgroundColor, "rgb(0, 255, 0)",
michael@0 199 ":hover applies");
michael@0 200 setResize("step11()");
michael@0 201 divtwoparent.scrollLeft = 0; /* mouse now over 2,5 */
michael@0 202 }
michael@0 203
michael@0 204 var step11called = false;
michael@0 205 function step11() {
michael@0 206 is(step11called, false, "step11 called only once");
michael@0 207 step11called = true;
michael@0 208 if (getComputedStyle(iframe, "").width == "100px") {
michael@0 209 // The two resize events may be coalesced into a single one.
michael@0 210 step12();
michael@0 211 return;
michael@0 212 }
michael@0 213 is(getComputedStyle(divtwo, "").backgroundColor, "transparent",
michael@0 214 ":hover does not apply");
michael@0 215 setResize("step12()");
michael@0 216 /* expect to get a second resize from the oscillation */
michael@0 217 }
michael@0 218
michael@0 219 var step12called = false;
michael@0 220 function step12() {
michael@0 221 is(step12called, false, "step12 called only once (more than two cycles of oscillation)");
michael@0 222 if (step12called)
michael@0 223 return;
michael@0 224 step12called = true;
michael@0 225 is(getComputedStyle(divtwo, "").backgroundColor, "rgb(0, 255, 0)",
michael@0 226 ":hover applies");
michael@0 227 setTimeout(step13, 500); // time to detect oscillations if they exist
michael@0 228 }
michael@0 229
michael@0 230 var step13called = false;
michael@0 231 function step13() {
michael@0 232 is(step13called, false, "step13 called only once");
michael@0 233 step13called = true;
michael@0 234 setResize("step14()");
michael@0 235 divtwoparent.scrollLeft = 25; /* mouse now over 27,5 */
michael@0 236 }
michael@0 237
michael@0 238 var step14called = false;
michael@0 239 function step14() {
michael@0 240 is(step14called, false, "step14 called only once");
michael@0 241 step14called = true;
michael@0 242 is(getComputedStyle(divtwo, "").backgroundColor, "transparent",
michael@0 243 ":hover does not apply");
michael@0 244 setResize("step15()");
michael@0 245 divtwoparent.scrollLeft = 0; /* mouse now over 2,5 */
michael@0 246 }
michael@0 247
michael@0 248 var step15called = false;
michael@0 249 function step15() {
michael@0 250 is(step15called, false, "step15 called only once");
michael@0 251 step15called = true;
michael@0 252 if (getComputedStyle(iframe, "").width == "50px") {
michael@0 253 // The two resize events may be coalesced into a single one.
michael@0 254 step16();
michael@0 255 return;
michael@0 256 }
michael@0 257 is(getComputedStyle(divtwo, "").backgroundColor, "rgb(0, 255, 0)",
michael@0 258 ":hover applies");
michael@0 259 setResize("step16()");
michael@0 260 /* expect to get a second resize from the oscillation */
michael@0 261 }
michael@0 262
michael@0 263 var step16called = false;
michael@0 264 function step16() {
michael@0 265 is(step16called, false, "step16 called only once (more than two cycles of oscillation)");
michael@0 266 if (step16called)
michael@0 267 return;
michael@0 268 step16called = true;
michael@0 269 is(getComputedStyle(divtwo, "").backgroundColor, "transparent",
michael@0 270 ":hover does not apply");
michael@0 271 setTimeout(finish, 500); // time to detect oscillations if they exist
michael@0 272 }
michael@0 273
michael@0 274 function finish() {
michael@0 275 document.getElementById("display").style.display = "none";
michael@0 276
michael@0 277 var tester = window.SimpleTest;
michael@0 278 window.close();
michael@0 279 tester.finish();
michael@0 280 }
michael@0 281
michael@0 282 </script>
michael@0 283 </pre>
michael@0 284 </body>
michael@0 285 </html>

mercurial