Bug 1539614 [wpt PR 16077] - HTML: move textarea tests together, a=testonly
[gecko.git] / testing / web-platform / tests / import-maps / resolving.tentative.html
blobf2b09a7ae02422c8f6fd3f8dad1f9b8d52a43831
1 <!DOCTYPE html>
2 <html>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script>
6 setup({allow_uncaught_exception : true});
8 // Hacky glue code to run Jest-based tests as WPT tests.
9 // Only supports resolving.js.
10 function require(name) {
11 return {
12 'URL': URL,
13 'parseFromString': parseFromString,
14 'resolve': resolve
18 function expect(v) {
19 return {
20 toMatchURL: expected => assert_equals(v, expected),
21 toThrow: expected => assert_throws(expected(), v)
25 let current_message = '';
26 function describe(message, f) {
27 const old = current_message;
28 if (current_message !== '') {
29 current_message += ' / ';
31 current_message += message;
32 f();
33 current_message = old;
35 function it(message, f) {
36 const old = current_message;
37 if (current_message !== '') {
38 current_message += ' / ';
40 current_message += message;
41 test(t => t.step_func(f)(), current_message);
42 current_message = old;
45 // Creates a new Document (via <iframe>) and add an inline import map.
46 // Currently document.write() is used to make everything synchronous, which
47 // is just needed for running the existing Jest-based tests easily.
48 function parseFromString(mapString, mapBaseURL) {
49 const iframe = document.createElement('iframe');
50 document.body.appendChild(iframe);
51 iframe.contentDocument.write(`
52 <base href="${mapBaseURL}">
53 <script>
54 let isError = false;
55 function onError() {
56 isError = true;
58 </sc` + `ript>
59 <script type="importmap" onerror="onError()">
60 ${mapString}
61 </sc` + `ript>
62 `);
63 iframe.contentDocument.close();
64 return iframe;
67 // URL resolution is tested using Chromium's `internals`.
68 // TODO(hiroshige): Remove the Chromium-specific dependency.
69 function resolve(specifier, map, baseURL) {
70 return internals.resolveModuleSpecifier(specifier,
71 baseURL,
72 map.contentDocument);
75 </script>
77 <!--
78 resolving.js is
79 https://github.com/WICG/import-maps/blob/master/reference-implementation/__tests__/resolving.js
80 -->
81 <script type="module" src="resources/resolving.js"></script>