summaryrefslogtreecommitdiffstats
path: root/dom/html/test/sw_formSubmission.js
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/test/sw_formSubmission.js')
-rw-r--r--dom/html/test/sw_formSubmission.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/dom/html/test/sw_formSubmission.js b/dom/html/test/sw_formSubmission.js
new file mode 100644
index 0000000000..e7b4a7872c
--- /dev/null
+++ b/dom/html/test/sw_formSubmission.js
@@ -0,0 +1,36 @@
+/**
+ * We are used by test_formSubmission.html to immediately activate and start
+ * controlling its page. We operate in 3 modes, conveyed via ?MODE appended to
+ * our URL.
+ *
+ * - "no-fetch": Don't register a fetch listener so that the optimized fetch
+ * event bypass happens.
+ * - "reset-fetch": Do register a fetch listener, reset every interception.
+ * - "proxy-fetch": Do register a fetch listener, resolve every interception
+ * with fetch(event.request).
+ */
+
+const mode = location.search.slice(1);
+
+// Fetch handling.
+if (mode !== "no-fetch") {
+ addEventListener("fetch", function (event) {
+ if (mode === "reset-fetch") {
+ // Don't invoke respondWith, resetting the interception.
+ return;
+ } else if (mode === "proxy-fetch") {
+ // Per the spec, there's an automatic waitUntil() on this too.
+ event.respondWith(fetch(event.request));
+ return;
+ }
+ });
+}
+
+// Go straight to activation, bypassing waiting.
+addEventListener("install", function (event) {
+ event.waitUntil(skipWaiting());
+});
+// Control the test document ASAP.
+addEventListener("activate", function (event) {
+ event.waitUntil(clients.claim());
+});