From b10070db184d166b9e795e1fee04883d0a38f4b1 Mon Sep 17 00:00:00 2001 From: Yoshi Cheng-Hao Huang Date: Tue, 26 Jul 2022 15:21:11 +0000 Subject: [PATCH] Part 4: wpt for injecting a element for import-maps. This test introduces two new functions to test the base url functionality. In addition, we have a new helper function: testInIframeInjectBase, which injects a base url before the content with the import map is parsed. The two tests test the following: 1. Static import coming after the import map and injected base element 2. Dynamic import coming after the import map and injected base element Differential Revision: https://phabricator.services.mozilla.com/D150719 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1773997 gecko-commit: 12620b755d6b0af8909f0249e37af4c5c1893b83 gecko-reviewers: jonco, yulia --- import-maps/import-maps-base-url.sub.html | 5 ++ import-maps/resources/inject-base.js | 3 ++ import-maps/resources/test-helper.js | 60 +++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 import-maps/resources/inject-base.js diff --git a/import-maps/import-maps-base-url.sub.html b/import-maps/import-maps-base-url.sub.html index 3e09aeff17b884..0a5f9c0beee76b 100644 --- a/import-maps/import-maps-base-url.sub.html +++ b/import-maps/import-maps-base-url.sub.html @@ -22,6 +22,11 @@ testDynamicImport(importMap, baseURL, "bare/bare", "log:bare", "module"); testDynamicImport(importMap, baseURL, "bare/bare", "log:bare", "text/javascript"); + + testStaticImportInjectBase(importMap, baseURL, "bare/bare", "log:bare"); + testDynamicImportInjectBase(importMap, baseURL, "bare/bare", "log:bare", "module"); + testDynamicImportInjectBase(importMap, baseURL, "bare/bare", "log:bare", + "text/javascript"); }); diff --git a/import-maps/resources/inject-base.js b/import-maps/resources/inject-base.js new file mode 100644 index 00000000000000..4d469aec89c398 --- /dev/null +++ b/import-maps/resources/inject-base.js @@ -0,0 +1,3 @@ +const el = document.createElement("base"); +el.href = "{{GET[baseurl]}}"; +document.currentScript.after(el); diff --git a/import-maps/resources/test-helper.js b/import-maps/resources/test-helper.js index 64982584ceb1b5..78215b2d017ac8 100644 --- a/import-maps/resources/test-helper.js +++ b/import-maps/resources/test-helper.js @@ -173,6 +173,66 @@ function testDynamicImport(importMapString, importMapBaseURL, specifier, expecte `); } +function testInIframeInjectBase(importMapString, importMapBaseURL, testScript) { + const iframe = document.createElement('iframe'); + document.body.appendChild(iframe); + let content = ` + + + + `; + + if (importMapString) { + content += ` +