Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / event-target.html
blob478680aba131ce49b05142b5516633f2c607eebd
1 <html>
2 <body>
3 <p>Tests for <a href="https://bugs.webkit.org/show_bug.cgi?id=11053"> bug 11053</a> -
4 XMLHttpRequest should be an EventTarget.</p>
5 <script>
6 if (window.testRunner)
7 testRunner.dumpAsText();
9 var console_messages = document.createElement("ul");
10 document.body.appendChild(console_messages);
12 function log(message)
14 var item = document.createElement("li");
15 item.appendChild(document.createTextNode(message));
16 console_messages.appendChild(item);
20 function onLoad() {
21 log("onload: this = " + this);
22 req.removeEventListener("load", eventListener4, false);
25 function eventListener() { log("eventListener: this = " + this); }
27 function eventListener2() {
28 log("eventListener2: this = " + this);
29 // Removing this event listener should prevent it from firing.
30 req.removeEventListener("load", eventListener3, false);
33 function eventListener3() { log("eventListener3: this = " + this); }
35 // This listener is removed before it gets a chance to fire.
36 function eventListener4() { log("eventListener4: this = " + this); }
38 function fooListener() { log("fooListener: this = " + this); }
41 req = new XMLHttpRequest;
42 req.onload = onLoad;
43 req.addEventListener("load", eventListener, false);
44 req.addEventListener("load", eventListener2, false);
45 req.addEventListener("load", eventListener, false); // eventListener must not be called twice, but it does in Mozilla 1.8.
46 req.addEventListener("load", eventListener3, false);
48 // XMLHttpRequest.dispatchEvent is not implemeted in Mozilla 1.8
49 // Furthermore, they raise an exception when trying to add any event listener except for "load" and "error".
50 try {
51 event = document.createEvent("Event");
52 event.initEvent("foo", false, false);
53 req.addEventListener("foo", fooListener, false);
54 req.dispatchEvent(event);
55 } catch (ex) {
56 log("foo: " + ex);
59 req.open("GET", "resources/reply.xml", false);
60 req.send("");
62 // WebKit doesn't remove event listeners when re-opening a request, unlike Mozilla.
63 req.open("GET", "resources/reply.xml", false);
64 req.send("");
66 </script>
67 </body>
68 </html>