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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const PERMISSIONS_URL =
"chrome://browser/content/preferences/dialogs/permissions.xhtml";
const TRACKING_URL = "https://example.com";
async function openETPExceptionsDialog(doc) {
let exceptionsButton = doc.getElementById("trackingProtectionExceptions");
ok(exceptionsButton, "trackingProtectionExceptions button found");
let dialogPromise = promiseLoadSubDialog(PERMISSIONS_URL);
exceptionsButton.click();
let dialog = await dialogPromise;
return dialog;
}
async function addETPPermission(doc) {
let dialog = await openETPExceptionsDialog(doc);
let url = dialog.document.getElementById("url");
let buttonDisableETP = dialog.document.getElementById("btnDisableETP");
let permissionsBox = dialog.document.getElementById("permissionsBox");
let currentPermissions = permissionsBox.itemCount;
url.value = TRACKING_URL;
url.dispatchEvent(new Event("input", { bubbles: true }));
is(
buttonDisableETP.hasAttribute("disabled"),
false,
"Disable ETP button is selectable after url is entered"
);
buttonDisableETP.click();
// Website is listed
is(
permissionsBox.itemCount,
currentPermissions + 1,
"Website added in url should be in the list"
);
let saveButton = dialog.document.querySelector("dialog").getButton("accept");
saveButton.click();
BrowserTestUtils.waitForEvent(dialog, "unload");
}
async function removeETPPermission(doc) {
let dialog = await openETPExceptionsDialog(doc);
let permissionsBox = dialog.document.getElementById("permissionsBox");
let elements = permissionsBox.getElementsByAttribute("origin", TRACKING_URL);
// Website is listed
ok(permissionsBox.itemCount, "List is not empty");
permissionsBox.selectItem(elements[0]);
let removePermissionButton =
dialog.document.getElementById("removePermission");
is(
removePermissionButton.hasAttribute("disabled"),
false,
"The button should be clickable to remove selected item"
);
removePermissionButton.click();
let saveButton = dialog.document.querySelector("dialog").getButton("accept");
saveButton.click();
BrowserTestUtils.waitForEvent(dialog, "unload");
}
async function checkShieldIcon(shieldIcon) {
// Open the website and check that the tracking protection icon is enabled/disabled
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TRACKING_URL);
let icon = document.getElementById("tracking-protection-icon");
is(
gBrowser.ownerGlobal
.getComputedStyle(icon)
.getPropertyValue("list-style-image"),
shieldIcon,
`The tracking protection icon shows the icon ${shieldIcon}`
);
BrowserTestUtils.removeTab(tab);
}
// test adds and removes an ETP permission via the about:preferences#privacy and checks if the ProtectionsUI shield icon resembles the state
add_task(async function ETPPermissionSyncedFromPrivacyPane() {
await openPreferencesViaOpenPreferencesAPI("panePrivacy", {
leaveOpen: true,
});
let win = gBrowser.selectedBrowser.contentWindow;
let doc = win.document;
await addETPPermission(doc);
await checkShieldIcon(
`url("chrome://browser/skin/tracking-protection-disabled.svg")`
);
await removeETPPermission(doc);
await checkShieldIcon(`url("chrome://browser/skin/tracking-protection.svg")`);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
|