11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<title>Event.initEvent</title> 31cb0ef41Sopenharmony_ci<link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com"> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci<div id="log"></div> 71cb0ef41Sopenharmony_ci<script> 81cb0ef41Sopenharmony_civar booleans = [true, false]; 91cb0ef41Sopenharmony_cibooleans.forEach(function(bubbles) { 101cb0ef41Sopenharmony_ci booleans.forEach(function(cancelable) { 111cb0ef41Sopenharmony_ci test(function() { 121cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 131cb0ef41Sopenharmony_ci e.initEvent("type", bubbles, cancelable) 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci // Step 2. 161cb0ef41Sopenharmony_ci // Stop (immediate) propagation flag is tested later 171cb0ef41Sopenharmony_ci assert_equals(e.defaultPrevented, false, "defaultPrevented") 181cb0ef41Sopenharmony_ci assert_equals(e.returnValue, true, "returnValue") 191cb0ef41Sopenharmony_ci // Step 3. 201cb0ef41Sopenharmony_ci assert_equals(e.isTrusted, false, "isTrusted") 211cb0ef41Sopenharmony_ci // Step 4. 221cb0ef41Sopenharmony_ci assert_equals(e.target, null, "target") 231cb0ef41Sopenharmony_ci assert_equals(e.srcElement, null, "srcElement") 241cb0ef41Sopenharmony_ci // Step 5. 251cb0ef41Sopenharmony_ci assert_equals(e.type, "type", "type") 261cb0ef41Sopenharmony_ci // Step 6. 271cb0ef41Sopenharmony_ci assert_equals(e.bubbles, bubbles, "bubbles") 281cb0ef41Sopenharmony_ci // Step 7. 291cb0ef41Sopenharmony_ci assert_equals(e.cancelable, cancelable, "cancelable") 301cb0ef41Sopenharmony_ci }, "Properties of initEvent(type, " + bubbles + ", " + cancelable + ")") 311cb0ef41Sopenharmony_ci }) 321cb0ef41Sopenharmony_ci}) 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_citest(function() { 351cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 361cb0ef41Sopenharmony_ci e.initEvent("type 1", true, false) 371cb0ef41Sopenharmony_ci assert_equals(e.type, "type 1", "type (first init)") 381cb0ef41Sopenharmony_ci assert_equals(e.bubbles, true, "bubbles (first init)") 391cb0ef41Sopenharmony_ci assert_equals(e.cancelable, false, "cancelable (first init)") 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci e.initEvent("type 2", false, true) 421cb0ef41Sopenharmony_ci assert_equals(e.type, "type 2", "type (second init)") 431cb0ef41Sopenharmony_ci assert_equals(e.bubbles, false, "bubbles (second init)") 441cb0ef41Sopenharmony_ci assert_equals(e.cancelable, true, "cancelable (second init)") 451cb0ef41Sopenharmony_ci}, "Calling initEvent multiple times (getting type).") 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_citest(function() { 481cb0ef41Sopenharmony_ci // https://bugzilla.mozilla.org/show_bug.cgi?id=998809 491cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 501cb0ef41Sopenharmony_ci e.initEvent("type 1", true, false) 511cb0ef41Sopenharmony_ci assert_equals(e.bubbles, true, "bubbles (first init)") 521cb0ef41Sopenharmony_ci assert_equals(e.cancelable, false, "cancelable (first init)") 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci e.initEvent("type 2", false, true) 551cb0ef41Sopenharmony_ci assert_equals(e.type, "type 2", "type (second init)") 561cb0ef41Sopenharmony_ci assert_equals(e.bubbles, false, "bubbles (second init)") 571cb0ef41Sopenharmony_ci assert_equals(e.cancelable, true, "cancelable (second init)") 581cb0ef41Sopenharmony_ci}, "Calling initEvent multiple times (not getting type).") 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci// Step 2. 611cb0ef41Sopenharmony_ciasync_test(function() { 621cb0ef41Sopenharmony_ci // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17715 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 651cb0ef41Sopenharmony_ci e.initEvent("type", false, false) 661cb0ef41Sopenharmony_ci assert_equals(e.type, "type", "type (first init)") 671cb0ef41Sopenharmony_ci assert_equals(e.bubbles, false, "bubbles (first init)") 681cb0ef41Sopenharmony_ci assert_equals(e.cancelable, false, "cancelable (first init)") 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci var target = document.createElement("div") 711cb0ef41Sopenharmony_ci target.addEventListener("type", this.step_func(function() { 721cb0ef41Sopenharmony_ci e.initEvent("fail", true, true) 731cb0ef41Sopenharmony_ci assert_equals(e.type, "type", "type (second init)") 741cb0ef41Sopenharmony_ci assert_equals(e.bubbles, false, "bubbles (second init)") 751cb0ef41Sopenharmony_ci assert_equals(e.cancelable, false, "cancelable (second init)") 761cb0ef41Sopenharmony_ci }), false) 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci this.done() 811cb0ef41Sopenharmony_ci}, "Calling initEvent must not have an effect during dispatching.") 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_citest(function() { 841cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 851cb0ef41Sopenharmony_ci e.stopPropagation() 861cb0ef41Sopenharmony_ci e.initEvent("type", false, false) 871cb0ef41Sopenharmony_ci var target = document.createElement("div") 881cb0ef41Sopenharmony_ci var called = false 891cb0ef41Sopenharmony_ci target.addEventListener("type", function() { called = true }, false) 901cb0ef41Sopenharmony_ci assert_false(e.cancelBubble, "cancelBubble must be false") 911cb0ef41Sopenharmony_ci assert_true(target.dispatchEvent(e), "dispatchEvent must return true") 921cb0ef41Sopenharmony_ci assert_true(called, "Listener must be called") 931cb0ef41Sopenharmony_ci}, "Calling initEvent must unset the stop propagation flag.") 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_citest(function() { 961cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 971cb0ef41Sopenharmony_ci e.stopImmediatePropagation() 981cb0ef41Sopenharmony_ci e.initEvent("type", false, false) 991cb0ef41Sopenharmony_ci var target = document.createElement("div") 1001cb0ef41Sopenharmony_ci var called = false 1011cb0ef41Sopenharmony_ci target.addEventListener("type", function() { called = true }, false) 1021cb0ef41Sopenharmony_ci assert_true(target.dispatchEvent(e), "dispatchEvent must return true") 1031cb0ef41Sopenharmony_ci assert_true(called, "Listener must be called") 1041cb0ef41Sopenharmony_ci}, "Calling initEvent must unset the stop immediate propagation flag.") 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ciasync_test(function() { 1071cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 1081cb0ef41Sopenharmony_ci e.initEvent("type", false, false) 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_ci var target = document.createElement("div") 1111cb0ef41Sopenharmony_ci target.addEventListener("type", this.step_func(function() { 1121cb0ef41Sopenharmony_ci e.initEvent("type2", true, true); 1131cb0ef41Sopenharmony_ci assert_equals(e.type, "type", "initEvent type setter should short-circuit"); 1141cb0ef41Sopenharmony_ci assert_false(e.bubbles, "initEvent bubbles setter should short-circuit"); 1151cb0ef41Sopenharmony_ci assert_false(e.cancelable, "initEvent cancelable setter should short-circuit"); 1161cb0ef41Sopenharmony_ci }), false) 1171cb0ef41Sopenharmony_ci assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true") 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ci this.done() 1201cb0ef41Sopenharmony_ci}, "Calling initEvent during propagation.") 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_citest(function() { 1231cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 1241cb0ef41Sopenharmony_ci assert_throws_js(TypeError, function() { 1251cb0ef41Sopenharmony_ci e.initEvent() 1261cb0ef41Sopenharmony_ci }) 1271cb0ef41Sopenharmony_ci}, "First parameter to initEvent should be mandatory.") 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_citest(function() { 1301cb0ef41Sopenharmony_ci var e = document.createEvent("Event") 1311cb0ef41Sopenharmony_ci e.initEvent("type") 1321cb0ef41Sopenharmony_ci assert_equals(e.type, "type", "type") 1331cb0ef41Sopenharmony_ci assert_false(e.bubbles, "bubbles") 1341cb0ef41Sopenharmony_ci assert_false(e.cancelable, "cancelable") 1351cb0ef41Sopenharmony_ci}, "Tests initEvent's default parameter values.") 1361cb0ef41Sopenharmony_ci</script> 137