It should be possible to re-initialize a CustomEvent after it's been dispatched
[WebKit-https.git] / LayoutTests / fast / events / initCustomEvent-after-dispatch.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../../resources/js-test-pre.js"></script>
5 <script>
6 description("Tests calling initCustomEvent() on an custom event while it is being dispatched and after.");
7
8 function eventHandler(ev) {
9     event = ev;
10     debug("");
11     debug("* In event handler");
12     shouldBeEqualToString("event.type", "foo");
13     shouldBeTrue("event.bubbles");
14     shouldBeFalse("event.cancelable");
15     shouldBe("event.target", "document.body");
16     shouldBe("event.currentTarget", "document.body");
17     shouldBe("event.eventPhase", "Event.AT_TARGET");
18     shouldBeEqualToString("event.detail", "detail");
19
20     debug("");
21     // It should not be possible to re-initialize an event being dispatched.
22     shouldNotThrow('event.initCustomEvent("bar", false, true, "detail2")');
23     shouldBeEqualToString("event.type", "foo");
24     shouldBeTrue("event.bubbles");
25     shouldBeFalse("event.cancelable");
26     shouldBe("event.target", "document.body");
27     shouldBe("event.currentTarget", "document.body");
28     shouldBe("event.eventPhase", "Event.AT_TARGET");
29     shouldBeEqualToString("event.detail", "detail");
30 }
31
32 var testEvent = document.createEvent("customevent");
33 shouldBe("testEvent.__proto__", "CustomEvent.prototype");
34 shouldNotThrow('testEvent.initCustomEvent("foo", true, false, "detail")');
35 shouldBeEqualToString("testEvent.type", "foo");
36 shouldBeTrue("testEvent.bubbles");
37 shouldBeFalse("testEvent.cancelable");
38 shouldBeNull("testEvent.target");
39 shouldBeNull("testEvent.currentTarget");
40 shouldBe("testEvent.eventPhase", "Event.NONE");
41 shouldBeEqualToString("testEvent.detail", "detail");
42
43 document.body.addEventListener("foo", eventHandler);
44 shouldNotThrow('document.body.dispatchEvent(testEvent)');
45
46 debug("");
47 debug("* After event has been dispatched");
48 shouldBeEqualToString("testEvent.type", "foo");
49 shouldBeTrue("testEvent.bubbles");
50 shouldBeFalse("testEvent.cancelable");
51 shouldBe("testEvent.target", "document.body");
52 shouldBeNull("testEvent.currentTarget");
53 shouldBe("testEvent.eventPhase", "Event.NONE");
54 shouldBeEqualToString("testEvent.detail", "detail");
55
56 // It should now be possible to re-initialize the event.
57 debug("");
58 shouldNotThrow('testEvent.initCustomEvent("bar", false, true, "detail2")');
59 shouldBeEqualToString("testEvent.type", "bar");
60 shouldBeFalse("testEvent.bubbles");
61 shouldBeTrue("testEvent.cancelable");
62 shouldBeNull("testEvent.target");
63 shouldBeNull("testEvent.currentTarget");
64 shouldBe("testEvent.eventPhase", "Event.NONE");
65 shouldBeEqualToString("testEvent.detail", "detail2");
66 </script>
67 <script src="../../resources/js-test-post.js"></script>
68 </body>
69 </html>