summaryrefslogtreecommitdiffstats
path: root/toolkit/components/timermanager/tests/unit/test_skipFirst.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/timermanager/tests/unit/test_skipFirst.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.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.js44
1 files changed, 44 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..bfdaa40de4
--- /dev/null
+++ b/toolkit/components/timermanager/tests/unit/test_skipFirst.js
@@ -0,0 +1,44 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+"use strict";
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+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);
+});