Bug 1803984 - Part 3: Add tests for the interaction between speculative preloading and module import maps r=allstarschh

Depends on D178787

Differential Revision: https://phabricator.services.mozilla.com/D178775
This commit is contained in:
Jon Coppeard 2023-06-28 08:43:43 +00:00
parent 71cd073308
commit e291474c06
13 changed files with 100 additions and 0 deletions

View file

@ -0,0 +1 @@
throw "Shouldn't load file bad/module_2.js";

View file

@ -0,0 +1,7 @@
import {} from "../circular_depdendency.js";
export function exportedFunction() {
throw "Wrong version of function called";
}
throw "Shouldn't laod file bad/module_3.js";

View file

@ -12,11 +12,23 @@ support-files =
scope1/module_simpleImportMap.js
scope1/scope2/module_simpleExport.js
scope1/scope2/module_simpleImportMap.js
module_importMap_with_external_script_0.js
module_importMap_with_external_script_1.js
module_importMap_with_external_script_2.js
module_importMap_with_external_script_3.js
bad/module_2.js
bad/module_3.js
good/module_0.js
good/module_1.js
good/module_2.js
good/module_3.js
circular_dependency.js
prefs =
dom.importMaps.enabled=true
[test_dynamic_import_reject_importMap.html]
[test_externalImportMap.html]
[test_importMap_with_external_script.html]
[test_import_meta_resolve_importMap.html]
[test_inline_module_reject_importMap.html]
[test_load_importMap_with_base.html]

View file

@ -0,0 +1,6 @@
// Should be remapped to good/module_3.js.
import { exportedFunction } from "./bad/module_3.js";
if (exportedFunction()) {
success("circular_dependency.js");
}

View file

@ -0,0 +1 @@
success("good/module_0.js");

View file

@ -0,0 +1 @@
success("good/module_1.js");

View file

@ -0,0 +1 @@
success("good/module_2.js");

View file

@ -0,0 +1,5 @@
import {} from "../circular_dependency.js";
export function exportedFunction() {
return true;
}

View file

@ -0,0 +1,2 @@
// Bareword specifier should be mapped to ./good/module_0.js.
import {} from "bare";

View file

@ -0,0 +1,2 @@
// Missing file ./bad/module_1.js should be mapped to ./good/module_1.js.
import {} from "./bad/module_1.js";

View file

@ -0,0 +1,2 @@
// Existing file ./bad/module_2.js should be mapped to ./good/module_2.js.
import {} from "./bad/module_2.js";

View file

@ -0,0 +1,2 @@
// Existing file ./bad/module_3.js should be mapped to ./good/module_3.js.
import {} from "./bad/module_3.js";

View file

@ -0,0 +1,58 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test speculative preload of external script doesn't conflict with import map</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<!--
These tests check that speculative preloading, which could happen before
the import map is installed, doesn't load the wrong modules.
-->
<script type="importmap">
{
"imports": {
"bare": "./good/module_0.js",
"./bad/module_1.js": "./good/module_1.js",
"./bad/module_2.js": "./good/module_2.js",
"./bad/module_3.js": "./good/module_3.js"
}
}
</script>
<!--
Test bareword import (not supported before import map installed).
-->
<script type="module" src="module_importMap_with_external_script_0.js"></script>
<!--
Test mapping from missing resource to existing resource (not found before
import map installed).
-->
<script type="module" src="module_importMap_with_external_script_1.js"></script>
<!--
Test mapping from one existing resource to another (would load wrong resource before
import map installed).
-->
<script type="module" src="module_importMap_with_external_script_2.js"></script>
<!--
Test mapping from one existing resource to another with circular dependency.
-->
<script type="module" src="module_importMap_with_external_script_3.js"></script>
<script>
SimpleTest.waitForExplicitFinish();
let passCount = 0;
const expectedCount = 4;
function success(name) {
ok(true, "Test passed, loaded " + name);
passCount++;
if (passCount == expectedCount) {
SimpleTest.finish();
}
}
</script>
<body></body>