tor-browser

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

inline-speculation-rules-errors.html (1213B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script>
      5 setup({ allow_uncaught_exception: true });
      6 
      7 promise_test(async t => {
      8  const script = document.createElement('script');
      9  script.type = 'speculationrules';
     10  script.textContent = 'invalid json';
     11 
     12  const log = [];
     13  const elementError = new Promise(resolve => {
     14    script.addEventListener('error', e => {
     15      assert_equals(e.constructor, Event, 'event should be a simple Event');
     16      log.push('element error');
     17      resolve();
     18    }, { once: true });
     19  });
     20 
     21  const globalError = new Promise(resolve => {
     22    window.addEventListener('error', e => {
     23      e.preventDefault();
     24      assert_equals(e.constructor, ErrorEvent, 'global event should be an ErrorEvent');
     25      assert_equals(e.error.constructor, TypeError, 'e.error should be a TypeError');
     26      log.push('global error');
     27      resolve();
     28    }, { once: true });
     29  });
     30 
     31  document.head.appendChild(script);
     32 
     33  await Promise.all([elementError, globalError]);
     34  assert_array_equals(log, ['element error', 'global error']);
     35 }, 'A script with invalid JSON should fire error events on the element and window');
     36 </script>