-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add tests for text modules #56812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add tests for text modules #56812
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
11f9f40
Add tests for text modules
eemeli cead577
Use "text file\n" as test file contents to ensure syntax error if par…
eemeli cf28ee6
Add tests for import that's first JS, then text
eemeli 8526c06
Add tests for "Sec-Fetch-Dest: text" header
eemeli 09ac337
Merge branch 'master' into import-text
eemeli 3fab960
Fix UTF-16 tests
eemeli c0a0799
Add modulepreload tests for text modules
eemeli f38b17a
Merge branch 'master' into import-text
eemeli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
content-security-policy/connect-src/connect-src-text-import-allowed.sub.html
This file contains hidden or 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,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> |
31 changes: 31 additions & 0 deletions
31
content-security-policy/connect-src/connect-src-text-import-blocked.sub.html
This file contains hidden or 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,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> |
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
fetch/api/request/destination/resources/import-declaration-type-text.js
This file contains hidden or 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 @@ | ||
| import "./dummy?dest=text" with { type: "text" }; |
Binary file added
BIN
+14 Bytes
html/semantics/scripting-1/the-script-element/text-module/bom-utf-16be.txt
Binary file not shown.
Binary file added
BIN
+14 Bytes
html/semantics/scripting-1/the-script-element/text-module/bom-utf-16le.txt
Binary file not shown.
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/text-module/bom-utf-8.txt
This file contains hidden or 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 @@ | ||
| hello |
18 changes: 18 additions & 0 deletions
18
html/semantics/scripting-1/the-script-element/text-module/charset-2.html
This file contains hidden or 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,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> |
17 changes: 17 additions & 0 deletions
17
html/semantics/scripting-1/the-script-element/text-module/charset-bom.any.js
This file contains hidden or 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,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'); | ||
|
|
||
| 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'); | ||
36 changes: 36 additions & 0 deletions
36
html/semantics/scripting-1/the-script-element/text-module/charset.html
This file contains hidden or 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,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> |
39 changes: 39 additions & 0 deletions
39
html/semantics/scripting-1/the-script-element/text-module/cors-crossorigin-requests.html
This file contains hidden or 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,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> |
33 changes: 33 additions & 0 deletions
33
html/semantics/scripting-1/the-script-element/text-module/credentials-iframe.sub.html
This file contains hidden or 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,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> |
55 changes: 55 additions & 0 deletions
55
html/semantics/scripting-1/the-script-element/text-module/credentials.sub.html
This file contains hidden or 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,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> |
14 changes: 14 additions & 0 deletions
14
html/semantics/scripting-1/the-script-element/text-module/cross-origin.py
This file contains hidden or 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,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' |
15 changes: 15 additions & 0 deletions
15
...emantics/scripting-1/the-script-element/text-module/crossorigin-import-with-cors.sub.html
This file contains hidden or 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,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> |
15 changes: 15 additions & 0 deletions
15
...ntics/scripting-1/the-script-element/text-module/crossorigin-import-without-cors.sub.html
This file contains hidden or 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,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> |
This file contains hidden or 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 @@ | ||
| hello |
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/text-module/file.js
This file contains hidden or 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 @@ | ||
| hello |
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/text-module/file.json
This file contains hidden or 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 @@ | ||
| hello |
1 change: 1 addition & 0 deletions
1
html/semantics/scripting-1/the-script-element/text-module/file.txt
This file contains hidden or 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 @@ | ||
| hello |
5 changes: 5 additions & 0 deletions
5
html/semantics/scripting-1/the-script-element/text-module/http-accept-header-checker.py
This file contains hidden or 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,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) |
27 changes: 27 additions & 0 deletions
27
html/semantics/scripting-1/the-script-element/text-module/http-accept-header.sub.html
This file contains hidden or 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,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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.