summaryrefslogtreecommitdiffstats
path: root/dom/cache/test/mochitest/test_cache_worker_gc.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/cache/test/mochitest/test_cache_worker_gc.html')
-rw-r--r--dom/cache/test/mochitest/test_cache_worker_gc.html58
1 files changed, 58 insertions, 0 deletions
diff --git a/dom/cache/test/mochitest/test_cache_worker_gc.html b/dom/cache/test/mochitest/test_cache_worker_gc.html
new file mode 100644
index 0000000000..798bafaf9b
--- /dev/null
+++ b/dom/cache/test/mochitest/test_cache_worker_gc.html
@@ -0,0 +1,58 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test CacheStorage does not prevent worker GC</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+ <script type="text/javascript" src="driver.js"></script>
+</head>
+<body>
+<iframe id="frame"></iframe>
+<script class="testbody" type="text/javascript">
+function startWorker() {
+ return new Promise(resolve => {
+ var w = new Worker("idle_worker.js");
+ w.addEventListener("message", function onMessage(evt) {
+ if (evt.data === "LOADED") {
+ w.removeEventListener("message", onMessage);
+ resolve(w);
+ }
+ });
+ });
+}
+
+function gc() {
+ return new Promise(resolve => {
+ SpecialPowers.exactGC(resolve);
+ });
+}
+
+SimpleTest.waitForExplicitFinish();
+
+async function test() {
+ let w = await startWorker();
+ let weakWorker = SpecialPowers.Cu.getWeakReference(w);
+ ok(weakWorker, "worker supports weak reference");
+ w = null;
+ await gc();
+ await gc();
+ ok(!weakWorker.get(), "worker weak reference should be garbage collected");
+ SimpleTest.finish();
+}
+// Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5)
+// Acquire storage access permission here so that the Cache API is avaialable
+SpecialPowers.wrap(document).notifyUserGestureActivation();
+SpecialPowers.addPermission("storageAccessAPI", true, window.location.href).then(() => {
+ SpecialPowers.wrap(document).requestStorageAccess().then(() => {
+ SpecialPowers.pushPrefEnv({
+ set: [["privacy.partition.always_partition_third_party_non_cookie_storage", false]],
+ }).then(() => {
+ test();
+ });
+ });
+});
+</script>
+</body>
+</html>