Bug 1857386 [wpt PR 42383] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / test / unit / test_bug411952.js
blob45849571887eb949b5ef69f8de1137c0e57f303f
1 "use strict";
3 function run_test() {
4   try {
5     var cm = Services.cookies;
6     Assert.notEqual(cm, null, "Retrieving the cookie manager failed");
8     const time = new Date("Jan 1, 2030").getTime() / 1000;
9     cm.add(
10       "example.com",
11       "/",
12       "C",
13       "V",
14       false,
15       true,
16       false,
17       time,
18       {},
19       Ci.nsICookie.SAMESITE_NONE,
20       Ci.nsICookie.SCHEME_HTTPS
21     );
22     const now = Math.floor(new Date().getTime() / 1000);
24     var found = false;
25     for (let cookie of cm.cookies) {
26       if (
27         cookie.host == "example.com" &&
28         cookie.path == "/" &&
29         cookie.name == "C"
30       ) {
31         Assert.ok(
32           "creationTime" in cookie,
33           "creationTime attribute is not accessible on the cookie"
34         );
35         var creationTime = Math.floor(cookie.creationTime / 1000000);
36         // allow the times to slip by one second at most,
37         // which should be fine under normal circumstances.
38         Assert.ok(
39           Math.abs(creationTime - now) <= 1,
40           "Cookie's creationTime is set incorrectly"
41         );
42         found = true;
43         break;
44       }
45     }
47     Assert.ok(found, "Didn't find the cookie we were after");
48   } catch (e) {
49     do_throw("Unexpected exception: " + e.toString());
50   }
52   do_test_finished();