Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / netwerk / test / unit / test_cookies_profile_close.js
blob6ea9ab23f3a5fb069a5817feaccc80de8fa46ba6
1 /* Any copyright is dedicated to the Public Domain.
2    http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Test that the cookie APIs behave sanely after 'profile-before-change'.
6 "use strict";
8 add_task(async () => {
9   // Set up a profile.
10   do_get_profile();
12   // Allow all cookies.
13   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
14   Services.prefs.setBoolPref(
15     "network.cookieJarSettings.unblocked_for_testing",
16     true
17   );
18   Services.prefs.setBoolPref("dom.security.https_first", false);
20   // Start the cookieservice.
21   Services.cookies;
23   CookieXPCShellUtils.createServer({ hosts: ["foo.com"] });
25   // Set a cookie.
26   let uri = NetUtil.newURI("http://foo.com");
27   let channel = NetUtil.newChannel({
28     uri,
29     loadUsingSystemPrincipal: true,
30     contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
31   });
33   Services.scriptSecurityManager.createContentPrincipal(uri, {});
35   await CookieXPCShellUtils.setCookieToDocument(
36     uri.spec,
37     "oh=hai; max-age=1000"
38   );
40   let cookies = Services.cookies.cookies;
41   Assert.ok(cookies.length == 1);
42   let cookie = cookies[0];
44   // Fire 'profile-before-change'.
45   do_close_profile();
47   let promise = new _promise_observer("cookie-db-closed");
49   // Check that the APIs behave appropriately.
50   Assert.equal(
51     await CookieXPCShellUtils.getCookieStringFromDocument("http://foo.com/"),
52     ""
53   );
55   Assert.equal(Services.cookies.getCookieStringFromHttp(uri, channel), "");
57   await CookieXPCShellUtils.setCookieToDocument(uri.spec, "oh2=hai");
59   Services.cookies.setCookieStringFromHttp(uri, "oh3=hai", channel);
60   Assert.equal(
61     await CookieXPCShellUtils.getCookieStringFromDocument("http://foo.com/"),
62     ""
63   );
65   do_check_throws(function () {
66     Services.cookies.removeAll();
67   }, Cr.NS_ERROR_NOT_AVAILABLE);
69   do_check_throws(function () {
70     Services.cookies.cookies;
71   }, Cr.NS_ERROR_NOT_AVAILABLE);
73   do_check_throws(function () {
74     Services.cookies.add(
75       "foo.com",
76       "",
77       "oh4",
78       "hai",
79       false,
80       false,
81       false,
82       0,
83       {},
84       Ci.nsICookie.SAMESITE_NONE,
85       Ci.nsICookie.SCHEME_HTTPS
86     );
87   }, Cr.NS_ERROR_NOT_AVAILABLE);
89   do_check_throws(function () {
90     Services.cookies.remove("foo.com", "", "oh4", {});
91   }, Cr.NS_ERROR_NOT_AVAILABLE);
93   do_check_throws(function () {
94     Services.cookies.cookieExists(cookie.host, cookie.path, cookie.name, {});
95   }, Cr.NS_ERROR_NOT_AVAILABLE);
97   do_check_throws(function () {
98     Services.cookies.countCookiesFromHost("foo.com");
99   }, Cr.NS_ERROR_NOT_AVAILABLE);
101   do_check_throws(function () {
102     Services.cookies.getCookiesFromHost("foo.com", {});
103   }, Cr.NS_ERROR_NOT_AVAILABLE);
105   // Wait for the database to finish closing.
106   await promise;
108   // Load the profile and check that the API is available.
109   do_load_profile();
110   Assert.ok(
111     Services.cookies.cookieExists(cookie.host, cookie.path, cookie.name, {})
112   );
113   Services.prefs.clearUserPref("dom.security.https_first");