Skip to content

Commit

Permalink
fixup! Add some initial tests for JSON modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed May 14, 2019
1 parent 535c067 commit 07042c1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["en", "try"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>JSON modules: invalid Content-Type</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
const content_types = [
"application/json+protobuf",
"application/json+blah",
"text/x-json",
"text/json+blah",
"application/blahjson",
"image/json",
];
for (const content_type of content_types) {
async_test(t => {
const script = document.createElement("script");
script.onerror = t.step_func_done();
script.onload = t.unreached_func("Should not load");
script.type = "module";
script.src = `module.json?pipe=header(Content-Type,${content_type})`;
document.body.appendChild(script);
}, content_type);
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// META: global=window,worker

for (const value of [null, true, false, "string"]) {
promise_test(async t => {
const result = await import(`./${value}.json`);
assert_equals(result, value);
}, `Non-object: ${value}`);
}

promise_test(async t => {
const result = await import("./array.json");
assert_array_equals(result, ["en", "try"]);
}, "Non-object: array");

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>JSON modules: Content-Type</title>
<title>JSON modules: parse error</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"string"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true

0 comments on commit 07042c1

Please sign in to comment.