2 getRootDirectory(gTestPath).replace(
3 "chrome://mochitests/content",
5 ) + "open_credentialless_document.sjs";
8 getRootDirectory(gTestPath).replace(
9 "chrome://mochitests/content",
11 ) + "credentialless_worker.sjs";
14 getRootDirectory(gTestPath).replace(
15 "chrome://mochitests/content",
17 ) + "store_header.sjs?getstate";
19 const SAME_ORIGIN = "https://example.com";
20 const CROSS_ORIGIN = "https://test1.example.com";
22 const WORKER_USES_CREDENTIALLESS = "credentialless";
23 const WORKER_NOT_USE_CREDENTIALLESS = "";
25 async function addCookieToOrigin(origin) {
26 const fetchRequestURL =
27 getRootDirectory(gTestPath).replace("chrome://mochitests/content", origin) +
28 "store_header.sjs?addcookie";
30 const addcookieTab = await BrowserTestUtils.openNewForegroundTab(
35 await SpecialPowers.spawn(addcookieTab.linkedBrowser, [], async function () {
36 content.document.cookie = "coep=credentialless; SameSite=None; Secure";
38 await BrowserTestUtils.removeTab(addcookieTab);
41 async function testOrigin(
44 workerUsesCredentialless,
47 let topLevelUrl = TOP_LEVEL_URL;
48 if (isCredentialless) {
49 topLevelUrl += "?credentialless";
51 const noCredentiallessTab = await BrowserTestUtils.openNewForegroundTab(
56 const fetchRequestURL =
57 getRootDirectory(gTestPath).replace(
58 "chrome://mochitests/content",
60 ) + "store_header.sjs?checkheader";
62 let workerScriptURL = WORKER_URL + "?" + workerUsesCredentialless;
64 await SpecialPowers.spawn(
65 noCredentiallessTab.linkedBrowser,
66 [fetchRequestURL, GET_STATE_URL, workerScriptURL, expectedCookieResult],
73 const worker = new content.Worker(workerScriptURL, {});
75 // When the worker receives this message, it'll send
76 // a fetch request to fetchRequestURL, and fetchRequestURL
77 // will store whether it has received the cookie as a
79 worker.postMessage(fetchRequestURL);
81 if (expectedCookieResult == "error") {
82 await new Promise(r => {
83 worker.onerror = function () {
84 ok(true, "worker has error");
89 await new Promise(r => {
90 worker.addEventListener("message", async function () {
91 // This request is used to get the saved state from the
92 // previous fetch request.
93 const response = await content.fetch(getStateURL, {
96 const text = await response.text();
97 is(text, expectedCookieResult);
104 await BrowserTestUtils.removeTab(noCredentiallessTab);
107 async function dedicatedWorkerTest(
110 expectedCookieResultForNoCredentialless,
111 expectedCookieResultForCredentialless
117 expectedCookieResultForNoCredentialless
123 expectedCookieResultForCredentialless
127 add_task(async function () {
128 await SpecialPowers.pushPrefEnv({
130 ["browser.tabs.remote.coep.credentialless", false], // Explicitly set credentialless to false because we want to test origin trial
131 ["dom.origin-trials.enabled", true],
132 ["dom.origin-trials.test-key.enabled", true],
136 await addCookieToOrigin(SAME_ORIGIN);
137 await addCookieToOrigin(CROSS_ORIGIN);
139 await dedicatedWorkerTest(
141 WORKER_NOT_USE_CREDENTIALLESS,
145 await dedicatedWorkerTest(
147 WORKER_USES_CREDENTIALLESS,
152 await dedicatedWorkerTest(
154 WORKER_NOT_USE_CREDENTIALLESS,
158 await dedicatedWorkerTest(
160 WORKER_USES_CREDENTIALLESS,