summaryrefslogtreecommitdiffstats
path: root/toolkit/components/normandy/test/browser/browser_about_preferences.js
blob: 7841d32c99c24cd8609b5b4b244cdd8c50abdaae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"use strict";

ChromeUtils.import("resource://gre/modules/Services.jsm", this);

const OPT_OUT_PREF = "app.shield.optoutstudies.enabled";

function withPrivacyPrefs(testFunc) {
  return async (...args) =>
    BrowserTestUtils.withNewTab("about:preferences#privacy", async browser =>
      testFunc(...args, browser)
    );
}

decorate_task(
  withPrefEnv({
    set: [[OPT_OUT_PREF, true]],
  }),
  withPrivacyPrefs,
  async function testCheckedOnLoad(browser) {
    const checkbox = browser.contentDocument.getElementById(
      "optOutStudiesEnabled"
    );
    ok(
      checkbox.checked,
      "Opt-out checkbox is checked on load when the pref is true"
    );
  }
);

decorate_task(
  withPrefEnv({
    set: [[OPT_OUT_PREF, false]],
  }),
  withPrivacyPrefs,
  async function testUncheckedOnLoad(browser) {
    const checkbox = browser.contentDocument.getElementById(
      "optOutStudiesEnabled"
    );
    ok(
      !checkbox.checked,
      "Opt-out checkbox is unchecked on load when the pref is false"
    );
  }
);

decorate_task(
  withPrefEnv({
    set: [[OPT_OUT_PREF, true]],
  }),
  withPrivacyPrefs,
  async function testCheckboxes(browser) {
    const optOutCheckbox = browser.contentDocument.getElementById(
      "optOutStudiesEnabled"
    );

    optOutCheckbox.click();
    ok(
      !Services.prefs.getBoolPref(OPT_OUT_PREF),
      "Unchecking the opt-out checkbox sets the pref to false."
    );
    optOutCheckbox.click();
    ok(
      Services.prefs.getBoolPref(OPT_OUT_PREF),
      "Checking the opt-out checkbox sets the pref to true."
    );
  }
);

decorate_task(
  withPrefEnv({
    set: [[OPT_OUT_PREF, true]],
  }),
  withPrivacyPrefs,
  async function testPrefWatchers(browser) {
    const optOutCheckbox = browser.contentDocument.getElementById(
      "optOutStudiesEnabled"
    );

    Services.prefs.setBoolPref(OPT_OUT_PREF, false);
    ok(
      !optOutCheckbox.checked,
      "Disabling the opt-out pref unchecks the opt-out checkbox."
    );
    Services.prefs.setBoolPref(OPT_OUT_PREF, true);
    ok(
      optOutCheckbox.checked,
      "Enabling the opt-out pref checks the opt-out checkbox."
    );
  }
);

decorate_task(withPrivacyPrefs, async function testViewStudiesLink(browser) {
  browser.contentDocument.getElementById("viewShieldStudies").click();
  await BrowserTestUtils.waitForLocationChange(gBrowser);

  is(
    gBrowser.currentURI.spec,
    "about:studies",
    "Clicking the view studies link opens about:studies in a new tab."
  );

  gBrowser.removeCurrentTab();
});