Bug 1869043 assert that graph set access is main thread only r=padenot
[gecko.git] / netwerk / cookie / CookieXPCShellUtils.sys.mjs
blobb6d0d3f26b4206f1b9e7947aefc9626bb67a65d9
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 = {
12   init(scope) {
13     AddonTestUtils.maybeInit(scope);
14     ExtensionTestUtils.init(scope);
15   },
17   createServer(args) {
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);
25     });
26     return server;
27   },
29   async loadContentPage(uri, options = {}) {
30     return ExtensionTestUtils.loadContentPage(uri, options);
31   },
33   async getCookieStringFromDocument(uri, options = {}) {
34     const contentPage = await this.loadContentPage(uri, options);
35     const cookies = await contentPage.spawn(
36       [],
37       // eslint-disable-next-line no-undef
38       () => content.document.cookie
39     );
40     await contentPage.close();
41     return cookies;
42   },
44   async setCookieToDocument(uri, set, options = {}) {
45     const contentPage = await this.loadContentPage(uri, options);
46     await contentPage.spawn(
47       [set],
48       // eslint-disable-next-line no-undef
49       cookies => (content.document.cookie = cookies)
50     );
51     await contentPage.close();
52   },