11cb0ef41Sopenharmony_ci<!doctype html>
21cb0ef41Sopenharmony_ci<title>Event propagation tests</title>
31cb0ef41Sopenharmony_ci<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name>
41cb0ef41Sopenharmony_ci<div id=log></div>
51cb0ef41Sopenharmony_ci<script src=/resources/testharness.js></script>
61cb0ef41Sopenharmony_ci<script src=/resources/testharnessreport.js></script>
71cb0ef41Sopenharmony_ci<script>
81cb0ef41Sopenharmony_ci"use strict";
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction testPropagationFlag(ev, expected, desc) {
111cb0ef41Sopenharmony_ci  test(function() {
121cb0ef41Sopenharmony_ci    var called = false;
131cb0ef41Sopenharmony_ci    var callback = function() { called = true };
141cb0ef41Sopenharmony_ci    this.add_cleanup(function() {
151cb0ef41Sopenharmony_ci      document.head.removeEventListener("foo", callback)
161cb0ef41Sopenharmony_ci    });
171cb0ef41Sopenharmony_ci    document.head.addEventListener("foo", callback);
181cb0ef41Sopenharmony_ci    document.head.dispatchEvent(ev);
191cb0ef41Sopenharmony_ci    assert_equals(called, expected, "Propagation flag");
201cb0ef41Sopenharmony_ci    // dispatchEvent resets the propagation flags so it will happily dispatch
211cb0ef41Sopenharmony_ci    // the event the second time around.
221cb0ef41Sopenharmony_ci    document.head.dispatchEvent(ev);
231cb0ef41Sopenharmony_ci    assert_equals(called, true, "Propagation flag after first dispatch");
241cb0ef41Sopenharmony_ci  }, desc);
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_civar ev = document.createEvent("Event");
281cb0ef41Sopenharmony_ciev.initEvent("foo", true, false);
291cb0ef41Sopenharmony_citestPropagationFlag(ev, true, "Newly-created Event");
301cb0ef41Sopenharmony_ciev.stopPropagation();
311cb0ef41Sopenharmony_citestPropagationFlag(ev, false, "After stopPropagation()");
321cb0ef41Sopenharmony_ciev.initEvent("foo", true, false);
331cb0ef41Sopenharmony_citestPropagationFlag(ev, true, "Reinitialized after stopPropagation()");
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_civar ev = document.createEvent("Event");
361cb0ef41Sopenharmony_ciev.initEvent("foo", true, false);
371cb0ef41Sopenharmony_ciev.stopImmediatePropagation();
381cb0ef41Sopenharmony_citestPropagationFlag(ev, false, "After stopImmediatePropagation()");
391cb0ef41Sopenharmony_ciev.initEvent("foo", true, false);
401cb0ef41Sopenharmony_citestPropagationFlag(ev, true, "Reinitialized after stopImmediatePropagation()");
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_civar ev = document.createEvent("Event");
431cb0ef41Sopenharmony_ciev.initEvent("foo", true, false);
441cb0ef41Sopenharmony_ciev.cancelBubble = true;
451cb0ef41Sopenharmony_citestPropagationFlag(ev, false, "After cancelBubble=true");
461cb0ef41Sopenharmony_ciev.initEvent("foo", true, false);
471cb0ef41Sopenharmony_citestPropagationFlag(ev, true, "Reinitialized after cancelBubble=true");
481cb0ef41Sopenharmony_ci</script>
49