tor-browser

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

browser_privacy_allowListPreference_telemetry.js (6351B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const BASELINE_PREF = "privacy.trackingprotection.allow_list.baseline.enabled";
      5 const CONVENIENCE_PREF =
      6  "privacy.trackingprotection.allow_list.convenience.enabled";
      7 const CB_CATEGORY_PREF = "browser.contentblocking.category";
      8 
      9 const ETP_STANDARD_ID = "standardRadio";
     10 const ETP_STRICT_ID = "strictRadio";
     11 const ETP_CUSTOM_ID = "customRadio";
     12 
     13 const STRICT_BASELINE_CHECKBOX_ID = "contentBlockingBaselineExceptionsStrict";
     14 const STRICT_CONVENIENCE_CHECKBOX_ID =
     15  "contentBlockingConvenienceExceptionsStrict";
     16 const CUSTOM_BASELINE_CHECKBOX_ID = "contentBlockingBaselineExceptionsCustom";
     17 const CUSTOM_CONVENIENCE_CHECKBOX_ID =
     18  "contentBlockingConvenienceExceptionsCustom";
     19 
     20 async function setup() {
     21  await SpecialPowers.pushPrefEnv({
     22    set: [[CB_CATEGORY_PREF, "standard"]],
     23  });
     24  Assert.ok(
     25    Services.prefs.getBoolPref(BASELINE_PREF),
     26    "The baseline preference should be initially true."
     27  );
     28  Assert.ok(
     29    Services.prefs.getBoolPref(CONVENIENCE_PREF),
     30    "The convenience preference should be initially true."
     31  );
     32 }
     33 
     34 add_task(async function test_baseline_telemetry() {
     35  const exceptionListServiceObserver = Cc[
     36    "@mozilla.org/url-classifier/exception-list-service;1"
     37  ].getService(Ci.nsIObserver);
     38 
     39  await setup();
     40  await openPreferencesViaOpenPreferencesAPI("privacy", {
     41    leaveOpen: true,
     42  });
     43 
     44  let doc = gBrowser.contentDocument;
     45 
     46  info("Sending idle-daily");
     47  exceptionListServiceObserver.observe(null, "idle-daily", null);
     48  info("Sent idle-daily");
     49 
     50  let value = Glean.contentblocking.tpAllowlistBaselineEnabled.testGetValue();
     51  Assert.equal(
     52    value,
     53    true,
     54    "Baseline telemetry should be true when ETP standard mode is selected"
     55  );
     56 
     57  doc.getElementById(ETP_STRICT_ID).click();
     58 
     59  info("Sending idle-daily");
     60  exceptionListServiceObserver.observe(null, "idle-daily", null);
     61  info("Sent idle-daily");
     62 
     63  value = Glean.contentblocking.tpAllowlistBaselineEnabled.testGetValue();
     64  Assert.equal(
     65    value,
     66    true,
     67    "Baseline telemetry should be true when ETP strict mode is selected"
     68  );
     69 
     70  await clickCheckboxWithConfirmDialog(
     71    doc,
     72    STRICT_BASELINE_CHECKBOX_ID,
     73    BASELINE_PREF,
     74    false,
     75    1
     76  );
     77 
     78  info("Sending idle-daily");
     79  exceptionListServiceObserver.observe(null, "idle-daily", null);
     80  info("Sent idle-daily");
     81 
     82  value = Glean.contentblocking.tpAllowlistBaselineEnabled.testGetValue();
     83  Assert.equal(
     84    value,
     85    false,
     86    "Baseline telemetry should be false when strict baseline checkbox is unchecked"
     87  );
     88 
     89  doc.getElementById(ETP_CUSTOM_ID).click();
     90 
     91  value = Glean.contentblocking.tpAllowlistBaselineEnabled.testGetValue();
     92  Assert.equal(
     93    value,
     94    false,
     95    "Baseline telemetry should be false when switching to custom mode after unchecking strict baseline"
     96  );
     97 
     98  await clickCheckboxAndWaitForPrefChange(
     99    doc,
    100    CUSTOM_BASELINE_CHECKBOX_ID,
    101    BASELINE_PREF,
    102    true
    103  );
    104 
    105  info("Sending idle-daily");
    106  exceptionListServiceObserver.observe(null, "idle-daily", null);
    107  info("Sent idle-daily");
    108 
    109  value = Glean.contentblocking.tpAllowlistBaselineEnabled.testGetValue();
    110  Assert.equal(
    111    value,
    112    true,
    113    "Baseline telemetry should be true when custom baseline checkbox is checked"
    114  );
    115 
    116  Services.fog.testResetFOG();
    117  await SpecialPowers.popPrefEnv();
    118  gBrowser.removeCurrentTab();
    119 });
    120 
    121 add_task(async function test_convenience_telemetry() {
    122  const exceptionListServiceObserver = Cc[
    123    "@mozilla.org/url-classifier/exception-list-service;1"
    124  ].getService(Ci.nsIObserver);
    125  await setup();
    126  await openPreferencesViaOpenPreferencesAPI("privacy", {
    127    leaveOpen: true,
    128  });
    129 
    130  let doc = gBrowser.contentDocument;
    131 
    132  info("Sending idle-daily");
    133  exceptionListServiceObserver.observe(null, "idle-daily", null);
    134  info("Sent idle-daily");
    135 
    136  let value =
    137    Glean.contentblocking.tpAllowlistConvenienceEnabled.testGetValue();
    138  Assert.equal(
    139    value,
    140    true,
    141    "Convenience telemetry should be true by default when ETP standard mode is selected"
    142  );
    143 
    144  await doc.getElementById(ETP_STRICT_ID).click();
    145 
    146  info("Sending idle-daily");
    147  exceptionListServiceObserver.observe(null, "idle-daily", null);
    148  info("Sent idle-daily");
    149 
    150  value = Glean.contentblocking.tpAllowlistConvenienceEnabled.testGetValue();
    151  Assert.equal(
    152    value,
    153    false,
    154    "Convenience telemetry should be false by default when ETP strict mode is selected"
    155  );
    156 
    157  await clickCheckboxAndWaitForPrefChange(
    158    doc,
    159    STRICT_CONVENIENCE_CHECKBOX_ID,
    160    CONVENIENCE_PREF,
    161    true
    162  );
    163 
    164  info("Sending idle-daily");
    165  exceptionListServiceObserver.observe(null, "idle-daily", null);
    166  info("Sent idle-daily");
    167 
    168  value = Glean.contentblocking.tpAllowlistConvenienceEnabled.testGetValue();
    169  Assert.equal(
    170    value,
    171    true,
    172    "Convenience telemetry should be true when strict convenience checkbox is checked"
    173  );
    174 
    175  await clickCheckboxWithConfirmDialog(
    176    doc,
    177    STRICT_BASELINE_CHECKBOX_ID,
    178    BASELINE_PREF,
    179    false,
    180    1
    181  );
    182 
    183  info("Sending idle-daily");
    184  exceptionListServiceObserver.observe(null, "idle-daily", null);
    185  info("Sent idle-daily");
    186 
    187  value = Glean.contentblocking.tpAllowlistConvenienceEnabled.testGetValue();
    188  Assert.equal(
    189    value,
    190    false,
    191    "Convenience telemetry be false when strict baseline checkbox is unchecked"
    192  );
    193 
    194  doc.getElementById(ETP_CUSTOM_ID).click();
    195 
    196  info("Sending idle-daily");
    197  exceptionListServiceObserver.observe(null, "idle-daily", null);
    198  info("Sent idle-daily");
    199 
    200  value = Glean.contentblocking.tpAllowlistConvenienceEnabled.testGetValue();
    201  Assert.equal(
    202    value,
    203    false,
    204    "Convenience telemetry should remain false when switching to custom mode after unchecking strict convenience"
    205  );
    206 
    207  await clickCheckboxAndWaitForPrefChange(
    208    doc,
    209    CUSTOM_BASELINE_CHECKBOX_ID,
    210    BASELINE_PREF,
    211    true
    212  );
    213 
    214  info("Sending idle-daily");
    215  exceptionListServiceObserver.observe(null, "idle-daily", null);
    216  info("Sent idle-daily");
    217 
    218  value = Glean.contentblocking.tpAllowlistConvenienceEnabled.testGetValue();
    219  Assert.equal(
    220    value,
    221    true,
    222    "Convenience telemetry should be true when custom convenience checkbox is checked"
    223  );
    224 
    225  Services.fog.testResetFOG();
    226  await SpecialPowers.popPrefEnv();
    227  gBrowser.removeCurrentTab();
    228 });