Skip to content

Commit

Permalink
Import maps: rearrange and update WPTs
Browse files Browse the repository at this point in the history
* Flips the pass condition for worker interaction. A module worker does
  not impact the import map of the outer page, since its constructor
  takes a URL, not a specifier that needs resolution.

* Removes leftover built-in module support and @std references.

* Removes .tentative filename suffixes.

* Renames "common" to "data-driven".

* Renames parsing.tentative.https.html to parsing-internal.https.html so
  that all internal tests to have -internal in the name. We should move
  them out of WPT (or convert them to not require internals),
  eventually, but for now making the difference clear is good.

* Moves "core" tests up to the top level.

* Removes references to future fetch-based import maps and Chromium
  implementation limitations.

* Adds OWNERS and META.yml

Bug: 1026809
Change-Id: I1807468a813ebee416cd8e05a272dbae6ea157bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491616
Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>
Commit-Queue: Domenic Denicola <domenic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825559}
  • Loading branch information
domenic authored and chromium-wpt-export-bot committed Nov 10, 2020
1 parent 2e85c09 commit bb36180
Show file tree
Hide file tree
Showing 57 changed files with 65 additions and 93 deletions.
4 changes: 4 additions & 0 deletions import-maps/META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spec: https://github.com/WICG/import-maps
suggested_reviewers:
- domenic
- hiroshige-g
9 changes: 0 additions & 9 deletions import-maps/README.md

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions import-maps/acquiring/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// https://github.com/WICG/import-maps/blob/master/spec.md#when-import-maps-can-be-encountered
const t = async_test(
'After dynamic imports, import maps should fire error events');
const log = [];
Expand All @@ -12,19 +11,19 @@
// 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)'),
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"
"../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")
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// https://github.com/WICG/import-maps/blob/master/spec.md#when-import-maps-can-be-encountered
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="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"
"../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")
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<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": {
Expand All @@ -10,16 +14,9 @@
}
</script>
<script>
const log = [];

// This test reflects the Chromium's current implementation.
// If the import map resolution is moved into the fetch spec, the module map's
// key will become the URL/specifier BEFORE import map resolution.
// https://crbug.com/928435
promise_test(() => {
return import("../resources/log.js?pipe=sub&name=A")
.then(() => import("../resources/log.js?pipe=sub&name=B"))
.then(() => assert_array_equals(log, ["log:B"]))
},
"Module map's key is the URL after import map resolution");
'After module worker creation import maps are still effective');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helper.js"></script>
<script src="resources/test-helper.js"></script>

