summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/performance/test_caching.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/serviceworkers/test/performance/test_caching.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/serviceworkers/test/performance/test_caching.html')
-rw-r--r--dom/serviceworkers/test/performance/test_caching.html89
1 files changed, 89 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/performance/test_caching.html b/dom/serviceworkers/test/performance/test_caching.html
new file mode 100644
index 0000000000..cd6d4cf493
--- /dev/null
+++ b/dom/serviceworkers/test/performance/test_caching.html
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Service worker performance test: caching</title>
+</head>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="../utils.js"></script>
+<script src="perfutils.js"></script>
+<script>
+
+ "use strict";
+
+ const NO_CACHE = "No cache";
+ const CACHED = "Cached";
+ const NO_CACHE_AGAIN = "No cache again";
+
+ var journal = {};
+ journal[NO_CACHE] = [];
+ journal[CACHED] = [];
+ journal[NO_CACHE_AGAIN] = [];
+
+ const ITERATIONS = 10;
+
+ var perfMetadata = {
+ owner: "DOM LWS",
+ name: "Service Worker Caching",
+ description: "Test service worker caching.",
+ options: {
+ default: {
+ perfherder: true,
+ perfherder_metrics: [
+ // Here, we can't use the constants defined above because perfherder
+ // grabs data from the parse tree.
+ { name: "No cache", unit: "ms", shouldAlert: true },
+ { name: "Cached", unit: "ms", shouldAlert: true },
+ { name: "No cache again", unit: "ms", shouldAlert: true },
+ ],
+ verbose: true,
+ manifest: "perftest.toml",
+ manifest_flavor: "plain",
+ },
+ },
+ };
+
+ add_task(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [["dom.serviceWorkers.testing.enabled", true]]
+ });
+ });
+
+ function create_iframe(url) {
+ return new Promise(function(res) {
+ let iframe = document.createElement("iframe");
+ iframe.src = url;
+ iframe.onload = function() { res(iframe) }
+ document.body.appendChild(iframe);
+ });
+ }
+
+ async function time_fetch(journal, iframe, filename) {
+ for (let i = 0; i < ITERATIONS; i++) {
+ let result = await iframe.contentWindow.time_fetch(filename);
+ is(result.status, 200);
+ is(result.data, filename);
+ journal.push(result.elapsed_ms);
+ }
+ }
+
+ add_task(async () => {
+ let reg = await navigator.serviceWorker.register("sw_cacher.js");
+ await waitForState(reg.installing, "activated");
+
+ let iframe = await create_iframe("time_fetch.html");
+
+ await time_fetch(journal[NO_CACHE], iframe, "uncached.txt");
+ await time_fetch(journal[CACHED], iframe, "cached.txt");
+ await time_fetch(journal[NO_CACHE_AGAIN], iframe, "uncached.txt");
+
+ await reg.unregister();
+ });
+
+ add_task(() => {
+ reportMetrics(journal);
+ });
+
+</script>
+<body>
+</body>
+</html>