summaryrefslogtreecommitdiffstats
path: root/extensions/permissions/test/unit/test_permmanager_default_pref.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /extensions/permissions/test/unit/test_permmanager_default_pref.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/permissions/test/unit/test_permmanager_default_pref.js')
-rw-r--r--extensions/permissions/test/unit/test_permmanager_default_pref.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/extensions/permissions/test/unit/test_permmanager_default_pref.js b/extensions/permissions/test/unit/test_permmanager_default_pref.js
new file mode 100644
index 0000000000..b2bae241f0
--- /dev/null
+++ b/extensions/permissions/test/unit/test_permmanager_default_pref.js
@@ -0,0 +1,75 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+ let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
+ "https://example.org"
+ );
+
+ // Check that without a pref the default return value is UNKNOWN.
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "camera"),
+ Services.perms.UNKNOWN_ACTION
+ );
+
+ // Check that the default return value changed after setting the pref.
+ Services.prefs.setIntPref(
+ "permissions.default.camera",
+ Services.perms.DENY_ACTION
+ );
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "camera"),
+ Services.perms.DENY_ACTION
+ );
+
+ // Check that functions that do not directly return a permission value still
+ // consider the permission as being set to its default.
+ Assert.equal(
+ null,
+ Services.perms.getPermissionObject(principal, "camera", false)
+ );
+
+ // Check that other permissions still return UNKNOWN.
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "geo"),
+ Services.perms.UNKNOWN_ACTION
+ );
+
+ // Check that the default return value changed after changing the pref.
+ Services.prefs.setIntPref(
+ "permissions.default.camera",
+ Services.perms.ALLOW_ACTION
+ );
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "camera"),
+ Services.perms.ALLOW_ACTION
+ );
+
+ // Check that the preference is ignored if there is a value.
+ Services.perms.addFromPrincipal(
+ principal,
+ "camera",
+ Services.perms.DENY_ACTION
+ );
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "camera"),
+ Services.perms.DENY_ACTION
+ );
+ Assert.ok(
+ Services.perms.getPermissionObject(principal, "camera", false) != null
+ );
+
+ // The preference should be honored again, after resetting the permissions.
+ Services.perms.removeAll();
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "camera"),
+ Services.perms.ALLOW_ACTION
+ );
+
+ // Should be UNKNOWN after clearing the pref.
+ Services.prefs.clearUserPref("permissions.default.camera");
+ Assert.equal(
+ Services.perms.testPermissionFromPrincipal(principal, "camera"),
+ Services.perms.UNKNOWN_ACTION
+ );
+}