From 6417d22f6d3b74671dd346014096ae49b08ae268 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 4 Oct 2019 18:22:13 +0000 Subject: [PATCH] Bug 1557436 [wpt PR 16734] - Add some initial tests for JSON modules., a=testonly Automatic update from web-platform-tests Add some initial tests for JSON modules. See . -- wp5At-commits: f510720b12c7d0dd3e0639bac35aceb237c2221c wpt-pr: 16734 UltraBlame original commit: d18767ce41b850b8929ad67e8367a5fb80eda67d --- .../the-script-element/json-module/array.json | 8 + .../the-script-element/json-module/false.json | 1 + .../json-module/invalid-content-type.html | 215 ++++++++ .../json-module/module.html | 170 ++++++ .../json-module/module.json | 7 + .../json-module/non-object.any.js | 99 ++++ .../the-script-element/json-module/null.json | 1 + .../json-module/parse-error.html | 181 +++++++ .../json-module/parse-error.json | 1 + .../json-module/string.json | 3 + .../the-script-element/json-module/true.json | 1 + .../the-script-element/json-module/utf8.html | 487 ++++++++++++++++++ .../the-script-element/json-module/utf8.json | 8 + .../json-module/valid-content-type.html | 467 +++++++++++++++++ 14 files changed, 1649 insertions(+) create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/array.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/false.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.html create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.html create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.js create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/null.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.html create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/string.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/true.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.html create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json create mode 100644 testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.html diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/array.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/array.json new file mode 100644 index 0000000000000..260592471ba05 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/array.json @@ -0,0 +1,8 @@ +[ +" +en +" +" +try +" +] diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/false.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/false.json new file mode 100644 index 0000000000000..c508d5366f70b --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/false.json @@ -0,0 +1 @@ +false diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.html new file mode 100644 index 0000000000000..8cef47e33e06e --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/invalid-content-type.html @@ -0,0 +1,215 @@ +< +! +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 +> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.html new file mode 100644 index 0000000000000..673aa4402c00d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.html @@ -0,0 +1,170 @@ +< +! +DOCTYPE +html +> +< +meta +charset += +utf +- +8 +> +< +title +> +JSON +modules +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +div +id += +log +> +< +/ +div +> +< +script +> +const +t += +async_test +( +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +/ +module +. +json +" +; +t +. +step +( +( +) += +> +{ +assert_equals +( +typeof +v +" +object +" +) +; +assert_array_equals +( +Object +. +keys +( +v +) +[ +" +test +" +] +) +; +assert_equals +( +v +. +test +true +) +; +t +. +done +( +) +; +} +) +; +< +/ +script +> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.json new file mode 100644 index 0000000000000..a11b1ba7fd7fc --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/module.json @@ -0,0 +1,7 @@ +{ +" +test +" +: +true +} diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.js new file mode 100644 index 0000000000000..3f8b7636ed05d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/non-object.any.js @@ -0,0 +1,99 @@ +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 +" +) +; diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/null.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/null.json new file mode 100644 index 0000000000000..19765bd501b63 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/null.json @@ -0,0 +1 @@ +null diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.html new file mode 100644 index 0000000000000..c152167d12230 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.html @@ -0,0 +1,181 @@ +< +! +DOCTYPE +html +> +< +meta +charset += +utf +- +8 +> +< +title +> +JSON +modules +: +parse +error +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +div +id += +log +> +< +/ +div +> +< +script +> +setup +( +{ +allow_uncaught_exception +: +true +} +) +; +async_test +( +t += +> +{ +window +. +addEventListener +( +" +error +" +t +. +step_func_done +( +e += +> +{ +assert_true +( +e +instanceof +ErrorEvent +" +ErrorEvent +" +) +; +assert_equals +( +e +. +filename +new +URL +( +" +parse +- +error +. +json +" +location +) +. +href +) +; +assert_true +( +e +. +error +instanceof +SyntaxError +" +SyntaxError +" +) +; +} +) +) +; +} +) +; +< +/ +script +> +< +script +type += +" +module +" +> +import +v +from +" +. +/ +parse +- +error +. +json +" +; +< +/ +script +> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.json new file mode 100644 index 0000000000000..98232c64fce93 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/parse-error.json @@ -0,0 +1 @@ +{ diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/string.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/string.json new file mode 100644 index 0000000000000..277d5bc4bacb5 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/string.json @@ -0,0 +1,3 @@ +" +string +" diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/true.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/true.json new file mode 100644 index 0000000000000..27ba77ddaf615 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/true.json @@ -0,0 +1 @@ +true diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.html new file mode 100644 index 0000000000000..7ceee072442cd --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.html @@ -0,0 +1,487 @@ +< +! +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 +> +function +check +( +t +v +) +{ +t +. +step +( +( +) += +> +{ +assert_equals +( +typeof +v +" +object +" +) +; +assert_array_equals +( +Object +. +keys +( +v +) +[ +" +test +" +] +) +; +assert_equals +( +v +. +test +" +\ +u2026 +" +) +; +t +. +done +( +) +; +} +) +; +} +const +t1 += +async_test +( +" +utf +- +8 +" +) +; +const +t2 += +async_test +( +" +shift +- +jis +" +) +; +const +t3 += +async_test +( +" +windows +- +1252 +" +) +; +const +t4 += +async_test +( +" +utf +- +7 +" +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t1 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +utf8 +. +json +& +ct += +text +/ +json +% +3Bcharset += +utf +- +8 +" +; +check +( +t1 +v +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t2 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +utf8 +. +json +& +ct += +text +/ +json +% +3Bcharset += +shift +- +jis +" +; +check +( +t2 +v +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t3 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +utf8 +. +json +& +ct += +text +/ +json +% +3Bcharset += +windows +- +1252 +" +; +check +( +t3 +v +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t4 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +utf8 +. +json +& +ct += +text +/ +json +% +3Bcharset += +utf +- +7 +" +; +check +( +t4 +v +) +; +< +/ +script +> diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json new file mode 100644 index 0000000000000..62f748058ba3c --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/utf8.json @@ -0,0 +1,8 @@ +{ +" +test +" +: +" +" +} diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.html new file mode 100644 index 0000000000000..a6f456f8ec52e --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type.html @@ -0,0 +1,467 @@ +< +! +DOCTYPE +html +> +< +meta +charset += +utf +- +8 +> +< +title +> +JSON +modules +: +Content +- +Type +< +/ +title +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +div +id += +log +> +< +/ +div +> +< +script +> +function +check +( +t +v +) +{ +t +. +step +( +( +) += +> +{ +assert_equals +( +typeof +v +" +object +" +) +; +assert_array_equals +( +Object +. +keys +( +v +) +[ +" +test +" +] +) +; +assert_equals +( +v +. +test +true +) +; +t +. +done +( +) +; +} +) +; +} +const +t1 += +async_test +( +" +text +/ +json +" +) +; +const +t2 += +async_test +( +" +application +/ +json +" +) +; +const +t3 += +async_test +( +" +text +/ +html ++ +json +" +) +; +const +t4 += +async_test +( +" +image +/ +svg ++ +json +" +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t1 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +module +. +json +& +ct += +text +/ +json +" +; +check +( +t1 +v +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t2 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +module +. +json +& +ct += +application +/ +json +" +; +check +( +t2 +v +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t3 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +module +. +json +& +ct += +text +/ +html ++ +json +" +; +check +( +t3 +v +) +; +< +/ +script +> +< +script +type += +" +module +" +onerror += +" +t4 +. +step +( +( +) += +> +assert_unreached +( +event +) +) +" +> +import +v +from +" +. +. +/ +serve +- +with +- +content +- +type +. +py +? +fn += +json +- +module +/ +module +. +json +& +ct += +image +/ +svg ++ +json +" +; +check +( +t4 +v +) +; +< +/ +script +>