Skip to content

Commit

Permalink
Bug 1508928 [wpt PR 14157] - Add tests for no active script in import…
Browse files Browse the repository at this point in the history
…(), a=testonly

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

Follows whatwg/html#4181.
--

wpt-commits: 5241a3fe2c638f9fadcc040f39f3e6a71a2be2e1
wpt-pr: 14157
  • Loading branch information
domenic authored and moz-wptsync-bot committed Dec 11, 2018
1 parent 737d896 commit d9c67b8
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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);");

0 comments on commit d9c67b8

Please sign in to comment.