1 const Cc
= Components
.classes
;
2 const Ci
= Components
.interfaces
;
6 var cm
= Cc
["@mozilla.org/cookiemanager;1"].
7 getService(Ci
.nsICookieManager2
);
8 do_check_neq(cm
, null, "Retrieving the cookie manager failed");
10 const time
= (new Date("Jan 1, 2030")).getTime() / 1000;
11 cm
.add("example.com", "/", "C", "V", false, true, false, time
);
12 const now
= Math
.floor((new Date()).getTime() / 1000);
14 var enumerator
= cm
.enumerator
, found
= false;
15 while (enumerator
.hasMoreElements()) {
16 var cookie
= enumerator
.getNext().QueryInterface(Ci
.nsICookie2
);
17 if (cookie
.host
== "example.com" &&
20 do_check_true("creationTime" in cookie
,
21 "creationTime attribute is not accessible on the cookie");
22 var creationTime
= Math
.floor(cookie
.creationTime
/ 1000000);
23 // allow the times to slip by one second at most,
24 // which should be fine under normal circumstances.
25 do_check_true(Math
.abs(creationTime
- now
) <= 1,
26 "Cookie's creationTime is set incorrectly");
32 do_check_true(found
, "Didn't find the cookie we were after");
34 do_throw("Unexpected exception: " + e
.toString());