tor-browser

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

browser_privacy_gpc.js (4720B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // This file tests the Privacy pane's Cookie Banner Handling UI.
      5 
      6 "use strict";
      7 
      8 const FEATURE_PREF = "privacy.globalprivacycontrol.functionality.enabled";
      9 const MODE_PREF = "privacy.globalprivacycontrol.enabled";
     10 const DNT_PREF = "privacy.donottrackheader.enabled";
     11 const RELAY_PREF = "signon.firefoxRelay.feature";
     12 
     13 const SECTION_ID = "nonTechnicalPrivacyGroup";
     14 const GPC_CHECKBOX_ID = "gpcEnabled";
     15 const NEW_DNT_ID = "dntRemoval";
     16 
     17 add_setup(function () {
     18  registerCleanupFunction(function () {
     19    Services.prefs.clearUserPref(
     20      "privacy.globalprivacycontrol.was_ever_enabled"
     21    );
     22  });
     23 });
     24 
     25 // Test the section is hidden on page load if the feature pref is disabled.
     26 // Also make sure we keep the old DNT interface.
     27 add_task(async function test_section_hidden_when_feature_flag_disabled() {
     28  await SpecialPowers.pushPrefEnv({
     29    set: [
     30      [FEATURE_PREF, false],
     31      [MODE_PREF, false],
     32      [RELAY_PREF, undefined],
     33    ],
     34  });
     35 
     36  await BrowserTestUtils.withNewTab(
     37    { gBrowser, url: "about:preferences#privacy" },
     38    async function (browser) {
     39      let section = browser.contentDocument.getElementById(SECTION_ID);
     40      is_element_hidden(section, "#nonTechnicalPrivacyGroup is hidden");
     41    }
     42  );
     43 
     44  await SpecialPowers.popPrefEnv();
     45 });
     46 
     47 // Test the section is shown on page load if the feature pref is enabled.
     48 // Also make sure we show the new DNT interface.
     49 add_task(async function test_section_shown_when_feature_flag_enabled() {
     50  await SpecialPowers.pushPrefEnv({
     51    set: [
     52      [FEATURE_PREF, true],
     53      [DNT_PREF, true],
     54      [MODE_PREF, false],
     55    ],
     56  });
     57 
     58  await BrowserTestUtils.withNewTab(
     59    { gBrowser, url: "about:preferences#privacy" },
     60    async function (browser) {
     61      let gpc = browser.contentDocument.getElementById(GPC_CHECKBOX_ID);
     62      is_element_visible(gpc, "#gpcEnabled is shown");
     63      let new_dnt = browser.contentDocument.getElementById(NEW_DNT_ID);
     64      is_element_visible(new_dnt, "#doNotTrackBox is shown");
     65      let section = browser.contentDocument.getElementById(SECTION_ID);
     66      is_element_visible(section, "#nonTechnicalPrivacyGroup is shown");
     67    }
     68  );
     69 
     70  await SpecialPowers.popPrefEnv();
     71 });
     72 
     73 // Test that we hide the new DNT section if DNT is disabled
     74 add_task(async function test_section_hide_dnt_link_when_disabled() {
     75  await SpecialPowers.pushPrefEnv({
     76    set: [
     77      [FEATURE_PREF, true],
     78      [DNT_PREF, false],
     79      [MODE_PREF, false],
     80    ],
     81  });
     82 
     83  await BrowserTestUtils.withNewTab(
     84    { gBrowser, url: "about:preferences#privacy" },
     85    async function (browser) {
     86      let gpc = browser.contentDocument.getElementById(GPC_CHECKBOX_ID);
     87      is_element_visible(gpc, "#gpcEnabled is shown");
     88      let new_dnt = browser.contentDocument.getElementById(NEW_DNT_ID);
     89      is_element_hidden(new_dnt, "#doNotTrackBox is hidden");
     90    }
     91  );
     92 
     93  await SpecialPowers.popPrefEnv();
     94 });
     95 
     96 // Test the checkbox is unchecked in DISABLED mode.
     97 add_task(async function test_checkbox_unchecked_disabled_mode() {
     98  await SpecialPowers.pushPrefEnv({
     99    set: [
    100      [FEATURE_PREF, true],
    101      [MODE_PREF, false],
    102    ],
    103  });
    104 
    105  await BrowserTestUtils.withNewTab(
    106    { gBrowser, url: "about:preferences#privacy" },
    107    async function (browser) {
    108      let checkbox = browser.contentDocument.getElementById(GPC_CHECKBOX_ID);
    109      ok(!checkbox.checked, "checkbox is not checked in DISABLED mode");
    110    }
    111  );
    112 
    113  await SpecialPowers.popPrefEnv();
    114 });
    115 
    116 // Test that toggling the checkbox toggles the mode pref value as expected
    117 add_task(async function test_checkbox_modifies_prefs() {
    118  await SpecialPowers.pushPrefEnv({
    119    set: [
    120      [FEATURE_PREF, true],
    121      [MODE_PREF, false],
    122    ],
    123  });
    124 
    125  await BrowserTestUtils.withNewTab(
    126    { gBrowser, url: "about:preferences#privacy" },
    127    async function (browser) {
    128      let gpc_checkbox =
    129        browser.contentDocument.getElementById(GPC_CHECKBOX_ID);
    130      let section = browser.contentDocument.getElementById(SECTION_ID);
    131 
    132      section.scrollIntoView();
    133 
    134      Assert.ok(
    135        !gpc_checkbox.checked,
    136        "initially, the checkbox should be unchecked"
    137      );
    138 
    139      gpc_checkbox.click();
    140      Assert.ok(gpc_checkbox.checked, "gpc checkbox should be checked");
    141      Assert.equal(
    142        true,
    143        Services.prefs.getBoolPref(MODE_PREF),
    144        "GPC should be on after checking the checkbox"
    145      );
    146 
    147      gpc_checkbox.click();
    148      Assert.ok(!gpc_checkbox.checked, "both checkboxes are disabled");
    149      Assert.equal(
    150        false,
    151        Services.prefs.getBoolPref(MODE_PREF),
    152        "GPC should be unchecked"
    153      );
    154    }
    155  );
    156 });