Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_hpke_out_of_process.js
blobfb8a79d0a6119876585d63318bb7e748123e1d10
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 const { HttpServer } = ChromeUtils.importESModule(
7 "resource://testing-common/httpd.sys.mjs"
8 );
10 const { XPCShellContentUtils } = ChromeUtils.importESModule(
11 "resource://testing-common/XPCShellContentUtils.sys.mjs"
14 XPCShellContentUtils.ensureInitialized(this);
16 let gHttpServer;
18 add_setup(async function () {
19 gHttpServer = new HttpServer();
20 let invalidHandler = (req, res) => {
21 res.setStatusLine(req.httpVersion, 500, "Oh no, it broke");
22 res.write("Uh oh, it broke.");
24 let validHandler = (req, res) => {
25 res.setHeader("Content-Type", "application/ohttp-keys");
26 res.write("1234");
29 gHttpServer.registerPathHandler("/.wellknown/invalid", invalidHandler);
30 gHttpServer.registerPathHandler("/.wellknown/valid", validHandler);
32 gHttpServer.start(-1);
33 });
35 function getLocalURL(path) {
36 return `http://localhost:${gHttpServer.identity.primaryPort}/.wellknown/${path}`;
39 add_task(async function test_out_of_process_use() {
40 let page = await XPCShellContentUtils.loadContentPage("about:certificate", {
41 remote: true,
42 });
44 let fetchURL = getLocalURL("valid");
45 let contentFetch = await page.spawn([fetchURL], url => {
46 // eslint-disable-next-line no-shadow
47 let { HPKEConfigManager } = ChromeUtils.importESModule(
48 "resource://gre/modules/HPKEConfigManager.sys.mjs"
51 return HPKEConfigManager.get(url);
52 });
53 Assert.deepEqual(contentFetch, new TextEncoder().encode("1234"));
54 Assert.ok(
55 page.browsingContext.currentWindowGlobal.domProcess.getActor(
56 "HPKEConfigManager"
58 "Should be able to get a parent actor for this browsingContext"
61 let randomPage = await XPCShellContentUtils.loadContentPage(
62 "data:text/html,2",
64 remote: true,
68 await Assert.rejects(
69 randomPage.spawn([fetchURL], async url => {
70 // eslint-disable-next-line no-shadow
71 let { HPKEConfigManager } = ChromeUtils.importESModule(
72 "resource://gre/modules/HPKEConfigManager.sys.mjs"
75 return HPKEConfigManager.get(url);
76 }),
77 /cannot be used/,
78 "Shouldn't be able to use HPKEConfigManager from random content processes."
80 Assert.throws(
81 () =>
82 randomPage.browsingContext.currentWindowGlobal.domProcess.getActor(
83 "HPKEConfigManager"
85 /Process protocol .*support remote type/,
86 "Should not be able to get a parent actor for a non-privilegedabout browsingContext"
88 });