tor-browser

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

head.js (2407B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 "use strict";
      5 
      6 const BackgroundJSM = ChromeUtils.importESModule(
      7  "resource://devtools/client/performance-new/shared/background.sys.mjs"
      8 );
      9 
     10 const PrefsPresets = ChromeUtils.importESModule(
     11  "resource://devtools/shared/performance-new/prefs-presets.sys.mjs"
     12 );
     13 
     14 // Recording already set preferences.
     15 const devtoolsPreferences = Services.prefs.getBranch("devtools");
     16 const alreadySetPreferences = new Set();
     17 for (const pref of devtoolsPreferences.getChildList("")) {
     18  if (devtoolsPreferences.prefHasUserValue(pref)) {
     19    alreadySetPreferences.add(pref);
     20  }
     21 }
     22 
     23 // Reset all devtools preferences on test end.
     24 registerCleanupFunction(async () => {
     25  await SpecialPowers.flushPrefEnv();
     26 
     27  // Reset devtools preferences modified by the test.
     28  for (const pref of devtoolsPreferences.getChildList("")) {
     29    if (
     30      devtoolsPreferences.prefHasUserValue(pref) &&
     31      !alreadySetPreferences.has(pref)
     32    ) {
     33      devtoolsPreferences.clearUserPref(pref);
     34    }
     35  }
     36 });
     37 
     38 registerCleanupFunction(() => {
     39  PrefsPresets.revertRecordingSettings();
     40 });
     41 
     42 /**
     43 * Allow tests to use "require".
     44 */
     45 const { require } = ChromeUtils.importESModule(
     46  "resource://devtools/shared/loader/Loader.sys.mjs"
     47 );
     48 
     49 {
     50  if (Services.env.get("MOZ_PROFILER_SHUTDOWN")) {
     51    throw new Error(
     52      "These tests cannot be run with shutdown profiling as they rely on manipulating " +
     53        "the state of the profiler."
     54    );
     55  }
     56 
     57  if (Services.profiler.IsActive()) {
     58    if (Services.env.exists("MOZ_PROFILER_STARTUP")) {
     59      // If the startup profiling environment variable exists, it is likely
     60      // that tests are being profiled.
     61      // Stop the profiler before starting profiler tests.
     62      info(
     63        "This test starts and stops the profiler and is not compatible " +
     64          "with the use of MOZ_PROFILER_STARTUP. " +
     65          "Stopping the profiler before starting the test."
     66      );
     67      Services.profiler.StopProfiler();
     68    } else {
     69      throw new Error(
     70        "The profiler must not be active before starting it in a test."
     71      );
     72    }
     73  }
     74 }
     75 
     76 Services.scriptloader.loadSubScript(
     77  "chrome://mochitests/content/browser/devtools/client/performance-new/test/browser/helpers.js",
     78  this
     79 );