tor-browser

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

clipboard-events-synthetic.html (1481B)


      1 <!doctype html>
      2 <title>synthetic clipboard events should not be composed</title>
      3 <link rel="help" href="https://w3c.github.io/clipboard-apis/#clipboard-event-copy">
      4 <link rel="help" href="https://w3c.github.io/clipboard-apis/#clipboard-event-cut">
      5 <link rel="help" href="https://w3c.github.io/clipboard-apis/#clipboard-event-paste">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <div id=log></div>
      9 <script>
     10 const EVENTS = [ 'copy', 'cut', 'paste' ];
     11 
     12 function testEvent(eventName, init, composed_flag_expectation, testName) {
     13  async_test(test => {
     14    document.addEventListener(eventName, test.step_func_done(e => {
     15      assert_false(e.isTrusted, `synthetic ${eventName} event is untrusted`);
     16      assert_equals(e.composed, composed_flag_expectation,
     17                    `composed flag should be ${composed_flag_expectation}`);
     18    }));
     19    const event = new ClipboardEvent(eventName, init);
     20    document.dispatchEvent(event);
     21  }, testName);
     22 }
     23 
     24 EVENTS.forEach(name => {
     25  testEvent(name, { bubbles: true, cancellable: true }, false,
     26            `Unspecified synthetic ${name} event should not be composed.`);
     27  testEvent(name, { bubbles: true, cancelable: true, composed: true }, true,
     28            `Synthetic ${name} event can be explicitly composed.`);
     29  testEvent(name, { bubbles: true, cancelable: true, composed: false }, false,
     30            `Synthetic ${name} event can be explicitly uncomposed.`);
     31 });
     32 </script>