summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve-multiple-scripts.html
blob: d2e0f185e0b3704e63ff38b999629d64de58c30b (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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe src="resources/store-import-meta.html"></iframe>

<script type="module">
import * as otherImportMeta from "./resources/export-import-meta.mjs";
setup({ explicit_done: true });

window.onload = () => {
  test(() => {
    assert_not_equals(frames[0].importMetaURL, import.meta.url,
      "Precondition check: we've set things up so that the other script has a different import.meta.url");

    const expected = (new URL("resources/x", location.href)).href;
    assert_equals(frames[0].importMetaResolve("./x"), expected);
  }, "import.meta.resolve resolves URLs relative to the import.meta.url, not relative to the active script when it is called: another global's inline script");

  test(() => {
    const otherFrameImportMetaResolve = frames[0].importMetaResolve;

    document.querySelector("iframe").remove();

    const expected = (new URL("resources/x", location.href)).href;
    assert_equals(otherFrameImportMetaResolve("./x"), expected);
  }, "import.meta.resolve still works if its global has been destroyed (by detaching the iframe)");

  test(() => {
    assert_not_equals(otherImportMeta.url, import.meta.url,
      "Precondition check: we've set things up so that the other script has a different import.meta.url");

    const expected = (new URL("resources/x", location.href)).href;
    assert_equals(otherImportMeta.resolve("./x"), expected);
  }, "import.meta.resolve resolves URLs relative to the import.meta.url, not relative to the active script when it is called: another module script");

  done();
};
</script>