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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
/*
* Test the Permissions section in the Control Center.
*/
const PERMISSIONS_PAGE =
getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
) + "permissions.html";
function testPermListHasEntries(expectEntries) {
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
let listEntryCount = permissionsList.querySelectorAll(
".permission-popup-permission-item"
).length;
if (expectEntries) {
ok(listEntryCount, "List of permissions is not empty");
return;
}
ok(!listEntryCount, "List of permissions is empty");
}
add_task(async function testMainViewVisible() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function () {
await openPermissionPopup();
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
testPermListHasEntries(false);
await closePermissionPopup();
PermissionTestUtils.add(
gBrowser.currentURI,
"camera",
Services.perms.ALLOW_ACTION
);
await openPermissionPopup();
testPermListHasEntries(true);
let labelText = SitePermissions.getPermissionLabel("camera");
let labels = permissionsList.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in main view");
is(labels[0].innerHTML, labelText, "Correct value");
let img = permissionsList.querySelector(
"image.permission-popup-permission-icon"
);
ok(img, "There is an image for the permissions");
ok(img.classList.contains("camera-icon"), "proper class is in image class");
await closePermissionPopup();
PermissionTestUtils.remove(gBrowser.currentURI, "camera");
// We intentionally turn off a11y_checks, because the following function
// is expected to click a toolbar button that may be already hidden
// with "display:none;". The permissions panel anchor is hidden because
// the last permission was removed, however we force opening the panel
// anyways in order to test that the list has been properly emptied:
AccessibilityUtils.setEnv({
mustHaveAccessibleRule: false,
});
await openPermissionPopup();
AccessibilityUtils.resetEnv();
testPermListHasEntries(false);
await closePermissionPopup();
});
});
add_task(async function testIdentityIcon() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, function () {
PermissionTestUtils.add(
gBrowser.currentURI,
"geo",
Services.perms.ALLOW_ACTION
);
ok(
gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box signals granted permissions"
);
PermissionTestUtils.remove(gBrowser.currentURI, "geo");
ok(
!gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box doesn't signal granted permissions"
);
PermissionTestUtils.add(
gBrowser.currentURI,
"not-a-site-permission",
Services.perms.ALLOW_ACTION
);
ok(
!gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box doesn't signal granted permissions"
);
PermissionTestUtils.add(
gBrowser.currentURI,
"cookie",
Ci.nsICookiePermission.ACCESS_SESSION
);
ok(
gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box signals granted permissions"
);
PermissionTestUtils.remove(gBrowser.currentURI, "cookie");
PermissionTestUtils.add(
gBrowser.currentURI,
"cookie",
Ci.nsICookiePermission.ACCESS_DENY
);
ok(
gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box signals granted permissions"
);
PermissionTestUtils.add(
gBrowser.currentURI,
"cookie",
Ci.nsICookiePermission.ACCESS_DEFAULT
);
ok(
!gPermissionPanel._identityPermissionBox.hasAttribute("hasPermissions"),
"identity-box doesn't signal granted permissions"
);
PermissionTestUtils.remove(gBrowser.currentURI, "geo");
PermissionTestUtils.remove(gBrowser.currentURI, "not-a-site-permission");
PermissionTestUtils.remove(gBrowser.currentURI, "cookie");
});
});
add_task(async function testCancelPermission() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function () {
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
PermissionTestUtils.add(
gBrowser.currentURI,
"geo",
Services.perms.ALLOW_ACTION
);
PermissionTestUtils.add(
gBrowser.currentURI,
"camera",
Services.perms.DENY_ACTION
);
await openPermissionPopup();
testPermListHasEntries(true);
permissionsList
.querySelector(".permission-popup-permission-remove-button")
.click();
is(
permissionsList.querySelectorAll(".permission-popup-permission-label")
.length,
1,
"First permission should be removed"
);
permissionsList
.querySelector(".permission-popup-permission-remove-button")
.click();
is(
permissionsList.querySelectorAll(".permission-popup-permission-label")
.length,
0,
"Second permission should be removed"
);
await closePermissionPopup();
});
});
add_task(async function testPermissionHints() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function (browser) {
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
let reloadHint = document.getElementById(
"permission-popup-permission-reload-hint"
);
await openPermissionPopup();
ok(BrowserTestUtils.isHidden(reloadHint), "Reload hint is hidden");
await closePermissionPopup();
PermissionTestUtils.add(
gBrowser.currentURI,
"geo",
Services.perms.ALLOW_ACTION
);
PermissionTestUtils.add(
gBrowser.currentURI,
"camera",
Services.perms.DENY_ACTION
);
await openPermissionPopup();
ok(BrowserTestUtils.isHidden(reloadHint), "Reload hint is hidden");
let cancelButtons = permissionsList.querySelectorAll(
".permission-popup-permission-remove-button"
);
PermissionTestUtils.remove(gBrowser.currentURI, "camera");
cancelButtons[0].click();
ok(!BrowserTestUtils.isHidden(reloadHint), "Reload hint is visible");
cancelButtons[1].click();
ok(!BrowserTestUtils.isHidden(reloadHint), "Reload hint is visible");
await closePermissionPopup();
let loaded = BrowserTestUtils.browserLoaded(browser);
BrowserTestUtils.startLoadingURIString(browser, PERMISSIONS_PAGE);
await loaded;
await openPermissionPopup();
ok(
BrowserTestUtils.isHidden(reloadHint),
"Reload hint is hidden after reloading"
);
await closePermissionPopup();
});
});
add_task(async function testPermissionIcons() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, function () {
PermissionTestUtils.add(
gBrowser.currentURI,
"camera",
Services.perms.ALLOW_ACTION
);
PermissionTestUtils.add(
gBrowser.currentURI,
"geo",
Services.perms.DENY_ACTION
);
let geoIcon = gPermissionPanel._identityPermissionBox.querySelector(
".blocked-permission-icon[data-permission-id='geo']"
);
ok(geoIcon.hasAttribute("showing"), "blocked permission icon is shown");
let cameraIcon = gPermissionPanel._identityPermissionBox.querySelector(
".blocked-permission-icon[data-permission-id='camera']"
);
ok(
!cameraIcon.hasAttribute("showing"),
"allowed permission icon is not shown"
);
PermissionTestUtils.remove(gBrowser.currentURI, "geo");
ok(
!geoIcon.hasAttribute("showing"),
"blocked permission icon is not shown after reset"
);
PermissionTestUtils.remove(gBrowser.currentURI, "camera");
});
});
add_task(async function testPermissionShortcuts() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function (browser) {
browser.focus();
await new Promise(r => {
SpecialPowers.pushPrefEnv(
{ set: [["permissions.default.shortcuts", 0]] },
r
);
});
async function tryKey(desc, expectedValue) {
await EventUtils.synthesizeAndWaitKey("c", { accelKey: true });
let result = await SpecialPowers.spawn(browser, [], function () {
return {
keydowns: content.wrappedJSObject.gKeyDowns,
keypresses: content.wrappedJSObject.gKeyPresses,
};
});
is(
result.keydowns,
expectedValue,
"keydown event was fired or not fired as expected, " + desc
);
is(
result.keypresses,
0,
"keypress event shouldn't be fired for shortcut key, " + desc
);
}
await tryKey("pressed with default permissions", 1);
PermissionTestUtils.add(
gBrowser.currentURI,
"shortcuts",
Services.perms.DENY_ACTION
);
await tryKey("pressed when site blocked", 1);
PermissionTestUtils.add(
gBrowser.currentURI,
"shortcuts",
PermissionTestUtils.ALLOW
);
await tryKey("pressed when site allowed", 2);
PermissionTestUtils.remove(gBrowser.currentURI, "shortcuts");
await new Promise(r => {
SpecialPowers.pushPrefEnv(
{ set: [["permissions.default.shortcuts", 2]] },
r
);
});
await tryKey("pressed when globally blocked", 2);
PermissionTestUtils.add(
gBrowser.currentURI,
"shortcuts",
Services.perms.ALLOW_ACTION
);
await tryKey("pressed when globally blocked but site allowed", 3);
PermissionTestUtils.add(
gBrowser.currentURI,
"shortcuts",
Services.perms.DENY_ACTION
);
await tryKey("pressed when globally blocked and site blocked", 3);
PermissionTestUtils.remove(gBrowser.currentURI, "shortcuts");
});
});
// Test the control center UI when policy permissions are set.
add_task(async function testPolicyPermission() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function () {
await SpecialPowers.pushPrefEnv({
set: [["dom.disable_open_during_load", true]],
});
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
PermissionTestUtils.add(
gBrowser.currentURI,
"popup",
Services.perms.ALLOW_ACTION,
Services.perms.EXPIRE_POLICY
);
await openPermissionPopup();
// Check if the icon, nameLabel and stateLabel are visible.
let img, labelText, labels;
img = permissionsList.querySelector(
"image.permission-popup-permission-icon"
);
ok(img, "There is an image for the popup permission");
ok(img.classList.contains("popup-icon"), "proper class is in image class");
labelText = SitePermissions.getPermissionLabel("popup");
labels = permissionsList.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in main view");
is(labels[0].innerHTML, labelText, "Correct name label value");
labelText = SitePermissions.getCurrentStateLabel(
SitePermissions.ALLOW,
SitePermissions.SCOPE_POLICY
);
labels = permissionsList.querySelectorAll(
".permission-popup-permission-state-label"
);
is(labels[0].innerHTML, labelText, "Correct state label value");
// Check if the menulist and the remove button are hidden.
// The menulist is specific to the "popup" permission.
let menulist = document.getElementById("permission-popup-menulist");
Assert.equal(
menulist,
null,
"The popup permission menulist is not visible"
);
let removeButton = permissionsList.querySelector(
".permission-popup-permission-remove-button"
);
Assert.equal(
removeButton,
null,
"The permission remove button is not visible"
);
Services.perms.removeAll();
await closePermissionPopup();
});
});
add_task(async function testHiddenAfterRefresh() {
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function (browser) {
ok(
BrowserTestUtils.isHidden(gPermissionPanel._permissionPopup),
"Popup is hidden"
);
await openPermissionPopup();
ok(
!BrowserTestUtils.isHidden(gPermissionPanel._permissionPopup),
"Popup is shown"
);
let reloaded = BrowserTestUtils.browserLoaded(
browser,
false,
PERMISSIONS_PAGE
);
EventUtils.synthesizeKey("VK_F5", {}, browser.ownerGlobal);
await reloaded;
ok(
BrowserTestUtils.isHidden(gPermissionPanel._permissionPopup),
"Popup is hidden"
);
});
});
async function helper3rdPartyStoragePermissionTest(permissionID) {
// 3rdPartyStorage permissions are listed under an anchor container - test
// that this works correctly, i.e. the permission items are added to the
// anchor when relevant, and other permission items are added to the default
// anchor, and adding/removing permissions preserves this behavior correctly.
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function (browser) {
await openPermissionPopup();
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
let storagePermissionAnchor = permissionsList.querySelector(
`.permission-popup-permission-list-anchor[anchorfor="3rdPartyStorage"]`
);
testPermListHasEntries(false);
ok(
BrowserTestUtils.isHidden(storagePermissionAnchor.firstElementChild),
"Anchor header is hidden"
);
await closePermissionPopup();
let storagePermissionID = `${permissionID}^https://example2.com`;
PermissionTestUtils.add(
browser.currentURI,
storagePermissionID,
Services.perms.ALLOW_ACTION
);
await openPermissionPopup();
testPermListHasEntries(true);
ok(
BrowserTestUtils.isVisible(storagePermissionAnchor.firstElementChild),
"Anchor header is visible"
);
let labelText = SitePermissions.getPermissionLabel(storagePermissionID);
let labels = storagePermissionAnchor.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in 3rdPartyStorage anchor");
is(
labels[0].getAttribute("value"),
labelText,
"Permission label has the correct value"
);
await closePermissionPopup();
PermissionTestUtils.add(
browser.currentURI,
"camera",
Services.perms.ALLOW_ACTION
);
await openPermissionPopup();
testPermListHasEntries(true);
ok(
BrowserTestUtils.isVisible(storagePermissionAnchor.firstElementChild),
"Anchor header is visible"
);
labels = permissionsList.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 2, "Two permissions visible in main view");
labels = storagePermissionAnchor.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in 3rdPartyStorage anchor");
storagePermissionAnchor
.querySelector(".permission-popup-permission-remove-button")
.click();
is(
storagePermissionAnchor.querySelectorAll(
".permission-popup-permission-label"
).length,
0,
"Permission item should be removed"
);
is(
PermissionTestUtils.testPermission(
browser.currentURI,
storagePermissionID
),
SitePermissions.UNKNOWN,
"Permission removed from permission manager"
);
await closePermissionPopup();
await openPermissionPopup();
testPermListHasEntries(true);
ok(
BrowserTestUtils.isHidden(storagePermissionAnchor.firstElementChild),
"Anchor header is hidden"
);
labels = permissionsList.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in main view");
await closePermissionPopup();
PermissionTestUtils.remove(browser.currentURI, "camera");
await openPermissionPopup();
testPermListHasEntries(false);
ok(
BrowserTestUtils.isHidden(storagePermissionAnchor.firstElementChild),
"Anchor header is hidden"
);
await closePermissionPopup();
});
}
add_task(async function test3rdPartyStoragePermission() {
await helper3rdPartyStoragePermissionTest("3rdPartyStorage");
});
add_task(async function test3rdPartyFrameStoragePermission() {
await helper3rdPartyStoragePermissionTest("3rdPartyFrameStorage");
});
add_task(async function test3rdPartyBothStoragePermission() {
// Test the handling of both types of 3rdParty(Frame)?Storage permissions together
await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function (browser) {
await openPermissionPopup();
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
let storagePermissionAnchor = permissionsList.querySelector(
`.permission-popup-permission-list-anchor[anchorfor="3rdPartyStorage"]`
);
testPermListHasEntries(false);
ok(
BrowserTestUtils.isHidden(storagePermissionAnchor.firstElementChild),
"Anchor header is hidden"
);
await closePermissionPopup();
let storagePermissionID = "3rdPartyFrameStorage^https://example2.com";
PermissionTestUtils.add(
browser.currentURI,
storagePermissionID,
Services.perms.ALLOW_ACTION
);
await openPermissionPopup();
testPermListHasEntries(true);
ok(
BrowserTestUtils.isVisible(storagePermissionAnchor.firstElementChild),
"Anchor header is visible"
);
let labelText = SitePermissions.getPermissionLabel(storagePermissionID);
let labels = storagePermissionAnchor.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in 3rdPartyStorage anchor");
is(
labels[0].getAttribute("value"),
labelText,
"Permission label has the correct value"
);
await closePermissionPopup();
PermissionTestUtils.add(
browser.currentURI,
"3rdPartyStorage^https://www.example2.com",
Services.perms.ALLOW_ACTION
);
await openPermissionPopup();
testPermListHasEntries(true);
ok(
BrowserTestUtils.isVisible(storagePermissionAnchor.firstElementChild),
"Anchor header is visible"
);
labels = permissionsList.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permissions visible in main view");
labels = storagePermissionAnchor.querySelectorAll(
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in 3rdPartyStorage anchor");
storagePermissionAnchor
.querySelector(".permission-popup-permission-remove-button")
.click();
is(
storagePermissionAnchor.querySelectorAll(
".permission-popup-permission-label"
).length,
0,
"Permission item should be removed"
);
is(
PermissionTestUtils.testPermission(
browser.currentURI,
storagePermissionID
),
SitePermissions.UNKNOWN,
"Permission removed from permission manager"
);
is(
PermissionTestUtils.testPermission(
browser.currentURI,
"3rdPartyStorage^https://www.example2.com"
),
SitePermissions.UNKNOWN,
"3rdPartyStorage permission removed from permission manager"
);
await closePermissionPopup();
});
});
|