commit 85ebe91247342b638c5c655eb594e0d5589300c2
parent 4a904c58049c98a11568eeb250d1d10e41509ec6
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Wed, 5 Nov 2025 04:09:48 +0000
Bug 1973221 - Part 2: Add tests. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D271031
Diffstat:
6 files changed, 455 insertions(+), 0 deletions(-)
diff --git a/dom/base/test/browser.toml b/dom/base/test/browser.toml
@@ -164,6 +164,10 @@ support-files = [
"file_js_cache_imported1.mjs",
"file_js_cache_imported2.mjs",
"file_js_cache_imported3.mjs",
+ "file_js_cache_dyn_importer.mjs",
+ "file_js_cache_dyn_imported1.mjs",
+ "file_js_cache_dyn_imported2.mjs",
+ "file_js_cache_dyn_imported3.mjs",
]
["browser_set_focus_after_reuse_bcg.js"]
diff --git a/dom/base/test/browser_script_loader_js_cache.js b/dom/base/test/browser_script_loader_js_cache.js
@@ -2929,3 +2929,377 @@ add_task(async function testMemoryCache_compression() {
await SpecialPowers.popPrefEnv();
});
+
+add_task(async function testDiskCache_dynamicImport() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.expose_test_interfaces", true],
+ ["dom.script_loader.bytecode_cache.enabled", true],
+ ["dom.script_loader.bytecode_cache.strategy", 0],
+ ["dom.script_loader.experimental.navigation_cache", false],
+ ],
+ });
+
+ await runTests([
+ {
+ title: "dynamically imported modules",
+ module: true,
+ items: [
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:register", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:register", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:register", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:register", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_importer.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:diskcache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:diskcache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:diskcache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:diskcache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ ],
+ },
+ ]);
+
+ await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function testMemoryCache_dynamicImport() {
+ if (!AppConstants.NIGHTLY_BUILD) {
+ todo(false, "navigation cache is not yet enabled on non-nightly");
+ return;
+ }
+
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.expose_test_interfaces", true],
+ ["dom.script_loader.bytecode_cache.enabled", true],
+ ["dom.script_loader.bytecode_cache.strategy", 0],
+ ["dom.script_loader.experimental.navigation_cache", true],
+ ],
+ });
+
+ await runTests([
+ {
+ title: "dynamically imported modules",
+ module: true,
+ items: [
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("memorycache:saved", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("memorycache:saved", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("memorycache:saved", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("memorycache:saved", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ unordered([
+ ev("diskcache:saved", "file_js_cache_dyn_importer.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported3.mjs", false),
+ ]),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ ],
+ },
+ ]);
+
+ await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function testDiskCache_dynamicImport() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.expose_test_interfaces", true],
+ ["dom.script_loader.bytecode_cache.enabled", true],
+ ["dom.script_loader.bytecode_cache.strategy", 0],
+ ["dom.script_loader.experimental.navigation_cache", false],
+ ],
+ });
+
+ await runTests([
+ {
+ title: "dynamically imported modules",
+ module: true,
+ items: [
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:register", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:register", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:register", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:register", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_importer.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:diskcache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("diskcache:disabled", "file_js_cache_dyn_importer.mjs"),
+ ev("load:diskcache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:diskcache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:diskcache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:disabled", "file_js_cache_dyn_imported3.mjs", false),
+ ],
+ },
+ ],
+ },
+ ]);
+
+ await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function testMemoryCache_dynamicImport() {
+ if (!AppConstants.NIGHTLY_BUILD) {
+ todo(false, "navigation cache is not yet enabled on non-nightly");
+ return;
+ }
+
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.expose_test_interfaces", true],
+ ["dom.script_loader.bytecode_cache.enabled", true],
+ ["dom.script_loader.bytecode_cache.strategy", 0],
+ ["dom.script_loader.experimental.navigation_cache", true],
+ ],
+ });
+
+ await runTests([
+ {
+ title: "dynamically imported modules",
+ module: true,
+ items: [
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:source", "file_js_cache_dyn_importer.mjs"),
+ ev("memorycache:saved", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:source", "file_js_cache_dyn_imported1.mjs", false),
+ ev("memorycache:saved", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported2.mjs", false),
+ ev("memorycache:saved", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:source", "file_js_cache_dyn_imported3.mjs", false),
+ ev("memorycache:saved", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ unordered([
+ ev("diskcache:saved", "file_js_cache_dyn_importer.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported1.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported2.mjs", false),
+ ev("diskcache:saved", "file_js_cache_dyn_imported3.mjs", false),
+ ]),
+ ],
+ },
+ {
+ file: "file_js_cache_dyn_importer.mjs",
+ events: [
+ ev("load:memorycache", "file_js_cache_dyn_importer.mjs"),
+ ev("evaluate:module", "file_js_cache_dyn_importer.mjs"),
+ ev("load:memorycache", "file_js_cache_dyn_imported1.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported2.mjs", false),
+ ev("load:memorycache", "file_js_cache_dyn_imported3.mjs", false),
+ ev("diskcache:noschedule"),
+ ],
+ },
+ ],
+ },
+ ]);
+
+ await SpecialPowers.popPrefEnv();
+});
diff --git a/dom/base/test/file_js_cache_dyn_imported1.mjs b/dom/base/test/file_js_cache_dyn_imported1.mjs
@@ -0,0 +1,18 @@
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+
+export function func1() {}
diff --git a/dom/base/test/file_js_cache_dyn_imported2.mjs b/dom/base/test/file_js_cache_dyn_imported2.mjs
@@ -0,0 +1,22 @@
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+
+const { func3 } = await import("./file_js_cache_dyn_imported3.mjs");
+
+export function func2() {
+ func3();
+}
diff --git a/dom/base/test/file_js_cache_dyn_imported3.mjs b/dom/base/test/file_js_cache_dyn_imported3.mjs
@@ -0,0 +1,18 @@
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+
+export function func3() {}
diff --git a/dom/base/test/file_js_cache_dyn_importer.mjs b/dom/base/test/file_js_cache_dyn_importer.mjs
@@ -0,0 +1,19 @@
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+// A large comment block to make the file size pass the condition.
+
+const { func1 } = await import("./file_js_cache_dyn_imported1.mjs");
+const { func2 } = await import("./file_js_cache_dyn_imported2.mjs");