summaryrefslogtreecommitdiffstats
path: root/dom/base/test/jsmodules/importmaps/test_sortedImportMap.html
blob: f4b98fdf1024743f198b76d5473a6d3d401d6e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test a sorted import map</title>

<!--
According to Import maps spec, the entries in "imports" and "scopes" need to be
sorted. Key with longest prefix should be chosen. So "a/b/" should take
precendence over "a/".
This test is verifying that requirement.

In "imports" below, "scope1/scope2/" and "scope1/scope2/scope3/scope4/" should
be chosen over "scope1" and "scope1/scope2/scop3/" respectively.
Also "scope1/scope2/" is listed _after_ "scope1/ and
"scope1/scope2/scope3/scope4" is listed _before_ "scope1/scope2/scope3/" to make
sure the map is sorted.

For "scopes" below, the "scope1/" is listed before "scope1/scope2/" in
test_simpleImportMap.html, here we reverse the order, for example, we list
"scope1/" after "scope1/scope2/" in this test.

See:
https://html.spec.whatwg.org/multipage/webappapis.html#sorting-and-normalizing-a-module-specifier-map, Step 3.
https://html.spec.whatwg.org/multipage/webappapis.html#sorting-and-normalizing-scopes, Step 3.
-->

<script type="importmap">
{
  "imports": {
    "scope1/": "/content/chrome/dom/base/test/jsmodules/importmaps/",
    "scope1/scope2/": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/",
    "scope1/scope2/scope3/scope4/": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/",
    "scope1/scope2/scope3/": "/content/chrome/dom/base/test/jsmodules/importmaps/"
  },
  "scopes": {
    "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/": {
      "simple": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/scope2/module_simpleExport.mjs"
    },
    "chrome://mochitests/content/chrome/dom/base/test/jsmodules/importmaps/scope1/": {
      "simple": "/content/chrome/dom/base/test/jsmodules/importmaps/scope1/module_simpleExport.mjs"
    }
  }
}
</script>

<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

<script>
  var sorted_result, sorted_result2;
  var result_scope2;

  SimpleTest.waitForExplicitFinish();

  function testLoaded() {
    ok(sorted_result == 126, 'Check imported value sorted_result: ' + sorted_result);
    ok(sorted_result2 == 126, 'Check imported value sorted_result: ' + sorted_result2);
    ok(result_scope2 == 126, 'Check imported value result_scope2: ' + result_scope2);
    SimpleTest.finish();
  }
</script>
<script type="module" src="module_sortedImportMap.mjs"></script>
<script type="module" src="scope1/scope2/module_simpleImportMap.mjs"></script>
<body onload='testLoaded()'></body>