tor-browser

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

test_prefs.js (2582B)


      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 file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const { Branch, EnvironmentPrefs, MarionettePrefs } =
      8  ChromeUtils.importESModule(
      9    "chrome://remote/content/marionette/prefs.sys.mjs"
     10  );
     11 
     12 function reset() {
     13  Services.prefs.setBoolPref("test.bool", false);
     14  Services.prefs.setStringPref("test.string", "foo");
     15  Services.prefs.setIntPref("test.int", 777);
     16 }
     17 
     18 // Give us something to work with:
     19 reset();
     20 
     21 add_task(function test_Branch_get_root() {
     22  let root = new Branch(null);
     23  equal(false, root.get("test.bool"));
     24  equal("foo", root.get("test.string"));
     25  equal(777, root.get("test.int"));
     26  Assert.throws(() => root.get("doesnotexist"), /TypeError/);
     27 });
     28 
     29 add_task(function test_Branch_get_branch() {
     30  let test = new Branch("test.");
     31  equal(false, test.get("bool"));
     32  equal("foo", test.get("string"));
     33  equal(777, test.get("int"));
     34  Assert.throws(() => test.get("doesnotexist"), /TypeError/);
     35 });
     36 
     37 add_task(function test_Branch_set_root() {
     38  let root = new Branch(null);
     39 
     40  try {
     41    root.set("test.string", "bar");
     42    root.set("test.in", 777);
     43    root.set("test.bool", true);
     44 
     45    equal("bar", Services.prefs.getStringPref("test.string"));
     46    equal(777, Services.prefs.getIntPref("test.int"));
     47    equal(true, Services.prefs.getBoolPref("test.bool"));
     48  } finally {
     49    reset();
     50  }
     51 });
     52 
     53 add_task(function test_Branch_set_branch() {
     54  let test = new Branch("test.");
     55 
     56  try {
     57    test.set("string", "bar");
     58    test.set("int", 888);
     59    test.set("bool", true);
     60 
     61    equal("bar", Services.prefs.getStringPref("test.string"));
     62    equal(888, Services.prefs.getIntPref("test.int"));
     63    equal(true, Services.prefs.getBoolPref("test.bool"));
     64  } finally {
     65    reset();
     66  }
     67 });
     68 
     69 add_task(function test_EnvironmentPrefs_from() {
     70  let prefsTable = {
     71    "test.bool": true,
     72    "test.int": 888,
     73    "test.string": "bar",
     74  };
     75  Services.env.set("FOO", JSON.stringify(prefsTable));
     76 
     77  try {
     78    for (let [key, value] of EnvironmentPrefs.from("FOO")) {
     79      equal(prefsTable[key], value);
     80    }
     81  } finally {
     82    Services.env.set("FOO", null);
     83  }
     84 });
     85 
     86 add_task(function test_MarionettePrefs_getters() {
     87  equal(false, MarionettePrefs.clickToStart);
     88  equal(2828, MarionettePrefs.port);
     89 });
     90 
     91 add_task(function test_MarionettePrefs_setters() {
     92  try {
     93    MarionettePrefs.port = 777;
     94    equal(777, MarionettePrefs.port);
     95  } finally {
     96    Services.prefs.clearUserPref("marionette.port");
     97  }
     98 });