tor-browser

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

browser_net_prefs-and-l10n.js (2101B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests if the preferences and localization objects work correctly.
      8 */
      9 
     10 add_task(async function () {
     11  const {
     12    L10N,
     13  } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
     14 
     15  const { monitor } = await initNetMonitor(SIMPLE_URL, { requestCount: 1 });
     16  info("Starting test... ");
     17 
     18  const { windowRequire } = monitor.panelWin;
     19  const { Prefs } = windowRequire("devtools/client/netmonitor/src/utils/prefs");
     20 
     21  testL10N();
     22  testPrefs();
     23 
     24  return teardown(monitor);
     25 
     26  function testL10N() {
     27    is(
     28      typeof L10N.getStr("netmonitor.security.enabled"),
     29      "string",
     30      "The getStr() method didn't return a valid string."
     31    );
     32    is(
     33      typeof L10N.getFormatStr("networkMenu.totalMS2", "foo"),
     34      "string",
     35      "The getFormatStr() method didn't return a valid string."
     36    );
     37  }
     38 
     39  function testPrefs() {
     40    is(
     41      Prefs.networkDetailsWidth,
     42      Services.prefs.getIntPref(
     43        "devtools.netmonitor.panes-network-details-width"
     44      ),
     45      "Getting a pref should work correctly."
     46    );
     47 
     48    const previousValue = Prefs.networkDetailsWidth;
     49    const bogusValue = ~~(Math.random() * 100);
     50    Prefs.networkDetailsWidth = bogusValue;
     51    is(
     52      Prefs.networkDetailsWidth,
     53      Services.prefs.getIntPref(
     54        "devtools.netmonitor.panes-network-details-width"
     55      ),
     56      "Getting a pref after it has been modified should work correctly."
     57    );
     58    is(
     59      Prefs.networkDetailsWidth,
     60      bogusValue,
     61      "The pref wasn't updated correctly in the preferences object."
     62    );
     63 
     64    Prefs.networkDetailsWidth = previousValue;
     65    is(
     66      Prefs.networkDetailsWidth,
     67      Services.prefs.getIntPref(
     68        "devtools.netmonitor.panes-network-details-width"
     69      ),
     70      "Getting a pref after it has been modified again should work correctly."
     71    );
     72    is(
     73      Prefs.networkDetailsWidth,
     74      previousValue,
     75      "The pref wasn't updated correctly again in the preferences object."
     76    );
     77  }
     78 });