Bug 1857386 [wpt PR 42383] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / test / unit / test_bug667818.js
blob9c6e495da0d8c886cd4307b5d8f70f6fbc94e35c
1 "use strict";
3 function makeURI(str) {
4   return Services.io.newURI(str);
7 add_task(async () => {
8   // Allow all cookies.
9   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
10   Services.prefs.setBoolPref(
11     "network.cookieJarSettings.unblocked_for_testing",
12     true
13   );
14   Services.prefs.setBoolPref("dom.security.https_first", false);
16   var uri = makeURI("http://example.com/");
17   var channel = NetUtil.newChannel({
18     uri,
19     loadUsingSystemPrincipal: true,
20     contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
21   });
22   Services.scriptSecurityManager.createContentPrincipal(uri, {});
24   CookieXPCShellUtils.createServer({ hosts: ["example.com"] });
26   // Try an expiration time before the epoch
28   await CookieXPCShellUtils.setCookieToDocument(
29     uri.spec,
30     "test=test; path=/; domain=example.com; expires=Sun, 31-Dec-1899 16:00:00 GMT;"
31   );
32   Assert.equal(
33     await CookieXPCShellUtils.getCookieStringFromDocument(uri.spec),
34     ""
35   );
37   // Now sanity check
38   Services.cookies.setCookieStringFromHttp(
39     uri,
40     "test2=test2; path=/; domain=example.com;",
41     channel
42   );
44   Assert.equal(
45     await CookieXPCShellUtils.getCookieStringFromDocument(uri.spec),
46     "test2=test2"
47   );
48   Services.prefs.clearUserPref("dom.security.https_first");
49 });