summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/no-active-script-classic-manual.html
blob: b01f595c03e9456b1da62bb4259a923a73ad8a34 (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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Dynamic import when there is no active script</title>
<link rel="help" href="https://github.com/whatwg/html/pull/4181">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<p>Click these buttons in sequence:</p>

<button id="button1">Click me 1</button>

<button id="button2">Click me 2</button>

<p>The result will be pass/fail per the testharness.js results</p>

<!-- We set the attributes from a separate script to specifically make
     sure that it's not that script's base URL that gets used, but instead this page's. -->
<script src="scripts/no-active-script.js"></script>

<script>
"use strict";
setup({ explicit_timeout: true });

promise_test(t => {
  t.add_cleanup(() => {
    delete window.evaluated_imports_a;
  });

  const promise = new Promise((resolve, reject) => {
    window.continueTest1 = resolve;
    window.errorTest1 = reject;
  });

  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");
  });
}, "onclick that directly imports should successfully import, using page's base URL");

promise_test(t => {
  t.add_cleanup(() => {
    delete window.evaluated_imports_a;
  });

  const promise = new Promise((resolve, reject) => {
    window.continueTest2 = resolve;
    window.errorTest2 = reject;
  });

  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");
  });
}, "onclick that indirectly imports after a task should successfully import, using page's base URL");
</script>