--- a/browser/modules/test/unit/test_SitePermissions.js
+++ b/browser/modules/test/unit/test_SitePermissions.js
@@ -2,26 +2,32 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
Components.utils.import("resource:///modules/SitePermissions.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
const STORAGE_MANAGER_ENABLED = Services.prefs.getBoolPref("browser.storageManager.enabled");
+const RESIST_FINGERPRINTING_ENABLED = Services.prefs.getBoolPref("privacy.resistFingerprinting");
add_task(async function testPermissionsListing() {
let expectedPermissions = ["camera", "cookie", "desktop-notification", "focus-tab-by-prompt",
"geo", "image", "install", "microphone", "popup", "screen", "shortcuts"];
if (STORAGE_MANAGER_ENABLED) {
// The persistent-storage permission is still only pref-on on Nightly
// so we add it only when it's pref-on.
// Should remove this checking and add it as default after it is fully pref-on.
expectedPermissions.push("persistent-storage");
}
+ if (RESIST_FINGERPRINTING_ENABLED) {
+ // Canvas permission should be hidden unless privacy.resistFingerprinting
+ // is true.
+ expectedPermissions.push("canvas/extractData");
+ }
Assert.deepEqual(SitePermissions.listPermissions().sort(), expectedPermissions.sort(),
"Correct list of all permissions");
});
add_task(async function testGetAllByURI() {
// check that it returns an empty array on an invalid URI
// like a file URI, which doesn't support site permissions
let wrongURI = Services.io.newURI("file:///example.js");
@@ -103,16 +109,21 @@ add_task(async function testExactHostMat
let exactHostMatched = ["desktop-notification", "focus-tab-by-prompt", "camera",
"microphone", "screen", "geo"];
if (STORAGE_MANAGER_ENABLED) {
// The persistent-storage permission is still only pref-on on Nightly
// so we add it only when it's pref-on.
// Should remove this checking and add it as default after it is fully pref-on.
exactHostMatched.push("persistent-storage");
}
+ if (RESIST_FINGERPRINTING_ENABLED) {
+ // Canvas permission should be hidden unless privacy.resistFingerprinting
+ // is true.
+ exactHostMatched.push("canvas/extractData");
+ }
let nonExactHostMatched = ["image", "cookie", "popup", "install", "shortcuts"];
let permissions = SitePermissions.listPermissions();
for (let permission of permissions) {
SitePermissions.set(uri, permission, SitePermissions.ALLOW);
if (exactHostMatched.includes(permission)) {
// Check that the sub-origin does not inherit the permission from its parent.
@@ -183,8 +194,28 @@ add_task(function* testDefaultPrefs() {
// Should be UNKNOWN after clearing the pref.
Services.prefs.clearUserPref("permissions.default.camera");
Assert.deepEqual(SitePermissions.get(uri, "camera"), {
state: SitePermissions.UNKNOWN,
scope: SitePermissions.SCOPE_PERSISTENT,
});
});
+add_task(async function testCanvasPermission() {
+ let resistFingerprinting = Services.prefs.getBoolPref("privacy.resistFingerprinting", false);
+ let uri = Services.io.newURI("https://example.com");
+
+ SitePermissions.set(uri, "canvas/extractData", SitePermissions.ALLOW);
+
+ // Canvas permission is hidden when privacy.resistFingerprinting is false.
+ Services.prefs.setBoolPref("privacy.resistFingerprinting", false);
+ Assert.equal(SitePermissions.listPermissions().indexOf("canvas/extractData"), -1);
+ Assert.equal(SitePermissions.getAllByURI(uri).filter(permission => permission.id === "canvas/extractData").length, 0);
+
+ // Canvas permission is visible when privacy.resistFingerprinting is true.
+ Services.prefs.setBoolPref("privacy.resistFingerprinting", true);
+ Assert.notEqual(SitePermissions.listPermissions().indexOf("canvas/extractData"), -1);
+ Assert.notEqual(SitePermissions.getAllByURI(uri).filter(permission => permission.id === "canvas/extractData").length, 0);
+
+ SitePermissions.remove(uri, "canvas/extractData");
+ Services.prefs.setBoolPref("privacy.resistFingerprinting", resistFingerprinting);
+});
+