blob: 004c02686d502f3c17d03a610231c097fc2f055a [file] [log] [blame]
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
let activeWorker;
let scope = "/workers/service/resources/";
promise_test(async (test) => {
let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration && registration.scope.endsWith(scope))
await registration.unregister();
registration = await navigator.serviceWorker.register("resources/service-worker-resource-timing.js", {scope});
activeWorker = registration.active;
if (activeWorker)
return;
activeWorker = registration.installing;
return new Promise((resolve) => {
activeWorker.addEventListener("statechange", () => {
if (activeWorker.state === "activated")
resolve();
});
});
}, "Setup worker");
promise_test(async (test) => {
activeWorker.postMessage("TEST-RESOURCE-TIMING");
await new Promise((resolve, reject) => {
navigator.serviceWorker.addEventListener("message", test.step_func((event) => {
let entries = JSON.parse(event.data.entries);
assert_equals(entries.length, 2);
assert_true(entries.some((entry) => entry.name.endsWith("data1.txt")));
assert_true(entries.some((entry) => entry.name.endsWith("data2.txt")));
resolve();
}));
});
}, "Verify service worker had 2 ResourceTiming entries");
</script>
</body>
</html>