tor-browser

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

clients-matchall-exact-controller.https.html (2245B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: Clients.matchAll with exact controller</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="resources/test-helpers.sub.js"></script>
      6 <script>
      7 const scope = 'resources/blank.html?clients-matchAll';
      8 let frames = [];
      9 
     10 function checkWorkerClients(worker, expected) {
     11  return new Promise((resolve, reject) => {
     12    let channel = new MessageChannel();
     13    channel.port1.onmessage = evt => {
     14      try {
     15        assert_equals(evt.data.length, expected.length);
     16        for (let i = 0; i < expected.length; ++i) {
     17          assert_array_equals(evt.data[i], expected[i]);
     18        }
     19        resolve();
     20      } catch (e) {
     21        reject(e);
     22      }
     23    };
     24 
     25    worker.postMessage({port:channel.port2}, [channel.port2]);
     26  });
     27 }
     28 
     29 let expected = [
     30    // visibilityState, focused, url, type, frameType
     31    ['visible', true, new URL(scope + '#1', location).toString(), 'window', 'nested'],
     32    ['visible', false, new URL(scope + '#2', location).toString(), 'window', 'nested']
     33 ];
     34 
     35 promise_test(t => {
     36    let script = 'resources/clients-matchall-worker.js';
     37    return service_worker_unregister_and_register(t, script, scope)
     38      .then(registration => {
     39          t.add_cleanup(() => service_worker_unregister(t, scope));
     40 
     41          return wait_for_state(t, registration.installing, 'activated');
     42        })
     43      .then(_ => with_iframe(scope + '#1') )
     44      .then(frame1 => {
     45          frames.push(frame1);
     46          frame1.focus();
     47          return with_iframe(scope + '#2');
     48        })
     49      .then(frame2 => {
     50          frames.push(frame2);
     51          return navigator.serviceWorker.register(script + '?updated', { scope: scope });
     52        })
     53      .then(registration => {
     54          return wait_for_state(t, registration.installing, 'installed')
     55            .then(_ => registration);
     56        })
     57      .then(registration => {
     58          return Promise.all([
     59            checkWorkerClients(registration.waiting, []),
     60            checkWorkerClients(registration.active, expected),
     61          ]);
     62        })
     63      .then(_ => {
     64          frames.forEach(f => f.remove() );
     65        });
     66 }, 'Test Clients.matchAll() with exact controller');
     67 </script>