Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
-
CI results over the last 21 days
- Manifest: dom/security/permissionspolicy/test/browser/browser.toml
"use strict";
// A document that sends its own Permissions-Policy header combines it with
// the policy inherited from its container instead of replacing it.
const PATH = "/browser/dom/security/permissionspolicy/test/browser/";
const EMPTY_PAGE = "empty.html";
const HEADER_PAGE = "file_header_policy.sjs";
async function addFrame(bc, src, allow) {
return SpecialPowers.spawn(bc, [src, allow], async (aSrc, aAllow) => {
let iframe = content.document.createElement("iframe");
iframe.allow = aAllow;
iframe.src = aSrc;
let loaded = new Promise(resolve =>
iframe.addEventListener("load", resolve, { once: true })
);
content.document.body.appendChild(iframe);
await loaded;
return iframe.browsingContext;
});
}
async function navigateFrame(parentBC, frameBC, target) {
let loaded = SpecialPowers.spawn(parentBC, [], () => {
let iframe = content.document.querySelector("iframe");
return new Promise(resolve =>
iframe.addEventListener("load", () => resolve(), { once: true })
);
});
await SpecialPowers.spawn(frameBC, [target], aTarget => {
content.location = aTarget;
});
await loaded;
}
function isGeoDelegationUnsafe(bc) {
return SpecialPowers.spawn(bc, [], () => {
is(
content.document.nodePrincipal.origin + "",
content.location.origin,
"Checking the expected document"
);
return content.document.permDelegateHandler
.QueryInterface(Ci.nsIPermissionDelegateHandler)
.maybeUnsafePermissionDelegate(["geo"]);
});
}
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [["dom.security.permissionsPolicy.header.enabled", true]],
});
});
add_task(async function testKeepsSrcOrigin() {
await BrowserTestUtils.withNewTab(
async browser => {
let frame = await addFrame(
browser,
"geolocation *"
);
ok(
!(await isGeoDelegationUnsafe(frame)),
"Document from the src origin is trusted"
);
}
);
});
add_task(async function testKeepsAncestorChain() {
await BrowserTestUtils.withNewTab(
async browser => {
let ancestor = await addFrame(
browser,
);
let frame = await addFrame(
ancestor,
"geolocation *"
);
await navigateFrame(
ancestor,
frame,
);
ok(
!(await isGeoDelegationUnsafe(frame)),
"Document from an origin allowed in the ancestor chain is trusted"
);
}
);
});
async function checkCombinedPolicy(allow, header, expected, message) {
await BrowserTestUtils.withNewTab(
async browser => {
let frame = await addFrame(
browser,
allow
);
let state = await SpecialPowers.spawn(
frame,
[],
async () =>
(await content.navigator.permissions.query({ name: "geolocation" }))
.state
);
is(state, expected, message);
}
);
}
add_task(async function testAttributeAllowsHeaderDenies() {
await checkCombinedPolicy(
"geolocation",
"geolocation=()",
"denied",
"Header denies what the attribute allows"
);
});
add_task(async function testAttributeDeniesHeaderAllows() {
await checkCombinedPolicy(
"geolocation 'none'",
"geolocation=*",
"denied",
"Header cannot allow what the attribute denies"
);
});
add_task(async function testAttributeAllowsHeaderAllows() {
await checkCombinedPolicy(
"geolocation",
"geolocation=*",
"prompt",
"Allowed when both the attribute and the header allow"
);
});