Truly independent web browser
LibWeb: Keep import map specifier maps and scopes sorted
Shannon Boothb0870333adfd
diff --git a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Libraries/LibWeb/HTML/Scripting/Fetching.cppindex e16afeffae6..e8bf3ef5ba2 100644--- a/Libraries/LibWeb/HTML/Scripting/Fetching.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Fetching.cpp@@ -441,12 +441,7 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referriOptional<URL::URL> result;// 10. For each scopePrefix → scopeImports of importMap's scopes:- for (auto const& entry : import_map.scopes()) {- // FIXME: Clarify if the serialization steps need to be run here. The steps below assume- // scopePrefix to be a string.- auto scope_prefix = utf16_string_from_url_ascii(entry.key.serialize());- auto const& scope_imports = entry.value;-+ for (auto const& [scope_prefix, scope_imports] : import_map.scopes()) {// 1. If scopePrefix is serializedBaseURL, or if scopePrefix ends with U+002F (/) and scopePrefix is a code unit prefix of serializedBaseURL, then:if (scope_prefix == serialized_base_url|| (scope_prefix.utf16_view().ends_with('/')diff --git a/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp b/Libraries/LibWeb/HTML/Scripting/ImportMap.cppindex 6eab667bd25..999bf001a85 100644--- a/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp+++ b/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp@@ -57,7 +57,7 @@ WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, Utf16Vi}// 5. Let sortedAndNormalizedScopes be an empty ordered map.- HashMap<URL::URL, ModuleSpecifierMap> sorted_and_normalized_scopes;+ ModuleScopesMap sorted_and_normalized_scopes;// 6. If parsed["scopes"] exists, then:if (TRY(parsed_object.has_property("scopes"_utf16_fly_string))) {@@ -196,14 +196,15 @@ WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(}// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.+ // NB: DescendingCodeUnitOrderedMap keeps normalized in this order.return normalized;}// https://html.spec.whatwg.org/multipage/webappapis.html#sorting-and-normalizing-scopes-WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url)+WebIDL::ExceptionOr<ModuleScopesMap> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url){// 1. Let normalized be an empty ordered map.- HashMap<URL::URL, ModuleSpecifierMap> normalized;+ ModuleScopesMap normalized;// 2. For each scopePrefix → potentialSpecifierMap of originalMap:auto scope_prefixes = TRY(original_map.internal_own_property_keys());@@ -230,11 +231,14 @@ WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_sc}// 4. Let normalizedScopePrefix be the serialization of scopePrefixURL.+ auto normalized_scope_prefix = utf16_string_from_url_ascii(scope_prefix_url->serialize());+// 5. Set normalized[normalizedScopePrefix] to the result of sorting and normalizing a module specifier map given potentialSpecifierMap and baseURL.- normalized.set(scope_prefix_url.value(), TRY(sort_and_normalise_module_specifier_map(realm, potential_specifier_map.as_object(), base_url)));+ normalized.set(move(normalized_scope_prefix), TRY(sort_and_normalise_module_specifier_map(realm, potential_specifier_map.as_object(), base_url)));}// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.+ // NB: DescendingCodeUnitOrderedMap keeps normalized in this order.return normalized;}@@ -304,6 +308,7 @@ static ModuleSpecifierMap merge_module_specifier_maps(JS::Realm& realm, ModuleSp}// 2. Set mergedMap[specifier] to url.+ // AD-HOC: This inserts in sorted order rather than appending, as resolution relies on the order.merged_map.set(specifier, url);}@@ -333,11 +338,10 @@ void merge_existing_and_new_import_maps(Window& global, ImportMap& new_import_ma// 1. For each record of global's resolved module set:for (auto const& record : global.resolved_module_set()) {// 1. If scopePrefix is record's serialized base URL, or if scopePrefix ends with U+002F (/) and scopePrefix is a code unit prefix of record's serialized base URL, then:- auto serialized_scope_prefix = utf16_string_from_url_ascii(scope_prefix.serialize());if (record.serialized_base_url.has_value()- && (serialized_scope_prefix == *record.serialized_base_url- || (serialized_scope_prefix.utf16_view().ends_with('/')- && Infra::is_code_unit_prefix(serialized_scope_prefix.utf16_view(), record.serialized_base_url->utf16_view())))) {+ && (scope_prefix == *record.serialized_base_url+ || (scope_prefix.utf16_view().ends_with('/')+ && Infra::is_code_unit_prefix(scope_prefix.utf16_view(), record.serialized_base_url->utf16_view())))) {// 1. For each specifierKey → resolutionResult of scopeImports:scope_imports.remove_all_matching([&](Utf16String const& specifier_key, Optional<URL::URL> const&) {// 1. If specifierKey is record's specifier, or if all of the following conditions are true:@@ -366,11 +370,12 @@ void merge_existing_and_new_import_maps(Window& global, ImportMap& new_import_ma// 2. If scopePrefix exists in oldImportMap's scopes, then set oldImportMap's scopes[scopePrefix] to the result// of merging module specifier maps, given scopeImports and oldImportMap's scopes[scopePrefix].- if (auto it = old_import_map.scopes().find(scope_prefix); it != old_import_map.scopes().end()) {- it->value = merge_module_specifier_maps(realm, scope_imports, it->value);+ if (auto* old_scope_imports = old_import_map.scopes().find(scope_prefix)) {+ *old_scope_imports = merge_module_specifier_maps(realm, scope_imports, *old_scope_imports);}// 3. Otherwise, set oldImportMap's scopes[scopePrefix] to scopeImports.else {+ // AD-HOC: This inserts in sorted order rather than appending, as resolution relies on the order.old_import_map.scopes().set(scope_prefix, scope_imports);}}diff --git a/Libraries/LibWeb/HTML/Scripting/ImportMap.h b/Libraries/LibWeb/HTML/Scripting/ImportMap.hindex 5238db6d6c2..7b1d5434d44 100644--- a/Libraries/LibWeb/HTML/Scripting/ImportMap.h+++ b/Libraries/LibWeb/HTML/Scripting/ImportMap.h@@ -9,12 +9,83 @@#include <AK/HashMap.h>#include <AK/Utf16String.h>+#include <AK/Vector.h>#include <LibURL/URL.h>#include <LibWeb/WebIDL/ExceptionOr.h>namespace Web::HTML {-using ModuleSpecifierMap = HashMap<Utf16String, Optional<URL::URL>>;+// An ordered map kept sorted in descending code unit order of its keys.+template<typename T>+class DescendingCodeUnitOrderedMap {+public:+ struct Entry {+ Utf16String key;+ T value;+ };++ auto begin() const { return m_entries.begin(); }+ auto end() const { return m_entries.end(); }+ auto begin() { return m_entries.begin(); }+ auto end() { return m_entries.end(); }++ bool contains(Utf16View key) const { return index_of(key).has_value(); }++ T const* find(Utf16View key) const+ {+ auto index = index_of(key);+ return index.has_value() ? &m_entries[*index].value : nullptr;+ }++ T* find(Utf16View key)+ {+ auto index = index_of(key);+ return index.has_value() ? &m_entries[*index].value : nullptr;+ }++ void set(Utf16String key, T value)+ {+ auto index = lower_bound(key);+ if (index < m_entries.size() && m_entries[index].key == key)+ m_entries[index].value = move(value);+ else+ m_entries.insert(index, Entry { move(key), move(value) });+ }++ template<typename Predicate>+ void remove_all_matching(Predicate const& predicate)+ {+ m_entries.remove_all_matching([&](Entry const& entry) { return predicate(entry.key, entry.value); });+ }++private:+ Optional<size_t> index_of(Utf16View key) const+ {+ auto index = lower_bound(key);+ if (index < m_entries.size() && m_entries[index].key == key)+ return index;+ return {};+ }++ size_t lower_bound(Utf16View key) const+ {+ size_t low = 0;+ size_t high = m_entries.size();+ while (low < high) {+ auto middle = low + (high - low) / 2;+ if (key.is_code_unit_less_than(m_entries[middle].key))+ low = middle + 1;+ else+ high = middle;+ }+ return low;+ }++ Vector<Entry> m_entries;+};++using ModuleSpecifierMap = DescendingCodeUnitOrderedMap<Optional<URL::URL>>;+using ModuleScopesMap = DescendingCodeUnitOrderedMap<ModuleSpecifierMap>;using ModuleIntegrityMap = HashMap<URL::URL, Utf16String>;// https://html.spec.whatwg.org/multipage/webappapis.html#import-map@@ -26,9 +97,9 @@ public:ModuleSpecifierMap& imports() { return m_imports; }void set_imports(ModuleSpecifierMap const& imports) { m_imports = imports; }- HashMap<URL::URL, ModuleSpecifierMap> const& scopes() const { return m_scopes; }- HashMap<URL::URL, ModuleSpecifierMap>& scopes() { return m_scopes; }- void set_scopes(HashMap<URL::URL, ModuleSpecifierMap> const& scopes) { m_scopes = scopes; }+ ModuleScopesMap const& scopes() const { return m_scopes; }+ ModuleScopesMap& scopes() { return m_scopes; }+ void set_scopes(ModuleScopesMap const& scopes) { m_scopes = scopes; }ModuleIntegrityMap const& integrity() const { return m_integrity; }ModuleIntegrityMap integrity() { return m_integrity; }@@ -36,14 +107,14 @@ public:private:ModuleSpecifierMap m_imports;- HashMap<URL::URL, ModuleSpecifierMap> m_scopes;+ ModuleScopesMap m_scopes;ModuleIntegrityMap m_integrity;};WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, Utf16View input, URL::URL base_url);Optional<Utf16String> normalize_specifier_key(JS::Realm& realm, Utf16View specifier_key, URL::URL base_url);WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);-WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);+WebIDL::ExceptionOr<ModuleScopesMap> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);WebIDL::ExceptionOr<ModuleIntegrityMap> normalize_module_integrity_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);void merge_existing_and_new_import_maps(Window&, ImportMap&);diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex f32a56084dd..40b0a4c24df 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -1220,6 +1220,7 @@ Text/input/wpt-import/workers/semantics/reporting-errors/001.htmlText/input/wpt-import/workers/semantics/reporting-errors/002.htmlText/input/wpt-import/workers/modules/dedicated-worker-import-failure.htmlText/input/wpt-import/workers/modules/shared-worker-import-failure.html+Text/input/wpt-import/import-maps/data-driven/resolving.html[CapFrameRate]; Ends a smooth scroll once 20 frames see no change, which frames faster than the compositor's ticks dodiff --git a/Tests/LibWeb/Text/expected/HTML/multiple-import-maps-most-specific-wins.txt b/Tests/LibWeb/Text/expected/HTML/multiple-import-maps-most-specific-wins.txtnew file mode 100644index 00000000000..89fc60a3623--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/multiple-import-maps-most-specific-wins.txt@@ -0,0 +1,3 @@+broad/module.js+narrow/module.js+specific/module.jsdiff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..9b7d94cc86b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass Test helper: fetching and sanity checking test JSON: data-url-prefix.json+Pass data: URL prefix: should not resolve since you can't resolve relative to a data: URL: foo/bar\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..b9fb0c40655--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,36 @@+Harness status: OK++Found 31 tests++31 Pass+Pass Test helper: fetching and sanity checking test JSON: empty-import-map.json+Pass valid relative specifiers: ./foo+Pass valid relative specifiers: ./foo/bar+Pass valid relative specifiers: ./foo/../bar+Pass valid relative specifiers: ./foo/../../bar+Pass valid relative specifiers: ../foo+Pass valid relative specifiers: ../foo/bar+Pass valid relative specifiers: ../../../foo/bar+Pass valid relative specifiers: /foo+Pass valid relative specifiers: /foo/bar+Pass valid relative specifiers: /../../foo/bar+Pass valid relative specifiers: /../foo/../bar+Pass HTTPS scheme absolute URLs: https://fetch-scheme.net+Pass HTTPS scheme absolute URLs: https:fetch-scheme.org+Pass HTTPS scheme absolute URLs: https://fetch%2Dscheme.com/+Pass HTTPS scheme absolute URLs: https://///fetch-scheme.com///+Pass valid relative URLs that are invalid as specifiers should fail: invalid-specifier+Pass valid relative URLs that are invalid as specifiers should fail: \invalid-specifier+Pass valid relative URLs that are invalid as specifiers should fail: :invalid-specifier+Pass valid relative URLs that are invalid as specifiers should fail: @invalid-specifier+Pass valid relative URLs that are invalid as specifiers should fail: %2E/invalid-specifier+Pass valid relative URLs that are invalid as specifiers should fail: %2E%2E/invalid-specifier+Pass valid relative URLs that are invalid as specifiers should fail: .%2Finvalid-specifier+Pass invalid absolute URLs should fail: https://invalid-url.com:demo+Pass invalid absolute URLs should fail: http://[invalid-url.com]/+Pass non-HTTPS fetch scheme absolute URLs: about:fetch-scheme+Pass non-fetch scheme absolute URLs: about:fetch-scheme+Pass non-fetch scheme absolute URLs: mailto:non-fetch-scheme+Pass non-fetch scheme absolute URLs: import:non-fetch-scheme+Pass non-fetch scheme absolute URLs: javascript:non-fetch-scheme+Pass non-fetch scheme absolute URLs: wss:non-fetch-scheme\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..2407691f2ba--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,17 @@+Harness status: OK++Found 12 tests++12 Pass+Pass Test helper: fetching and sanity checking test JSON: empty-scopes.json+Pass Scope sorting with multiple empty scopes: Multiple empty scopes before specific scope: Import from foo should use version2: bar+Pass Scope sorting with multiple empty scopes: Multiple empty scopes before specific scope: Import from root bundles should use version1: bar+Pass Scope sorting with multiple empty scopes: Multiple empty scopes before specific scope: Import from asdfasdf should use version1 (empty scope): bar+Pass Scope sorting with multiple empty scopes: Multiple empty scopes before specific scope: Import from qwerqwer should use version1 (empty scope): bar+Pass Scope sorting with multiple empty scopes: Empty scopes after specific scope: Import from foo should use version2 (order independent): bar+Pass Scope sorting with multiple empty scopes: Empty scopes after specific scope: Import from root bundles should use version1: bar+Pass Scope sorting with multiple empty scopes: Single empty scope before specific scope: Import from foo should use version2 (single empty scope): bar+Pass Scope sorting with multiple empty scopes: Deeply nested scopes with empty scopes: Import from a/b/foo should use version2: pkg+Pass Scope sorting with multiple empty scopes: Deeply nested scopes with empty scopes: Import from a/b/ should use version1: pkg+Pass Scope sorting with multiple empty scopes: Many empty scopes with different lengths: Import from packages/foo should use version2: bar+Pass Scope sorting with multiple empty scopes: Many empty scopes with different lengths: Import from packages/ should use version1: bar\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..0918add5455--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,12 @@+Harness status: OK++Found 7 tests++7 Pass+Pass Test helper: fetching and sanity checking test JSON: overlapping-entries.json+Pass should favor the most-specific key: Overlapping entries with trailing slashes: a+Pass should favor the most-specific key: Overlapping entries with trailing slashes: a/+Pass should favor the most-specific key: Overlapping entries with trailing slashes: a/x+Pass should favor the most-specific key: Overlapping entries with trailing slashes: a/b+Pass should favor the most-specific key: Overlapping entries with trailing slashes: a/b/+Pass should favor the most-specific key: Overlapping entries with trailing slashes: a/b/c\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..4eccfe8de59--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,38 @@+Harness status: OK++Found 33 tests++33 Pass+Pass Test helper: fetching and sanity checking test JSON: packages-via-trailing-slashes.json+Pass Package-like scenarios: package main modules: moment+Pass Package-like scenarios: package main modules: lodash-dot+Pass Package-like scenarios: package main modules: lodash-dotdot+Pass Package-like scenarios: package submodules: moment/foo+Pass Package-like scenarios: package submodules: moment/foo?query+Pass Package-like scenarios: package submodules: moment/foo#fragment+Pass Package-like scenarios: package submodules: moment/foo?query#fragment+Pass Package-like scenarios: package submodules: lodash-dot/foo+Pass Package-like scenarios: package submodules: lodash-dotdot/foo+Pass Package-like scenarios: package names that end in a slash should just pass through: moment/+Pass Package-like scenarios: package modules that are not declared should fail: underscore/+Pass Package-like scenarios: package modules that are not declared should fail: underscore/foo+Pass Package-like scenarios: backtracking via ..: mapped/path+Pass Package-like scenarios: backtracking via ..: mapped/path/+Pass Package-like scenarios: backtracking via ..: mapped/path/..+Pass Package-like scenarios: backtracking via ..: mapped/path/../path/+Pass Package-like scenarios: backtracking via ..: mapped/path/../207+Pass Package-like scenarios: backtracking via ..: mapped/path/../207/+Pass Package-like scenarios: backtracking via ..: mapped/path//+Pass Package-like scenarios: backtracking via ..: mapped/path/WICG/import-maps/issues/207/+Pass Package-like scenarios: backtracking via ..: mapped/path//WICG/import-maps/issues/207/+Pass Package-like scenarios: backtracking via ..: mapped/path/../backtrack+Pass Package-like scenarios: backtracking via ..: mapped/path/../../backtrack+Pass Package-like scenarios: backtracking via ..: mapped/path/../../../backtrack+Pass Package-like scenarios: backtracking via ..: moment/../backtrack+Pass Package-like scenarios: backtracking via ..: moment/..+Pass Package-like scenarios: backtracking via ..: mapped/non-ascii-1/+Pass Package-like scenarios: backtracking via ..: mapped/non-ascii-1/../%E3%81%8D%E3%81%A4%E3%81%AD/+Pass Package-like scenarios: backtracking via ..: mapped/non-ascii-1/../きつね/+Pass Package-like scenarios: backtracking via ..: mapped/non-ascii-2/+Pass Package-like scenarios: backtracking via ..: mapped/non-ascii-2/../%E3%81%8D%E3%81%A4%E3%81%AD/+Pass Package-like scenarios: backtracking via ..: mapped/non-ascii-2/../きつね/\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..2135acefc3b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,26 @@+Harness status: OK++Found 21 tests++21 Pass+Pass Test helper: fetching and sanity checking test JSON: resolving-null.json+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: null/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: null/b/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: null/b/c/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: invalid-url/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: invalid-url/b/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: invalid-url/b/c/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: without-trailing-slashes/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: without-trailing-slashes/b/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: without-trailing-slashes/b/c/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: prefix-resolution-error/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: prefix-resolution-error/b/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific prefixes: prefix-resolution-error/b/c/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific scopes: null+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific scopes: invalid-url+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific scopes: without-trailing-slashes/x+Pass Entries with errors shouldn't allow fallback: No fallback to less-specific scopes: prefix-resolution-error/x+Pass Entries with errors shouldn't allow fallback: No fallback to absolute URL parsing: https://example.com/null+Pass Entries with errors shouldn't allow fallback: No fallback to absolute URL parsing: https://example.com/invalid-url+Pass Entries with errors shouldn't allow fallback: No fallback to absolute URL parsing: https://example.com/without-trailing-slashes/x+Pass Entries with errors shouldn't allow fallback: No fallback to absolute URL parsing: https://example.com/prefix-resolution-error/x\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..f419b256960--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,30 @@+Harness status: OK++Found 25 tests++25 Pass+Pass Test helper: fetching and sanity checking test JSON: scopes-exact-vs-prefix.json+Pass Exact vs. prefix based matching: Scope without trailing slash only: Non-trailing-slash base URL (exact match): moment+Pass Exact vs. prefix based matching: Scope without trailing slash only: Non-trailing-slash base URL (exact match): moment/foo+Pass Exact vs. prefix based matching: Scope without trailing slash only: Trailing-slash base URL (fail): moment+Pass Exact vs. prefix based matching: Scope without trailing slash only: Trailing-slash base URL (fail): moment/foo+Pass Exact vs. prefix based matching: Scope without trailing slash only: Subpath base URL (fail): moment+Pass Exact vs. prefix based matching: Scope without trailing slash only: Subpath base URL (fail): moment/foo+Pass Exact vs. prefix based matching: Scope without trailing slash only: Non-subpath base URL (fail): moment+Pass Exact vs. prefix based matching: Scope without trailing slash only: Non-subpath base URL (fail): moment/foo+Pass Exact vs. prefix based matching: Scope with trailing slash only: Non-trailing-slash base URL (fail): moment+Pass Exact vs. prefix based matching: Scope with trailing slash only: Non-trailing-slash base URL (fail): moment/foo+Pass Exact vs. prefix based matching: Scope with trailing slash only: Trailing-slash base URL (exact match): moment+Pass Exact vs. prefix based matching: Scope with trailing slash only: Trailing-slash base URL (exact match): moment/foo+Pass Exact vs. prefix based matching: Scope with trailing slash only: Subpath base URL (prefix match): moment+Pass Exact vs. prefix based matching: Scope with trailing slash only: Subpath base URL (prefix match): moment/foo+Pass Exact vs. prefix based matching: Scope with trailing slash only: Non-subpath base URL (fail): moment+Pass Exact vs. prefix based matching: Scope with trailing slash only: Non-subpath base URL (fail): moment/foo+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Non-trailing-slash base URL (exact match): moment+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Non-trailing-slash base URL (exact match): moment/foo+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Trailing-slash base URL (exact match): moment+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Trailing-slash base URL (exact match): moment/foo+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Subpath base URL (prefix match): moment+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Subpath base URL (prefix match): moment/foo+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Non-subpath base URL (fail): moment+Pass Exact vs. prefix based matching: Scopes with and without trailing slash: Non-subpath base URL (fail): moment/foo\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..84d7543e3ac--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,42 @@+Harness status: OK++Found 37 tests++37 Pass+Pass Test helper: fetching and sanity checking test JSON: scopes.json+Pass Fallback to toplevel and between scopes: should fall back to `imports` when no scopes match: a+Pass Fallback to toplevel and between scopes: should fall back to `imports` when no scopes match: b+Pass Fallback to toplevel and between scopes: should fall back to `imports` when no scopes match: c+Pass Fallback to toplevel and between scopes: should fall back to `imports` when no scopes match: d+Pass Fallback to toplevel and between scopes: should use a direct scope override: a+Pass Fallback to toplevel and between scopes: should use a direct scope override: b+Pass Fallback to toplevel and between scopes: should use a direct scope override: c+Pass Fallback to toplevel and between scopes: should use a direct scope override: d+Pass Fallback to toplevel and between scopes: should use an indirect scope override: a+Pass Fallback to toplevel and between scopes: should use an indirect scope override: b+Pass Fallback to toplevel and between scopes: should use an indirect scope override: c+Pass Fallback to toplevel and between scopes: should use an indirect scope override: d+Pass Relative URL scope keys: An empty string scope is a scope with import map base URL: a+Pass Relative URL scope keys: An empty string scope is a scope with import map base URL: b+Pass Relative URL scope keys: An empty string scope is a scope with import map base URL: c+Pass Relative URL scope keys: './' scope is a scope with import map base URL's directory: a+Pass Relative URL scope keys: './' scope is a scope with import map base URL's directory: b+Pass Relative URL scope keys: './' scope is a scope with import map base URL's directory: c+Pass Relative URL scope keys: '../' scope is a scope with import map base URL's parent directory: a+Pass Relative URL scope keys: '../' scope is a scope with import map base URL's parent directory: b+Pass Relative URL scope keys: '../' scope is a scope with import map base URL's parent directory: c+Pass Package-like scenarios: Base URLs inside the scope should use the scope if the scope has matching keys: lodash-dot+Pass Package-like scenarios: Base URLs inside the scope should use the scope if the scope has matching keys: lodash-dot/foo+Pass Package-like scenarios: Base URLs inside the scope should use the scope if the scope has matching keys: lodash-dotdot+Pass Package-like scenarios: Base URLs inside the scope should use the scope if the scope has matching keys: lodash-dotdot/foo+Pass Package-like scenarios: Base URLs inside the scope fallback to less specific scope: moment+Pass Package-like scenarios: Base URLs inside the scope fallback to less specific scope: vue+Pass Package-like scenarios: Base URLs inside the scope fallback to toplevel: moment/foo+Pass Package-like scenarios: Base URLs outside a scope shouldn't use the scope even if the scope has matching keys: lodash-dot+Pass Package-like scenarios: Base URLs outside a scope shouldn't use the scope even if the scope has matching keys: lodash-dotdot+Pass Package-like scenarios: Base URLs outside a scope shouldn't use the scope even if the scope has matching keys: lodash-dot/foo+Pass Package-like scenarios: Base URLs outside a scope shouldn't use the scope even if the scope has matching keys: lodash-dotdot/foo+Pass Package-like scenarios: Fallback to toplevel or not, depending on trailing slash match: moment+Pass Package-like scenarios: Fallback to toplevel or not, depending on trailing slash match: moment/foo+Pass Package-like scenarios: should still fail for package-like specifiers that are not declared: underscore/+Pass Package-like scenarios: should still fail for package-like specifiers that are not declared: underscore/foo\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..c0c81ee6088--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,30 @@+Harness status: OK++Found 25 tests++25 Pass+Pass Test helper: fetching and sanity checking test JSON: tricky-specifiers.json+Pass Tricky specifiers: explicitly-mapped specifiers that happen to have a slash: package/withslash+Pass Tricky specifiers: specifier with punctuation: .+Pass Tricky specifiers: specifier with punctuation: ..+Pass Tricky specifiers: specifier with punctuation: ..\+Pass Tricky specifiers: specifier with punctuation: %2E+Pass Tricky specifiers: specifier with punctuation: %2F+Pass Tricky specifiers: submodule of something not declared with a trailing slash should fail: not-a-package/foo+Pass Tricky specifiers: module for which only a trailing-slash version is present should fail: only-slash+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/bar+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/fox/+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/fox/bar+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/きつね/+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/きつね/bar+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/きつね/fox/+Pass Tricky specifiers: URL-like specifiers are normalized: https://map.example/きつね/fox/bar+Pass Tricky specifiers: Bare specifiers are not normalized: %E3%81%8D%E3%81%A4%E3%81%AD/+Pass Tricky specifiers: Bare specifiers are not normalized: %E3%81%8D%E3%81%A4%E3%81%AD/bar+Pass Tricky specifiers: Bare specifiers are not normalized: %E3%81%8D%E3%81%A4%E3%81%AD/fox/+Pass Tricky specifiers: Bare specifiers are not normalized: %E3%81%8D%E3%81%A4%E3%81%AD/fox/bar+Pass Tricky specifiers: Bare specifiers are not normalized: きつね/+Pass Tricky specifiers: Bare specifiers are not normalized: きつね/bar+Pass Tricky specifiers: Bare specifiers are not normalized: きつね/fox/+Pass Tricky specifiers: Bare specifiers are not normalized: きつね/fox/bar\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..34eb3e8ddd0--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,26 @@+Harness status: OK++Found 21 tests++21 Pass+Pass Test helper: fetching and sanity checking test JSON: url-specifiers-schemes.json+Pass URL-like specifiers: Non-special vs. special schemes: data:text/javascript,console.log('foo')+Pass URL-like specifiers: Non-special vs. special schemes: data:text/+Pass URL-like specifiers: Non-special vs. special schemes: about:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: about:text/+Pass URL-like specifiers: Non-special vs. special schemes: blob:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: blob:text/+Pass URL-like specifiers: Non-special vs. special schemes: blah:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: blah:text/+Pass URL-like specifiers: Non-special vs. special schemes: http:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: http:text/+Pass URL-like specifiers: Non-special vs. special schemes: https:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: https:text/+Pass URL-like specifiers: Non-special vs. special schemes: ftp:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: ftp:text/+Pass URL-like specifiers: Non-special vs. special schemes: file:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: file:text/+Pass URL-like specifiers: Non-special vs. special schemes: ws:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: ws:text/+Pass URL-like specifiers: Non-special vs. special schemes: wss:text/foo+Pass URL-like specifiers: Non-special vs. special schemes: wss:text/\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]new file mode 100644index 00000000000..0cf9dea3b81--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/import-maps/data-driven/[email protected]@@ -0,0 +1,30 @@+Harness status: OK++Found 25 tests++25 Pass+Pass Test helper: fetching and sanity checking test JSON: url-specifiers.json+Pass URL-like specifiers: Ordinary URL-like specifiers: https://example.com/lib/foo.mjs+Pass URL-like specifiers: Ordinary URL-like specifiers: https://///example.com/lib/foo.mjs+Pass URL-like specifiers: Ordinary URL-like specifiers: /lib/foo.mjs+Pass URL-like specifiers: Ordinary URL-like specifiers: https://example.com/app/dotrelative/foo.mjs+Pass URL-like specifiers: Ordinary URL-like specifiers: ../app/dotrelative/foo.mjs+Pass URL-like specifiers: Ordinary URL-like specifiers: https://example.com/dotdotrelative/foo.mjs+Pass URL-like specifiers: Ordinary URL-like specifiers: ../dotdotrelative/foo.mjs+Pass URL-like specifiers: Import map entries just composed from / and .: https://example.com/+Pass URL-like specifiers: Import map entries just composed from / and .: /+Pass URL-like specifiers: Import map entries just composed from / and .: ../+Pass URL-like specifiers: Import map entries just composed from / and .: https://example.com/app/+Pass URL-like specifiers: Import map entries just composed from / and .: /app/+Pass URL-like specifiers: Import map entries just composed from / and .: ../app/+Pass URL-like specifiers: prefix-matched by keys with trailing slashes: /test/foo.mjs+Pass URL-like specifiers: prefix-matched by keys with trailing slashes: https://example.com/app/test/foo.mjs+Pass URL-like specifiers: should use the last entry's address when URL-like specifiers parse to the same absolute URL: /test+Pass URL-like specifiers: backtracking (relative URLs): /test/..+Pass URL-like specifiers: backtracking (relative URLs): /test/../backtrack+Pass URL-like specifiers: backtracking (relative URLs): /test/../../backtrack+Pass URL-like specifiers: backtracking (relative URLs): /test/../../../backtrack+Pass URL-like specifiers: backtracking (absolute URLs): https://example.com/test/..+Pass URL-like specifiers: backtracking (absolute URLs): https://example.com/test/../backtrack+Pass URL-like specifiers: backtracking (absolute URLs): https://example.com/test/../../backtrack+Pass URL-like specifiers: backtracking (absolute URLs): https://example.com/test/../../../backtrack\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/HTML/multiple-import-maps-most-specific-wins.html b/Tests/LibWeb/Text/input/HTML/multiple-import-maps-most-specific-wins.htmlnew file mode 100644index 00000000000..b3af3411ac4--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/multiple-import-maps-most-specific-wins.html@@ -0,0 +1,37 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script type="importmap">+ {+ "imports": {+ "pkg/": "./broad/"+ },+ "scopes": {+ "./": {+ "scoped/": "./general/"+ }+ }+ }+</script>+<script type="importmap">+ {+ "imports": {+ "pkg/narrow/": "./narrow/"+ },+ "scopes": {+ "./multiple-import-maps-most-specific-wins.html": {+ "scoped/": "./specific/"+ }+ }+ }+</script>+<script type="module">+ function resolved(specifier) {+ return new URL(import.meta.resolve(specifier)).pathname.split("/").slice(-2).join("/");+ }++ test(() => {+ println(resolved("pkg/module.js"));+ println(resolved("pkg/narrow/module.js"));+ println(resolved("scoped/module.js"));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resolving.html b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resolving.htmlnew file mode 100644index 00000000000..32cc6965057--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resolving.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<meta name="variant" content="?data-url-prefix.json">+<meta name="variant" content="?empty-import-map.json">+<meta name="variant" content="?overlapping-entries.json">+<meta name="variant" content="?packages-via-trailing-slashes.json">+<meta name="variant" content="?resolving-null.json">+<meta name="variant" content="?empty-scopes.json">+<meta name="variant" content="?scopes-exact-vs-prefix.json">+<meta name="variant" content="?scopes.json">+<meta name="variant" content="?tricky-specifiers.json">+<meta name="variant" content="?url-specifiers-schemes.json">+<meta name="variant" content="?url-specifiers.json">++<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<body>+<script type="module">+import { runTestsFromJSON } from "./resources/test-helper.js";++const filename = location.search.substring(1);+promise_test(+ () => runTestsFromJSON('resources/' + filename),+ "Test helper: fetching and sanity checking test JSON: " + filename);+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/data-url-prefix.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/data-url-prefix.jsonnew file mode 100644index 00000000000..980f6e005f6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/data-url-prefix.json@@ -0,0 +1,17 @@+{+ "importMap": {+ "imports": {+ "foo/": "data:text/javascript,foo/"+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "data: URL prefix",+ "tests": {+ "should not resolve since you can't resolve relative to a data: URL": {+ "expectedResults": {+ "foo/bar": null+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/empty-import-map.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/empty-import-map.jsonnew file mode 100644index 00000000000..f488759aa4a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/empty-import-map.json@@ -0,0 +1,61 @@+{+ "importMap": {},+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "tests": {+ "valid relative specifiers": {+ "expectedResults": {+ "./foo": "https://example.com/js/foo",+ "./foo/bar": "https://example.com/js/foo/bar",+ "./foo/../bar": "https://example.com/js/bar",+ "./foo/../../bar": "https://example.com/bar",+ "../foo": "https://example.com/foo",+ "../foo/bar": "https://example.com/foo/bar",+ "../../../foo/bar": "https://example.com/foo/bar",+ "/foo": "https://example.com/foo",+ "/foo/bar": "https://example.com/foo/bar",+ "/../../foo/bar": "https://example.com/foo/bar",+ "/../foo/../bar": "https://example.com/bar"+ }+ },+ "HTTPS scheme absolute URLs": {+ "expectedResults": {+ "https://fetch-scheme.net": "https://fetch-scheme.net/",+ "https:fetch-scheme.org": "https://fetch-scheme.org/",+ "https://fetch%2Dscheme.com/": "https://fetch-scheme.com/",+ "https://///fetch-scheme.com///": "https://fetch-scheme.com///"+ }+ },+ "valid relative URLs that are invalid as specifiers should fail": {+ "expectedResults": {+ "invalid-specifier": null,+ "\\invalid-specifier": null,+ ":invalid-specifier": null,+ "@invalid-specifier": null,+ "%2E/invalid-specifier": null,+ "%2E%2E/invalid-specifier": null,+ ".%2Finvalid-specifier": null+ }+ },+ "invalid absolute URLs should fail": {+ "expectedResults": {+ "https://invalid-url.com:demo": null,+ "http://[invalid-url.com]/": null+ }+ },+ "non-HTTPS fetch scheme absolute URLs": {+ "expectedResults": {+ "about:fetch-scheme": "about:fetch-scheme"+ }+ },+ "non-fetch scheme absolute URLs": {+ "expectedResults": {+ "about:fetch-scheme": "about:fetch-scheme",+ "mailto:non-fetch-scheme": "mailto:non-fetch-scheme",+ "import:non-fetch-scheme": "import:non-fetch-scheme",+ "javascript:non-fetch-scheme": "javascript:non-fetch-scheme",+ "wss:non-fetch-scheme": "wss://non-fetch-scheme/"+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/empty-scopes.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/empty-scopes.jsonnew file mode 100644index 00000000000..259471ad04d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/empty-scopes.json@@ -0,0 +1,160 @@+{+ "name": "Scope sorting with multiple empty scopes",+ "details": "Tests that empty scopes don't interfere with scope resolution priority. This reproduces a bug where having multiple empty scope entries before a more specific scope causes the wrong scope to be selected.",+ "link": "https://github.com/astegmaier/playground-import-maps",+ "tests": {+ "Multiple empty scopes before specific scope": {+ "importMap": {+ "scopes": {+ "./__bundles__/asdfasdf/": {},+ "./__bundles__/qwerqwer/": {},+ "./__bundles__/foo/": {+ "bar": "./__bundles__/bar/version2/index.js"+ },+ "./__bundles__/": {+ "bar": "./__bundles__/bar/version1/index.js"+ }+ }+ },+ "importMapBaseURL": "https://example.com/",+ "tests": {+ "Import from foo should use version2": {+ "baseURL": "https://example.com/__bundles__/foo/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version2/index.js"+ }+ },+ "Import from root bundles should use version1": {+ "baseURL": "https://example.com/__bundles__/other/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version1/index.js"+ }+ },+ "Import from asdfasdf should use version1 (empty scope)": {+ "baseURL": "https://example.com/__bundles__/asdfasdf/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version1/index.js"+ }+ },+ "Import from qwerqwer should use version1 (empty scope)": {+ "baseURL": "https://example.com/__bundles__/qwerqwer/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version1/index.js"+ }+ }+ }+ },+ "Empty scopes after specific scope": {+ "importMap": {+ "scopes": {+ "./__bundles__/foo/": {+ "bar": "./__bundles__/bar/version2/index.js"+ },+ "./__bundles__/": {+ "bar": "./__bundles__/bar/version1/index.js"+ },+ "./__bundles__/asdfasdf/": {},+ "./__bundles__/qwerqwer/": {}+ }+ },+ "importMapBaseURL": "https://example.com/",+ "tests": {+ "Import from foo should use version2 (order independent)": {+ "baseURL": "https://example.com/__bundles__/foo/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version2/index.js"+ }+ },+ "Import from root bundles should use version1": {+ "baseURL": "https://example.com/__bundles__/other/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version1/index.js"+ }+ }+ }+ },+ "Single empty scope before specific scope": {+ "importMap": {+ "scopes": {+ "./__bundles__/asdfasdf/": {},+ "./__bundles__/foo/": {+ "bar": "./__bundles__/bar/version2/index.js"+ },+ "./__bundles__/": {+ "bar": "./__bundles__/bar/version1/index.js"+ }+ }+ },+ "importMapBaseURL": "https://example.com/",+ "tests": {+ "Import from foo should use version2 (single empty scope)": {+ "baseURL": "https://example.com/__bundles__/foo/index.js",+ "expectedResults": {+ "bar": "https://example.com/__bundles__/bar/version2/index.js"+ }+ }+ }+ },+ "Deeply nested scopes with empty scopes": {+ "importMap": {+ "scopes": {+ "./a/b/c/d/": {},+ "./a/b/c/e/": {},+ "./a/b/foo/": {+ "pkg": "./resolved/version2.js"+ },+ "./a/b/": {+ "pkg": "./resolved/version1.js"+ }+ }+ },+ "importMapBaseURL": "https://example.com/",+ "tests": {+ "Import from a/b/foo should use version2": {+ "baseURL": "https://example.com/a/b/foo/index.js",+ "expectedResults": {+ "pkg": "https://example.com/resolved/version2.js"+ }+ },+ "Import from a/b/ should use version1": {+ "baseURL": "https://example.com/a/b/other.js",+ "expectedResults": {+ "pkg": "https://example.com/resolved/version1.js"+ }+ }+ }+ },+ "Many empty scopes with different lengths": {+ "importMap": {+ "scopes": {+ "./x/": {},+ "./xy/": {},+ "./xyz/": {},+ "./xyzw/": {},+ "./xyzwv/": {},+ "./packages/foo/": {+ "bar": "./bar/version2.js"+ },+ "./packages/": {+ "bar": "./bar/version1.js"+ }+ }+ },+ "importMapBaseURL": "https://example.com/",+ "tests": {+ "Import from packages/foo should use version2": {+ "baseURL": "https://example.com/packages/foo/index.js",+ "expectedResults": {+ "bar": "https://example.com/bar/version2.js"+ }+ },+ "Import from packages/ should use version1": {+ "baseURL": "https://example.com/packages/other.js",+ "expectedResults": {+ "bar": "https://example.com/bar/version1.js"+ }+ }+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/overlapping-entries.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/overlapping-entries.jsonnew file mode 100644index 00000000000..21354025451--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/overlapping-entries.json@@ -0,0 +1,25 @@+{+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "should favor the most-specific key",+ "tests": {+ "Overlapping entries with trailing slashes": {+ "importMap": {+ "imports": {+ "a": "/1",+ "a/": "/2/",+ "a/b": "/3",+ "a/b/": "/4/"+ }+ },+ "expectedResults": {+ "a": "https://example.com/1",+ "a/": "https://example.com/2/",+ "a/x": "https://example.com/2/x",+ "a/b": "https://example.com/3",+ "a/b/": "https://example.com/4/",+ "a/b/c": "https://example.com/4/c"+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/packages-via-trailing-slashes.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/packages-via-trailing-slashes.jsonnew file mode 100644index 00000000000..03959fafd21--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/packages-via-trailing-slashes.json@@ -0,0 +1,74 @@+{+ "importMap": {+ "imports": {+ "moment": "/node_modules/moment/src/moment.js",+ "moment/": "/node_modules/moment/src/",+ "lodash-dot": "./node_modules/lodash-es/lodash.js",+ "lodash-dot/": "./node_modules/lodash-es/",+ "lodash-dotdot": "../node_modules/lodash-es/lodash.js",+ "lodash-dotdot/": "../node_modules/lodash-es/",+ "mapped/": "https://example.com/",+ "mapped/path/": "https://github.com/WICG/import-maps/issues/207/",+ "mapped/non-ascii-1/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/",+ "mapped/non-ascii-2/": "https://example.com/きつね/"+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "Package-like scenarios",+ "link": "https://github.com/WICG/import-maps#packages-via-trailing-slashes",+ "tests": {+ "package main modules": {+ "expectedResults": {+ "moment": "https://example.com/node_modules/moment/src/moment.js",+ "lodash-dot": "https://example.com/app/node_modules/lodash-es/lodash.js",+ "lodash-dotdot": "https://example.com/node_modules/lodash-es/lodash.js"+ }+ },+ "package submodules": {+ "expectedResults": {+ "moment/foo": "https://example.com/node_modules/moment/src/foo",+ "moment/foo?query": "https://example.com/node_modules/moment/src/foo?query",+ "moment/foo#fragment": "https://example.com/node_modules/moment/src/foo#fragment",+ "moment/foo?query#fragment": "https://example.com/node_modules/moment/src/foo?query#fragment",+ "lodash-dot/foo": "https://example.com/app/node_modules/lodash-es/foo",+ "lodash-dotdot/foo": "https://example.com/node_modules/lodash-es/foo"+ }+ },+ "package names that end in a slash should just pass through": {+ "expectedResults": {+ "moment/": "https://example.com/node_modules/moment/src/"+ }+ },+ "package modules that are not declared should fail": {+ "expectedResults": {+ "underscore/": null,+ "underscore/foo": null+ }+ },+ "backtracking via ..": {+ "expectedResults": {+ "mapped/path": "https://example.com/path",+ "mapped/path/": "https://github.com/WICG/import-maps/issues/207/",+ "mapped/path/..": null,+ "mapped/path/../path/": null,+ "mapped/path/../207": null,+ "mapped/path/../207/": "https://github.com/WICG/import-maps/issues/207/",+ "mapped/path//": null,+ "mapped/path/WICG/import-maps/issues/207/": "https://github.com/WICG/import-maps/issues/207/WICG/import-maps/issues/207/",+ "mapped/path//WICG/import-maps/issues/207/": "https://github.com/WICG/import-maps/issues/207/",+ "mapped/path/../backtrack": null,+ "mapped/path/../../backtrack": null,+ "mapped/path/../../../backtrack": null,+ "moment/../backtrack": null,+ "moment/..": null,+ "mapped/non-ascii-1/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/",+ "mapped/non-ascii-1/../%E3%81%8D%E3%81%A4%E3%81%AD/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/",+ "mapped/non-ascii-1/../きつね/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/",+ "mapped/non-ascii-2/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/",+ "mapped/non-ascii-2/../%E3%81%8D%E3%81%A4%E3%81%AD/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/",+ "mapped/non-ascii-2/../きつね/": "https://example.com/%E3%81%8D%E3%81%A4%E3%81%AD/"+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/resolving-null.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/resolving-null.jsonnew file mode 100644index 00000000000..77563155d11--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/resolving-null.json@@ -0,0 +1,82 @@+{+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "Entries with errors shouldn't allow fallback",+ "tests": {+ "No fallback to less-specific prefixes": {+ "importMap": {+ "imports": {+ "null/": "/1/",+ "null/b/": null,+ "null/b/c/": "/1/2/",+ "invalid-url/": "/1/",+ "invalid-url/b/": "https://:invalid-url:/",+ "invalid-url/b/c/": "/1/2/",+ "without-trailing-slashes/": "/1/",+ "without-trailing-slashes/b/": "/x",+ "without-trailing-slashes/b/c/": "/1/2/",+ "prefix-resolution-error/": "/1/",+ "prefix-resolution-error/b/": "data:text/javascript,/",+ "prefix-resolution-error/b/c/": "/1/2/"+ }+ },+ "expectedResults": {+ "null/x": "https://example.com/1/x",+ "null/b/x": null,+ "null/b/c/x": "https://example.com/1/2/x",+ "invalid-url/x": "https://example.com/1/x",+ "invalid-url/b/x": null,+ "invalid-url/b/c/x": "https://example.com/1/2/x",+ "without-trailing-slashes/x": "https://example.com/1/x",+ "without-trailing-slashes/b/x": null,+ "without-trailing-slashes/b/c/x": "https://example.com/1/2/x",+ "prefix-resolution-error/x": "https://example.com/1/x",+ "prefix-resolution-error/b/x": null,+ "prefix-resolution-error/b/c/x": "https://example.com/1/2/x"+ }+ },+ "No fallback to less-specific scopes": {+ "importMap": {+ "imports": {+ "null": "https://example.com/a",+ "invalid-url": "https://example.com/b",+ "without-trailing-slashes/": "https://example.com/c/",+ "prefix-resolution-error/": "https://example.com/d/"+ },+ "scopes": {+ "/js/": {+ "null": null,+ "invalid-url": "https://:invalid-url:/",+ "without-trailing-slashes/": "/x",+ "prefix-resolution-error/": "data:text/javascript,/"+ }+ }+ },+ "expectedResults": {+ "null": null,+ "invalid-url": null,+ "without-trailing-slashes/x": null,+ "prefix-resolution-error/x": null+ }+ },+ "No fallback to absolute URL parsing": {+ "importMap": {+ "imports": {},+ "scopes": {+ "/js/": {+ "https://example.com/null": null,+ "https://example.com/invalid-url": "https://:invalid-url:/",+ "https://example.com/without-trailing-slashes/": "/x",+ "https://example.com/prefix-resolution-error/": "data:text/javascript,/"+ }+ }+ },+ "expectedResults": {+ "https://example.com/null": null,+ "https://example.com/invalid-url": null,+ "https://example.com/without-trailing-slashes/x": null,+ "https://example.com/prefix-resolution-error/x": null+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/scopes-exact-vs-prefix.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/scopes-exact-vs-prefix.jsonnew file mode 100644index 00000000000..3d9d50349f0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/scopes-exact-vs-prefix.json@@ -0,0 +1,134 @@+{+ "name": "Exact vs. prefix based matching",+ "details": "Scopes are matched with base URLs that are exactly the same or subpaths under the scopes with trailing shashes",+ "link": "https://wicg.github.io/import-maps/#resolve-a-module-specifier Step 8.1",+ "tests": {+ "Scope without trailing slash only": {+ "importMap": {+ "scopes": {+ "/js": {+ "moment": "/only-triggered-by-exact/moment",+ "moment/": "/only-triggered-by-exact/moment/"+ }+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "tests": {+ "Non-trailing-slash base URL (exact match)": {+ "baseURL": "https://example.com/js",+ "expectedResults": {+ "moment": "https://example.com/only-triggered-by-exact/moment",+ "moment/foo": "https://example.com/only-triggered-by-exact/moment/foo"+ }+ },+ "Trailing-slash base URL (fail)": {+ "baseURL": "https://example.com/js/",+ "expectedResults": {+ "moment": null,+ "moment/foo": null+ }+ },+ "Subpath base URL (fail)": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "moment": null,+ "moment/foo": null+ }+ },+ "Non-subpath base URL (fail)": {+ "baseURL": "https://example.com/jsiscool",+ "expectedResults": {+ "moment": null,+ "moment/foo": null+ }+ }+ }+ },+ "Scope with trailing slash only": {+ "importMap": {+ "scopes": {+ "/js/": {+ "moment": "/triggered-by-any-subpath/moment",+ "moment/": "/triggered-by-any-subpath/moment/"+ }+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "tests": {+ "Non-trailing-slash base URL (fail)": {+ "baseURL": "https://example.com/js",+ "expectedResults": {+ "moment": null,+ "moment/foo": null+ }+ },+ "Trailing-slash base URL (exact match)": {+ "baseURL": "https://example.com/js/",+ "expectedResults": {+ "moment": "https://example.com/triggered-by-any-subpath/moment",+ "moment/foo": "https://example.com/triggered-by-any-subpath/moment/foo"+ }+ },+ "Subpath base URL (prefix match)": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "moment": "https://example.com/triggered-by-any-subpath/moment",+ "moment/foo": "https://example.com/triggered-by-any-subpath/moment/foo"+ }+ },+ "Non-subpath base URL (fail)": {+ "baseURL": "https://example.com/jsiscool",+ "expectedResults": {+ "moment": null,+ "moment/foo": null+ }+ }+ }+ },+ "Scopes with and without trailing slash": {+ "importMap": {+ "scopes": {+ "/js": {+ "moment": "/only-triggered-by-exact/moment",+ "moment/": "/only-triggered-by-exact/moment/"+ },+ "/js/": {+ "moment": "/triggered-by-any-subpath/moment",+ "moment/": "/triggered-by-any-subpath/moment/"+ }+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "tests": {+ "Non-trailing-slash base URL (exact match)": {+ "baseURL": "https://example.com/js",+ "expectedResults": {+ "moment": "https://example.com/only-triggered-by-exact/moment",+ "moment/foo": "https://example.com/only-triggered-by-exact/moment/foo"+ }+ },+ "Trailing-slash base URL (exact match)": {+ "baseURL": "https://example.com/js/",+ "expectedResults": {+ "moment": "https://example.com/triggered-by-any-subpath/moment",+ "moment/foo": "https://example.com/triggered-by-any-subpath/moment/foo"+ }+ },+ "Subpath base URL (prefix match)": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "moment": "https://example.com/triggered-by-any-subpath/moment",+ "moment/foo": "https://example.com/triggered-by-any-subpath/moment/foo"+ }+ },+ "Non-subpath base URL (fail)": {+ "baseURL": "https://example.com/jsiscool",+ "expectedResults": {+ "moment": null,+ "moment/foo": null+ }+ }+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/scopes.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/scopes.jsonnew file mode 100644index 00000000000..c266e4c6c1d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/scopes.json@@ -0,0 +1,171 @@+{+ "importMapBaseURL": "https://example.com/app/index.html",+ "tests": {+ "Fallback to toplevel and between scopes": {+ "importMap": {+ "imports": {+ "a": "/a-1.mjs",+ "b": "/b-1.mjs",+ "c": "/c-1.mjs",+ "d": "/d-1.mjs"+ },+ "scopes": {+ "/scope2/": {+ "a": "/a-2.mjs",+ "d": "/d-2.mjs"+ },+ "/scope2/scope3/": {+ "b": "/b-3.mjs",+ "d": "/d-3.mjs"+ }+ }+ },+ "tests": {+ "should fall back to `imports` when no scopes match": {+ "baseURL": "https://example.com/scope1/foo.mjs",+ "expectedResults": {+ "a": "https://example.com/a-1.mjs",+ "b": "https://example.com/b-1.mjs",+ "c": "https://example.com/c-1.mjs",+ "d": "https://example.com/d-1.mjs"+ }+ },+ "should use a direct scope override": {+ "baseURL": "https://example.com/scope2/foo.mjs",+ "expectedResults": {+ "a": "https://example.com/a-2.mjs",+ "b": "https://example.com/b-1.mjs",+ "c": "https://example.com/c-1.mjs",+ "d": "https://example.com/d-2.mjs"+ }+ },+ "should use an indirect scope override": {+ "baseURL": "https://example.com/scope2/scope3/foo.mjs",+ "expectedResults": {+ "a": "https://example.com/a-2.mjs",+ "b": "https://example.com/b-3.mjs",+ "c": "https://example.com/c-1.mjs",+ "d": "https://example.com/d-3.mjs"+ }+ }+ }+ },+ "Relative URL scope keys": {+ "importMap": {+ "imports": {+ "a": "/a-1.mjs",+ "b": "/b-1.mjs",+ "c": "/c-1.mjs"+ },+ "scopes": {+ "": {+ "a": "/a-empty-string.mjs"+ },+ "./": {+ "b": "/b-dot-slash.mjs"+ },+ "../": {+ "c": "/c-dot-dot-slash.mjs"+ }+ }+ },+ "tests": {+ "An empty string scope is a scope with import map base URL": {+ "baseURL": "https://example.com/app/index.html",+ "expectedResults": {+ "a": "https://example.com/a-empty-string.mjs",+ "b": "https://example.com/b-dot-slash.mjs",+ "c": "https://example.com/c-dot-dot-slash.mjs"+ }+ },+ "'./' scope is a scope with import map base URL's directory": {+ "baseURL": "https://example.com/app/foo.mjs",+ "expectedResults": {+ "a": "https://example.com/a-1.mjs",+ "b": "https://example.com/b-dot-slash.mjs",+ "c": "https://example.com/c-dot-dot-slash.mjs"+ }+ },+ "'../' scope is a scope with import map base URL's parent directory": {+ "baseURL": "https://example.com/foo.mjs",+ "expectedResults": {+ "a": "https://example.com/a-1.mjs",+ "b": "https://example.com/b-1.mjs",+ "c": "https://example.com/c-dot-dot-slash.mjs"+ }+ }+ }+ },+ "Package-like scenarios": {+ "importMap": {+ "imports": {+ "moment": "/node_modules/moment/src/moment.js",+ "moment/": "/node_modules/moment/src/",+ "lodash-dot": "./node_modules/lodash-es/lodash.js",+ "lodash-dot/": "./node_modules/lodash-es/",+ "lodash-dotdot": "../node_modules/lodash-es/lodash.js",+ "lodash-dotdot/": "../node_modules/lodash-es/"+ },+ "scopes": {+ "/": {+ "moment": "/node_modules_3/moment/src/moment.js",+ "vue": "/node_modules_3/vue/dist/vue.runtime.esm.js"+ },+ "/js/": {+ "lodash-dot": "./node_modules_2/lodash-es/lodash.js",+ "lodash-dot/": "./node_modules_2/lodash-es/",+ "lodash-dotdot": "../node_modules_2/lodash-es/lodash.js",+ "lodash-dotdot/": "../node_modules_2/lodash-es/"+ }+ }+ },+ "tests": {+ "Base URLs inside the scope should use the scope if the scope has matching keys": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "lodash-dot": "https://example.com/app/node_modules_2/lodash-es/lodash.js",+ "lodash-dot/foo": "https://example.com/app/node_modules_2/lodash-es/foo",+ "lodash-dotdot": "https://example.com/node_modules_2/lodash-es/lodash.js",+ "lodash-dotdot/foo": "https://example.com/node_modules_2/lodash-es/foo"+ }+ },+ "Base URLs inside the scope fallback to less specific scope": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "moment": "https://example.com/node_modules_3/moment/src/moment.js",+ "vue": "https://example.com/node_modules_3/vue/dist/vue.runtime.esm.js"+ }+ },+ "Base URLs inside the scope fallback to toplevel": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "moment/foo": "https://example.com/node_modules/moment/src/foo"+ }+ },+ "Base URLs outside a scope shouldn't use the scope even if the scope has matching keys": {+ "baseURL": "https://example.com/app.mjs",+ "expectedResults": {+ "lodash-dot": "https://example.com/app/node_modules/lodash-es/lodash.js",+ "lodash-dotdot": "https://example.com/node_modules/lodash-es/lodash.js",+ "lodash-dot/foo": "https://example.com/app/node_modules/lodash-es/foo",+ "lodash-dotdot/foo": "https://example.com/node_modules/lodash-es/foo"+ }+ },+ "Fallback to toplevel or not, depending on trailing slash match": {+ "baseURL": "https://example.com/app.mjs",+ "expectedResults": {+ "moment": "https://example.com/node_modules_3/moment/src/moment.js",+ "moment/foo": "https://example.com/node_modules/moment/src/foo"+ }+ },+ "should still fail for package-like specifiers that are not declared": {+ "baseURL": "https://example.com/js/app.mjs",+ "expectedResults": {+ "underscore/": null,+ "underscore/foo": null+ }+ }+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/test-helper-iframe.js b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/test-helper-iframe.jsnew file mode 100644index 00000000000..3f38a5f0faa--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/test-helper-iframe.js@@ -0,0 +1,46 @@+// Handle errors around fetching, parsing and registering import maps.+window.onScriptError = event => {+ window.registrationResult = {type: 'FetchError', error: event.error};+ return false;+};+window.windowErrorHandler = event => {+ window.registrationResult = {type: 'ParseError', error: event.error};+ return false;+};+window.addEventListener('error', window.windowErrorHandler);++// Handle specifier resolution requests from the parent frame.+// For failures, we post error names and messages instead of error+// objects themselves and re-create error objects later, to avoid+// issues around serializing error objects which is a quite new feature.+window.addEventListener('message', event => {+ if (event.data.action !== 'resolve') {+ parent.postMessage({+ type: 'Failure',+ result: 'Error',+ message: 'Invalid Action: ' + event.data.action}, '*');+ return;+ }++ // To respond to a resolution request, we:+ // 1. Save the specifier to resolve into a global.+ // 2. Update the document's base URL to the requested base URL.+ // 3. Create a new inline script, parsed with that base URL, which+ // resolves the saved specifier using import.meta.resolve(), and+ // sents the result to the parent window.+ window.specifierToResolve = event.data.specifier;+ document.querySelector('base').href = event.data.baseURL;++ const inlineScript = document.createElement('script');+ inlineScript.type = 'module';+ inlineScript.textContent = `+ try {+ const result = import.meta.resolve(window.specifierToResolve);+ parent.postMessage({type: 'ResolutionSuccess', result}, '*');+ } catch (e) {+ parent.postMessage(+ {type: 'Failure', result: e.name, message: e.message}, '*');+ }+ `;+ document.body.append(inlineScript);+});diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/test-helper.js b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/test-helper.jsnew file mode 100644index 00000000000..d34869b0134--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/test-helper.js@@ -0,0 +1,142 @@+setup({allow_uncaught_exception : true});++// Creates a new Document (via <iframe>) and add an inline import map.+function createTestIframe(importMap, importMapBaseURL) {+ return new Promise(resolve => {+ const iframe = document.createElement('iframe');++ window.addEventListener('message', event => {+ // Parsing result is saved here and checked later, rather than+ // rejecting the promise on errors.+ iframe.parseImportMapResult = event.data.type;+ resolve(iframe);+ },+ {once: true});++ const testHTML = createTestHTML(importMap, importMapBaseURL);++ if (new URL(importMapBaseURL).protocol === 'data:') {+ iframe.src = 'data:text/html;base64,' + btoa(testHTML);+ } else {+ iframe.src = '/common/blank.html';+ iframe.addEventListener('load', () => {+ iframe.contentDocument.write(testHTML);+ iframe.contentDocument.close();+ }, {once: true});+ }+ document.body.appendChild(iframe);+ });+}++function createTestHTML(importMap, importMapBaseURL) {+ return `+ <!DOCTYPE html>+ <script src="${location.origin}/import-maps/data-driven/resources/test-helper-iframe.js"></script>++ <base href="${importMapBaseURL}">+ <script type="importmap" onerror="onScriptError(event)">+ ${JSON.stringify(importMap)}+ </script>++ <script type="module">+ if (!window.registrationResult) {+ window.registrationResult = {type: 'Success'};+ }+ window.removeEventListener('error', window.windowErrorHandler);+ parent.postMessage(window.registrationResult, '*');+ </script>+ `;+}++// Returns a promise that is resolved with the resulting URL, or rejected if+// the resolution fails.+function resolve(specifier, baseURL, iframe) {+ return new Promise((resolve, reject) => {+ window.addEventListener('message', event => {+ if (event.data.type === 'ResolutionSuccess') {+ resolve(event.data.result);+ } else if (event.data.type === 'Failure') {+ if (event.data.result === 'TypeError') {+ reject(new TypeError(event.data.message));+ } else {+ reject(new Error(event.data.message));+ }+ } else {+ assert_unreached('Invalid message: ' + event.data.type);+ }+ },+ {once: true});++ iframe.contentWindow.postMessage(+ {action: 'resolve', specifier, baseURL},+ '*'+ );+ });+}++function assert_no_extra_properties(object, expectedProperties, description) {+ for (const actualProperty in object) {+ assert_true(expectedProperties.indexOf(actualProperty) !== -1,+ description + ': unexpected property ' + actualProperty);+ }+}++async function runTests(j) {+ const tests = j.tests;+ delete j.tests;++ if (j.hasOwnProperty('importMap')) {+ assert_own_property(j, 'importMap');+ assert_own_property(j, 'importMapBaseURL');+ j.iframe = await createTestIframe(j.importMap, j.importMapBaseURL);+ delete j.importMap;+ delete j.importMapBaseURL;+ }++ assert_no_extra_properties(+ j,+ ['expectedResults', 'expectedParsedImportMap',+ 'baseURL', 'name', 'iframe',+ 'importMap', 'importMapBaseURL',+ 'link', 'details'],+ j.name);++ if (tests) {+ // Nested node.+ for (const testName in tests) {+ let fullTestName = testName;+ if (j.name) {+ fullTestName = j.name + ': ' + testName;+ }+ tests[testName].name = fullTestName;+ const k = Object.assign({}, j, tests[testName]);+ await runTests(k);+ }+ } else {+ // Leaf node.+ for (const key of ['iframe', 'name', 'expectedResults']) {+ assert_own_property(j, key, j.name);+ }++ assert_equals(+ j.iframe.parseImportMapResult,+ 'Success',+ 'Import map registration should be successful for resolution tests');+ for (const [specifier, expected] of Object.entries(j.expectedResults)) {+ promise_test(async t => {+ if (expected === null) {+ return promise_rejects_js(t, TypeError, resolve(specifier, j.baseURL, j.iframe));+ } else {+ assert_equals(await resolve(specifier, j.baseURL, j.iframe), expected);+ }+ },+ j.name + ': ' + specifier);+ }+ }+}++export async function runTestsFromJSON(jsonURL) {+ const response = await fetch(jsonURL);+ const json = await response.json();+ await runTests(json);+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/tricky-specifiers.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/tricky-specifiers.jsonnew file mode 100644index 00000000000..998fe7fb67d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/tricky-specifiers.json@@ -0,0 +1,71 @@+{+ "importMap": {+ "imports": {+ "package/withslash": "/node_modules/package-with-slash/index.mjs",+ "not-a-package": "/lib/not-a-package.mjs",+ "only-slash/": "/lib/only-slash/",+ ".": "/lib/dot.mjs",+ "..": "/lib/dotdot.mjs",+ "..\\": "/lib/dotdotbackslash.mjs",+ "%2E": "/lib/percent2e.mjs",+ "%2F": "/lib/percent2f.mjs",+ "https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/": "/a/",+ "https://map.example/きつね/fox/": "/b/",+ "%E3%81%8D%E3%81%A4%E3%81%AD/": "/c/",+ "きつね/fox/": "/d/"+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "Tricky specifiers",+ "tests": {+ "explicitly-mapped specifiers that happen to have a slash": {+ "expectedResults": {+ "package/withslash": "https://example.com/node_modules/package-with-slash/index.mjs"+ }+ },+ "specifier with punctuation": {+ "expectedResults": {+ ".": "https://example.com/lib/dot.mjs",+ "..": "https://example.com/lib/dotdot.mjs",+ "..\\": "https://example.com/lib/dotdotbackslash.mjs",+ "%2E": "https://example.com/lib/percent2e.mjs",+ "%2F": "https://example.com/lib/percent2f.mjs"+ }+ },+ "submodule of something not declared with a trailing slash should fail": {+ "expectedResults": {+ "not-a-package/foo": null+ }+ },+ "module for which only a trailing-slash version is present should fail": {+ "expectedResults": {+ "only-slash": null+ }+ },+ "URL-like specifiers are normalized": {+ "expectedResults": {+ "https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/": "https://example.com/a/",+ "https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/bar": "https://example.com/a/bar",+ "https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/fox/": "https://example.com/b/",+ "https://map.example/%E3%81%8D%E3%81%A4%E3%81%AD/fox/bar": "https://example.com/b/bar",+ "https://map.example/きつね/": "https://example.com/a/",+ "https://map.example/きつね/bar": "https://example.com/a/bar",+ "https://map.example/きつね/fox/": "https://example.com/b/",+ "https://map.example/きつね/fox/bar": "https://example.com/b/bar"+ }+ },+ "Bare specifiers are not normalized": {+ "expectedResults": {+ "%E3%81%8D%E3%81%A4%E3%81%AD/": "https://example.com/c/",+ "%E3%81%8D%E3%81%A4%E3%81%AD/bar": "https://example.com/c/bar",+ "%E3%81%8D%E3%81%A4%E3%81%AD/fox/": "https://example.com/c/fox/",+ "%E3%81%8D%E3%81%A4%E3%81%AD/fox/bar": "https://example.com/c/fox/bar",+ "きつね/": null,+ "きつね/bar": null,+ "きつね/fox/": "https://example.com/d/",+ "きつね/fox/bar": "https://example.com/d/bar"+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/url-specifiers-schemes.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/url-specifiers-schemes.jsonnew file mode 100644index 00000000000..58a97642c2b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/url-specifiers-schemes.json@@ -0,0 +1,45 @@+{+ "importMap": {+ "imports": {+ "data:text/": "/lib/test-data/",+ "about:text/": "/lib/test-about/",+ "blob:text/": "/lib/test-blob/",+ "blah:text/": "/lib/test-blah/",+ "http:text/": "/lib/test-http/",+ "https:text/": "/lib/test-https/",+ "file:text/": "/lib/test-file/",+ "ftp:text/": "/lib/test-ftp/",+ "ws:text/": "/lib/test-ws/",+ "wss:text/": "/lib/test-wss/"+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "URL-like specifiers",+ "tests": {+ "Non-special vs. special schemes": {+ "expectedResults": {+ "data:text/javascript,console.log('foo')": "data:text/javascript,console.log('foo')",+ "data:text/": "https://example.com/lib/test-data/",+ "about:text/foo": "about:text/foo",+ "about:text/": "https://example.com/lib/test-about/",+ "blob:text/foo": "blob:text/foo",+ "blob:text/": "https://example.com/lib/test-blob/",+ "blah:text/foo": "blah:text/foo",+ "blah:text/": "https://example.com/lib/test-blah/",+ "http:text/foo": "https://example.com/lib/test-http/foo",+ "http:text/": "https://example.com/lib/test-http/",+ "https:text/foo": "https://example.com/lib/test-https/foo",+ "https:text/": "https://example.com/lib/test-https/",+ "ftp:text/foo": "https://example.com/lib/test-ftp/foo",+ "ftp:text/": "https://example.com/lib/test-ftp/",+ "file:text/foo": "https://example.com/lib/test-file/foo",+ "file:text/": "https://example.com/lib/test-file/",+ "ws:text/foo": "https://example.com/lib/test-ws/foo",+ "ws:text/": "https://example.com/lib/test-ws/",+ "wss:text/foo": "https://example.com/lib/test-wss/foo",+ "wss:text/": "https://example.com/lib/test-wss/"+ }+ }+ }+}diff --git a/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/url-specifiers.json b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/url-specifiers.jsonnew file mode 100644index 00000000000..6fcf7f46635--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/import-maps/data-driven/resources/url-specifiers.json@@ -0,0 +1,68 @@+{+ "importMap": {+ "imports": {+ "/lib/foo.mjs": "./more/bar.mjs",+ "./dotrelative/foo.mjs": "/lib/dot.mjs",+ "../dotdotrelative/foo.mjs": "/lib/dotdot.mjs",+ "/": "/lib/slash-only/",+ "./": "/lib/dotslash-only/",+ "/test/": "/lib/url-trailing-slash/",+ "./test/": "/lib/url-trailing-slash-dot/",+ "/test": "/lib/test1.mjs",+ "../test": "/lib/test2.mjs"+ }+ },+ "importMapBaseURL": "https://example.com/app/index.html",+ "baseURL": "https://example.com/js/app.mjs",+ "name": "URL-like specifiers",+ "tests": {+ "Ordinary URL-like specifiers": {+ "expectedResults": {+ "https://example.com/lib/foo.mjs": "https://example.com/app/more/bar.mjs",+ "https://///example.com/lib/foo.mjs": "https://example.com/app/more/bar.mjs",+ "/lib/foo.mjs": "https://example.com/app/more/bar.mjs",+ "https://example.com/app/dotrelative/foo.mjs": "https://example.com/lib/dot.mjs",+ "../app/dotrelative/foo.mjs": "https://example.com/lib/dot.mjs",+ "https://example.com/dotdotrelative/foo.mjs": "https://example.com/lib/dotdot.mjs",+ "../dotdotrelative/foo.mjs": "https://example.com/lib/dotdot.mjs"+ }+ },+ "Import map entries just composed from / and .": {+ "expectedResults": {+ "https://example.com/": "https://example.com/lib/slash-only/",+ "/": "https://example.com/lib/slash-only/",+ "../": "https://example.com/lib/slash-only/",+ "https://example.com/app/": "https://example.com/lib/dotslash-only/",+ "/app/": "https://example.com/lib/dotslash-only/",+ "../app/": "https://example.com/lib/dotslash-only/"+ }+ },+ "prefix-matched by keys with trailing slashes": {+ "expectedResults": {+ "/test/foo.mjs": "https://example.com/lib/url-trailing-slash/foo.mjs",+ "https://example.com/app/test/foo.mjs": "https://example.com/lib/url-trailing-slash-dot/foo.mjs"+ }+ },+ "should use the last entry's address when URL-like specifiers parse to the same absolute URL": {+ "expectedResults": {+ "/test": "https://example.com/lib/test2.mjs"+ }+ },+ "backtracking (relative URLs)": {+ "expectedResults": {+ "/test/..": "https://example.com/lib/slash-only/",+ "/test/../backtrack": "https://example.com/lib/slash-only/backtrack",+ "/test/../../backtrack": "https://example.com/lib/slash-only/backtrack",+ "/test/../../../backtrack": "https://example.com/lib/slash-only/backtrack"+ }+ },+ "backtracking (absolute URLs)": {+ "expectedResults": {+ "https://example.com/test/..": "https://example.com/lib/slash-only/",+ "https://example.com/test/../backtrack": "https://example.com/lib/slash-only/backtrack",+ "https://example.com/test/../../backtrack": "https://example.com/lib/slash-only/backtrack",+ "https://example.com/test/../../../backtrack": "https://example.com/lib/slash-only/backtrack"+ }+ }+ }+}