tor-browser

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

notify-event-invalid.https.html (3689B)


      1 <!DOCTYPE html>
      2 <meta name="timeout" content="long">
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/resources/testdriver.js"></script>
      6 <script src="/resources/testdriver-actions.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script src="/common/utils.js"></script>
      9 <script src="/common/dispatcher/dispatcher.js"></script>
     10 <script src="/common/get-host-info.sub.js"></script>
     11 <script src="resources/utils.js"></script>
     12 <title>Test that fenced frame notifyEvent() fails with invalid event parameters</title>
     13 
     14 <body>
     15  <script>
     16    promise_test(async (t) => {
     17      const fencedframe = await attachFencedFrameContext(
     18                  {generator_api: 'fledge'});
     19      let notified = false;
     20      fencedframe.element.addEventListener('fencedtreeclick', () => notified = true);
     21 
     22      // Only "click" is supported for now, so any other type of event should
     23      // fail to notify.
     24      await fencedframe.execute(() => {
     25        document.addEventListener('mousedown', (e) => {
     26          try {
     27            window.fence.notifyEvent(e);
     28          } catch (err) {
     29            window.click_error = err;
     30            return;
     31          }
     32          window.click_error = new TypeError('No exception');
     33        });
     34      });
     35 
     36      await multiClick(10, 10, fencedframe.element);
     37 
     38      await fencedframe.execute(() => {
     39        assert_equals(window.click_error.name, 'SecurityError');
     40        assert_equals(window.click_error.message,
     41        "Failed to execute 'notifyEvent' on 'Fence': notifyEvent called with an unsupported event type.");
     42      });
     43 
     44      assert_false(notified);
     45    }, "Test that fenced frame notifyEvent() fails using the incorrect event type.");
     46 
     47    promise_test(async (t) => {
     48      const fencedframe = await attachFencedFrameContext(
     49                  {generator_api: 'fledge'});
     50      let notified = false;
     51      fencedframe.element.addEventListener('fencedtreeclick', () => notified = true);
     52 
     53      await fencedframe.execute(() => {
     54        // Event objects constructed manually are not "trusted", so this event
     55        // should fail to notify. "Trusted" means that the event was created by
     56        // the user agent itself.
     57        let fake_click = new Event('click');
     58        try {
     59          window.fence.notifyEvent(fake_click);
     60        } catch (err) {
     61          assert_equals(err.name, 'SecurityError');
     62          assert_equals(err.message, "Failed to execute 'notifyEvent' on 'Fence': The triggering_event object is in an invalid state.");
     63          return;
     64        }
     65        assert_unreached('An untrusted event must cause a SecurityError.');
     66      });
     67 
     68      assert_false(notified);
     69    }, "Test that fenced frame notifyEvent() fails using an untrusted event.");
     70 
     71    promise_test(async (t) => {
     72      const fencedframe = await attachFencedFrameContext(
     73                  {generator_api: 'fledge'});
     74      let notified = false;
     75      fencedframe.element.addEventListener('fencedtreemousedown', () => {
     76        notified = true;
     77      });
     78 
     79      // This click handler should not trigger the above handler on the
     80      // HTMLFencedFrameElement, because its type is not 'fencedtreeclick'.
     81      await fencedframe.execute(() => {
     82        document.addEventListener('click', (e) => {
     83          window.fence.notifyEvent(e);
     84        });
     85      });
     86 
     87      await multiClick(10, 10, fencedframe.element);
     88 
     89      // Wait 2s to let any event handling code settle.
     90      await new Promise((resolve) => t.step_timeout(
     91          () => resolve(), 2000));
     92 
     93      assert_false(notified);
     94    }, "Test that fenced frame notifyEvent() only invokes 'fencedtreeclick'.");
     95  </script>
     96 </body>