summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/ForceRefreshParent.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/serviceworkers/test/ForceRefreshParent.sys.mjs
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/serviceworkers/test/ForceRefreshParent.sys.mjs')
-rw-r--r--dom/serviceworkers/test/ForceRefreshParent.sys.mjs77
1 files changed, 77 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/ForceRefreshParent.sys.mjs b/dom/serviceworkers/test/ForceRefreshParent.sys.mjs
new file mode 100644
index 0000000000..cb2d4809e9
--- /dev/null
+++ b/dom/serviceworkers/test/ForceRefreshParent.sys.mjs
@@ -0,0 +1,77 @@
+var maxCacheLoadCount = 3;
+var cachedLoadCount = 0;
+var baseLoadCount = 0;
+var done = false;
+
+export class ForceRefreshParent extends JSWindowActorParent {
+ constructor() {
+ super();
+ }
+
+ receiveMessage(msg) {
+ // if done is called, ignore the msg.
+ if (done) {
+ return;
+ }
+ if (msg.data.type === "base-load") {
+ baseLoadCount += 1;
+ if (cachedLoadCount === maxCacheLoadCount) {
+ ForceRefreshParent.SimpleTest.is(
+ baseLoadCount,
+ 2,
+ "cached load should occur before second base load"
+ );
+ done = true;
+ return ForceRefreshParent.done();
+ }
+ if (baseLoadCount !== 1) {
+ ForceRefreshParent.SimpleTest.ok(
+ false,
+ "base load without cached load should only occur once"
+ );
+ done = true;
+ return ForceRefreshParent.done();
+ }
+ } else if (msg.data.type === "base-register") {
+ ForceRefreshParent.SimpleTest.ok(
+ !cachedLoadCount,
+ "cached load should not occur before base register"
+ );
+ ForceRefreshParent.SimpleTest.is(
+ baseLoadCount,
+ 1,
+ "register should occur after first base load"
+ );
+ } else if (msg.data.type === "base-sw-ready") {
+ ForceRefreshParent.SimpleTest.ok(
+ !cachedLoadCount,
+ "cached load should not occur before base ready"
+ );
+ ForceRefreshParent.SimpleTest.is(
+ baseLoadCount,
+ 1,
+ "ready should occur after first base load"
+ );
+ ForceRefreshParent.refresh();
+ } else if (msg.data.type === "cached-load") {
+ ForceRefreshParent.SimpleTest.ok(
+ cachedLoadCount < maxCacheLoadCount,
+ "cached load should not occur too many times"
+ );
+ ForceRefreshParent.SimpleTest.is(
+ baseLoadCount,
+ 1,
+ "cache load occur after first base load"
+ );
+ cachedLoadCount += 1;
+ if (cachedLoadCount < maxCacheLoadCount) {
+ return ForceRefreshParent.refresh();
+ }
+ ForceRefreshParent.forceRefresh();
+ } else if (msg.data.type === "cached-failure") {
+ ForceRefreshParent.SimpleTest.ok(false, "failure: " + msg.data.detail);
+ done = true;
+ ForceRefreshParent.done();
+ }
+ }
+}