diff options
Diffstat (limited to 'testing/web-platform/tests/import-maps/acquiring')
8 files changed, 155 insertions, 0 deletions
diff --git a/testing/web-platform/tests/import-maps/acquiring/README.md b/testing/web-platform/tests/import-maps/acquiring/README.md new file mode 100644 index 0000000000..189d190217 --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/README.md @@ -0,0 +1 @@ +These tests are about the impact of the [acquiring import maps](https://wicg.github.io/import-maps/#document-acquiring-import-maps) boolean, which prevents import maps from taking effect after a module import has started. diff --git a/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html b/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html new file mode 100644 index 0000000000..49d8a701da --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/dynamic-import.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const t = async_test( + 'After dynamic imports, import maps should fire error events'); +const log = []; +// To ensure we are testing that the flag is cleared at the beginning of module +// script loading unconditionally, not at the end of loading or not at the +// first attempt to resolve a module specifier, trickle(d1) is used to ensure +// the following import map is added after module loading is triggered but +// before the first module script is parsed. +promise_test(() => import('../resources/empty.js?pipe=trickle(d1)'), + "A dynamic import succeeds"); +</script> +<script type="importmap" onload="t.assert_unreached('onload')" onerror="t.done()"> +{ + "imports": { + "../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B" + } +} +</script> +<script> +promise_test(() => { + return import("../resources/log.js?pipe=sub&name=A") + .then(() => assert_array_equals(log, ["log:A"])) + }, + 'After a dynamic import(), import maps are not effective'); +</script> 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 new file mode 100644 index 0000000000..dde8cabb93 --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const t = async_test( + 'With modulepreload link header, import maps should fire error events'); +const log = []; +</script> +<script type="importmap" onerror="t.done()"> +{ + "imports": { + "../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B" + } +} +</script> +<script> +promise_test(() => { + return import("../resources/log.js?pipe=sub&name=A") + .then(() => assert_array_equals(log, ["log:A"])) + }, + 'With modulepreload link header, import maps are not effective'); +</script> diff --git a/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html.headers b/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html.headers new file mode 100644 index 0000000000..bb81a4c569 --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/modulepreload-link-header.html.headers @@ -0,0 +1 @@ +Link: <../resources/empty.js?pipe=trickle(d1)>;rel=modulepreload diff --git a/testing/web-platform/tests/import-maps/acquiring/modulepreload.html b/testing/web-platform/tests/import-maps/acquiring/modulepreload.html new file mode 100644 index 0000000000..68b66a8ae3 --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/modulepreload.html @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const t = async_test( + 'After <link rel=modulepreload> import maps should fire error events'); +const log = []; +</script> +<link rel="modulepreload" href="../resources/empty.js?pipe=trickle(d1)"></link> +<script type="importmap" onerror="t.done()"> +{ + "imports": { + "../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B" + } +} +</script> +<script> +promise_test(() => { + return import("../resources/log.js?pipe=sub&name=A") + .then(() => assert_array_equals(log, ["log:A"])) + }, + 'After <link rel=modulepreload> import maps are not effective'); +</script> 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 new file mode 100644 index 0000000000..683ce83c3a --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/script-tag-inline.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const t = async_test( + 'After inline <script type="module"> import maps should fire error events'); +const log = []; +</script> +<script type="module"> +// While this inline module script doesn't have any specifiers and doesn't fetch +// anything, this still disables subsequent import maps, because +// https://wicg.github.io/import-maps/#wait-for-import-maps +// is anyway called at the beginning of +// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-an-inline-module-script-graph +</script> +<script type="importmap" onerror="t.done()"> +{ + "imports": { + "../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B" + } +} +</script> +<script> +promise_test(() => { + return import("../resources/log.js?pipe=sub&name=A") + .then(() => assert_array_equals(log, ["log:A"])) + }, + 'After inline <script type="module"> import maps are not effective'); +</script> diff --git a/testing/web-platform/tests/import-maps/acquiring/script-tag.html b/testing/web-platform/tests/import-maps/acquiring/script-tag.html new file mode 100644 index 0000000000..2792c2a31d --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/script-tag.html @@ -0,0 +1,24 @@ +<!DOCTYPE html> +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const t = async_test( + 'After <script type="module"> import maps should fire error events'); +const log = []; +</script> +<script type="module" src="../resources/empty.js?pipe=trickle(d1)"></script> +<script type="importmap" onerror="t.done()"> +{ + "imports": { + "../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B" + } +} +</script> +<script> +promise_test(() => { + return import("../resources/log.js?pipe=sub&name=A") + .then(() => assert_array_equals(log, ["log:A"])) + }, + 'After <script type="module"> import maps are not effective'); +</script> diff --git a/testing/web-platform/tests/import-maps/acquiring/worker-request.html b/testing/web-platform/tests/import-maps/acquiring/worker-request.html new file mode 100644 index 0000000000..05474ddff2 --- /dev/null +++ b/testing/web-platform/tests/import-maps/acquiring/worker-request.html @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const log = []; +new Worker('../resources/empty.js?pipe=trickle(d1)', {type: "module"}); +</script> +<script type="importmap"> +{ + "imports": { + "../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=B" + } +} +</script> +<script> +promise_test(() => { + return import("../resources/log.js?pipe=sub&name=A") + .then(() => assert_array_equals(log, ["log:B"])) + }, + 'After module worker creation import maps are still effective'); +</script> |