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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
<!doctype html>
<meta charset=utf-8>
<title>Check import() works when active script is in another document</title>
<link rel="author" title="Jon Coppeard" href="mailto:jcoppeard@mozilla.com">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<iframe id="frame" src="resources/empty-iframe.html"></iframe>
<script>
function startTest() {
const otherWindow = document.getElementById("frame").contentWindow;
const otherDiv = otherWindow.document.getElementById("dummy");
function createTestPromise() {
return new Promise((resolve, reject) => {
otherWindow.continueTest = resolve;
otherWindow.errorTest = reject;
});
}
const evaluators = {
eval: otherWindow.eval,
setTimeout: otherWindow.setTimeout,
"the Function constructor"(x) {
otherWindow.Function(x)();
},
};
for (const [label, evaluator] of Object.entries(evaluators)) {
promise_test(t => {
t.add_cleanup(() => {
otherDiv.removeAttribute("onclick");
delete otherWindow.evaluated_imports_a;
});
const promise = createTestPromise();
evaluator(`import('../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`);
return promise.then(module => {
assert_true(otherWindow.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");
};
const eventHandlerEvaluators = {
"reflected inline event handlers"(x) {
otherDiv.setAttribute("onclick", x);
otherDiv.onclick();
},
"inline event handlers triggered by JS"(x) {
otherDiv.setAttribute("onclick", x);
otherDiv.click(); // different from .**on**click()
}
};
for (const [label, evaluator] of Object.entries(eventHandlerEvaluators)) {
promise_test(t => {
t.add_cleanup(() => {
otherDiv.removeAttribute("onclick");
delete otherWindow.evaluated_imports_a;
});
const promise = createTestPromise();
evaluator(`import('../../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`);
return promise.then(module => {
assert_true(otherWindow.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>
<body onLoad="startTest()"></body>
|