Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: caps/tests/unit/xpcshell.toml
const scriptSecMan = Services.scriptSecurityManager;
// SystemPrincipal checks
let systemPrincipal = scriptSecMan.getSystemPrincipal();
Assert.ok(systemPrincipal.isSystemPrincipal);
Assert.equal(systemPrincipal.origin, "[System Principal]");
Assert.equal(systemPrincipal.originNoSuffix, "[System Principal]");
Assert.equal(systemPrincipal.siteOrigin, "[System Principal]");
Assert.equal(systemPrincipal.siteOriginNoSuffix, "[System Principal]");
// ContentPrincipal checks
let prinicpal1 = scriptSecMan.createContentPrincipal(uri1, {
userContextId: 11,
});
Assert.ok(prinicpal1.isContentPrincipal);
let prinicpal2 = scriptSecMan.createContentPrincipal(uri2, {
userContextId: 22,
});
Assert.ok(prinicpal2.isContentPrincipal);
let prinicpal3 = scriptSecMan.createContentPrincipal(uri3, {
userContextId: 5555,
});
Assert.ok(prinicpal3.isContentPrincipal);
Assert.equal(
prinicpal3.origin,
);
let prinicpal4 = scriptSecMan.createContentPrincipal(uri4, {
userContextId: 6666,
});
Assert.ok(prinicpal4.isContentPrincipal);
let aboutURI = Services.io.newURI("about:preferences");
let aboutPrincipal = scriptSecMan.createContentPrincipal(aboutURI, {
userContextId: 66,
});
Assert.ok(aboutPrincipal.isContentPrincipal);
Assert.equal(aboutPrincipal.origin, "about:preferences^userContextId=66");
Assert.equal(aboutPrincipal.originNoSuffix, "about:preferences");
Assert.equal(aboutPrincipal.siteOrigin, "about:preferences^userContextId=66");
Assert.equal(aboutPrincipal.siteOriginNoSuffix, "about:preferences");
let viewSourceURI = Services.io.newURI(
);
let viewSourcePrincipal = scriptSecMan.createContentPrincipal(viewSourceURI, {
userContextId: 101,
});
Assert.ok(viewSourcePrincipal.isContentPrincipal);
Assert.ok(viewSourcePrincipal.schemeIs("view-source"));
Assert.equal(
viewSourcePrincipal.origin,
);
Assert.equal(
viewSourcePrincipal.originNoSuffix,
);
Assert.equal(
viewSourcePrincipal.siteOrigin,
);
let mozExtensionURI = Services.io.newURI(
);
let mozExtensionPrincipal = scriptSecMan.createContentPrincipal(
mozExtensionURI,
{
userContextId: 102,
}
);
Assert.ok(mozExtensionPrincipal.isContentPrincipal);
Assert.ok(mozExtensionPrincipal.schemeIs("moz-extension"));
Assert.equal(
mozExtensionPrincipal.origin,
);
Assert.equal(
mozExtensionPrincipal.originNoSuffix,
);
Assert.equal(
mozExtensionPrincipal.siteOrigin,
);
Assert.equal(
mozExtensionPrincipal.siteOriginNoSuffix,
);
let localhostPrincipal = scriptSecMan.createContentPrincipal(localhostURI, {
userContextId: 144,
});
Assert.ok(localhostPrincipal.isContentPrincipal);
Assert.ok(localhostPrincipal.schemeIs("http"));
Assert.equal(
localhostPrincipal.origin,
);
Assert.equal(
localhostPrincipal.siteOrigin,
);
// NullPrincipal checks
let nullPrincipal = scriptSecMan.createNullPrincipal({ userContextId: 33 });
Assert.ok(nullPrincipal.isNullPrincipal);
Assert.ok(nullPrincipal.origin.includes("moz-nullprincipal"));
Assert.ok(nullPrincipal.origin.includes("^userContextId=33"));
Assert.ok(nullPrincipal.originNoSuffix.includes("moz-nullprincipal"));
Assert.ok(!nullPrincipal.originNoSuffix.includes("^userContextId=33"));
Assert.ok(nullPrincipal.siteOrigin.includes("moz-nullprincipal"));
Assert.ok(nullPrincipal.siteOrigin.includes("^userContextId=33"));
Assert.ok(nullPrincipal.siteOriginNoSuffix.includes("moz-nullprincipal"));
Assert.ok(!nullPrincipal.siteOriginNoSuffix.includes("^userContextId=33"));
// ExpandedPrincipal checks
let expandedPrincipal = Cu.getObjectPrincipal(Cu.Sandbox([prinicpal2]));
Assert.ok(expandedPrincipal.isExpandedPrincipal);
Assert.equal(
expandedPrincipal.origin,
);
Assert.equal(
expandedPrincipal.originNoSuffix,
);
Assert.equal(
expandedPrincipal.siteOrigin,
);
Assert.equal(
expandedPrincipal.siteOriginNoSuffix,
);
let ipv6Principal = scriptSecMan.createContentPrincipal(ipv6URI, {
userContextId: 6,
});
Assert.ok(ipv6Principal.isContentPrincipal);
Assert.equal(
ipv6Principal.origin,
);
Assert.equal(
ipv6Principal.originNoSuffix,
);
Assert.equal(
ipv6Principal.siteOrigin,
);
Assert.equal(
ipv6Principal.siteOriginNoSuffix,
);