Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | function run_test() { |
michael@0 | 2 | try { |
michael@0 | 3 | var cm = Cc["@mozilla.org/cookiemanager;1"]. |
michael@0 | 4 | getService(Ci.nsICookieManager2); |
michael@0 | 5 | do_check_neq(cm, null, "Retrieving the cookie manager failed"); |
michael@0 | 6 | |
michael@0 | 7 | const time = (new Date("Jan 1, 2030")).getTime() / 1000; |
michael@0 | 8 | cm.add("example.com", "/", "C", "V", false, true, false, time); |
michael@0 | 9 | const now = Math.floor((new Date()).getTime() / 1000); |
michael@0 | 10 | |
michael@0 | 11 | var enumerator = cm.enumerator, found = false; |
michael@0 | 12 | while (enumerator.hasMoreElements()) { |
michael@0 | 13 | var cookie = enumerator.getNext().QueryInterface(Ci.nsICookie2); |
michael@0 | 14 | if (cookie.host == "example.com" && |
michael@0 | 15 | cookie.path == "/" && |
michael@0 | 16 | cookie.name == "C") { |
michael@0 | 17 | do_check_true("creationTime" in cookie, |
michael@0 | 18 | "creationTime attribute is not accessible on the cookie"); |
michael@0 | 19 | var creationTime = Math.floor(cookie.creationTime / 1000000); |
michael@0 | 20 | // allow the times to slip by one second at most, |
michael@0 | 21 | // which should be fine under normal circumstances. |
michael@0 | 22 | do_check_true(Math.abs(creationTime - now) <= 1, |
michael@0 | 23 | "Cookie's creationTime is set incorrectly"); |
michael@0 | 24 | found = true; |
michael@0 | 25 | break; |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | do_check_true(found, "Didn't find the cookie we were after"); |
michael@0 | 30 | } catch (e) { |
michael@0 | 31 | do_throw("Unexpected exception: " + e.toString()); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | do_test_finished(); |
michael@0 | 35 | } |