summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html
blob: d90af9c96abaccf3e7509a05a28524eadf6d4e5b (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
63
64
<!DOCTYPE html>
<meta charset="utf-8">
<title>import() inside compiled strings uses the script base URL inside a module script that is loaded from a file</title>
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id="dummy"></div>

<base href="scripts/foo/">
<script type="module">
// Tweak the base URL of the document here to distinguish:
// - document URL
// - document base URL = ../
// - External scripts' base URL = ./scripts/eval.js etc.
// - This inline script's base URL = ./scripts/foo/
document.querySelector("base").remove();
const base = document.createElement("base");
base.setAttribute("href", "../");
document.body.appendChild(base);

function load(scriptSrc) {
  const el = document.createElement("script");
  el.type = "module";
  el.src = scriptSrc;
  document.body.appendChild(el);
}

function createTestPromise() {
  return new Promise((resolve, reject) => {
    window.dummyDiv.removeAttribute("onclick");
    delete window.evaluated_imports_a;
    delete window.label;

    window.continueTest = resolve;
    window.errorTest = reject;
  });
}

window.dummyDiv = document.querySelector("#dummy");

const evaluators = [
  "setTimeout",
  "eval",
  "Function",
  "reflected-inline-event-handlers",
  "inline-event-handlers-UA-code"
];

for (const label of evaluators) {
  promise_test(() => {
    const promise = createTestPromise();

    window.label = label;
    load(`dynamic-import/scripts/${label}.js`);

    return promise.then(module => {
      assert_true(window.evaluated_imports_a, "The module must have been evaluated");
      assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct");
    });
  }, label + " should successfully import");
};
</script>