tor-browser

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

browser_performance_non_e10s.js (4995B)


      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 () {
     25  let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     26    leaveOpen: true,
     27  });
     28  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
     29 
     30  let doc = gBrowser.contentDocument;
     31  let useRecommendedPerformanceSettings = doc.querySelector(
     32    "#useRecommendedPerformanceSettings"
     33  );
     34  let allowHWAccel = doc.querySelector("#allowHWAccel");
     35 
     36  is(
     37    Services.prefs.getBoolPref(
     38      "browser.preferences.defaultPerformanceSettings.enabled"
     39    ),
     40    true,
     41    "pref value should be true before clicking on checkbox"
     42  );
     43  ok(
     44    useRecommendedPerformanceSettings.checked,
     45    "checkbox should be checked before clicking on checkbox"
     46  );
     47 
     48  useRecommendedPerformanceSettings.click();
     49  await allowHWAccel.updateComplete;
     50 
     51  ok(BrowserTestUtils.isVisible(allowHWAccel), "allowHWAccel setting is shown");
     52 
     53  is(
     54    Services.prefs.getBoolPref(
     55      "browser.preferences.defaultPerformanceSettings.enabled"
     56    ),
     57    false,
     58    "pref value should be false after clicking on checkbox"
     59  );
     60  ok(
     61    !useRecommendedPerformanceSettings.checked,
     62    "checkbox should not be checked after clicking on checkbox"
     63  );
     64 
     65  let allowHWAccelPref = Services.prefs.getBoolPref(
     66    "layers.acceleration.disabled"
     67  );
     68  is(
     69    allowHWAccelPref,
     70    DEFAULT_HW_ACCEL_PREF,
     71    "pref value should be the default value before clicking on checkbox"
     72  );
     73  is(
     74    allowHWAccel.checked,
     75    !DEFAULT_HW_ACCEL_PREF,
     76    "checkbox should show the invert of the default value"
     77  );
     78 
     79  allowHWAccel.click();
     80  allowHWAccelPref = Services.prefs.getBoolPref("layers.acceleration.disabled");
     81  is(
     82    allowHWAccelPref,
     83    !DEFAULT_HW_ACCEL_PREF,
     84    "pref value should be opposite of the default value after clicking on checkbox"
     85  );
     86  is(
     87    allowHWAccel.checked,
     88    !allowHWAccelPref,
     89    "checkbox should show the invert of the current value"
     90  );
     91 
     92  allowHWAccel.click();
     93  allowHWAccelPref = Services.prefs.getBoolPref("layers.acceleration.disabled");
     94  is(
     95    allowHWAccelPref,
     96    DEFAULT_HW_ACCEL_PREF,
     97    "pref value should be the default value after clicking on checkbox"
     98  );
     99  is(
    100    allowHWAccel.checked,
    101    !allowHWAccelPref,
    102    "checkbox should show the invert of the current value"
    103  );
    104 
    105  ok(
    106    BrowserTestUtils.isVisible(allowHWAccel),
    107    "allowHWAccel setting should be still shown"
    108  );
    109 
    110  Services.prefs.setBoolPref(
    111    "browser.preferences.defaultPerformanceSettings.enabled",
    112    true
    113  );
    114  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    115 });
    116 
    117 add_task(async function () {
    118  let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
    119    leaveOpen: true,
    120  });
    121  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
    122 
    123  let doc = gBrowser.contentDocument;
    124  let allowHWAccel = doc.querySelector("#allowHWAccel");
    125 
    126  ok(
    127    !BrowserTestUtils.isVisible(allowHWAccel),
    128    "allowHWAccel setting should not be shown"
    129  );
    130 
    131  Services.prefs.setBoolPref(
    132    "browser.preferences.defaultPerformanceSettings.enabled",
    133    false
    134  );
    135  await allowHWAccel.updateComplete;
    136 
    137  ok(
    138    BrowserTestUtils.isVisible(allowHWAccel),
    139    "allowHWAccel setting should be shown"
    140  );
    141 
    142  Services.prefs.setBoolPref(
    143    "browser.preferences.defaultPerformanceSettings.enabled",
    144    true
    145  );
    146  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    147 });
    148 
    149 add_task(async function () {
    150  Services.prefs.setBoolPref("layers.acceleration.disabled", true);
    151 
    152  let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
    153    leaveOpen: true,
    154  });
    155  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
    156 
    157  let doc = gBrowser.contentDocument;
    158 
    159  let allowHWAccel = doc.querySelector("#allowHWAccel");
    160  ok(
    161    BrowserTestUtils.isVisible(allowHWAccel),
    162    "allowHWAccel setting should be shown"
    163  );
    164 
    165  is(
    166    Services.prefs.getBoolPref("layers.acceleration.disabled"),
    167    true,
    168    "pref value is false"
    169  );
    170  ok(!allowHWAccel.checked, "checkbox should not be checked");
    171 
    172  Services.prefs.setBoolPref(
    173    "browser.preferences.defaultPerformanceSettings.enabled",
    174    true
    175  );
    176  BrowserTestUtils.removeTab(gBrowser.selectedTab);
    177 });