tor-browser

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

browser_performance_e10srollout.js (3705B)


      1 const DEFAULT_HW_ACCEL_PREF = Services.prefs
      2  .getDefaultBranch(null)
      3  .getBoolPref("layers.acceleration.disabled");
      4 const DEFAULT_PROCESS_COUNT = Services.prefs
      5  .getDefaultBranch(null)
      6  .getIntPref("dom.ipc.processCount");
      7 
      8 add_task(async function () {
      9  // We must temporarily disable `Once` StaticPrefs check for the duration of
     10  // this test (see bug 1556131). We must do so in a separate operation as
     11  // pushPrefEnv doesn't set the preferences in the order one could expect.
     12  await SpecialPowers.pushPrefEnv({
     13    set: [["preferences.force-disable.check.once.policy", true]],
     14  });
     15  await SpecialPowers.pushPrefEnv({
     16    set: [
     17      ["layers.acceleration.disabled", DEFAULT_HW_ACCEL_PREF],
     18      ["dom.ipc.processCount", DEFAULT_PROCESS_COUNT],
     19      ["browser.preferences.defaultPerformanceSettings.enabled", true],
     20    ],
     21  });
     22 });
     23 
     24 add_task(async function testPrefsAreDefault() {
     25  Services.prefs.setIntPref("dom.ipc.processCount", DEFAULT_PROCESS_COUNT);
     26  Services.prefs.setBoolPref(
     27    "browser.preferences.defaultPerformanceSettings.enabled",
     28    true
     29  );
     30 
     31  let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     32    leaveOpen: true,
     33  });
     34  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
     35 
     36  let doc = gBrowser.contentDocument;
     37  let useRecommendedPerformanceSettings = doc.querySelector(
     38    "#useRecommendedPerformanceSettings"
     39  );
     40  let allowHWAccel = doc.querySelector("#allowHWAccel");
     41 
     42  is(
     43    Services.prefs.getBoolPref(
     44      "browser.preferences.defaultPerformanceSettings.enabled"
     45    ),
     46    true,
     47    "pref value should be true before clicking on checkbox"
     48  );
     49  ok(
     50    useRecommendedPerformanceSettings.checked,
     51    "checkbox should be checked before clicking on checkbox"
     52  );
     53 
     54  useRecommendedPerformanceSettings.click();
     55  await allowHWAccel.updateComplete;
     56 
     57  ok(BrowserTestUtils.isVisible(allowHWAccel), "allowHWAccel setting is shown");
     58 
     59  is(
     60    Services.prefs.getBoolPref(
     61      "browser.preferences.defaultPerformanceSettings.enabled"
     62    ),
     63    false,
     64    "pref value should be false after clicking on checkbox"
     65  );
     66  ok(
     67    !useRecommendedPerformanceSettings.checked,
     68    "checkbox should not be checked after clicking on checkbox"
     69  );
     70 
     71  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     72 
     73  Services.prefs.setBoolPref(
     74    "browser.preferences.defaultPerformanceSettings.enabled",
     75    true
     76  );
     77 });
     78 
     79 add_task(async function testPrefsSetByUser() {
     80  const kNewCount = DEFAULT_PROCESS_COUNT - 2;
     81 
     82  Services.prefs.setIntPref("dom.ipc.processCount", kNewCount);
     83  Services.prefs.setBoolPref(
     84    "browser.preferences.defaultPerformanceSettings.enabled",
     85    false
     86  );
     87 
     88  let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     89    leaveOpen: true,
     90  });
     91  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
     92 
     93  let doc = gBrowser.contentDocument;
     94  let allowHWAccel = doc.querySelector("#allowHWAccel");
     95  ok(BrowserTestUtils.isVisible(allowHWAccel), "allowHWAccel setting is shown");
     96 
     97  let useRecommendedPerformanceSettings = doc.querySelector(
     98    "#useRecommendedPerformanceSettings"
     99  );
    100  useRecommendedPerformanceSettings.click();
    101 
    102  is(
    103    Services.prefs.getBoolPref(
    104      "browser.preferences.defaultPerformanceSettings.enabled"
    105    ),
    106    true,
    107    "pref value should be true after clicking on checkbox"
    108  );
    109  is(
    110    Services.prefs.getIntPref("dom.ipc.processCount"),
    111    DEFAULT_PROCESS_COUNT,
    112    "process count should be default value"
    113  );
    114 
    115  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    116 
    117  Services.prefs.clearUserPref("dom.ipc.processCount");
    118  Services.prefs.setBoolPref(
    119    "browser.preferences.defaultPerformanceSettings.enabled",
    120    true
    121  );
    122 });