| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script src="script-tests/dispatchEvent.js"></script> | 7 <script> |
| 8 description("Test window.dispatchEvent()."); |
| 9 |
| 10 // Test that non-events throw |
| 11 var event = {}; |
| 12 shouldThrow("window.dispatchEvent(event)"); |
| 13 |
| 14 // Test that non-initialized events throw |
| 15 event = document.createEvent("Event"); |
| 16 shouldThrow("window.dispatchEvent(event)"); |
| 17 |
| 18 // Test basic dispatch |
| 19 var myEventDispatched = false; |
| 20 var target; |
| 21 var currentTarget; |
| 22 window.addEventListener("myEvent", function(evt) { |
| 23 myEventDispatched = true; |
| 24 target = evt.target; |
| 25 currentTarget = evt.currentTarget; |
| 26 }, false); |
| 27 event = document.createEvent("Event"); |
| 28 event.initEvent("myEvent", false, false); |
| 29 window.dispatchEvent(event); |
| 30 shouldBeTrue("myEventDispatched"); |
| 31 shouldBe("target", "window"); |
| 32 shouldBe("currentTarget", "window"); |
| 33 |
| 34 // Test that both useCapture and non-useCapture listeners are dispatched to |
| 35 var useCaptureDispatched = false; |
| 36 window.addEventListener("myEvent", function(evt) { |
| 37 useCaptureDispatched = true; |
| 38 }, true); |
| 39 var nonUseCaptureDispatched = false; |
| 40 window.addEventListener("myEvent", function(evt) { |
| 41 nonUseCaptureDispatched = true; |
| 42 }, false); |
| 43 event = document.createEvent("Event"); |
| 44 event.initEvent("myEvent", false, false); |
| 45 window.dispatchEvent(event); |
| 46 shouldBeTrue("useCaptureDispatched"); |
| 47 shouldBeTrue("nonUseCaptureDispatched"); |
| 48 </script> |
| 8 </body> | 49 </body> |
| 9 </html> | 50 </html> |
| OLD | NEW |