-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some dynamic import string compilation tests
Part of #7446.
- Loading branch information
Showing
4 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...pting-1/the-script-element/module/dynamic-import/string-compilation-base-url-classic.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>import() inside compiled strings uses the document base URL inside a classic script</title> | ||
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> | ||
|
||
<base href=".."> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<div id="dummy"></div> | ||
|
||
<script> | ||
function createTestPromise() { | ||
return new Promise((resolve, reject) => { | ||
window.continueTest = resolve; | ||
window.errorTest = reject; | ||
}); | ||
} | ||
|
||
const dummyDiv = document.querySelector("#dummy"); | ||
|
||
const evaluators = { | ||
eval, | ||
setTimeout, | ||
"the Function constructor"(x) { | ||
Function(x)(); | ||
}, | ||
"reflected inline event handlers"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.onclick(); | ||
}, | ||
"inline event handlers triggered via UA code"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.click(); // different from .**on**click() | ||
} | ||
}; | ||
|
||
for (const [label, evaluator] of Object.entries(evaluators)) { | ||
promise_test(t => { | ||
t.add_cleanup(() => { | ||
dummyDiv.removeAttribute("onclick"); | ||
delete window.evaluated_imports_a; | ||
}); | ||
|
||
const promise = createTestPromise(); | ||
|
||
evaluator(`import('./imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); | ||
|
||
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> |
56 changes: 56 additions & 0 deletions
56
...ipting-1/the-script-element/module/dynamic-import/string-compilation-base-url-module.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>import() inside compiled strings uses the document base URL inside a module script</title> | ||
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> | ||
|
||
<base href=".."> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<div id="dummy"></div> | ||
|
||
<script type="module"> | ||
function createTestPromise() { | ||
return new Promise((resolve, reject) => { | ||
window.continueTest = resolve; | ||
window.errorTest = reject; | ||
}); | ||
} | ||
|
||
const dummyDiv = document.querySelector("#dummy"); | ||
|
||
const evaluators = { | ||
eval, | ||
setTimeout, | ||
"the Function constructor"(x) { | ||
Function(x)(); | ||
}, | ||
"reflected inline event handlers"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.onclick(); | ||
}, | ||
"inline event handlers triggered via UA code"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.click(); // different from .**on**click() | ||
} | ||
}; | ||
|
||
for (const [label, evaluator] of Object.entries(evaluators)) { | ||
promise_test(t => { | ||
t.add_cleanup(() => { | ||
dummyDiv.removeAttribute("onclick"); | ||
delete window.evaluated_imports_a; | ||
}); | ||
|
||
const promise = createTestPromise(); | ||
|
||
evaluator(`import('./imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); | ||
|
||
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> |
54 changes: 54 additions & 0 deletions
54
...tics/scripting-1/the-script-element/module/dynamic-import/string-compilation-classic.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>import() inside compiled strings inside a classic script</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> | ||
|
||
<script> | ||
function createTestPromise() { | ||
return new Promise((resolve, reject) => { | ||
window.continueTest = resolve; | ||
window.errorTest = reject; | ||
}); | ||
} | ||
|
||
const dummyDiv = document.querySelector("#dummy"); | ||
|
||
const evaluators = { | ||
eval, | ||
setTimeout, | ||
"the Function constructor"(x) { | ||
Function(x)(); | ||
}, | ||
"reflected inline event handlers"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.onclick(); | ||
}, | ||
"inline event handlers triggered via UA code"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.click(); // different from .**on**click() | ||
} | ||
}; | ||
|
||
for (const [label, evaluator] of Object.entries(evaluators)) { | ||
promise_test(t => { | ||
t.add_cleanup(() => { | ||
dummyDiv.removeAttribute("onclick"); | ||
delete window.evaluated_imports_a; | ||
}); | ||
|
||
const promise = createTestPromise(); | ||
|
||
evaluator(`import('../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); | ||
|
||
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> |
54 changes: 54 additions & 0 deletions
54
...ntics/scripting-1/the-script-element/module/dynamic-import/string-compilation-module.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>import() inside compiled strings inside a module script</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> | ||
|
||
<script type="module"> | ||
function createTestPromise() { | ||
return new Promise((resolve, reject) => { | ||
window.continueTest = resolve; | ||
window.errorTest = reject; | ||
}); | ||
} | ||
|
||
const dummyDiv = document.querySelector("#dummy"); | ||
|
||
const evaluators = { | ||
eval, | ||
setTimeout, | ||
"the Function constructor"(x) { | ||
Function(x)(); | ||
}, | ||
"reflected inline event handlers"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.onclick(); | ||
}, | ||
"inline event handlers triggered via UA code"(x) { | ||
dummyDiv.setAttribute("onclick", x); | ||
dummyDiv.click(); // different from .**on**click() | ||
} | ||
}; | ||
|
||
for (const [label, evaluator] of Object.entries(evaluators)) { | ||
promise_test(t => { | ||
t.add_cleanup(() => { | ||
dummyDiv.removeAttribute("onclick"); | ||
delete window.evaluated_imports_a; | ||
}); | ||
|
||
const promise = createTestPromise(); | ||
|
||
evaluator(`import('../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`); | ||
|
||
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> |