tor-browser

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

resources.js (1830B)


      1 'use strict';
      2 
      3 const swUrl = 'resources/sw.js';
      4 const scope = 'resources/';
      5 
      6 async function expectTypeError(promise) {
      7  try {
      8    await promise;
      9    assert_unreached('Promise should have rejected');
     10  } catch (e) {
     11    assert_equals(e.name, 'TypeError');
     12  }
     13 }
     14 
     15 function createDescription({id = 'id', title = 'title', description = 'description',
     16                            category = 'homepage', iconUrl = '/images/green-256x256.png',
     17                            url = scope, includeIcons = true}) {
     18  return {id, title, description, category, icons: includeIcons ? [{src: iconUrl}] : [], url};
     19 }
     20 
     21 // Creates a Promise test for |func| given the |description|. The |func| will be
     22 // executed with the `index` object of an activated Service Worker Registration.
     23 function contentIndexTest(func, description) {
     24  promise_test(async t => {
     25    const registration = await service_worker_unregister_and_register(t, swUrl, scope);
     26    await wait_for_state(t, registration.installing, 'activated');
     27    return func(t, registration.index);
     28  }, description);
     29 }
     30 
     31 async function waitForMessageFromServiceWorker() {
     32  return await new Promise(resolve => {
     33    const listener = event => {
     34      navigator.serviceWorker.removeEventListener('message', listener);
     35      resolve(event.data);
     36    };
     37 
     38    navigator.serviceWorker.addEventListener('message', listener);
     39  });
     40 }
     41 
     42 // Returns a promise if the chromium based browser fetches icons for
     43 // content-index.
     44 async function fetchesIconsChromium() {
     45  const {fetchesIcons} =
     46      await import('/resources/chromium/content-index-helpers.js');
     47  return fetchesIcons();
     48 }
     49 
     50 // Returns a promise if the browser fetches icons for content-index and should
     51 // therefore validate them.
     52 async function fetchesIcons() {
     53  if (isChromiumBased) {
     54    return fetchesIconsChromium();
     55  }
     56  return false;
     57 }