<script>
// "bare/..." (i.e. without leading "./") are bare specifiers
// (not relative paths).
const importMap = `
{
"imports": {
"bare/bare": "../resources/log.js?pipe=sub&name=bare",
"bare/bare": "./resources/log.js?pipe=sub&name=bare",
"bare/cross-origin-bare": "https://{{domains[www1]}}:{{ports[https][0]}}/import-maps/resources/log.js?pipe=sub&name=cross-origin-bare",
"bare/to-data": "data:text/javascript,log.push('dataURL')",
Expand All @@ -26,11 +26,6 @@
// - static import, and
// - dynamic import.

// Currently, Chromium's implementation resolves import maps as a part of
// specifier resolution, and thus failure in import map resolution causes
// a parse error, not fetch error. Therefore, we use Result.PARSE_ERROR
// below. https://crbug.com/928435

// Bare to HTTP(S).
"bare/bare":
[Result.URL, Result.URL, "log:bare", "log:bare"],
Expand Down
1 change: 1 addition & 0 deletions import-maps/bare/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains resources which might get imported, post-mapping. The exact URLs are important, which is why we don't place it under resources/ or similar.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Import maps test JSON format
# Data-driven import maps tests

In this directory, test inputs and expectations are expressed as JSON files.
This is in order to share the same JSON files between WPT tests and Jest-based
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</script>
<body>
<script type="module">
import { runTestsFromJSON, setupGlobalCleanup } from "./resources/common-test-helper.js";
import { runTestsFromJSON, setupGlobalCleanup } from "./resources/test-helper.js";

const promises = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// This test file is for resolution tests that require Chromium's internal
// methods.
// For tests that don't use Chromium's internal methods, see
// resolving.tentative.https.html.
// resolving.https.html.
globalThis.useInternalMethods = true;
</script>
<body>
<script type="module">
import { runTestsFromJSON, setupGlobalCleanup } from "./resources/common-test-helper.js";
import { runTestsFromJSON, setupGlobalCleanup } from "./resources/test-helper.js";

const promises = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<body>
<script type="module">
import { runTestsFromJSON, setupGlobalCleanup } from "./resources/common-test-helper.js";
import { runTestsFromJSON, setupGlobalCleanup } from "./resources/test-helper.js";

const promises = [];

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const scope = './scope/';

// Global setup: this must be the first promise_test.
promise_test(async (t) => {
const script = 'common-test-service-worker.js';
const script = 'service-worker.js';

registration =
await service_worker_unregister_and_register(t, script, scope);
Expand Down Expand Up @@ -38,7 +38,7 @@ function parse(importMap, importMapBaseURL) {

const testHTML = `
<body>
<script src="${location.origin}/import-maps/common/resources/common-test-helper-iframe.js"></script>
<script src="${location.origin}/import-maps/data-driven/resources/test-helper-iframe.js"></script>
<script type="importmap" onerror="onScriptError(event)">
${importMapString}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ self.addEventListener('message', event => {
});

