Commit f8c5a025 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Chromium LUCI CQ

[Import Maps] Add tests for rejecting multiple import maps

According to the spec after
https://github.com/WICG/import-maps/pull/242.

Bug: 848607
Change-Id: I21e2d494c75ddf9187d2a8d8b63bc59bccd9beb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2618680Reviewed-by: default avatarDomenic Denicola <domenic@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842149}
parent 2059e3a7
This is a testharness.js-based test.
FAIL Second import map should be rejected assert_array_equals: lengths differ, expected array ["onerror 2", "log:B1", "log:B2", "log:A3"] length 4, got ["log:B1", "log:B2", "log:A3"] length 3
Harness: the test ran to completion.
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const log = [];
</script>
<script type="importmap" onerror="log.push('onerror 1')">
{
"imports": {
"../resources/log.js?pipe=sub&name=A1": "../resources/log.js?pipe=sub&name=B1",
"../resources/log.js?pipe=sub&name=A2": "../resources/log.js?pipe=sub&name=B2"
}
}
</script>
<script type="importmap" onerror="log.push('onerror 2')">
{
"imports": {
"../resources/log.js?pipe=sub&name=A1": "../resources/log.js?pipe=sub&name=C1",
"../resources/log.js?pipe=sub&name=A3": "../resources/log.js?pipe=sub&name=C3"
}
}
</script>
<script>
// Currently the spec doesn't allow multiple import maps, by setting acquiring
// import maps to false on preparing the first import map.
promise_test(() => {
return import("../resources/log.js?pipe=sub&name=A1")
.then(() => import("../resources/log.js?pipe=sub&name=A2"))
.then(() => import("../resources/log.js?pipe=sub&name=A3"))
.then(() => assert_array_equals(
log,
["onerror 2", "log:B1", "log:B2", "log:A3"]))
},
"Second import map should be rejected");
</script>
This is a testharness.js-based test.
FAIL Second import map should be rejected after an import map with errors assert_array_equals: lengths differ, expected array ["onerror 2", "log:A"] length 2, got ["log:C"] length 1
Harness: the test ran to completion.
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({allow_uncaught_exception : true});
const log = [];
</script>
<script type="importmap" onerror="log.push('onerror 1')">
Parse Error
</script>
<script type="importmap" onerror="log.push('onerror 2')">
{
"imports": {
"../resources/log.js?pipe=sub&name=A": "../resources/log.js?pipe=sub&name=C"
}
}
</script>
<script>
// Currently the spec doesn't allow multiple import maps, by setting acquiring
// import maps to false on preparing the first import map.
// Even the first import map has errors and thus Document's import map is not
// updated, the second import map is still rejected at preparationg.
promise_test(() => {
return import("../resources/log.js?pipe=sub&name=A")
.then(() => assert_array_equals(
log,
["onerror 2", "log:A"]))
},
"Second import map should be rejected after an import map with errors");
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment