test_bug411952.js (1375B)
1 "use strict"; 2 3 function run_test() { 4 try { 5 var cm = Services.cookies; 6 Assert.notEqual(cm, null, "Retrieving the cookie manager failed"); 7 8 const time = Date.now() + 24 * 60 * 1000; 9 const cv = cm.add( 10 "example.com", 11 "/", 12 "C", 13 "V", 14 false, 15 true, 16 false, 17 time, 18 {}, 19 Ci.nsICookie.SAMESITE_UNSET, 20 Ci.nsICookie.SCHEME_HTTPS 21 ); 22 Assert.equal(cv.result, Ci.nsICookieValidation.eOK, "Valid cookie"); 23 const now = new Date().getTime(); 24 25 var found = false; 26 for (let cookie of cm.cookies) { 27 if ( 28 cookie.host == "example.com" && 29 cookie.path == "/" && 30 cookie.name == "C" 31 ) { 32 Assert.ok( 33 "creationTime" in cookie, 34 "creationTime attribute is not accessible on the cookie" 35 ); 36 var creationTime = Math.floor(cookie.creationTime / 1000); 37 // allow the times to slip by one second at most, 38 // which should be fine under normal circumstances. 39 Assert.lessOrEqual( 40 Math.abs(creationTime - now), 41 1000, 42 "Cookie's creationTime is set incorrectly" 43 ); 44 found = true; 45 break; 46 } 47 } 48 49 Assert.ok(found, "Didn't find the cookie we were after"); 50 } catch (e) { 51 do_throw("Unexpected exception: " + e.toString()); 52 } 53 54 do_test_finished(); 55 }