tor-browser

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

restriction-push.https.html (2543B)


      1 <!DOCTYPE html>
      2 <title>Access to the Push API is deferred</title>
      3 <meta name="timeout" content="long">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <script src="/common/utils.js"></script>
      9 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
     10 <script src="../resources/utils.js"></script>
     11 <script src="resources/utils.js"></script>
     12 
     13 <body>
     14 <script>
     15 setup(() => assertSpeculationRulesIsSupported());
     16 
     17 promise_test(async t => {
     18  const uid = token();
     19  const bc = new PrerenderChannel('test-channel', uid);
     20  t.add_cleanup(_ => bc.close());
     21 
     22  const gotMessage = new Promise(resolve => {
     23    bc.addEventListener('message', e => {
     24      resolve(e.data);
     25    }, {
     26      once: true
     27    });
     28  });
     29 
     30  // We grant the permission here to make a more discerning test because
     31  // pushManager.subscribe() waits until the permission is granted, which
     32  // is deferred during prerendering so the test would trivially pass without
     33  // the permission.
     34  await test_driver.set_permission({ name: 'push', userVisibleOnly: true },
     35                                   'granted');
     36 
     37  // Install the service worker first to test pushManager.subscribe in the
     38  // prerendering page.
     39  const scope = `resources/`;
     40  const script = `resources/do-nothing-worker.js`;
     41  const registration =
     42      await service_worker_unregister_and_register(t, script, scope);
     43  t.add_cleanup(() => registration.unregister());
     44  await wait_for_state(t, registration.installing, 'activated');
     45 
     46  const url = `resources/push.https.html?uid=${uid}`;
     47  window.open(url, '_blank', 'noopener');
     48 
     49  const result = await gotMessage;
     50  const expected = [
     51    {event: 'started waiting pushManager.subscribe',    prerendering: true},
     52    {event: 'prerendering change',                      prerendering: false},
     53    {event: 'finished waiting pushManager.subscribe',   prerendering: false},
     54  ];
     55  assert_equals(result.length, expected.length);
     56  for (let i = 0; i < result.length; i++) {
     57    assert_equals(result[i].event, expected[i].event, `event[${i}]`);
     58    assert_equals(result[i].prerendering, expected[i].prerendering,
     59      `prerendering[${i}]`);
     60  }
     61 
     62  // Send a close signal to PrerenderEventCollector on the prerendered page.
     63  new PrerenderChannel('close', uid).postMessage('');
     64 }, `The access to the Push API should be deferred until the prerendered page is
     65    activated`);
     66 </script>