Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / event-fire-order.html
blobb00acc3570bd9855a51a7bc58417cb3d4f990111
1 <p>This page tests event listener fire order for a few objects that had it wrong in the past.</p>
2 <p>If the test passes, you'll see a series of PASS messages below.</p>
4 <pre id="console"></pre>
6 <div id="div"></div>
8 <script>
9 if (window.testRunner)
10 testRunner.dumpAsText();
12 function log(s)
14 document.getElementById("console").appendChild(document.createTextNode(s + "\n"));
17 var result;
19 function reset()
21 result = [ ];
24 function f1()
26 result.push("f1");
29 function f2(event)
31 result.push("f2");
32 event.target.removeEventListener(event.type, f3, false); // Removed: should not fire.
33 event.target.addEventListener(event.type, f4, false); // Added after dispatch began: should not fire.
36 function f3()
38 result.push("f3");
41 function f4()
43 result.push("f4");
46 function reportResult(name, expected)
48 var passed = true;
49 var end = result.length > expected.length ? result.length : expected.length;
50 for (var i = 0; i < end; ++i) {
51 if (result[i] != expected[i]) {
52 log("FAIL: " + name + " result[" + i + "] should be " + expected[i] + " but instead is " + result[i] + ".");
53 passed = false;
56 if (passed)
57 log("PASS: result should be " + expected + " and is.");
60 var tests = [
61 function testDiv()
63 reset();
64 var x = document.getElementById("div");
65 x.addEventListener("click", f1, false);
66 x.onclick = f2;
67 x.addEventListener("click", f3, false);
69 var event = document.createEvent("MouseEvent");
70 event.initMouseEvent("click", true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, document);
71 x.dispatchEvent(event);
73 reportResult(arguments.callee.name, [ "f1", "f2" ]);
76 function testXHR()
78 reset();
79 var x = new XMLHttpRequest;
80 x.addEventListener("readystatechange", f1, false);
81 x.onreadystatechange = f2;
82 x.addEventListener("readystatechange", f3, false);
84 x.open("GET", "resources/does-not-exist");
86 reportResult(arguments.callee.name, [ "f1", "f2" ]);
89 function testXHRUpload()
91 reset();
92 var x = new XMLHttpRequest;
93 x.upload.addEventListener("abort", f1, false);
94 x.upload.onabort = f2;
95 x.upload.addEventListener("abort", f3, false);
97 x.open("POST", "resources/does-not-exist");
98 x.send();
99 x.abort();
101 reportResult(arguments.callee.name, [ "f1", "f2" ]);
105 for (var i = 0; i < tests.length; ++i)
106 tests[i]();
107 </script>