test_maybeCapExpiry.js (776B)
1 "use strict"; 2 3 add_task(function test_maybeCapExpiry() { 4 const CAP_PREF = "network.cookie.maxageCap"; 5 Services.prefs.setIntPref(CAP_PREF, 10); // 10 seconds cap 6 7 let now = Date.now(); 8 let expiry = now + 60 * 1000; // 60 seconds in future 9 let capped = Services.cookies.maybeCapExpiry(expiry); 10 11 Assert.lessOrEqual( 12 capped, 13 now + 20 * 1000, 14 "expiry should be capped to about now + cap" 15 ); 16 Assert.lessOrEqual( 17 capped, 18 expiry, 19 "result should not exceed original expiry" 20 ); 21 22 // Expiry below cap should be returned unchanged 23 let smallExpiry = now + 1000; // 1 seconds 24 let res = Services.cookies.maybeCapExpiry(smallExpiry); 25 Assert.equal(res, smallExpiry, "expiry below cap unchanged"); 26 27 Services.prefs.clearUserPref(CAP_PREF); 28 });