/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ /** * Bug 1929881 - A test to ensure that we don't treat the top-level view-source * local host requests as foreign. The test creates a localhost server and a * page that sets a cookie. It then opens the view-source URL for the page and * ensures that the cookie is set in the unpartitioned cookie jar. */ let { HttpServer } = ChromeUtils.importESModule( "resource://testing-common/httpd.sys.mjs" ); const TEST_PAGE = TEST_DOMAIN_HTTPS + TEST_PATH + "cookies.sjs"; let gHttpServer = null; add_setup(async function () { await SpecialPowers.pushPrefEnv({ set: [["network.cookie.CHIPS.enabled", true]], }); Services.cookies.removeAll(); // Create a http server for the test. if (!gHttpServer) { gHttpServer = new HttpServer(); gHttpServer.registerPathHandler("/setCookie", loadSetCookieHandler); gHttpServer.start(-1); } registerCleanupFunction(async _ => { Services.cookies.removeAll(); if (gHttpServer) { await new Promise(resolve => { gHttpServer.stop(() => { gHttpServer = null; resolve(); }); }); } }); }); function loadSetCookieHandler(request, response) { response.setStatusLine(request.httpVersion, 200, "OK"); response.setHeader("Content-Type", "text/html", false); response.setHeader("Set-Cookie", "test=1", false); let body = `