diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/serviceworkers/test/match_all_clients | |
parent | Initial commit. (diff) | |
download | firefox-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/match_all_clients')
-rw-r--r-- | dom/serviceworkers/test/match_all_clients/match_all_controlled.html | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/match_all_clients/match_all_controlled.html b/dom/serviceworkers/test/match_all_clients/match_all_controlled.html new file mode 100644 index 0000000000..35f064815d --- /dev/null +++ b/dom/serviceworkers/test/match_all_clients/match_all_controlled.html @@ -0,0 +1,83 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<!DOCTYPE HTML> +<html> +<head> + <title>Bug 1058311 - controlled page</title> +<script class="testbody" type="text/javascript"> + var re = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; + var frameType = "none"; + var testWindow = parent; + + if (parent != window) { + frameType = "nested"; + } else if (opener) { + frameType = "auxiliary"; + testWindow = opener; + } else if (parent == window) { + frameType = "top-level"; + } else { + postResult(false, "Unexpected frameType"); + } + + window.onload = function() { + navigator.serviceWorker.ready.then(function(swr) { + // Send a message to our SW that will cause it to do clients.matchAll() + // and send a message *to each client about themselves* (rather than + // replying directly to us with all the clients it finds). + swr.active.postMessage("Start"); + }); + } + + function postResult(result, msg) { + response = { + result, + message: msg + }; + + testWindow.postMessage(response, "*"); + } + + navigator.serviceWorker.onmessage = async function(msg) { + // ## Verify the contents of the SW's serialized rep of our client info. + // Clients are opaque identifiers at a spec level, but we want to verify + // that they are UUID's *without wrapping "{}" characters*. + result = re.test(msg.data.id); + postResult(result, "Client id test"); + + result = msg.data.url == window.location; + postResult(result, "Client url test"); + + result = msg.data.visibilityState === document.visibilityState; + postResult(result, "Client visibility test. expected=" +document.visibilityState); + + result = msg.data.focused === document.hasFocus(); + postResult(result, "Client focus test. expected=" + document.hasFocus()); + + result = msg.data.frameType === frameType; + postResult(result, "Client frameType test. expected=" + frameType); + + result = msg.data.type === "window"; + postResult(result, "Client type test. expected=window"); + + // ## Verify the FetchEvent.clientId + // In bug 1446225 it turned out we provided UUID's wrapped with {}'s. We + // now also get coverage by forcing our clients.get() to forbid UUIDs + // with that form. + + const clientIdResp = await fetch('clientId'); + const fetchClientId = await clientIdResp.text(); + result = re.test(fetchClientId); + postResult(result, "Fetch clientId test"); + + postResult(true, "DONE"); + window.close(); + }; +</script> + +</head> +<body> +</body> +</html> |