tor-browser

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

browser_privacy_allowListPreference_dialog.js (5412B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BASELINE_PREF = "privacy.trackingprotection.allow_list.baseline.enabled";
      7 const CONVENIENCE_PREF =
      8  "privacy.trackingprotection.allow_list.convenience.enabled";
      9 const CB_CATEGORY_PREF = "browser.contentblocking.category";
     10 
     11 const ETP_STANDARD_ID = "standardRadio";
     12 const ETP_STRICT_ID = "strictRadio";
     13 const ETP_CUSTOM_ID = "customRadio";
     14 
     15 const STRICT_BASELINE_CHECKBOX_ID = "contentBlockingBaselineExceptionsStrict";
     16 const STRICT_CONVENIENCE_CHECKBOX_ID =
     17  "contentBlockingConvenienceExceptionsStrict";
     18 const CUSTOM_BASELINE_CHECKBOX_ID = "contentBlockingBaselineExceptionsCustom";
     19 const CUSTOM_CONVENIENCE_CHECKBOX_ID =
     20  "contentBlockingConvenienceExceptionsCustom";
     21 
     22 async function cleanUp() {
     23  await SpecialPowers.popPrefEnv();
     24  gBrowser.removeCurrentTab();
     25 }
     26 
     27 async function setup() {
     28  await SpecialPowers.pushPrefEnv({
     29    set: [[CB_CATEGORY_PREF, "standard"]],
     30  });
     31  Assert.ok(
     32    Services.prefs.getBoolPref(BASELINE_PREF),
     33    "The baseline preference should be initially true."
     34  );
     35  Assert.ok(
     36    Services.prefs.getBoolPref(CONVENIENCE_PREF),
     37    "The convenience preference should be initially true."
     38  );
     39 }
     40 
     41 add_task(async function test_baseline_checkbox_dialog_cancel() {
     42  await setup();
     43  await openPreferencesViaOpenPreferencesAPI("privacy", {
     44    leaveOpen: true,
     45  });
     46  let doc = gBrowser.contentDocument;
     47  doc.getElementById(ETP_STRICT_ID).click();
     48 
     49  // Initially, baseline should be checked
     50  let baselineCheckbox = doc.getElementById(STRICT_BASELINE_CHECKBOX_ID);
     51  is(
     52    baselineCheckbox.checked,
     53    true,
     54    "The baseline checkbox should be checked initially."
     55  );
     56 
     57  await clickCheckboxWithConfirmDialog(
     58    doc,
     59    STRICT_BASELINE_CHECKBOX_ID,
     60    BASELINE_PREF,
     61    true,
     62    0
     63  );
     64 
     65  // Verify the checkbox is still checked and pref is still true
     66  is(
     67    baselineCheckbox.checked,
     68    true,
     69    "The baseline checkbox should remain checked after canceling dialog."
     70  );
     71  Assert.ok(
     72    Services.prefs.getBoolPref(BASELINE_PREF),
     73    "The baseline pref should remain true after canceling dialog."
     74  );
     75 
     76  await cleanUp();
     77 });
     78 
     79 add_task(async function test_baseline_checkbox_dialog_confirm() {
     80  await setup();
     81  await openPreferencesViaOpenPreferencesAPI("privacy", {
     82    leaveOpen: true,
     83  });
     84  let doc = gBrowser.contentDocument;
     85  doc.getElementById(ETP_STRICT_ID).click();
     86 
     87  let baselineCheckbox = doc.getElementById(STRICT_BASELINE_CHECKBOX_ID);
     88  is(
     89    baselineCheckbox.checked,
     90    true,
     91    "The baseline checkbox should be checked initially."
     92  );
     93 
     94  await clickCheckboxWithConfirmDialog(
     95    doc,
     96    STRICT_BASELINE_CHECKBOX_ID,
     97    BASELINE_PREF,
     98    false,
     99    1
    100  );
    101 
    102  is(
    103    baselineCheckbox.checked,
    104    false,
    105    "The baseline checkbox should be unchecked after confirming dialog."
    106  );
    107  Assert.ok(
    108    !Services.prefs.getBoolPref(BASELINE_PREF),
    109    "The baseline pref should be false after confirming dialog."
    110  );
    111 
    112  Assert.ok(
    113    !Services.prefs.getBoolPref(CONVENIENCE_PREF),
    114    "The convenience pref should be false when baseline is disabled."
    115  );
    116 
    117  await cleanUp();
    118 });
    119 
    120 add_task(async function test_custom_baseline_checkbox_dialog_cancel() {
    121  await setup();
    122  await openPreferencesViaOpenPreferencesAPI("privacy", {
    123    leaveOpen: true,
    124  });
    125  let doc = gBrowser.contentDocument;
    126  doc.getElementById(ETP_CUSTOM_ID).click();
    127 
    128  let baselineCheckbox = doc.getElementById(CUSTOM_BASELINE_CHECKBOX_ID);
    129  is(
    130    baselineCheckbox.checked,
    131    true,
    132    "The custom baseline checkbox should be checked initially."
    133  );
    134 
    135  await clickCheckboxWithConfirmDialog(
    136    doc,
    137    CUSTOM_BASELINE_CHECKBOX_ID,
    138    BASELINE_PREF,
    139    true,
    140    0
    141  );
    142 
    143  is(
    144    baselineCheckbox.checked,
    145    true,
    146    "The custom baseline checkbox should remain checked after canceling dialog."
    147  );
    148  Assert.ok(
    149    Services.prefs.getBoolPref(BASELINE_PREF),
    150    "The baseline pref should remain true after canceling dialog."
    151  );
    152 
    153  Assert.ok(
    154    Services.prefs.getBoolPref(CONVENIENCE_PREF),
    155    "The convenience pref should remain true when baseline is enabled."
    156  );
    157 
    158  await cleanUp();
    159 });
    160 
    161 add_task(async function test_custom_baseline_checkbox_dialog_confirm() {
    162  await setup();
    163  await openPreferencesViaOpenPreferencesAPI("privacy", {
    164    leaveOpen: true,
    165  });
    166  let doc = gBrowser.contentDocument;
    167  doc.getElementById(ETP_CUSTOM_ID).click();
    168 
    169  let baselineCheckbox = doc.getElementById(CUSTOM_BASELINE_CHECKBOX_ID);
    170  is(
    171    baselineCheckbox.checked,
    172    true,
    173    "The custom baseline checkbox should be checked initially."
    174  );
    175 
    176  await clickCheckboxWithConfirmDialog(
    177    doc,
    178    CUSTOM_BASELINE_CHECKBOX_ID,
    179    BASELINE_PREF,
    180    false,
    181    1
    182  );
    183 
    184  is(
    185    baselineCheckbox.checked,
    186    false,
    187    "The custom baseline checkbox should be unchecked after confirming dialog."
    188  );
    189  Assert.ok(
    190    !Services.prefs.getBoolPref(BASELINE_PREF),
    191    "The baseline pref should be false after confirming dialog."
    192  );
    193 
    194  let convenienceCheckbox = doc.getElementById(CUSTOM_CONVENIENCE_CHECKBOX_ID);
    195  is(
    196    convenienceCheckbox.checked,
    197    true,
    198    "The custom convenience checkbox should be unchanged when baseline is disabled."
    199  );
    200  Assert.ok(
    201    Services.prefs.getBoolPref(CONVENIENCE_PREF),
    202    "The convenience pref should be unchanged when baseline is disabled."
    203  );
    204 
    205  await cleanUp();
    206 });