4 <script src=
"../../resources/js-test.js"></script>
7 <p class=
"description">
8 Tests that dispatchEvent raises DISPATCH_REQUEST_ERR if the event
9 being dispatched is already being dispatched.
14 if (window
.testRunner
)
15 testRunner
.dumpAsText();
19 function shouldBeDispatchRequestErr(exception
) {
20 var ok
= Object
.getPrototypeOf(exception
) == DOMException
.prototype && exception
.name
== 'InvalidStateError';
21 (ok
? testPassed
: testFailed
)("should have got DISPATCH_REQUEST_ERR EventException");
24 // try redispatching an event in the process of being dispatched with
27 function redispatchCustom(event
) {
29 window
.dispatchEvent(event
);
30 testFailed('dispatchEvent of an event being dispatched should throw an exception');
32 shouldBeDispatchRequestErr(ex
);
35 redispatchCustom
.wasInvoked
= true;
38 var customEvent
= document
.createEvent('CustomEvent');
39 customEvent
.initCustomEvent('foo', true, true, null);
40 var p
= document
.querySelector('.description');
41 p
.addEventListener('foo', redispatchCustom
);
42 p
.dispatchEvent(customEvent
);
43 shouldBeTrue('redispatchCustom.wasInvoked');
45 // try redispatching an event that has already finished being dispatched
47 function checkCustom(event
) {
48 checkCustom
.wasInvoked
= true;
51 p
.removeEventListener('foo', redispatchCustom
, true);
52 p
.addEventListener('foo', checkCustom
, true);
53 p
.dispatchEvent(customEvent
);
54 shouldBeTrue('checkCustom.wasInvoked');
56 // try redispatching an event in the process of being dispatched by
59 function redispatchLoad(event
) {
60 if (redispatchLoad
.dispatching
) {
61 testFailed('dispatchEvent of an event being dispatched should not dispatch the event again');
66 redispatchLoad
.dispatching
= true;
67 document
.dispatchEvent(event
);
68 testFailed('dispatchEvent of an event being dispatched should throw an exception');
70 shouldBeDispatchRequestErr(ex
);
72 delete redispatchLoad
.dispatching
;
78 window
.addEventListener('load', redispatchLoad
, true);