self.addEventListener('fetch', event => {
if (event.request.url.indexOf('common-test-helper-iframe.js') >= 0) {
if (event.request.url.indexOf('test-helper-iframe.js') >= 0) {
return;
}
if (serveImporterScript) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helper.js"></script>
<script src="resources/test-helper.js"></script>

<script>
// "bare/..." (i.e. without leading "./") are bare specifiers
// (not relative paths).
const importMap = `
{
"imports": {
"bare": "../resources/log.js?pipe=sub&name=bare",
"bare": "./resources/log.js?pipe=sub&name=bare",
"data:text/javascript,log.push('data:foo')": "../resources/log.js?pipe=sub&name=foo",
"data:text/javascript,log.push('data:foo')": "./resources/log.js?pipe=sub&name=foo",
"data:text/javascript,log.push('data:cross-origin-foo')": "https://{{domains[www1]}}:{{ports[https][0]}}/import-maps/resources/log.js?pipe=sub&name=cross-origin-foo",
"data:text/javascript,log.push('data:to-data')": "data:text/javascript,log.push('dataURL')",
Expand All @@ -28,11 +28,6 @@
// - static import, and
// - dynamic import.

// Currently, Chromium's implementation resolves import maps as a part of
// specifier resolution, and thus failure in import map resolution causes
// a parse error, not fetch error. Therefore, we use Result.PARSE_ERROR
// below. https://crbug.com/928435

// data: to HTTP(S).
"data:text/javascript,log.push('data:foo')":
[Result.URL, Result.URL, "log:foo", "log:foo"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/test-helper.js"></script>
<script src="resources/test-helper.js"></script>

<script>
// "bare/..." (i.e. without leading "./") are bare specifiers
// (not relative paths).
const importMap = `
{
"imports": {
"bare": "../resources/log.js?pipe=sub&name=bare",
"bare": "./resources/log.js?pipe=sub&name=bare",
"../resources/log.js?pipe=sub&name=foo": "../resources/log.js?pipe=sub&name=bar",
"../resources/log.js?pipe=sub&name=cross-origin-foo": "https://{{domains[www1]}}:{{ports[https][0]}}/import-maps/resources/log.js?pipe=sub&name=cross-origin-bar",
"../resources/log.js?pipe=sub&name=to-data": "data:text/javascript,log.push('dataURL')",
"./resources/log.js?pipe=sub&name=foo": "./resources/log.js?pipe=sub&name=bar",
"./resources/log.js?pipe=sub&name=cross-origin-foo": "https://{{domains[www1]}}:{{ports[https][0]}}/import-maps/resources/log.js?pipe=sub&name=cross-origin-bar",
"./resources/log.js?pipe=sub&name=to-data": "data:text/javascript,log.push('dataURL')",
"../resources/log.js?pipe=sub&name=to-bare": "bare"
"./resources/log.js?pipe=sub&name=to-bare": "bare"
}
}
`;
Expand All @@ -27,11 +27,6 @@
// - static import, and
// - dynamic import.

// Currently, Chromium's implementation resolves import maps as a part of
// specifier resolution, and thus failure in import map resolution causes
// a parse error, not fetch error. Therefore, we use Result.PARSE_ERROR
// below. https://crbug.com/928435

// HTTP(S) to HTTP(S).
"{{location[server]}}/import-maps/resources/log.js?pipe=sub&name=foo":
[Result.URL, Result.URL, "log:bar", "log:bar"],
Expand Down
21 changes: 21 additions & 0 deletions import-maps/module-map-key.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="importmap">
{
"imports": {
"./resources/log.js?pipe=sub&name=A": "./resources/log.js?pipe=sub&name=B"
}
}
</script>
<script>
const log = [];

promise_test(() => {
return import("./resources/log.js?pipe=sub&name=A")
.then(() => import("./resources/log.js?pipe=sub&name=B"))
.then(() => assert_array_equals(log, ["log:B"]))
},
"Module map's key is the URL after import map resolution");
</script>
File renamed without changes.
11 changes: 3 additions & 8 deletions import-maps/resources/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ function expect_log(test, expected_log) {

// Results of resolving a specifier using import maps.
const Result = {
// A built-in module (std:blank) is loaded.
BUILTIN: "builtin",

// A failure considered as a fetch error in a module script tree.
// <script>'s error event is fired.
FETCH_ERROR: "fetch_error",
Expand All @@ -26,9 +23,9 @@ const Result = {
// ------------------------- ----------------------
// ...?name=foo log:foo
// data:...log('foo') foo
// Others, e.g. @std/blank relative:@std/blank
// Others, e.g. bare/bare relative:bare/bare
// ------------------------- ----------------------
// (The last case assumes a file `@std/blank` that logs `relative:@std/blank`
// (The last case assumes a file `bare/bare` that logs `relative:bare/bare`
// exists)
URL: "URL",
};
Expand Down Expand Up @@ -79,9 +76,7 @@ function getHandlers(t, specifier, expected) {
});
} else {
let expected_log;
if (expected === Result.BUILTIN) {
expected_log = [];
} else if (expected === Result.URL) {
if (expected === Result.URL) {
const match_data_url = specifier.match(/data:.*log\.push\('(.*)'\)/);
const match_log_js = specifier.match(/name=(.*)/);
if (match_data_url) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# This file needs to be a sibling of the test files (and not under resources/)
# so that base URL resolution is the same between those test files and <script>s
# pointing to this file.

from wptserve.utils import isomorphic_decode

def main(request, response):
Expand Down
2 changes: 1 addition & 1 deletion lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ MISSING-LINK: css/geometry/*.any.js
MISSING-LINK: css/filter-effects/*.any.js

# Tests that use WebKit/Blink testing APIs
LAYOUTTESTS APIS: import-maps/common/resources/common-test-helper-iframe.js
LAYOUTTESTS APIS: import-maps/data-driven/resources/test-helper-iframe.js
LAYOUTTESTS APIS: resources/chromium/enable-hyperlink-auditing.js
LAYOUTTESTS APIS: resources/chromium/generic_sensor_mocks.js
LAYOUTTESTS APIS: resources/chromium/webxr-test.js
Expand Down

0 comments on commit bb36180

Please sign in to comment.