1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* vim: set sts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 import { ExtensionTestUtils } from "resource://testing-common/ExtensionXPCShellUtils.sys.mjs";
9 import { AddonTestUtils } from "resource://testing-common/AddonTestUtils.sys.mjs";
11 export const CookieXPCShellUtils = {
13 AddonTestUtils.maybeInit(scope);
14 ExtensionTestUtils.init(scope);
18 const server = AddonTestUtils.createHttpServer(args);
19 server.registerPathHandler("/", (metadata, response) => {
20 response.setStatusLine(metadata.httpVersion, 200, "OK");
21 response.setHeader("Content-Type", "text/html", false);
23 let body = "<body><h1>Hello world!</h1></body>";
24 response.bodyOutputStream.write(body, body.length);
29 async loadContentPage(uri, options = {}) {
30 return ExtensionTestUtils.loadContentPage(uri, options);
33 async getCookieStringFromDocument(uri, options = {}) {
34 const contentPage = await this.loadContentPage(uri, options);
35 const cookies = await contentPage.spawn(
37 // eslint-disable-next-line no-undef
38 () => content.document.cookie
40 await contentPage.close();
44 async setCookieToDocument(uri, set, options = {}) {
45 const contentPage = await this.loadContentPage(uri, options);
46 await contentPage.spawn(
48 // eslint-disable-next-line no-undef
49 cookies => (content.document.cookie = cookies)
51 await contentPage.close();