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'.
13 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
14 Services.prefs.setBoolPref(
15 "network.cookieJarSettings.unblocked_for_testing",
18 Services.prefs.setBoolPref("dom.security.https_first", false);
20 // Start the cookieservice.
23 CookieXPCShellUtils.createServer({ hosts: ["foo.com"] });
26 let uri = NetUtil.newURI("http://foo.com");
27 let channel = NetUtil.newChannel({
29 loadUsingSystemPrincipal: true,
30 contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
33 Services.scriptSecurityManager.createContentPrincipal(uri, {});
35 await CookieXPCShellUtils.setCookieToDocument(
37 "oh=hai; max-age=1000"
40 let cookies = Services.cookies.cookies;
41 Assert.ok(cookies.length == 1);
42 let cookie = cookies[0];
44 // Fire 'profile-before-change'.
47 let promise = new _promise_observer("cookie-db-closed");
49 // Check that the APIs behave appropriately.
51 await CookieXPCShellUtils.getCookieStringFromDocument("http://foo.com/"),
55 Assert.equal(Services.cookies.getCookieStringFromHttp(uri, channel), "");
57 await CookieXPCShellUtils.setCookieToDocument(uri.spec, "oh2=hai");
59 Services.cookies.setCookieStringFromHttp(uri, "oh3=hai", channel);
61 await CookieXPCShellUtils.getCookieStringFromDocument("http://foo.com/"),
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 () {
84 Ci.nsICookie.SAMESITE_NONE,
85 Ci.nsICookie.SCHEME_HTTPS
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.
108 // Load the profile and check that the API is available.
111 Services.cookies.cookieExists(cookie.host, cookie.path, cookie.name, {})
113 Services.prefs.clearUserPref("dom.security.https_first");