tor-browser

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

managed-configuration-helper.js (1774B)


      1 'use strict';
      2 
      3 // These tests rely on the User Agent providing an implementation of
      4 // Managed Configuration API
      5 // (https://wicg.github.io/WebApiDevice/managed_config).
      6 //
      7 // In Chromium-based browsers this implementation is provided by a polyfill
      8 // in order to reduce the amount of test-only code shipped to users. To enable
      9 // these tests the browser must be run with these options:
     10 //
     11 //   --enable-blink-features=MojoJS,MojoJSTest
     12 let fakeManagedConfigurationService = undefined;
     13 
     14 async function loadChromiumResources() {
     15  await import('/resources/chromium/mock-managed-config.js');
     16 }
     17 
     18 // User Agents must provide their own implementation of `ManagedConfigTest`,
     19 // which must contain the following this interface:
     20 // class ManagedConfigTest {
     21 //   /** Replaces the provided managed config with the given one. */
     22 //   /** @param {?Object} config */
     23 //   setManagedConfig(config);
     24 //   /** Asynchronously waits for a new observer to be added */
     25 //   waitTillObserverAdded();
     26 // }
     27 
     28 async function createManagedConfigTest() {
     29  if (typeof ManagedConfigTest === 'undefined') {
     30    if (isChromiumBased) {
     31      await loadChromiumResources();
     32    }
     33  }
     34  assert_implements(ManagedConfigTest, 'ManagedConfigTest is unavailable.');
     35 
     36  if (fakeManagedConfigurationService !== undefined) {
     37    await fakeManagedConfigurationService.initialize();
     38    return fakeManagedConfigurationService;
     39  }
     40  let managedConfigTest = new ManagedConfigTest();
     41  await managedConfigTest.initialize();
     42  fakeManagedConfigurationService = managedConfigTest;
     43  return managedConfigTest;
     44 }
     45 
     46 function managed_config_test(func, description) {
     47  promise_test(async test => {
     48    const managedConfigTest = await createManagedConfigTest();
     49    await func(test, managedConfigTest);
     50  }, description);
     51 }