Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>connect-src-text-import-allowed</title>
<meta
http-equiv="Content-Security-Policy"
content="connect-src 'self'; script-src http://{{host}}:{{ports[http][0]}}/resources/testharness.js http://{{host}}:{{ports[http][0]}}/resources/testharnessreport.js 'unsafe-inline';"
/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<script>
promise_test(t => new Promise((resolve, reject) => {
window.addEventListener("securitypolicyviolation", (err) => {
if (err.blockedURI.endsWith("/common/text-plain.txt")) {
reject("Should not raise securitypolicyviolation.");
}
});
import("/common/text-plain.txt", { with: { type: "text" } }).then(resolve, reject)
}), "import should be allowed");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>connect-src-text-import-blocked</title>
<meta
http-equiv="Content-Security-Policy"
content="connect-src 'none'; script-src 'self' 'unsafe-inline';"
/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>

<body>
<script>
promise_test((t) => {
let check_spv = new Promise((resolve) => {
window.addEventListener("securitypolicyviolation", (e) => {
if (e.blockedURI.endsWith("text-plain.txt")) {
resolve();
}
});
});

return Promise.all([
promise_rejects_js(t, TypeError, import("/common/text-plain.txt", { with: { type: "text" } })),
check_spv,
]);
});
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions fetch/api/request/destination/fetch-destination.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@
});
}, 'Import declaration with `type: "json"` fetches with a "json" Request.destination');

// Text destination
///////////////////

// Import declaration with `type: "text"` - text destination
promise_test(t => {
return new Promise((resolve, reject) => {
frame.contentWindow.onerror = reject;
let node = frame.contentWindow.document.createElement("script");
node.onload = resolve;
node.onerror = reject;
node.src = "import-declaration-type-text.js";
node.type = "module";
frame.contentWindow.document.body.appendChild(node);
}).then(() => {
frame.contentWindow.onerror = null;
});
}, 'Import declaration with `type: "text"` fetches with a "text" Request.destination');

// Preload tests
////////////////
// HTMLLinkElement with rel=preload and as=fetch - empty string destination
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./dummy?dest=text" with { type: "text" };
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset="windows-1250">
<title>Text modules: UTF-8 decoding</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script type="module">
import text from "../serve-with-content-type.py?fn=text-module/utf-8.txt" with { type: "text" };
test(() => {
assert_true(text.startsWith("śćążź"));
}, "Text module should be loaded as utf-8 even though document's encoding is windows-1250");
</script>
<script type="module">
import text from "../serve-with-content-type.py?fn=text-module/windows-1250.txt&ct=text/plain%3Bcharset=windows-1250" with { type: "text" };
test(() => {
assert_false(text.startsWith("śćążź"), 'Should be decoded as UTF-8');
}, "Text module should be loaded as utf-8 even if it is encoded in windows-1250 and served with a windows-1250 charset response header, and this document's encoding is windows-1250");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// META: global=window,dedicatedworker,sharedworker
// META: script=/common/utils.js

promise_test(async () => {
const jsonModule = await import('./bom-utf-8.txt', { with: { type: 'text' } });
assert_equals(jsonModule.default, 'hello');
}, 'UTF-8 BOM should be stripped when decoding text module script');

promise_test(async test => {
await promise_rejects_js(test, SyntaxError,
import('./bom-utf-16be.txt', { with: { type: 'text' } }), 'Expected parse error from UTF-16BE BOM');
}, 'UTF-16BE BOM should result in parse error in text module script');
Comment thread
zcorpan marked this conversation as resolved.
Outdated

