1 description("Test window.dispatchEvent().");
3 // Test that non-events throw
5 shouldThrow("window.dispatchEvent(event)");
7 // Test that non-initialized events throw
8 event = document.createEvent("Event");
9 shouldThrow("window.dispatchEvent(event)");
11 // Test basic dispatch
12 var myEventDispatched = false;
15 window.addEventListener("myEvent", function(evt) {
16 myEventDispatched = true;
18 currentTarget = evt.currentTarget;
20 event = document.createEvent("Event");
21 event.initEvent("myEvent", false, false);
22 window.dispatchEvent(event);
23 shouldBeTrue("myEventDispatched");
24 shouldBe("target", "window");
25 shouldBe("currentTarget", "window");
27 // Test that both useCapture and non-useCapture listeners are dispatched to
28 var useCaptureDispatched = false;
29 window.addEventListener("myEvent", function(evt) {
30 useCaptureDispatched = true;
32 var nonUseCaptureDispatched = false;
33 window.addEventListener("myEvent", function(evt) {
34 nonUseCaptureDispatched = true;
36 event = document.createEvent("Event");
37 event.initEvent("myEvent", false, false);
38 window.dispatchEvent(event);
39 shouldBeTrue("useCaptureDispatched");
40 shouldBeTrue("nonUseCaptureDispatched");