Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
*/
// Checks that permissions set in preferences are correctly imported but can
// be removed by the user.
const { PermissionTestUtils } = ChromeUtils.importESModule(
);
const XPI_MIMETYPE = "application/x-xpinstall";
function newPrincipal(uri) {
return Services.scriptSecurityManager.createContentPrincipal(
NetUtil.newURI(uri),
{}
);
}
add_task(async function setup() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
Services.prefs.setCharPref(
"xpinstall.whitelist.add",
);
Services.prefs.setCharPref(
"xpinstall.whitelist.add.36",
);
Services.prefs.setCharPref(
"xpinstall.whitelist.add.test5",
);
PermissionTestUtils.add(
"install",
Ci.nsIPermissionManager.ALLOW_ACTION
);
await promiseStartupManager();
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("http://test1.com")
)
);
Assert.ok(
AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test1.com")
)
);
Assert.ok(
AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test2.com")
)
);
Assert.ok(
AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test3.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test4.com")
)
);
Assert.ok(
AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test4.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("http://www.test5.com")
)
);
Assert.ok(
AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test5.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("http://www.test6.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test6.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test7.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test8.com")
)
);
// This should remain unaffected
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("http://www.test9.com")
)
);
Assert.ok(
AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test9.com")
)
);
Services.perms.removeAll();
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test1.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test2.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test3.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test4.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test5.com")
)
);
// Upgrade the application and verify that the permissions are still not there
await promiseRestartManager("2");
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test1.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test2.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://test3.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test4.com")
)
);
Assert.ok(
!AddonManager.isInstallAllowed(
XPI_MIMETYPE,
newPrincipal("https://www.test5.com")
)
);
});