diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/file/tests/test_bug1742540.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/file/tests/test_bug1742540.html')
-rw-r--r-- | dom/file/tests/test_bug1742540.html | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/dom/file/tests/test_bug1742540.html b/dom/file/tests/test_bug1742540.html new file mode 100644 index 0000000000..7516f38a85 --- /dev/null +++ b/dom/file/tests/test_bug1742540.html @@ -0,0 +1,83 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1742540</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> + <script> + +SimpleTest.waitForExplicitFinish(); + +add_task(function setupPrefs() { + return SpecialPowers.pushPrefEnv({ + set: [ + ["dom.serviceWorkers.enabled", true], + ["dom.serviceWorkers.testing.enabled", true], + ], + }); +}); + +function get_file() { + return new Promise(resolve => { + let xhr = new XMLHttpRequest(); + xhr.open("GET", "/dynamic/getMyDirectory.sjs", false); + xhr.send(); + let basePath = xhr.responseText; + + let script = SpecialPowers.loadChromeScript( + SimpleTest.getTestFileURL("create_file_objects.js") + ); + script.addMessageListener("created-file-objects", files => { + resolve(files[0]); + }); + script.sendAsyncMessage("create-file-objects", { + fileNames: [basePath + "file_mozfiledataurl_audio.ogg"], + }); + }); +} + +function wait_for_message(port, expected_message) { + return new Promise(resolve => { + port.onmessage = event => { + port.onmessage = null; + ok(event.data === expected_message, event.data); + resolve(); + }; + }); +} + +function unregister_and_done(registration) { + return registration.unregister().then(() => { + ok(true, "Will find leaks of nsPipe in BloatView without fix."); + SimpleTest.finish; + }); +} + +add_task(async function send_file_to_serviceworker() { + let registration = await navigator.serviceWorker + .register("worker_bug1742540.js", { scope: "./" }) + .then(() => { + return navigator.serviceWorker.ready; + }); + + ok(registration.active, "ServiceWorker is activated"); + + let file = await get_file(); + ok(file.size > 100000, "File size is big enough."); + let message = "ServiceWorker receives a file and did not reference it."; + let channel = new MessageChannel(); + let received = wait_for_message(channel.port1, message); + registration.active.postMessage({ port: channel.port2, message, file }, [ + channel.port2, + ]); + await received; + + let finish = await unregister_and_done(registration); +}); + + </script> +</body> +</html> |