diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/components/timermanager/tests/unit/test_skipFirst.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/timermanager/tests/unit/test_skipFirst.js')
-rw-r--r-- | toolkit/components/timermanager/tests/unit/test_skipFirst.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/toolkit/components/timermanager/tests/unit/test_skipFirst.js b/toolkit/components/timermanager/tests/unit/test_skipFirst.js new file mode 100644 index 0000000000..a0306ec430 --- /dev/null +++ b/toolkit/components/timermanager/tests/unit/test_skipFirst.js @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ +"use strict"; + +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); + +XPCOMUtils.defineLazyServiceGetter( + this, + "gUpdateTimerManager", + "@mozilla.org/updates/timer-manager;1", + "nsIUpdateTimerManager" +); + +const PREF_APP_UPDATE_LASTUPDATETIME_FMT = "app.update.lastUpdateTime.%ID%"; + +add_task(async function() { + const testId = "test_timer_id"; + const testPref = PREF_APP_UPDATE_LASTUPDATETIME_FMT.replace(/%ID%/, testId); + const testInterval = 100000000; // Just needs to be longer than the test. + + Services.prefs.clearUserPref(testPref); + gUpdateTimerManager.registerTimer( + testId, + {}, + testInterval, + true /* skipFirst */ + ); + let prefValue = Services.prefs.getIntPref(testPref, 0); + Assert.notEqual( + prefValue, + 0, + "Last update time for test timer must not be 0." + ); + let nowSeconds = Date.now() / 1000; // update timer lastUpdate prefs are set in seconds. + Assert.ok( + Math.abs(nowSeconds - prefValue) < 2, + "Last update time for test timer must be now-ish." + ); + + gUpdateTimerManager.unregisterTimer(testId); +}); |