tor-browser

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

test_sharedMap_static_prefs.js (2599B)


      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 // Tests that static preferences in the content process
      7 // correctly handle values which are different from their
      8 // statically-defined defaults.
      9 //
     10 // Since we can't access static preference values from JS, this tests relies on
     11 // assertions in debug builds to detect mismatches. The default and user
     12 // values of two preferences are changed (respectively) before a content
     13 // process is started. Once the content process is launched, the
     14 // preference service asserts that the values stored in all static prefs
     15 // match their current values as known to the preference service. If
     16 // there's a mismatch, the shell will crash, and the test will fail.
     17 //
     18 // For sanity, we also check that the dynamically retrieved preference
     19 // values in the content process match our expectations, though this is
     20 // not strictly part of the test.
     21 
     22 const PREF1_NAME = "dom.webcomponents.shadowdom.report_usage";
     23 const PREF1_VALUE = false;
     24 
     25 const PREF2_NAME = "full-screen-api.enabled";
     26 const PREF2_VALUE = true;
     27 
     28 const { XPCShellContentUtils } = ChromeUtils.importESModule(
     29  "resource://testing-common/XPCShellContentUtils.sys.mjs"
     30 );
     31 
     32 XPCShellContentUtils.init(this);
     33 
     34 const { prefs } = Services;
     35 const defaultPrefs = prefs.getDefaultBranch("");
     36 
     37 add_task(async function test_sharedMap_static_prefs() {
     38  equal(
     39    prefs.getBoolPref(PREF1_NAME),
     40    PREF1_VALUE,
     41    `Expected initial value for ${PREF1_NAME}`
     42  );
     43  equal(
     44    prefs.getBoolPref(PREF2_NAME),
     45    PREF2_VALUE,
     46    `Expected initial value for ${PREF2_NAME}`
     47  );
     48 
     49  defaultPrefs.setBoolPref(PREF1_NAME, !PREF1_VALUE);
     50  prefs.setBoolPref(PREF2_NAME, !PREF2_VALUE);
     51 
     52  equal(
     53    prefs.getBoolPref(PREF1_NAME),
     54    !PREF1_VALUE,
     55    `Expected updated value for ${PREF1_NAME}`
     56  );
     57  equal(
     58    prefs.getBoolPref(PREF2_NAME),
     59    !PREF2_VALUE,
     60    `Expected updated value for ${PREF2_NAME}`
     61  );
     62 
     63  let contentPage = await XPCShellContentUtils.loadContentPage("about:blank", {
     64    remote: true,
     65  });
     66  registerCleanupFunction(() => contentPage.close());
     67 
     68  /* eslint-disable no-shadow */
     69  let values = await contentPage.spawn([[PREF1_NAME, PREF2_NAME]], prefs => {
     70    return prefs.map(pref => Services.prefs.getBoolPref(pref));
     71  });
     72  /* eslint-enable no-shadow */
     73 
     74  equal(values[0], !PREF1_VALUE, `Expected content value for ${PREF1_NAME}`);
     75  equal(values[1], !PREF2_VALUE, `Expected content value for ${PREF2_NAME}`);
     76 });