11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<meta charset="utf-8">
31cb0ef41Sopenharmony_ci<title>Re-initializing events while dispatching them</title>
41cb0ef41Sopenharmony_ci<link rel="author" title="Josh Matthews" href="mailto:josh@joshmatthews.net">
51cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
61cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
71cb0ef41Sopenharmony_ci<div id="log"></div>
81cb0ef41Sopenharmony_ci<script>
91cb0ef41Sopenharmony_civar events = {
101cb0ef41Sopenharmony_ci  'KeyboardEvent': {
111cb0ef41Sopenharmony_ci    'constructor': function() { return new KeyboardEvent("type", {key: "A"}); },
121cb0ef41Sopenharmony_ci    'init': function(ev) { ev.initKeyboardEvent("type2", true, true, null, "a", 1, "", true, "") },
131cb0ef41Sopenharmony_ci    'check': function(ev) {
141cb0ef41Sopenharmony_ci       assert_equals(ev.key, "A", "initKeyboardEvent key setter should short-circuit");
151cb0ef41Sopenharmony_ci       assert_false(ev.repeat, "initKeyboardEvent repeat setter should short-circuit");
161cb0ef41Sopenharmony_ci       assert_equals(ev.location, 0, "initKeyboardEvent location setter should short-circuit");
171cb0ef41Sopenharmony_ci     }
181cb0ef41Sopenharmony_ci  },
191cb0ef41Sopenharmony_ci  'MouseEvent': {
201cb0ef41Sopenharmony_ci    'constructor': function() { return new MouseEvent("type"); },
211cb0ef41Sopenharmony_ci    'init': function(ev) { ev.initMouseEvent("type2", true, true, null, 0, 1, 1, 1, 1, true, true, true, true, 1, null) },
221cb0ef41Sopenharmony_ci    'check': function(ev) {
231cb0ef41Sopenharmony_ci      assert_equals(ev.screenX, 0, "initMouseEvent screenX setter should short-circuit");
241cb0ef41Sopenharmony_ci      assert_equals(ev.screenY, 0, "initMouseEvent screenY setter should short-circuit");
251cb0ef41Sopenharmony_ci      assert_equals(ev.clientX, 0, "initMouseEvent clientX setter should short-circuit");
261cb0ef41Sopenharmony_ci      assert_equals(ev.clientY, 0, "initMouseEvent clientY setter should short-circuit");
271cb0ef41Sopenharmony_ci      assert_false(ev.ctrlKey, "initMouseEvent ctrlKey setter should short-circuit");
281cb0ef41Sopenharmony_ci      assert_false(ev.altKey, "initMouseEvent altKey setter should short-circuit");
291cb0ef41Sopenharmony_ci      assert_false(ev.shiftKey, "initMouseEvent shiftKey setter should short-circuit");
301cb0ef41Sopenharmony_ci      assert_false(ev.metaKey, "initMouseEvent metaKey setter should short-circuit");
311cb0ef41Sopenharmony_ci      assert_equals(ev.button, 0, "initMouseEvent button setter should short-circuit");
321cb0ef41Sopenharmony_ci    }
331cb0ef41Sopenharmony_ci  },
341cb0ef41Sopenharmony_ci  'CustomEvent': {
351cb0ef41Sopenharmony_ci    'constructor': function() { return new CustomEvent("type") },
361cb0ef41Sopenharmony_ci    'init': function(ev) { ev.initCustomEvent("type2", true, true, 1) },
371cb0ef41Sopenharmony_ci    'check': function(ev) {
381cb0ef41Sopenharmony_ci      assert_equals(ev.detail, null, "initCustomEvent detail setter should short-circuit");
391cb0ef41Sopenharmony_ci    }
401cb0ef41Sopenharmony_ci  },
411cb0ef41Sopenharmony_ci  'UIEvent': {
421cb0ef41Sopenharmony_ci    'constructor': function() { return new UIEvent("type") },
431cb0ef41Sopenharmony_ci    'init': function(ev) { ev.initUIEvent("type2", true, true, window, 1) },
441cb0ef41Sopenharmony_ci    'check': function(ev) {
451cb0ef41Sopenharmony_ci      assert_equals(ev.view, null, "initUIEvent view setter should short-circuit");
461cb0ef41Sopenharmony_ci      assert_equals(ev.detail, 0, "initUIEvent detail setter should short-circuit");
471cb0ef41Sopenharmony_ci    }
481cb0ef41Sopenharmony_ci  },
491cb0ef41Sopenharmony_ci  'Event': {
501cb0ef41Sopenharmony_ci    'constructor': function() { return new Event("type") },
511cb0ef41Sopenharmony_ci    'init': function(ev) { ev.initEvent("type2", true, true) },
521cb0ef41Sopenharmony_ci    'check': function(ev) {
531cb0ef41Sopenharmony_ci      assert_equals(ev.bubbles, false, "initEvent bubbles setter should short-circuit");
541cb0ef41Sopenharmony_ci      assert_equals(ev.cancelable, false, "initEvent cancelable setter should short-circuit");
551cb0ef41Sopenharmony_ci      assert_equals(ev.type, "type", "initEvent type setter should short-circuit");
561cb0ef41Sopenharmony_ci    }
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci};
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_civar names = Object.keys(events);
611cb0ef41Sopenharmony_cifor (var i = 0; i < names.length; i++) {
621cb0ef41Sopenharmony_ci  var t = async_test("Calling init" + names[i] + " while dispatching.");
631cb0ef41Sopenharmony_ci  t.step(function() {
641cb0ef41Sopenharmony_ci    var e = events[names[i]].constructor();
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci    var target = document.createElement("div")
671cb0ef41Sopenharmony_ci    target.addEventListener("type", t.step_func(function() {
681cb0ef41Sopenharmony_ci      events[names[i]].init(e);
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci      var o = e;
711cb0ef41Sopenharmony_ci      while ((o = Object.getPrototypeOf(o))) {
721cb0ef41Sopenharmony_ci        if (!(o.constructor.name in events)) {
731cb0ef41Sopenharmony_ci          break;
741cb0ef41Sopenharmony_ci        }
751cb0ef41Sopenharmony_ci        events[o.constructor.name].check(e);
761cb0ef41Sopenharmony_ci      }
771cb0ef41Sopenharmony_ci    }), false);
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci    assert_equals(target.dispatchEvent(e), true, "dispatchEvent must return true")
801cb0ef41Sopenharmony_ci  });
811cb0ef41Sopenharmony_ci  t.done();
821cb0ef41Sopenharmony_ci}
831cb0ef41Sopenharmony_ci</script>
84