Skip to content

Commit 5419f98

Browse files
authored
Add tests for text modules
This is to support the spec changes in: - https://github.com/tc39/proposal-import-text - whatwg/html#11933 - whatwg/fetch#1898 - w3c/webappsec-csp#794
1 parent d6c8b6f commit 5419f98

57 files changed

Lines changed: 1795 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>connect-src-text-import-allowed</title>
5+
<meta
6+
http-equiv="Content-Security-Policy"
7+
content="connect-src 'self'; script-src http://{{host}}:{{ports[http][0]}}/resources/testharness.js http://{{host}}:{{ports[http][0]}}/resources/testharnessreport.js 'unsafe-inline';"
8+
/>
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
</head>
12+
13+
<body>
14+
<script>
15+
promise_test(t => new Promise((resolve, reject) => {
16+
window.addEventListener("securitypolicyviolation", (err) => {
17+
if (err.blockedURI.endsWith("/common/text-plain.txt")) {
18+
reject("Should not raise securitypolicyviolation.");
19+
}
20+
});
21+
import("/common/text-plain.txt", { with: { type: "text" } }).then(resolve, reject)
22+
}), "import should be allowed");
23+
</script>
24+
</body>
25+
</html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>connect-src-text-import-blocked</title>
5+
<meta
6+
http-equiv="Content-Security-Policy"
7+
content="connect-src 'none'; script-src 'self' 'unsafe-inline';"
8+
/>
9+
<script src="/resources/testharness.js"></script>
10+
<script src="/resources/testharnessreport.js"></script>
11+
</head>
12+
13+
<body>
14+
<script>
15+
promise_test((t) => {
16+
let check_spv = new Promise((resolve) => {
17+
window.addEventListener("securitypolicyviolation", (e) => {
18+
if (e.blockedURI.endsWith("text-plain.txt")) {
19+
resolve();
20+
}
21+
});
22+
});
23+
24+
return Promise.all([
25+
promise_rejects_js(t, TypeError, import("/common/text-plain.txt", { with: { type: "text" } })),
26+
check_spv,
27+
]);
28+
});
29+
</script>
30+
</body>
31+
</html>

fetch/api/request/destination/fetch-destination.https.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@
228228
});
229229
}, 'Import declaration with `type: "json"` fetches with a "json" Request.destination');
230230

231+
// Text destination
232+
///////////////////
233+
234+
// Import declaration with `type: "text"` - text destination
235+
promise_test(t => {
236+
return new Promise((resolve, reject) => {
237+
frame.contentWindow.onerror = reject;
238+
let node = frame.contentWindow.document.createElement("script");
239+
node.onload = resolve;
240+
node.onerror = reject;
241+
node.src = "import-declaration-type-text.js";
242+
node.type = "module";
243+
frame.contentWindow.document.body.appendChild(node);
244+
}).then(() => {
245+
frame.contentWindow.onerror = null;
246+
});
247+
}, 'Import declaration with `type: "text"` fetches with a "text" Request.destination');
248+
231249
// Preload tests
232250
////////////////
233251
// HTMLLinkElement with rel=preload and as=fetch - empty string destination
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./dummy?dest=text" with { type: "text" };

0 commit comments

Comments
 (0)