Bug 1622730 - Support `file://` principals for the site permission setting.r=pbz

Differential Revision: https://phabricator.services.mozilla.com/D68970

--HG--
extra : moz-landing-system : lando
This commit is contained in:
jayati 2020-04-01 14:02:22 +00:00
Родитель 4f2c05e8cd
Коммит 2e7e4c38ec
2 изменённых файлов: 22 добавлений и 5 удалений

Просмотреть файл

@ -382,8 +382,7 @@ var SitePermissions = {
/**
* Checks whether a UI for managing permissions should be exposed for a given
* principal. This excludes file URIs, for instance, as they don't have a host,
* even though nsIPermissionManager can still handle them.
* principal.
*
* @param {nsIPrincipal} principal
* The principal to check.
@ -399,7 +398,7 @@ var SitePermissions = {
"Argument passed as principal is not an instance of Ci.nsIPrincipal"
);
}
return ["http", "https", "moz-extension"].some(scheme =>
return ["http", "https", "moz-extension", "file"].some(scheme =>
principal.schemeIs(scheme)
);
},

Просмотреть файл

@ -49,9 +49,9 @@ add_task(async function testPermissionsListing() {
add_task(async function testGetAllByPrincipal() {
// check that it returns an empty array on an invalid principal
// like a principal with a file URI, which doesn't support site permissions
// like a principal with an about URI, which doesn't support site permissions
let wrongPrincipal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"file:///example.js"
"about:config"
);
Assert.deepEqual(SitePermissions.getAllByPrincipal(wrongPrincipal), []);
@ -353,3 +353,21 @@ add_task(async function testCanvasPermission() {
resistFingerprinting
);
});
add_task(async function testFilePermissions() {
let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"file:///example.js"
);
Assert.deepEqual(SitePermissions.getAllByPrincipal(principal), []);
SitePermissions.setForPrincipal(principal, "camera", SitePermissions.ALLOW);
Assert.deepEqual(SitePermissions.getAllByPrincipal(principal), [
{
id: "camera",
state: SitePermissions.ALLOW,
scope: SitePermissions.SCOPE_PERSISTENT,
},
]);
SitePermissions.removeFromPrincipal(principal, "camera");
Assert.deepEqual(SitePermissions.getAllByPrincipal(principal), []);
});