layout/style/test/test_transitions_events.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 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=531585
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 531585 (transitionend event)</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <style type="text/css">
michael@0 12
michael@0 13 .bar { margin: 10px; }
michael@0 14
michael@0 15 #one { transition-duration: 500ms; transition-property: all; }
michael@0 16 #two { transition: margin-left 1s; }
michael@0 17 #three { transition: margin 0.5s 0.25s; }
michael@0 18
michael@0 19 #four, #five, #six, #seven::before, #seven::after {
michael@0 20 transition: 500ms color;
michael@0 21 border-color: black; /* don't derive from color */
michael@0 22 -moz-column-rule-color: black; /* don't derive from color */
michael@0 23 -moz-text-decoration-color: black; /* don't derive from color */
michael@0 24 }
michael@0 25
michael@0 26 #four {
michael@0 27 /* give the reversing transition a long duration; the reversing will
michael@0 28 still be quick */
michael@0 29 transition-duration: 30s;
michael@0 30 transition-timing-function: cubic-bezier(0, 1, 1, 0);
michael@0 31 }
michael@0 32
michael@0 33 #seven::before, #seven::after {
michael@0 34 content: "x";
michael@0 35 transition-duration: 50ms;
michael@0 36 }
michael@0 37 #seven[foo]::before, #seven[foo]::after { color: lime; }
michael@0 38
michael@0 39 </style>
michael@0 40 <body>
michael@0 41 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=531585">Mozilla Bug 531585</a>
michael@0 42 <p id="display">
michael@0 43
michael@0 44 <span id="one" style="color:blue"></span>
michael@0 45 <span id="two"></span>
michael@0 46 <span id="three"></span>
michael@0 47 <span id="four" style="color: blue"></span>
michael@0 48 <span id="five" style="color: blue"></span>
michael@0 49 <span id="six" style="color: blue"></span>
michael@0 50 <span id="seven" style="color: blue"></span>
michael@0 51
michael@0 52 </p>
michael@0 53 <pre id="test">
michael@0 54 <script type="application/javascript">
michael@0 55
michael@0 56 /** Test for Bug 531585 (transitionend event) **/
michael@0 57
michael@0 58 SimpleTest.waitForExplicitFinish();
michael@0 59 var gTestCount = 0;
michael@0 60 function started_test() { ++gTestCount; }
michael@0 61 function finished_test() { if (--gTestCount == 0) { SimpleTest.finish(); } }
michael@0 62
michael@0 63 function $(id) { return document.getElementById(id); }
michael@0 64 function cs(id) { return getComputedStyle($(id), ""); }
michael@0 65
michael@0 66 var got_one_root = false;
michael@0 67 var got_one_target = false;
michael@0 68 var got_one_target_bordertop = false;
michael@0 69 var got_one_target_borderright = false;
michael@0 70 var got_one_target_borderbottom = false;
michael@0 71 var got_one_target_borderleft = false;
michael@0 72 var got_one_target_columnrule = false;
michael@0 73 var got_one_target_textdecorationcolor = false;
michael@0 74 var got_two_target = false;
michael@0 75 var got_three_top = false;
michael@0 76 var got_three_right = false;
michael@0 77 var got_three_bottom = false;
michael@0 78 var got_three_left = false;
michael@0 79 var got_four_root = false;
michael@0 80 var got_body = false;
michael@0 81 var did_stops = false;
michael@0 82 var got_before = false;
michael@0 83
michael@0 84 document.documentElement.addEventListener("transitionend",
michael@0 85 function(event) {
michael@0 86 if (event.target == $("one")) {
michael@0 87 ok(!got_one_root, "transitionend on one on root");
michael@0 88 is(event.propertyName, "border-right-color",
michael@0 89 "propertyName for transitionend on one");
michael@0 90 is(event.elapsedTime, 0.5,
michael@0 91 "elapsedTime for transitionend on one");
michael@0 92 is(cs("one").borderRightColor, "rgb(0, 255, 0)",
michael@0 93 "computed style for transitionend on one");
michael@0 94 got_one_root = true;
michael@0 95 finished_test();
michael@0 96 } else if (event.target == $("four")) {
michael@0 97 ok(!got_four_root, "transitionend on four on root");
michael@0 98 is(event.propertyName, "color",
michael@0 99 "propertyName for transitionend on four");
michael@0 100 // Reported time should (really?) be shortened by reversing.
michael@0 101 ok(event.elapsedTime < 30,
michael@0 102 "elapsedTime for transitionend on four");
michael@0 103 is(cs("four").color, "rgb(0, 0, 255)",
michael@0 104 "computed style for transitionend on four (end of reverse transition)");
michael@0 105 got_four_root = true;
michael@0 106 finished_test();
michael@0 107 } else if (event.target == document.body) {
michael@0 108 // A synthesized event.
michael@0 109 ok(!got_body, "transitionend on body on root");
michael@0 110 is(event.propertyName, "some-unknown-prop",
michael@0 111 "propertyName for transitionend on body");
michael@0 112 // Reported time should (really?) be shortened by reversing.
michael@0 113 is(event.elapsedTime, 0.5,
michael@0 114 "elapsedTime for transitionend on body");
michael@0 115 got_body = true;
michael@0 116 finished_test();
michael@0 117 } else if (event.target == $("seven")) {
michael@0 118 if (!got_before) {
michael@0 119 got_before = true;
michael@0 120 is(event.pseudoElement, "::before");
michael@0 121 } else {
michael@0 122 is(event.pseudoElement, "::after");
michael@0 123 }
michael@0 124 is(event.propertyName, "color");
michael@0 125 is(event.isTrusted, true);
michael@0 126 } else {
michael@0 127 if (!did_stops &&
michael@0 128 (event.target == $("five") || event.target == $("six"))) {
michael@0 129 todo(false,
michael@0 130 "timeout to stop transitions firing later than it should be");
michael@0 131 return;
michael@0 132 }
michael@0 133 ok(false,
michael@0 134 "unexpected event on " + event.target.nodeName +
michael@0 135 " element with id '" + event.target.id + "' " +
michael@0 136 "elapsedTime=" + event.elapsedTime +
michael@0 137 " propertyName='" + event.propertyName + "'");
michael@0 138 }
michael@0 139 }, false);
michael@0 140
michael@0 141 $("one").addEventListener("transitionend",
michael@0 142 function(event) {
michael@0 143 switch (event.propertyName) {
michael@0 144 case "color":
michael@0 145 ok(!got_one_target,
michael@0 146 "transitionend on one on target (color)");
michael@0 147 got_one_target = true;
michael@0 148 event.stopPropagation();
michael@0 149 break;
michael@0 150 case "border-top-color":
michael@0 151 ok(!got_one_target_bordertop,
michael@0 152 "transitionend on one on target (border-top-color)");
michael@0 153 got_one_target_bordertop = true;
michael@0 154 event.stopPropagation();
michael@0 155 break;
michael@0 156 case "border-right-color":
michael@0 157 ok(!got_one_target_borderright,
michael@0 158 "transitionend on one on target (border-right-color)");
michael@0 159 got_one_target_borderright = true;
michael@0 160 // Let this event through to body
michael@0 161 break;
michael@0 162 case "border-bottom-color":
michael@0 163 ok(!got_one_target_borderbottom,
michael@0 164 "transitionend on one on target (border-bottom-color)");
michael@0 165 got_one_target_borderbottom = true;
michael@0 166 event.stopPropagation();
michael@0 167 break;
michael@0 168 case "border-left-color":
michael@0 169 ok(!got_one_target_borderleft,
michael@0 170 "transitionend on one on target (border-left-color)");
michael@0 171 got_one_target_borderleft = true;
michael@0 172 event.stopPropagation();
michael@0 173 break;
michael@0 174 case "-moz-column-rule-color":
michael@0 175 ok(!got_one_target_columnrule,
michael@0 176 "transitionend on one on target (-moz-column-rule-color)");
michael@0 177 got_one_target_columnrule = true;
michael@0 178 event.stopPropagation();
michael@0 179 break;
michael@0 180 case "-moz-text-decoration-color":
michael@0 181 ok(!got_one_target_textdecorationcolor,
michael@0 182 "transitionend on one on target (-moz-text-decoration-color)");
michael@0 183 got_one_target_textdecorationcolor = true;
michael@0 184 event.stopPropagation();
michael@0 185 break;
michael@0 186 default:
michael@0 187 ok(false, "unexpected property name " + event.propertyName +
michael@0 188 " for transitionend on one on target");
michael@0 189 }
michael@0 190 is(event.elapsedTime, 0.5,
michael@0 191 "elapsedTime for transitionend on one");
michael@0 192 is(cs("one").getPropertyValue(event.propertyName), "rgb(0, 255, 0)",
michael@0 193 "computed style of " + event.propertyName + " for transitionend on one");
michael@0 194 finished_test();
michael@0 195 }, false);
michael@0 196
michael@0 197 started_test();
michael@0 198 started_test();
michael@0 199 started_test();
michael@0 200 started_test();
michael@0 201 started_test();
michael@0 202 started_test();
michael@0 203 $("one").style.color = "lime";
michael@0 204
michael@0 205
michael@0 206 $("two").addEventListener("transitionend",
michael@0 207 function(event) {
michael@0 208 event.stopPropagation();
michael@0 209
michael@0 210 ok(!got_two_target, "transitionend on two on target");
michael@0 211 is(event.propertyName, "margin-left",
michael@0 212 "propertyName for transitionend on two");
michael@0 213 is(event.elapsedTime, 1,
michael@0 214 "elapsedTime for transitionend on two");
michael@0 215 is(event.bubbles, true,
michael@0 216 "transitionend events should bubble");
michael@0 217 is(event.cancelable, false,
michael@0 218 "transitionend events should not be cancelable");
michael@0 219 is(cs("two").marginLeft, "10px",
michael@0 220 "computed style for transitionend on two");
michael@0 221 got_two_target = true;
michael@0 222 finished_test();
michael@0 223 }, false);
michael@0 224
michael@0 225 started_test();
michael@0 226 $("two").className = "bar";
michael@0 227
michael@0 228 $("three").addEventListener("transitionend",
michael@0 229 function(event) {
michael@0 230 event.stopPropagation();
michael@0 231
michael@0 232 switch (event.propertyName) {
michael@0 233 case "margin-top":
michael@0 234 ok(!got_three_top, "should only get margin-top once");
michael@0 235 got_three_top = true;
michael@0 236 break;
michael@0 237 case "margin-right":
michael@0 238 ok(!got_three_right, "should only get margin-right once");
michael@0 239 got_three_right = true;
michael@0 240 break;
michael@0 241 case "margin-bottom":
michael@0 242 ok(!got_three_bottom, "should only get margin-bottom once");
michael@0 243 got_three_bottom = true;
michael@0 244 break;
michael@0 245 case "margin-left":
michael@0 246 ok(!got_three_left, "should only get margin-left once");
michael@0 247 got_three_left = true;
michael@0 248 break;
michael@0 249 default:
michael@0 250 ok(false, "unexpected property name " + event.propertyName +
michael@0 251 " for transitionend on three");
michael@0 252 }
michael@0 253 is(event.elapsedTime, 0.5,
michael@0 254 "elapsedTime for transitionend on three");
michael@0 255 is(cs("three").getPropertyValue(event.propertyName), "10px",
michael@0 256 "computed style for transitionend on three");
michael@0 257 finished_test();
michael@0 258 }, true);
michael@0 259
michael@0 260 started_test();
michael@0 261 started_test();
michael@0 262 started_test();
michael@0 263 started_test();
michael@0 264 $("three").className = "bar";
michael@0 265
michael@0 266 // We reverse the transition on four, and we should only get an event
michael@0 267 // at the end of the second transition.
michael@0 268 started_test();
michael@0 269 $("four").style.color = "lime";
michael@0 270
michael@0 271 // We cancel the transition on five by changing 'transition-property',
michael@0 272 // and should thus get no event.
michael@0 273 $("five").style.color = "lime";
michael@0 274
michael@0 275 // We cancel the transition on six by changing 'transition-duration' and
michael@0 276 // then changing the value, so we should get no event.
michael@0 277 $("six").style.color = "lime";
michael@0 278
michael@0 279 started_test();
michael@0 280 started_test();
michael@0 281 $("seven").setAttribute("foo", "bar");
michael@0 282
michael@0 283 setTimeout(function() {
michael@0 284 if (cs("five") != "rgb(0, 255, 0)" &&
michael@0 285 cs("six") != "rgb(0, 255, 0)") {
michael@0 286 // The transition hasn't finished already.
michael@0 287 did_stops = true;
michael@0 288 }
michael@0 289 $("five").style.transitionProperty = "margin-left";
michael@0 290 $("six").style.transitionDuration = "0s";
michael@0 291 $("six").style.transitionDelay = "0s";
michael@0 292 $("six").style.color = "blue";
michael@0 293 }, 100);
michael@0 294 function poll_start_reversal() {
michael@0 295 if (cs("four").color != "rgb(0, 0, 255)") {
michael@0 296 // The forward transition has started.
michael@0 297 $("four").style.color = "blue";
michael@0 298 } else {
michael@0 299 // The forward transition has not started yet.
michael@0 300 setTimeout(poll_start_reversal, 20);
michael@0 301 }
michael@0 302 }
michael@0 303 setTimeout(poll_start_reversal, 200);
michael@0 304
michael@0 305 // And make our own event to dispatch to the body.
michael@0 306 started_test();
michael@0 307
michael@0 308 var e = new TransitionEvent("transitionend",
michael@0 309 {
michael@0 310 bubbles: true,
michael@0 311 cancelable: true,
michael@0 312 propertyName: "some-unknown-prop",
michael@0 313 elapsedTime: 0.5,
michael@0 314 pseudoElement: "pseudo"
michael@0 315 });
michael@0 316 is(e.bubbles, true);
michael@0 317 is(e.cancelable, true);
michael@0 318 is(e.propertyName, "some-unknown-prop");
michael@0 319 is(e.elapsedTime, "0.5");
michael@0 320 is(e.pseudoElement, "pseudo");
michael@0 321 is(e.isTrusted, false)
michael@0 322
michael@0 323 document.body.dispatchEvent(e);
michael@0 324
michael@0 325 </script>
michael@0 326 </pre>
michael@0 327 </body>
michael@0 328 </html>

mercurial