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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/ */
// This file tests the Privacy pane's Cookie Banner Handling UI.
"use strict";
const FEATURE_PREF = "privacy.globalprivacycontrol.functionality.enabled";
const MODE_PREF = "privacy.globalprivacycontrol.enabled";
const DNT_PREF = "privacy.donottrackheader.enabled";
const SECTION_ID = "nonTechnicalPrivacyBox";
const GPC_ID = "globalPrivacyControlBox";
const GPC_CHECKBOX_ID = "globalPrivacyControlCheckbox";
const OLD_DNT_ID = "legacyDoNotTrackBox";
const NEW_DNT_ID = "doNotTrackBox";
const DNT_CHECKBOX_ID = "doNotTrackCheckbox";
// Test the section is hidden on page load if the feature pref is disabled.
// Also make sure we keep the old DNT interface.
add_task(async function test_section_hidden_when_feature_flag_disabled() {
await SpecialPowers.pushPrefEnv({
set: [
[FEATURE_PREF, false],
[MODE_PREF, false],
],
});
await BrowserTestUtils.withNewTab(
{ gBrowser, url: "about:preferences#privacy" },
async function (browser) {
let gpc = browser.contentDocument.getElementById(GPC_ID);
is_element_hidden(gpc, "#globalPrivacyControlBox is hidden");
let new_dnt = browser.contentDocument.getElementById(NEW_DNT_ID);
is_element_hidden(new_dnt, "#doNotTrackBox is hidden");
let old_dnt = browser.contentDocument.getElementById(OLD_DNT_ID);
is_element_visible(old_dnt, "#doNotTrackBox is shown");
}
);
await SpecialPowers.popPrefEnv();
});
// Test the section is shown on page load if the feature pref is enabled.
// Also make sure we show the new DNT interface.
add_task(async function test_section_shown_when_feature_flag_enabled() {
await SpecialPowers.pushPrefEnv({
set: [
[FEATURE_PREF, true],
[MODE_PREF, false],
],
});
await BrowserTestUtils.withNewTab(
{ gBrowser, url: "about:preferences#privacy" },
async function (browser) {
let gpc = browser.contentDocument.getElementById(GPC_ID);
is_element_visible(gpc, "#globalPrivacyControlBox is shown");
let new_dnt = browser.contentDocument.getElementById(NEW_DNT_ID);
is_element_visible(new_dnt, "#doNotTrackBox is shown");
let old_dnt = browser.contentDocument.getElementById(OLD_DNT_ID);
is_element_hidden(old_dnt, "#doNotTrackBox is hidden");
}
);
await SpecialPowers.popPrefEnv();
});
// Test the checkbox is unchecked in DISABLED mode.
add_task(async function test_checkbox_unchecked_disabled_mode() {
await SpecialPowers.pushPrefEnv({
set: [
[FEATURE_PREF, true],
[MODE_PREF, false],
],
});
await BrowserTestUtils.withNewTab(
{ gBrowser, url: "about:preferences#privacy" },
async function (browser) {
let checkbox = browser.contentDocument.getElementById(GPC_CHECKBOX_ID);
ok(!checkbox.checked, "checkbox is not checked in DISABLED mode");
}
);
await SpecialPowers.popPrefEnv();
});
// Test that toggling the checkbox toggles the mode pref value as expected
add_task(async function test_checkbox_modifies_prefs() {
await SpecialPowers.pushPrefEnv({
set: [
[FEATURE_PREF, true],
[MODE_PREF, false],
],
});
await BrowserTestUtils.withNewTab(
{ gBrowser, url: "about:preferences#privacy" },
async function (browser) {
let gpc_checkbox =
browser.contentDocument.getElementById(GPC_CHECKBOX_ID);
let dnt_checkbox =
browser.contentDocument.getElementById(DNT_CHECKBOX_ID);
let section = browser.contentDocument.getElementById(SECTION_ID);
section.scrollIntoView();
Assert.ok(
!gpc_checkbox.checked && !dnt_checkbox.checked,
"initially, the checkbox should be unchecked"
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"#" + GPC_CHECKBOX_ID,
{},
browser
);
Assert.ok(
gpc_checkbox.checked && !dnt_checkbox.checked,
"gpc checkbox should be checked"
);
Assert.equal(
true,
Services.prefs.getBoolPref(MODE_PREF),
"GPC should be on after checking the checkbox"
);
Assert.equal(
false,
Services.prefs.getBoolPref(DNT_PREF),
"DNT should still be disabled after checking the checkbox"
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"#" + DNT_CHECKBOX_ID,
{},
browser
);
Assert.ok(
gpc_checkbox.checked && dnt_checkbox.checked,
"both checkboxes are enabled"
);
Assert.equal(
true,
Services.prefs.getBoolPref(MODE_PREF),
"GPC should still be on after checking the DNT checkbox"
);
Assert.equal(
true,
Services.prefs.getBoolPref(DNT_PREF),
"DNT should still be enabled after checking the checkbox"
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"#" + DNT_CHECKBOX_ID,
{},
browser
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"#" + GPC_CHECKBOX_ID,
{},
browser
);
Assert.ok(
!gpc_checkbox.checked && !dnt_checkbox.checked,
"both checkboxes are disabled"
);
Assert.equal(
false,
Services.prefs.getBoolPref(MODE_PREF),
"GPC should be unchecked"
);
Assert.equal(
false,
Services.prefs.getBoolPref(DNT_PREF),
"DNT should be unchecked"
);
}
);
await SpecialPowers.popPrefEnv();
});
|