promise_test(async test => {
await promise_rejects_js(test, SyntaxError,
import('./bom-utf-16le.txt', { with: { type: 'text' } }), 'Expected parse error from UTF-16LE BOM');
}, 'UTF-16LE BOM should result in parse error in text module script');
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Text modules: UTF-8 decoding</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script type="module" onerror="unreachable()">
import text from "../serve-with-content-type.py?fn=text-module/utf-8.txt&ct=text/plain%3Bcharset=utf-8" with { type: "text" };
test(() => {
assert_true(text.startsWith("śćążź"));
}, "Text module should be loaded as utf-8 when charset=utf8 is specified");
</script>
<script type="module" onerror="unreachable()">
import text from "../serve-with-content-type.py?fn=text-module/utf-8.txt&ct=text/plain%3Bcharset=shift-jis" with { type: "text" };
test(() => {
assert_true(text.startsWith("śćążź"));
}, "Text module should be loaded as utf-8 when charset=shift-jis is specified");
</script>
<script type="module" onerror="unreachable()">
import text from "../serve-with-content-type.py?fn=text-module/utf-8.txt&ct=text/plain%3Bcharset=windows-1252" with { type: "text" };
test(() => {
assert_true(text.startsWith("śćążź"));
}, "Text module should be loaded as utf-8 when charset=windows-1252 is specified");
</script>
<script type="module" onerror="unreachable()">
import text from "../serve-with-content-type.py?fn=text-module/utf-8.txt&ct=text/plain%3Bcharset=utf-7" with { type: "text" };;
test(() => {
assert_true(text.startsWith("śćążź"));
}, "Text module should be loaded as utf-8 when charset=utf-7 is specified");
</script>
<script type="module" onerror="unreachable()">
import text from "../serve-with-content-type.py?fn=text-module/windows-1250.txt&ct=text/plain%3Bcharset=windows-1250" with { type: "text" };
test(() => {
assert_false(text.startsWith("śćążź"), 'Should be decoded as UTF-8');
}, "Text module should be loaded as utf-8 even if it is encoded in windows-1250 and served with a windows-1250 charset response header");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!doctype html>
<html>
<head>
<title>text-module-crossorigin</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>text-module-crossorigin</h1>
<script>

var tests = [
{ "obj": async_test("Imported text module, cross-origin with CORS"), "id": "import-WithCORS", "expected": "imported text: hello\n", "url": "crossorigin-import-with-cors.sub.html" },
{ "obj": async_test("Imported text module, cross-origin, missing CORS ACAO header"), "id": "import-NoCORS", "expected": "error", "url": "crossorigin-import-without-cors.sub.html" },
];

async function loadTest(test) {
return new Promise((resolve) => {
const iframe = document.createElement('iframe');
iframe.id = test.id;
iframe.src = test.url;
iframe.onload = () => resolve(iframe);
document.body.appendChild(iframe);
});
}

(async function () {
for (const test of tests) {
const target = await loadTest(test);
test.obj.step(function () {
assert_equals(target.contentDocument._log, test.expected, "Unexpected _log value");
});
test.obj.done();
}
})();

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<meta charset="utf-8">

<script type="module">
import text from "./cross-origin.py?id=sameOriginNoneDescendant&origin=http://{{host}}:{{ports[http][0]}}" with { type: "text" };
window.sameOriginNoneDescendant = text;
</script>
<script type="module" crossOrigin="anonymous">
import text from "./cross-origin.py?id=sameOriginAnonymousDescendant&origin=http://{{host}}:{{ports[http][0]}}" with { type: "text" };
window.sameOriginAnonymousDescendant = text;
</script>
<script type="module" crossOrigin="use-credentials">
import text from "./cross-origin.py?id=sameOriginUseCredentialsDescendant&origin=http://{{host}}:{{ports[http][0]}}" with { type: "text" };
window.sameOriginUseCredentialsDescendant = text;
</script>
<script type="module">
import text from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/text-module/cross-origin.py?id=crossOriginNoneDescendant&origin=http://{{host}}:{{ports[http][0]}}" with { type: "text" };
window.crossOriginNoneDescendant = text;
</script>
<script type="module" crossOrigin="anonymous">
import text from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/text-module/cross-origin.py?id=crossOriginAnonymousDescendant&origin=http://{{host}}:{{ports[http][0]}}" with { type: "text" };
window.crossOriginAnonymousDescendant = text;
</script>
<script type="module" crossOrigin="use-credentials">
import text from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/text-module/cross-origin.py?id=crossOriginUseCredentialsDescendant&origin=http://{{host}}:{{ports[http][0]}}" with { type: "text" };
window.crossOriginUseCredentialsDescendant = text;
</script>

