1<!doctype html> 2<title>Event propagation tests</title> 3<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name> 4<div id=log></div> 5<script src=/resources/testharness.js></script> 6<script src=/resources/testharnessreport.js></script> 7<script> 8"use strict"; 9 10function testPropagationFlag(ev, expected, desc) { 11 test(function() { 12 var called = false; 13 var callback = function() { called = true }; 14 this.add_cleanup(function() { 15 document.head.removeEventListener("foo", callback) 16 }); 17 document.head.addEventListener("foo", callback); 18 document.head.dispatchEvent(ev); 19 assert_equals(called, expected, "Propagation flag"); 20 // dispatchEvent resets the propagation flags so it will happily dispatch 21 // the event the second time around. 22 document.head.dispatchEvent(ev); 23 assert_equals(called, true, "Propagation flag after first dispatch"); 24 }, desc); 25} 26 27var ev = document.createEvent("Event"); 28ev.initEvent("foo", true, false); 29testPropagationFlag(ev, true, "Newly-created Event"); 30ev.stopPropagation(); 31testPropagationFlag(ev, false, "After stopPropagation()"); 32ev.initEvent("foo", true, false); 33testPropagationFlag(ev, true, "Reinitialized after stopPropagation()"); 34 35var ev = document.createEvent("Event"); 36ev.initEvent("foo", true, false); 37ev.stopImmediatePropagation(); 38testPropagationFlag(ev, false, "After stopImmediatePropagation()"); 39ev.initEvent("foo", true, false); 40testPropagationFlag(ev, true, "Reinitialized after stopImmediatePropagation()"); 41 42var ev = document.createEvent("Event"); 43ev.initEvent("foo", true, false); 44ev.cancelBubble = true; 45testPropagationFlag(ev, false, "After cancelBubble=true"); 46ev.initEvent("foo", true, false); 47testPropagationFlag(ev, true, "Reinitialized after cancelBubble=true"); 48</script> 49