tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Event-propagation.html (1772B)


      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 
     10 function 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 
     27 var ev = document.createEvent("Event");
     28 ev.initEvent("foo", true, false);
     29 testPropagationFlag(ev, true, "Newly-created Event");
     30 ev.stopPropagation();
     31 testPropagationFlag(ev, false, "After stopPropagation()");
     32 ev.initEvent("foo", true, false);
     33 testPropagationFlag(ev, true, "Reinitialized after stopPropagation()");
     34 
     35 var ev = document.createEvent("Event");
     36 ev.initEvent("foo", true, false);
     37 ev.stopImmediatePropagation();
     38 testPropagationFlag(ev, false, "After stopImmediatePropagation()");
     39 ev.initEvent("foo", true, false);
     40 testPropagationFlag(ev, true, "Reinitialized after stopImmediatePropagation()");
     41 
     42 var ev = document.createEvent("Event");
     43 ev.initEvent("foo", true, false);
     44 ev.cancelBubble = true;
     45 testPropagationFlag(ev, false, "After cancelBubble=true");
     46 ev.initEvent("foo", true, false);
     47 testPropagationFlag(ev, true, "Reinitialized after cancelBubble=true");
     48 </script>