<script type="text/javascript">
window.addEventListener('load', event => {
window.parent.postMessage({}, '*');
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
document.cookie = 'milk=1';

const setCookiePromise = fetch(
'http://{{domains[www2]}}:{{ports[http][0]}}/cookies/resources/set-cookie.py?name=milk&path=/html/semantics/scripting-1/the-script-element/text-module/',
{
mode: 'no-cors',
credentials: 'include',
});

const windowLoadPromise = new Promise(resolve => {
window.addEventListener('load', () => {
resolve();
});
});

promise_test(t => {
const iframe = document.createElement('iframe');

return Promise.all([setCookiePromise, windowLoadPromise]).then(() => {
const messagePromise = new Promise(resolve => {
window.addEventListener('message', event => {
resolve();
});
});

iframe.src = 'credentials-iframe.sub.html';
document.body.appendChild(iframe);

return messagePromise;
}).then(() => {
const w = iframe.contentWindow;

assert_equals(w.sameOriginNoneDescendant, 'request had cookies',
'Descendant text modules should be loaded with the credentials when the crossOrigin attribute is not specified and the target is same-origin');
assert_equals(w.sameOriginAnonymousDescendant, 'request had cookies',
'Descendant text modules should be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is same-origin');
assert_equals(w.sameOriginUseCredentialsDescendant, 'request had cookies',
'Descendant text modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is same-origin');
assert_equals(w.crossOriginNoneDescendant, 'request did not have cookies',
'Descendant text modules should not be loaded with the credentials when the crossOrigin attribute is not specified and the target is cross-origin');
assert_equals(w.crossOriginAnonymousDescendant, 'request did not have cookies',
'Descendant text modules should not be loaded with the credentials when the crossOrigin attribute is specified with "anonymous" as its value and the target is cross-origin');
assert_equals(w.crossOriginUseCredentialsDescendant, 'request had cookies',
'Descendant text modules should be loaded with the credentials when the crossOrigin attribute is specified with "use-credentials" as its value and the target is cross-origin');
});
}, 'Text Modules should be loaded with or without the credentials based on the same-origin-ness and the crossOrigin attribute');
</script>
<body>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def main(request, response):

headers = [
(b"Content-Type", b"text/plain"),
(b"Access-Control-Allow-Origin", request.GET.first(b"origin")),
(b"Access-Control-Allow-Credentials", b"true")
]

milk = request.cookies.first(b"milk", None)

if milk is not None and milk.value == b"1":
return headers, u'request had cookies'
else:
return headers, u'request did not have cookies'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>text-module-import-cross-domain-WithCORS</title>
<script src="../module/crossorigin-common.js"></script>
</head>
<body>
<h1>text-module-import-cross-domain-WithCORS</h1>
<script type="module" crossorigin>
import text from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/text-module/file.txt?pipe=header(Access-Control-Allow-Origin,*)" with { type: "text" };
// Push an event to the log indicating that the script was executed.
document._log.push(`imported text: ${text}`);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>text-module-import-cross-domain-NoCORS</title>
<script src="../module/crossorigin-common.js"></script>
</head>
<body>
<h1>text-module-import-cross-domain-NoCORS</h1>
<script type="module" onerror="document._log.push('error');">
import text from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/text-module/file.txt" with { type: "text" };
// Push an event to the log indicating that the script was executed.
document._log.push(`imported text: ${text}`);
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def main(request, response):
accept = request.headers.get(b"accept", b"")
response_headers = [(b"Content-Type", b"text/plain"),
(b"Access-Control-Allow-Origin", b"*")]
return (200, response_headers, accept)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>HTTP Accept header with text module requests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script type="module">
import text from "./http-accept-header-checker.py" with { type: "text"};
test(t => {
assert_equals(
text, "text/plain,*/*;q=0.5",
"The HTTP Accept header should be set to 'text/plain' when statically importing a text module.");
}, "Static import of a text module should send a valid HTTP Accept header.");
</script>

<script type="module">
promise_test(async () => {
const module = await import("./http-accept-header-checker.py", { with: { type: "text"} });
assert_equals(
module.default, "text/plain,*/*;q=0.5",
"The HTTP Accept header should be set to 'text/plain' when dynamically importing a text module.");
}, "Dynamic import of a text module should send a valid HTTP Accept header.");
</script>
</body>
</html>
Loading