summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/browser_force_refresh.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 /dom/serviceworkers/test/browser_force_refresh.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/serviceworkers/test/browser_force_refresh.js')
-rw-r--r--dom/serviceworkers/test/browser_force_refresh.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/browser_force_refresh.js b/dom/serviceworkers/test/browser_force_refresh.js
new file mode 100644
index 0000000000..11c3c3f1f7
--- /dev/null
+++ b/dom/serviceworkers/test/browser_force_refresh.js
@@ -0,0 +1,87 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var gTestRoot = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content/",
+ "http://mochi.test:8888/"
+);
+
+async function refresh() {
+ EventUtils.synthesizeKey("R", { accelKey: true });
+}
+
+async function forceRefresh() {
+ EventUtils.synthesizeKey("R", { accelKey: true, shiftKey: true });
+}
+
+async function done() {
+ // unregister window actors
+ ChromeUtils.unregisterWindowActor("ForceRefresh");
+ let tab = gBrowser.selectedTab;
+ let tabBrowser = gBrowser.getBrowserForTab(tab);
+ await ContentTask.spawn(tabBrowser, null, async function() {
+ const swr = await content.navigator.serviceWorker.getRegistration();
+ await swr.unregister();
+ });
+
+ BrowserTestUtils.removeTab(tab);
+ executeSoon(finish);
+}
+
+function test() {
+ waitForExplicitFinish();
+ SpecialPowers.pushPrefEnv(
+ {
+ set: [
+ ["dom.serviceWorkers.enabled", true],
+ ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+ ["dom.serviceWorkers.testing.enabled", true],
+ ["dom.caches.enabled", true],
+ ["browser.cache.disk.enable", false],
+ ["browser.cache.memory.enable", false],
+ ],
+ },
+ async function() {
+ // create ForceRefreseh window actor
+ const { ForceRefreshParent } = ChromeUtils.importESModule(
+ getRootDirectory(gTestPath) + "ForceRefreshParent.sys.mjs"
+ );
+
+ // setup helper functions for ForceRefreshParent
+ ForceRefreshParent.SimpleTest = SimpleTest;
+ ForceRefreshParent.refresh = refresh;
+ ForceRefreshParent.forceRefresh = forceRefresh;
+ ForceRefreshParent.done = done;
+
+ // setup window actor options
+ let windowActorOptions = {
+ parent: {
+ esModuleURI:
+ getRootDirectory(gTestPath) + "ForceRefreshParent.sys.mjs",
+ },
+ child: {
+ esModuleURI:
+ getRootDirectory(gTestPath) + "ForceRefreshChild.sys.mjs",
+ events: {
+ "base-register": { capture: true, wantUntrusted: true },
+ "base-sw-ready": { capture: true, wantUntrusted: true },
+ "base-load": { capture: true, wantUntrusted: true },
+ "cached-load": { capture: true, wantUntrusted: true },
+ "cached-failure": { capture: true, wantUntrusted: true },
+ },
+ },
+ allFrames: true,
+ };
+
+ // register ForceRefresh window actors
+ ChromeUtils.registerWindowActor("ForceRefresh", windowActorOptions);
+
+ // create a new tab and load test url
+ var url = gTestRoot + "browser_base_force_refresh.html";
+ var tab = BrowserTestUtils.addTab(gBrowser);
+ var tabBrowser = gBrowser.getBrowserForTab(tab);
+ gBrowser.selectedTab = tab;
+ BrowserTestUtils.loadURI(gBrowser, url);
+ }
+ );
+}