From b3328eecc8e691dfbd8ba0a4121c49749502d9db Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Thu, 7 Nov 2024 04:37:38 +0000 Subject: [PATCH] Bug 1929548 [wpt PR 49004] - Multiple import maps, a=testonly Automatic update from web-platform-tests Multiple import maps Import maps currently have to load before any ES module and there can only be a single import map per document. That makes them fragile and potentially slow to use in real-life scenarios: Any module that loads before them breaks the entire app, and in apps with many modules the become a large blocking resource, as the entire map for all possible modules needs to load first. This implements https://github.com/whatwg/html/pull/10528 to solve that. Change-Id: I54e1b9cdfe989d61c85d73a5fd384f860273ad9a Bug: 358379381 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5776262 Commit-Queue: Yoav Weiss (@Shopify) Reviewed-by: Kouhei Ueno Cr-Commit-Position: refs/heads/main@{#1378943} -- wpt-commits: 3f26764c67f20c6f5306063fc9bcda13930a51ca wpt-pr: 49004 --- .../import-maps/acquiring/dynamic-import.html | 9 +-- .../acquiring/modulepreload-link-header.html | 8 +- .../import-maps/acquiring/modulepreload.html | 8 +- .../acquiring/script-tag-inline.html | 13 +-- .../import-maps/acquiring/script-tag.html | 8 +- .../already-resolved-dropped.html | 26 ++++++ .../multiple-import-maps/basic.html | 6 +- .../conflict-first-persists.html | 49 +++++++++++ ...ion-consistency-in-module-tree-inline.html | 45 +++++++++++ ...resolution-consistency-in-module-tree.html | 33 ++++++++ .../url-resolution-conflict.html | 32 ++++++++ .../multiple-import-maps/with-errors.html | 8 +- .../import-maps/not-overridden/dynamic.html | 40 +++++++++ .../external-script-bare-descendent.html | 52 ++++++++++++ ...external-script-descendent-with-scope.html | 81 +++++++++++++++++++ .../external-script-descendent.html | 40 +++++++++ .../not-overridden/failed-resolution.html | 60 ++++++++++++++ .../import-maps/not-overridden/integrity.html | 38 +++++++++ .../modulepreload-header.html.headers | 2 + .../import-maps/not-overridden/prefix.html | 40 +++++++++ .../not-overridden/script-descendent.html | 33 ++++++++ .../url-resolution-conflict.html | 28 +++++++ .../import-maps/resources/importer.sub.js | 1 + .../import-maps/resources/in-scope-test.js | 3 + .../tests/import-maps/resources/log.sub.js | 2 + .../import-maps/resources/test-helper.js | 8 ++ .../tests/resources/out-of-scope-test.js | 5 ++ 27 files changed, 637 insertions(+), 41 deletions(-) create mode 100644 testing/web-platform/tests/import-maps/multiple-import-maps/already-resolved-dropped.html create mode 100644 testing/web-platform/tests/import-maps/multiple-import-maps/conflict-first-persists.html create mode 100644 testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html create mode 100644 testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html create mode 100644 testing/web-platform/tests/import-maps/multiple-import-maps/url-resolution-conflict.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/dynamic.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/external-script-bare-descendent.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/external-script-descendent-with-scope.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/external-script-descendent.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/failed-resolution.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/integrity.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/modulepreload-header.html.headers create mode 100644 testing/web-platform/tests/import-maps/not-overridden/prefix.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/script-descendent.html create mode 100644 testing/web-platform/tests/import-maps/not-overridden/url-resolution-conflict.html create mode 100644 testing/web-platform/tests/import-maps/resources/importer.sub.js create mode 100644 testing/web-platform/tests/import-maps/resources/in-scope-test.js create mode 100644 testing/web-platform/tests/import-maps/resources/log.sub.js create mode 100644 testing/web-platform/tests/resources/out-of-scope-test.js diff --git a/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html b/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html index 49d8a701da2e4..2521b2fb7f4de 100644 --- a/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html +++ b/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html @@ -3,8 +3,6 @@ - diff --git a/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html b/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html index dde8cabb9323f..5d3eaabd8f521 100644 --- a/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html +++ b/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html @@ -3,11 +3,9 @@ - diff --git a/testing/web-platform/tests/import-maps/acquiring/modulepreload.html b/testing/web-platform/tests/import-maps/acquiring/modulepreload.html index 68b66a8ae330e..0571c7dcbe4c4 100644 --- a/testing/web-platform/tests/import-maps/acquiring/modulepreload.html +++ b/testing/web-platform/tests/import-maps/acquiring/modulepreload.html @@ -3,12 +3,10 @@ - diff --git a/testing/web-platform/tests/import-maps/acquiring/script-tag-inline.html b/testing/web-platform/tests/import-maps/acquiring/script-tag-inline.html index 683ce83c3a4b3..602ddc41a257b 100644 --- a/testing/web-platform/tests/import-maps/acquiring/script-tag-inline.html +++ b/testing/web-platform/tests/import-maps/acquiring/script-tag-inline.html @@ -3,18 +3,11 @@ - diff --git a/testing/web-platform/tests/import-maps/acquiring/script-tag.html b/testing/web-platform/tests/import-maps/acquiring/script-tag.html index 2792c2a31d971..e03f24dc0afb4 100644 --- a/testing/web-platform/tests/import-maps/acquiring/script-tag.html +++ b/testing/web-platform/tests/import-maps/acquiring/script-tag.html @@ -3,12 +3,10 @@ - diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/already-resolved-dropped.html b/testing/web-platform/tests/import-maps/multiple-import-maps/already-resolved-dropped.html new file mode 100644 index 0000000000000..631af5dc3ce39 --- /dev/null +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/already-resolved-dropped.html @@ -0,0 +1,26 @@ + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/basic.html b/testing/web-platform/tests/import-maps/multiple-import-maps/basic.html index 9ab03ddc302af..1c55e09e79f42 100644 --- a/testing/web-platform/tests/import-maps/multiple-import-maps/basic.html +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/basic.html @@ -22,15 +22,13 @@ } diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/conflict-first-persists.html b/testing/web-platform/tests/import-maps/multiple-import-maps/conflict-first-persists.html new file mode 100644 index 0000000000000..2e197244be55c --- /dev/null +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/conflict-first-persists.html @@ -0,0 +1,49 @@ + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html b/testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html new file mode 100644 index 0000000000000..a248977b90dd9 --- /dev/null +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree-inline.html @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html b/testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html new file mode 100644 index 0000000000000..e0767a6c61056 --- /dev/null +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/resolution-consistency-in-module-tree.html @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/url-resolution-conflict.html b/testing/web-platform/tests/import-maps/multiple-import-maps/url-resolution-conflict.html new file mode 100644 index 0000000000000..e8d06bdf52489 --- /dev/null +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/url-resolution-conflict.html @@ -0,0 +1,32 @@ + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/multiple-import-maps/with-errors.html b/testing/web-platform/tests/import-maps/multiple-import-maps/with-errors.html index a93ecaaeff5b3..3ba9b07359253 100644 --- a/testing/web-platform/tests/import-maps/multiple-import-maps/with-errors.html +++ b/testing/web-platform/tests/import-maps/multiple-import-maps/with-errors.html @@ -18,15 +18,11 @@ } diff --git a/testing/web-platform/tests/import-maps/not-overridden/dynamic.html b/testing/web-platform/tests/import-maps/not-overridden/dynamic.html new file mode 100644 index 0000000000000..dbc839a928c0c --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/dynamic.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/external-script-bare-descendent.html b/testing/web-platform/tests/import-maps/not-overridden/external-script-bare-descendent.html new file mode 100644 index 0000000000000..bff33f8d6abc2 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/external-script-bare-descendent.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/external-script-descendent-with-scope.html b/testing/web-platform/tests/import-maps/not-overridden/external-script-descendent-with-scope.html new file mode 100644 index 0000000000000..9f04548cc2d74 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/external-script-descendent-with-scope.html @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/external-script-descendent.html b/testing/web-platform/tests/import-maps/not-overridden/external-script-descendent.html new file mode 100644 index 0000000000000..122e8204f18fc --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/external-script-descendent.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/failed-resolution.html b/testing/web-platform/tests/import-maps/not-overridden/failed-resolution.html new file mode 100644 index 0000000000000..eae6febddf157 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/failed-resolution.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/integrity.html b/testing/web-platform/tests/import-maps/not-overridden/integrity.html new file mode 100644 index 0000000000000..7770899728706 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/integrity.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/modulepreload-header.html.headers b/testing/web-platform/tests/import-maps/not-overridden/modulepreload-header.html.headers new file mode 100644 index 0000000000000..785378622d4d8 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/modulepreload-header.html.headers @@ -0,0 +1,2 @@ +Link: <../resources/log.js?pipe=sub&name=A>;rel=modulepreload + diff --git a/testing/web-platform/tests/import-maps/not-overridden/prefix.html b/testing/web-platform/tests/import-maps/not-overridden/prefix.html new file mode 100644 index 0000000000000..99449b890e602 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/prefix.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/script-descendent.html b/testing/web-platform/tests/import-maps/not-overridden/script-descendent.html new file mode 100644 index 0000000000000..4d1e08d41298e --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/script-descendent.html @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/not-overridden/url-resolution-conflict.html b/testing/web-platform/tests/import-maps/not-overridden/url-resolution-conflict.html new file mode 100644 index 0000000000000..d070863216439 --- /dev/null +++ b/testing/web-platform/tests/import-maps/not-overridden/url-resolution-conflict.html @@ -0,0 +1,28 @@ + + + + + + + + + + diff --git a/testing/web-platform/tests/import-maps/resources/importer.sub.js b/testing/web-platform/tests/import-maps/resources/importer.sub.js new file mode 100644 index 0000000000000..6b55546d0d9a5 --- /dev/null +++ b/testing/web-platform/tests/import-maps/resources/importer.sub.js @@ -0,0 +1 @@ +import "{{GET[name]}}"; diff --git a/testing/web-platform/tests/import-maps/resources/in-scope-test.js b/testing/web-platform/tests/import-maps/resources/in-scope-test.js new file mode 100644 index 0000000000000..aa64e89514c69 --- /dev/null +++ b/testing/web-platform/tests/import-maps/resources/in-scope-test.js @@ -0,0 +1,3 @@ +// Testing that the resolution is correct using `resolve`, as you can't import +// the same module twice. +window.inscope_test_result = import.meta.resolve("a"); diff --git a/testing/web-platform/tests/import-maps/resources/log.sub.js b/testing/web-platform/tests/import-maps/resources/log.sub.js new file mode 100644 index 0000000000000..3588867d52cc9 --- /dev/null +++ b/testing/web-platform/tests/import-maps/resources/log.sub.js @@ -0,0 +1,2 @@ +log.push("log:{{GET[name]}}"); + diff --git a/testing/web-platform/tests/import-maps/resources/test-helper.js b/testing/web-platform/tests/import-maps/resources/test-helper.js index f12e84c685d54..258d8f4afe93f 100644 --- a/testing/web-platform/tests/import-maps/resources/test-helper.js +++ b/testing/web-platform/tests/import-maps/resources/test-helper.js @@ -244,3 +244,11 @@ function doTests(importMapString, importMapBaseURL, tests) { }); }, { explicit_done: true }); } + +function test_loaded(specifier, expected_log, description) { + promise_test(async t => { + log = []; + await import(specifier); + assert_array_equals(log, expected_log); + }, description); +}; diff --git a/testing/web-platform/tests/resources/out-of-scope-test.js b/testing/web-platform/tests/resources/out-of-scope-test.js new file mode 100644 index 0000000000000..ce24124646dc8 --- /dev/null +++ b/testing/web-platform/tests/resources/out-of-scope-test.js @@ -0,0 +1,5 @@ +// Testing that the resolution is correct using `resolve`, as you can't import +// the same module twice. +window.outscope_test_result = import.meta.resolve("a"); +window.outscope_test_result2 = import.meta.resolve("../resources/log.sub.js?name=E"); +