tor-browser

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

clients-matchall-frozen.https.html (2552B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: Clients.matchAll</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 var scope = 'resources/clients-frame-freeze.html';
      8 var windows = [];
      9 var expected_window_1 =
     10    {visibilityState: 'visible', focused: false, lifecycleState: "frozen", url: new URL(scope + '#1', location).toString(), type: 'window', frameType: 'top-level'};
     11 var expected_window_2 =
     12    {visibilityState: 'visible', focused: false, lifecycleState: "active", url: new URL(scope + '#2', location).toString(), type: 'window', frameType: 'top-level'};
     13 function with_window(url, name) {
     14  return new Promise(function(resolve) {
     15    var child = window.open(url, name);
     16    window.onmessage = () => {resolve(child)};
     17  });
     18 }
     19 
     20 promise_test(function(t) {
     21    return service_worker_unregister_and_register(
     22        t, 'resources/clients-matchall-worker.js', scope)
     23      .then(function(registration) {
     24          t.add_cleanup(function() {
     25              return service_worker_unregister(t, scope);
     26            });
     27 
     28          return wait_for_state(t, registration.installing, 'activated');
     29        })
     30      .then(function() { return with_window(scope + '#1', 'Child 1'); })
     31      .then(function(window1) {
     32          windows.push(window1);
     33          return with_window(scope + '#2', 'Child 2');
     34        })
     35      .then(function(window2) {
     36          windows.push(window2);
     37          return new Promise(function(resolve) {
     38              window.onmessage = resolve;
     39              windows[0].postMessage('freeze');
     40            });
     41        })
     42      .then(function() {
     43          var channel = new MessageChannel();
     44 
     45          return new Promise(function(resolve) {
     46              channel.port1.onmessage = resolve;
     47              windows[1].navigator.serviceWorker.controller.postMessage(
     48                  {port:channel.port2, includeLifecycleState: true}, [channel.port2]);
     49            });
     50        })
     51      .then(function(e) {
     52          assert_equals(e.data.length, 2);
     53          // No specific order is required, so support inversion.
     54          if (e.data[0][3] == new URL(scope + '#2', location)) {
     55            assert_object_equals(e.data[0], expected_window_2);
     56            assert_object_equals(e.data[1], expected_window_1);
     57          } else {
     58            assert_object_equals(e.data[0], expected_window_1);
     59            assert_object_equals(e.data[1], expected_window_2);
     60          }
     61      });
     62 }, 'Test Clients.matchAll()');
     63 
     64 </script>