fune/extensions/permissions/test/unit/test_permmanager_default_pref.js
Paul Zuehlcke abeca18f1c Bug 1402957 - Refactored nsIPermissionManager tests to use principals. r=johannh
Differential Revision: https://phabricator.services.mozilla.com/D47251

--HG--
rename : extensions/permissions/test/unit/test_permmanager_getAllForURI.js => extensions/permissions/test/unit/test_permmanager_getAllForPrincipal.js
extra : moz-landing-system : lando
2019-09-27 09:48:39 +00:00

75 lines
2.2 KiB
JavaScript

/* 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
);
}