tor-browser

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

shared-worker-options-mismatch.html (2805B)


      1 <!DOCTYPE html>
      2 <title>SharedWorker: type or credentials mismatch failure</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script>
      6 
      7 const mismatch_test = (testName, firstOptions, secondOptions) => {
      8  promise_test(async () => {
      9    firstOptions.name = testName;
     10    secondOptions.name = testName;
     11    const scriptURL = 'support/SharedWorker-common.js';
     12    const firstWorker = new SharedWorker(scriptURL, firstOptions);
     13    const secondWorker = new SharedWorker(scriptURL, secondOptions);
     14    const result = new Promise((resolve, reject) => {
     15      secondWorker.onerror = resolve;
     16      secondWorker.port.onmessage = () => reject("Worker loaded succesfully");
     17    });
     18    secondWorker.port.postMessage("ping");
     19    await result;
     20    firstWorker.port.postMessage("close");
     21    secondWorker.port.postMessage("close");
     22    return result;
     23  }, 'Connecting to shared worker with different options should be blocked: '
     24  + testName);
     25 };
     26 
     27 // Tests different type.
     28 mismatch_test('default to module', {}, { type: 'module' });
     29 mismatch_test('module to default', { type: 'module' }, {});
     30 mismatch_test('classic to module', { type: 'classic' }, { type: 'module' });
     31 mismatch_test('module to classic', { type: 'module' }, { type: 'classic' });
     32 
     33 // Tests different credentials in classic and module.
     34 ['classic', 'module'].forEach(type => {
     35  mismatch_test('default to omit in ' + type,
     36                { type },
     37                { type, credentials: 'omit' });
     38  mismatch_test('default to include in ' + type,
     39                { type },
     40                { type, credentials: 'include' });
     41  mismatch_test('omit to default in ' + type,
     42                { type, credentials: 'omit' },
     43                { type });
     44  mismatch_test('omit to same-origin in ' + type,
     45                { type, credentials: 'omit' },
     46                { type, credentials: 'same-origin' });
     47  mismatch_test('omit to include in ' + type,
     48                { type, credentials: 'omit' },
     49                { type, credentials: 'include' });
     50  mismatch_test('same-origin to omit in ' + type,
     51                { type, credentials: 'same-origin'},
     52                { type, credentials: 'omit' });
     53  mismatch_test('same-origin to include in ' + type,
     54                { type, credentials: 'same-origin'},
     55                { type, credentials: 'include' });
     56  mismatch_test('include to default in ' + type,
     57                { type, credentials: 'include' },
     58                { type });
     59  mismatch_test('include to omit in ' + type,
     60                { type, credentials: 'include' },
     61                { type, credentials: 'omit' });
     62  mismatch_test('include to same-origin in ' + type,
     63                { type, credentials: 'include' },
     64                { type, credentials: 'same-origin' });
     65 });
     66 
     67 </script>