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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
const { PermissionTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/PermissionTestUtils.sys.mjs"
);
const TEST_ORIGIN = "https://example.com";
const TEST_ORIGIN_CERT_ERROR = "https://expired.example.com";
const LOW_TLS_VERSION = "https://tls1.example.com/";
async function testPermissions(defaultPermission) {
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let defaultCheckbox = await TestUtils.waitForCondition(() =>
pageInfo.document.getElementById("geoDef")
);
let radioGroup = pageInfo.document.getElementById("geoRadioGroup");
let defaultRadioButton = pageInfo.document.getElementById(
"geo#" + defaultPermission
);
let blockRadioButton = pageInfo.document.getElementById("geo#2");
ok(defaultCheckbox.checked, "The default checkbox should be checked.");
PermissionTestUtils.add(
gBrowser.currentURI,
"geo",
Services.perms.DENY_ACTION
);
ok(!defaultCheckbox.checked, "The default checkbox should not be checked.");
defaultCheckbox.checked = true;
defaultCheckbox.dispatchEvent(new Event("command"));
ok(
!PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo"),
"Checking the default checkbox should reset the permission."
);
defaultCheckbox.checked = false;
defaultCheckbox.dispatchEvent(new Event("command"));
ok(
!PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo"),
"Unchecking the default checkbox should pick the default permission."
);
is(
radioGroup.selectedItem,
defaultRadioButton,
"The unknown radio button should be selected."
);
radioGroup.selectedItem = blockRadioButton;
blockRadioButton.dispatchEvent(new Event("command"));
is(
PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo")
.capability,
Services.perms.DENY_ACTION,
"Selecting a value in the radio group should set the corresponding permission"
);
radioGroup.selectedItem = defaultRadioButton;
defaultRadioButton.dispatchEvent(new Event("command"));
ok(
!PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo"),
"Selecting the default value should reset the permission."
);
ok(defaultCheckbox.checked, "The default checkbox should be checked.");
pageInfo.close();
PermissionTestUtils.remove(gBrowser.currentURI, "geo");
});
}
// Test displaying website permissions on certificate error pages.
add_task(async function test_CertificateError() {
let browser;
let pageLoaded;
await BrowserTestUtils.openNewForegroundTab(
gBrowser,
() => {
gBrowser.selectedTab = BrowserTestUtils.addTab(
gBrowser,
TEST_ORIGIN_CERT_ERROR
);
browser = gBrowser.selectedBrowser;
pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
},
false
);
await pageLoaded;
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN_CERT_ERROR, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let permissionTab = pageInfo.document.getElementById("permTab");
await TestUtils.waitForCondition(
() => BrowserTestUtils.isVisible(permissionTab),
"Permission tab should be visible."
);
let hostText = pageInfo.document.getElementById("hostText");
let permList = pageInfo.document.getElementById("permList");
let excludedPermissions = pageInfo.window.getExcludedPermissions();
let permissions = SitePermissions.listPermissions().filter(
p =>
SitePermissions.getPermissionLabel(p) != null &&
!excludedPermissions.includes(p)
);
await TestUtils.waitForCondition(
() => hostText.value === browser.currentURI.displayPrePath,
`Value of owner should be "${browser.currentURI.displayPrePath}" instead got "${hostText.value}".`
);
await TestUtils.waitForCondition(
() => permList.childElementCount === permissions.length,
`Value of verifier should be ${permissions.length}, instead got ${permList.childElementCount}.`
);
pageInfo.close();
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
// Test displaying website permissions on network error pages.
add_task(async function test_NetworkError() {
// Setup for TLS error
Services.prefs.setIntPref("security.tls.version.max", 3);
Services.prefs.setIntPref("security.tls.version.min", 3);
let browser;
let pageLoaded;
await BrowserTestUtils.openNewForegroundTab(
gBrowser,
() => {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, LOW_TLS_VERSION);
browser = gBrowser.selectedBrowser;
pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
},
false
);
await pageLoaded;
let pageInfo = BrowserCommands.pageInfo(LOW_TLS_VERSION, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let permissionTab = pageInfo.document.getElementById("permTab");
await TestUtils.waitForCondition(
() => BrowserTestUtils.isVisible(permissionTab),
"Permission tab should be visible."
);
let hostText = pageInfo.document.getElementById("hostText");
let permList = pageInfo.document.getElementById("permList");
let excludedPermissions = pageInfo.window.getExcludedPermissions();
let permissions = SitePermissions.listPermissions().filter(
p =>
SitePermissions.getPermissionLabel(p) != null &&
!excludedPermissions.includes(p)
);
await TestUtils.waitForCondition(
() => hostText.value === browser.currentURI.displayPrePath,
`Value of host should be should be "${browser.currentURI.displayPrePath}" instead got "${hostText.value}".`
);
await TestUtils.waitForCondition(
() => permList.childElementCount === permissions.length,
`Value of permissions list should be ${permissions.length}, instead got ${permList.childElementCount}.`
);
pageInfo.close();
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
// Test some standard operations in the permission tab.
add_task(async function test_geo_permission() {
await testPermissions(Services.perms.UNKNOWN_ACTION);
});
// Test some standard operations in the permission tab, falling back to a custom
// default permission instead of UNKNOWN.
add_task(async function test_default_geo_permission() {
await SpecialPowers.pushPrefEnv({
set: [["permissions.default.geo", SitePermissions.ALLOW]],
});
await testPermissions(Services.perms.ALLOW_ACTION);
});
// Test special behavior for cookie permissions.
add_task(async function test_cookie_permission() {
await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function () {
let pageInfo = BrowserCommands.pageInfo(TEST_ORIGIN, "permTab");
await BrowserTestUtils.waitForEvent(pageInfo, "load");
let defaultCheckbox = await TestUtils.waitForCondition(() =>
pageInfo.document.getElementById("cookieDef")
);
let radioGroup = pageInfo.document.getElementById("cookieRadioGroup");
let allowRadioButton = pageInfo.document.getElementById("cookie#1");
let blockRadioButton = pageInfo.document.getElementById("cookie#2");
ok(defaultCheckbox.checked, "The default checkbox should be checked.");
defaultCheckbox.checked = false;
defaultCheckbox.dispatchEvent(new Event("command"));
is(
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.ALLOW,
"Unchecking the default checkbox should pick the default permission."
);
is(
radioGroup.selectedItem,
allowRadioButton,
"The unknown radio button should be selected."
);
radioGroup.selectedItem = blockRadioButton;
blockRadioButton.dispatchEvent(new Event("command"));
is(
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.BLOCK,
"Selecting a value in the radio group should set the corresponding permission"
);
radioGroup.selectedItem = allowRadioButton;
allowRadioButton.dispatchEvent(new Event("command"));
is(
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.ALLOW,
"Selecting a value in the radio group should set the corresponding permission"
);
ok(!defaultCheckbox.checked, "The default checkbox should not be checked.");
defaultCheckbox.checked = true;
defaultCheckbox.dispatchEvent(new Event("command"));
is(
PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
SitePermissions.UNKNOWN,
"Checking the default checkbox should reset the permission."
);
is(
radioGroup.selectedItem,
null,
"For cookies, no item should be selected when the checkbox is checked."
);
pageInfo.close();
PermissionTestUtils.remove(gBrowser.currentURI, "cookie");
});
});
|