| <!DOCTYPE html> | |
| <title>Event.initEvent</title> | |
| <link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com"> | |
| <script src="/resources/testharness.js"></script> | |
| <script src="/resources/testharnessreport.js"></script> | |
| <div id="log"></div> | |
| <script> | |
| var booleans = [true, false]; | |
| booleans.forEach(function(bubbles) { | |
| booleans.forEach(function(cancelable) { | |
| test(function() { | |
| var e = document.createEvent("Event") | |
| e.initEvent("type", bubbles, cancelable) | |
| // Step 3. | |
| // Can't test the stop propagation flag and stop immediate propagation flag. | |
| assert_equals(e.defaultPrevented, false, "defaultPrevented") | |
| // Step 4. | |
| assert_equals(e.isTrusted, false, "isTrusted") | |
| // Step 5. | |
| assert_equals(e.target, null, "target") | |
| // Step 6. | |
| assert_equals(e.type, "type", "type") | |
| // Step 7. | |
| assert_equals(e.bubbles, bubbles, "bubbles") | |
| // Step 8. | |
| assert_equals(e.cancelable, cancelable, "cancelable") | |
| }, "Properties of initEvent(type, " + bubbles + ", " + cancelable + ")") | |
| }) | |
| }) | |
| test(function() { | |
| var e = document.createEvent("Event") | |
| e.initEvent("type 1", true, false) | |
| assert_equals(e.type, "type 1", "type (first init)") | |
| assert_equals(e.bubbles, true, "bubbles (first init)") | |
| assert_equals(e.cancelable, false, "cancelable (first init)") | |
| e.initEvent("type 2", false, true) | |
| assert_equals(e.type, "type 2", "type (second init)") | |
| assert_equals(e.bubbles, false, "bubbles (second init)") | |
| assert_equals(e.cancelable, true, "cancelable (second init)") | |
| }, "Calling initEvent multiple times (getting type).") | |
| test(function() { | |
| // https://bugzilla.mozilla.org/show_bug.cgi?id=998809 | |
| var e = document.createEvent("Event") | |
| e.initEvent("type 1", true, false) | |
| assert_equals(e.bubbles, true, "bubbles (first init)") | |
| assert_equals(e.cancelable, false, "cancelable (first init)") | |
| e.initEvent("type 2", false, true) | |
| assert_equals(e.type, "type 2", "type (second init)") | |
| assert_equals(e.bubbles, false, "bubbles (second init)") | |
| assert_equals(e.cancelable, true, "cancelable (second init)") | |
| }, "Calling initEvent multiple times (not getting type).") | |
| // Step 2. | |
| async_test(function() { | |
| // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17715 | |
| var e = document.createEvent("Event") | |
| e.initEvent("type", false, false) | |
| assert_equals(e.type, "type", "type (first init)") | |
| assert_equals(e.bubbles, false, "bubbles (first init)") | |
| assert_equals(e.cancelable, false, "cancelable (first init)") | |
| var target = document.createElement("div") | |
| target.addEventListener("type", this.step_func(function() { | |
| e.initEvent("fail", true, true) | |
| assert_equals(e.type, "type", "type (second init)") | |
| assert_equals(e.bubbles, false, "bubbles (second init)") | |
| assert_equals(e.cancelable, false, "cancelable (second init)") | |
| }), false) | |
| assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") | |
| this.done() | |
| }, "Calling initEvent must not have an effect during dispatching.") | |
| async_test(function() { | |
| var e = document.createEvent("Event") | |
| e.initEvent("type", false, false) | |
| e.stopPropagation() | |
| var target = document.createElement("div") | |
| target.addEventListener("type", this.step_func(function() { | |
| assert_unreached("") | |
| }), false) | |
| assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") | |
| assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") | |
| e.initEvent("type", false, false) | |
| var called = false | |
| var target = document.createElement("div") | |
| target.addEventListener("type", this.step_func(function() { | |
| called = true | |
| }), false) | |
| assert_false(called) | |
| assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") | |
| assert_true(called) | |
| this.done() | |
| }, "Calling initEvent must unset the stop propagation flag.") | |
| async_test(function() { | |
| var e = document.createEvent("Event") | |
| e.initEvent("type", false, false) | |
| var target = document.createElement("div") | |
| target.addEventListener("type", this.step_func(function() { | |
| e.initEvent("type2", true, true); | |
| assert_equals(e.type, "type", "initEvent type setter should short-circuit"); | |
| assert_false(e.bubbles, "initEvent bubbles setter should short-circuit"); | |
| assert_false(e.cancelable, "initEvent cancelable setter should short-circuit"); | |
| }), false) | |
| assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") | |
| this.done() | |
| }, "Calling initEvent during propagation.") | |
| </script> |