-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON modules tests for charset, integrity, and MIME type parameters
Add JSON modules tests for the following: - The <script> element's integrity attribute is respected. - JSON modules are always decoded as UTF-8 regardless of Content-Type or the document's encoding. The existing coverage we had on this in utf8.tenative.html was renamed to charset.html, refactored, and expanded. - Adding parameters to the MIME type doesn't prevent it from being evaluated as a JSON MIME type. Note, some of the existing MIME type tests for */*+json still fail because it seems the spec issue on these at whatwg/mimesniff#112 hasn't been fully resolved. I'll follow up with that separately. Bug: 1132413 Change-Id: I682de01bbb14b53214fcc16f427a4875f8cfed7f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2841103 Reviewed-by: Domenic Denicola <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Dan Clark <[email protected]> Cr-Commit-Position: refs/heads/master@{#875274}
- Loading branch information
1 parent
99efbde
commit cda4273
Showing
10 changed files
with
106 additions
and
39 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
html/semantics/scripting-1/the-script-element/json-module/charset-2.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,19 @@ | ||
<!DOCTYPE html> | ||
<meta charset="windows-1250"> | ||
<title>JSON 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 json from "../serve-with-content-type.py?fn=json-module/utf-8.json" assert { type: "json"}; | ||
test(() => { | ||
assert_equals(json.data, "śćążź"); | ||
}, "JSON module should be loaded as utf-8 even though document's encoding is windows-1250"); | ||
</script> | ||
<script type="module"> | ||
import json from "../serve-with-content-type.py?fn=json-module/windows-1250.json&ct=text/json%3Bcharset=windows-1250" assert { type: "json"}; | ||
test(() => { | ||
assert_not_equals(json.data, "śćążź", | ||
'Should be decoded as UTF-8'); | ||
}, "JSON 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> |
37 changes: 37 additions & 0 deletions
37
html/semantics/scripting-1/the-script-element/json-module/charset.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,37 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<title>JSON 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 json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=utf-8" assert { type: "json"}; | ||
test(() => { | ||
assert_equals(json.data, "śćążź"); | ||
}, "JSON module should be loaded as utf-8 when charset=utf8 is specified"); | ||
</script> | ||
<script type="module" onerror="unreachable()"> | ||
import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=shift-jis" assert { type: "json"}; | ||
test(() => { | ||
assert_equals(json.data, "śćążź"); | ||
}, "JSON module should be loaded as utf-8 when charset=shift-jis is specified"); | ||
</script> | ||
<script type="module" onerror="unreachable()"> | ||
import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=windows-1252" assert { type: "json"}; | ||
test(() => { | ||
assert_equals(json.data, "śćążź"); | ||
}, "JSON module should be loaded as utf-8 when charset=windows-1252 is specified"); | ||
</script> | ||
<script type="module" onerror="unreachable()"> | ||
import json from "../serve-with-content-type.py?fn=json-module/utf-8.json&ct=text/json%3Bcharset=utf-7" assert { type: "json"};; | ||
test(() => { | ||
assert_equals(json.data, "śćążź"); | ||
}, "JSON module should be loaded as utf-8 when charset=utf-7 is specified"); | ||
</script> | ||
<script type="module" onerror="unreachable()"> | ||
import json from "../serve-with-content-type.py?fn=json-module/windows-1250.json&ct=text/json%3Bcharset=windows-1250" assert { type: "json"}; | ||
test(() => { | ||
assert_not_equals(json.data, "śćążź", | ||
'Should be decoded as UTF-8'); | ||
}, "JSON 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> |
2 changes: 2 additions & 0 deletions
2
html/semantics/scripting-1/the-script-element/json-module/integrity-matches.js
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,2 @@ | ||
import json from "./data.json" assert { type: "json" }; | ||
window.matchesLog.push(`integrity-matches,json:${json.answer}`); |
2 changes: 2 additions & 0 deletions
2
html/semantics/scripting-1/the-script-element/json-module/integrity-mismatches.js
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,2 @@ | ||
import json "./data.json" assert { type: "json" }; | ||
window.mismatchesLog.push(`integrity-mismatches,json:${json.answer}`); |
28 changes: 28 additions & 0 deletions
28
html/semantics/scripting-1/the-script-element/json-module/integrity.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,28 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title><script> integrity=""</title> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<script> | ||
window.matchesLog = []; | ||
window.matchesEvents = []; | ||
|
||
window.mismatchesLog = []; | ||
window.mismatchesEvents = []; | ||
</script> | ||
<script type="module" src="integrity-matches.js" integrity="sha384-VmQQfGzBiLKdyzw4FA4kL4ohu4tyujV68ddgW1aN/1v3cBZNNBn2gDFdVQxfL7+a" onload="window.matchesEvents.push('load');" onerror="window.matchesEvents.push('error')"></script> | ||
<script type="module" src="integrity-mismatches.js" integrity="sha384-doesnotmatch" onload="window.mismatchesEvents.push('load');" onerror="window.mismatchesEvents.push('error')"></script> | ||
|
||
<script type="module"> | ||
test(() => { | ||
assert_array_equals(window.matchesLog, ["integrity-matches,json:42"], "The module and its dependency must have executed"); | ||
assert_array_equals(window.matchesEvents, ["load"], "The load event must have fired"); | ||
}, "The integrity attribute must be verified on the top-level of a module loading a JSON module and allow it to execute when it matches"); | ||
|
||
test(() => { | ||
assert_array_equals(window.mismatchesLog, [], "The module and its dependency must not have executed"); | ||
assert_array_equals(window.mismatchesEvents, ["error"], "The error event must have fired"); | ||
}, "The integrity attribute must be verified on the top-level of a module loading a JSON module and not allow it to execute when there's a mismatch"); | ||
</script> |
4 changes: 4 additions & 0 deletions
4
html/semantics/scripting-1/the-script-element/json-module/utf-8.json
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,4 @@ | ||
{ | ||
"data": "śćążź", | ||
"comment": "The data above are five Polish letters, similar to scazz. It can be read correctly only with utf-8 encoding." | ||
} |
3 changes: 0 additions & 3 deletions
3
html/semantics/scripting-1/the-script-element/json-module/utf8.json
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
html/semantics/scripting-1/the-script-element/json-module/utf8.tentative.html
This file was deleted.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
html/semantics/scripting-1/the-script-element/json-module/windows-1250.json
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,4 @@ | ||
{ | ||
"data": "�湿�", | ||
"comment": "The data above are five Polish letters, similar to scazz. It can be read correctly only with windows1250 encoding." | ||
} |