Bug 1508928 [wpt PR 14157] - Add tests for no active script in import(), a=testonly

Automatic update from web-platform-testsAdd tests for no active script in import() (#14157)

Follows https://github.com/whatwg/html/pull/4181.
--

wpt-commits: 5241a3fe2c638f9fadcc040f39f3e6a71a2be2e1
wpt-pr: 14157
This commit is contained in:
Domenic Denicola 2018-11-30 16:53:51 +00:00 коммит произвёл moz-wptsync-bot
Родитель 5c87a7966b
Коммит 28b299a4a9
3 изменённых файлов: 115 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,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>

Просмотреть файл

@ -0,0 +1,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" type="module"></script>
<script type="module">
"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>

Просмотреть файл

@ -0,0 +1,5 @@
"use strict";
document.querySelector("#button1").setAttribute("onclick", "import('../imports-a.js?label=button1').then(window.continueTest1, window.errorTest1)");
document.querySelector("#button2").setAttribute("onclick", "Promise.resolve(`import('../imports-a.js?label=button2')`).then(eval).then(window.continueTest2, window.errorTest2);");