From b2a6c8b54bdea4958544f672895ae7ae2ecb559f Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Oct 2019 23:56:22 +0000 Subject: [PATCH] Bug 1452928 [wpt PR 8449] - Add more XMLHttpRequest overrideMimeType() tests, a=testonly Automatic update from web-platform-testsAdd more XMLHttpRequest overrideMimeType() tests For https://github.com/whatwg/xhr/issues/157, https://github.com/whatwg/xhr/pull/174, and https://github.com/whatwg/mimesniff/issues/42. -- wpt-commits: ae41496630ba35cff974877498383f1280ca07c2 wpt-pr: 8449 UltraBlame original commit: a743786f569a9e77f8c86a2882abee702f58f981 --- testing/web-platform/meta/MANIFEST.json | 62 +++- .../mime-types/resources/mime-types.json | 28 ++ .../tests/xhr/overridemimetype-blob.html | 329 +++++++--------- .../xhr/overridemimetype-edge-cases.window.js | 350 ++++++++++++++++++ .../tests/xhr/responsetext-decoding.htm | 24 ++ 5 files changed, 596 insertions(+), 197 deletions(-) create mode 100644 testing/web-platform/tests/xhr/overridemimetype-edge-cases.window.js diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index fb18f50f5ce5..a6178657030a 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -2426213,6 +2426213,40 @@ xhr / overridemimetype - +edge +- +cases +. +window +. +js +" +: +[ +[ +" +/ +xhr +/ +overridemimetype +- +edge +- +cases +. +window +. +html +" +{ +} +] +] +" +xhr +/ +overridemimetype +- headers - received @@ -3863267,7 +3863301,7 @@ json : [ " -9271134541b22f4af44b6d179606c7a6cb8f3227 +b214e6025adc09d310f47eea34f2ea316f6132ec " " support @@ -4146648,7 +4146682,7 @@ html : [ " -462d95dec7146c2a7beba5d8b2285fd2b8460002 +38a7f6e2871ac0def651e5b82bb8a43b061633bb " " testharness @@ -4146679,6 +4146713,28 @@ xhr / overridemimetype - +edge +- +cases +. +window +. +js +" +: +[ +" +a76e1c81a86823765be280747d2fa6994395cc25 +" +" +testharness +" +] +" +xhr +/ +overridemimetype +- headers - received @@ -4149276,7 +4149332,7 @@ htm : [ " -538d6d5121157e04c44fd947140f2c913dc3b65e +d08dd5c1d0b21b639389dfc1deec65215b3334dc " " testharness diff --git a/testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json b/testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json index 0869ee8be1d2..a2b07b645923 100644 --- a/testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json +++ b/testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json @@ -2663,6 +2663,20 @@ input " : " +/ +" +" +output +" +: +null +} +{ +" +input +" +: +" bogus " " @@ -2757,6 +2771,20 @@ input " : " +/ +" +" +output +" +: +null +} +{ +" +input +" +: +" text / html diff --git a/testing/web-platform/tests/xhr/overridemimetype-blob.html b/testing/web-platform/tests/xhr/overridemimetype-blob.html index 5668357e2ceb..453b3853dfdd 100644 --- a/testing/web-platform/tests/xhr/overridemimetype-blob.html +++ b/testing/web-platform/tests/xhr/overridemimetype-blob.html @@ -93,6 +93,7 @@ XMLHttpRequest ( ) +; client . onload @@ -121,6 +122,7 @@ " " ) +; assert_equals ( client @@ -134,8 +136,10 @@ xml " ) +; } ) +; client . open @@ -151,6 +155,7 @@ py " ) +; client . responseType @@ -158,11 +163,13 @@ " blob " +; client . send ( ) +; } " Use @@ -175,6 +182,7 @@ type " ) +; async_test ( t @@ -188,6 +196,7 @@ XMLHttpRequest ( ) +; client . onload @@ -216,6 +225,7 @@ " " ) +; assert_equals ( client @@ -229,6 +239,7 @@ xml " ) +; } ) client @@ -250,6 +261,7 @@ thisshouldnotmakeadifferencebutdoes " ) +; client . responseType @@ -257,11 +269,13 @@ " blob " +; client . send ( ) +; } " Use @@ -275,230 +289,124 @@ 2 " ) -async_test -( -t -= -> -{ -const -client -= -new -XMLHttpRequest -( -) -client -. -onload -= -t -. -step_func_done +; +promise_test ( ( ) = > { -assert_equals -( -client +/ +/ +Don +' +t +load +generated +- +mime +- +types . -getResponseHeader +json +as +sending +them +all +over +the +network +would +be +prohibitive +return +fetch ( " -Content -- -Type -" -) -" -" -) -assert_equals -( -client . -response . -type -" -application / -octet +mimesniff +/ +mime - -stream -" -) -} -) -client -. -open -( -" -GET -" -" +types +/ resources / -status +mime +- +types . -py +json " ) -client . -responseType +then +( +res = -" -blob -" -client +> +res . -overrideMimeType +json ( -" -bogus -" ) -client +) . -send +then ( +runTests ) +; } " -Bogus -MIME -type -should -end -up -as -application -/ -octet -- -stream +Loading +data " ) -async_test -( -t -= -> -{ -const -client -= -new -XMLHttpRequest +; +function +runTests ( +tests ) -client -. -onload +{ +let +index = -t +0 +; +tests . -step_func_done +forEach ( ( +val ) = > { -assert_equals -( -client -. -getResponseHeader -( -" -Content -- -Type -" -) -" -" -) -assert_equals +if ( -client -. -response -. -type -" -application -/ -octet -- -stream -" -) -} -) -client -. -open -( -" -GET -" -" -resources -/ -status -. -py -" -) -client -. -responseType +typeof +val += = -" -blob -" -client -. -overrideMimeType -( -" -text -/ -xml -; -charset = " -) -client -. -send -( -) -} -" -Bogus -MIME -type -should -end -up -as -application -/ -octet -- -stream -2 +string " ) +{ +return +; +} +index ++ ++ +; async_test ( t @@ -512,6 +420,28 @@ XMLHttpRequest ( ) +expectedOutput += +val +. +output +! += += +null +? +val +. +output +: +" +application +/ +octet +- +stream +" +; client . onload @@ -540,6 +470,7 @@ " " ) +; assert_equals ( client @@ -547,14 +478,12 @@ response . type -" -hi -/ -x -" +expectedOutput ) +; } ) +; client . open @@ -570,6 +499,7 @@ py " ) +; client . responseType @@ -577,36 +507,47 @@ " blob " +; client . overrideMimeType ( -" -HI -/ -x -; -test -= -test -" +val +. +input ) +; client . send ( ) +; } +index ++ " -Valid +) MIME types need to be -normalized +parsed +and +serialized +: " ++ +val +. +input ) +; +} +) +; +} < / script diff --git a/testing/web-platform/tests/xhr/overridemimetype-edge-cases.window.js b/testing/web-platform/tests/xhr/overridemimetype-edge-cases.window.js new file mode 100644 index 000000000000..51f1629095e5 --- /dev/null +++ b/testing/web-platform/tests/xhr/overridemimetype-edge-cases.window.js @@ -0,0 +1,350 @@ +const +testURL += +" +resources +/ +status +. +py +? +type += +" ++ +encodeURIComponent +( +" +text +/ +plain +; +charset += +windows +- +1252 +" +) ++ +" +& +content += +% +C2 +% +F0 +" +; +async_test +( +t += +> +{ +const +client += +new +XMLHttpRequest +( +) +; +let +secondTime += +false +; +client +. +onload += +t +. +step_func +( +( +) += +> +{ +if +( +! +secondTime +) +{ +assert_equals +( +client +. +responseText +" +\ +uFFFD +" +) +; +secondTime += +true +; +client +. +open +( +" +GET +" +testURL +) +; +client +. +send +( +) +; +} +else +{ +assert_equals +( +client +. +responseText +" +" +) +; +t +. +done +( +) +; +} +} +) +; +client +. +open +( +" +GET +" +testURL +) +; +client +. +overrideMimeType +( +" +text +/ +plain +; +charset += +UTF +- +8 +" +) +client +. +send +( +) +; +} +" +overrideMimeType +( +) +state +needs +to +be +reset +across +requests +" +) +; +async_test +( +t += +> +{ +const +client += +new +XMLHttpRequest +( +) +; +client +. +onload += +t +. +step_func_done +( +( +) += +> +{ +assert_equals +( +client +. +responseText +" +" +) +} +) +; +client +. +open +( +" +GET +" +testURL +) +; +client +. +overrideMimeType +( +" +text +/ +xml +" +) +; +client +. +send +( +) +; +} +" +If +charset +is +not +overridden +by +overrideMimeType +( +) +the +original +continues +to +be +used +" +) +; +async_test +( +t += +> +{ +const +client += +new +XMLHttpRequest +( +) +; +client +. +onload += +t +. +step_func_done +( +( +) += +> +{ +assert_equals +( +client +. +responseText +" +\ +uFFFD +" +) +} +) +; +client +. +open +( +" +GET +" +testURL +) +; +client +. +overrideMimeType +( +" +text +/ +plain +; +charset += +342 +" +) +; +client +. +send +( +) +; +} +" +Charset +can +be +overridden +by +overrideMimeType +( +) +with +a +bogus +charset +" +) +; diff --git a/testing/web-platform/tests/xhr/responsetext-decoding.htm b/testing/web-platform/tests/xhr/responsetext-decoding.htm index 254bf3efef84..7a64ef96c140 100644 --- a/testing/web-platform/tests/xhr/responsetext-decoding.htm +++ b/testing/web-platform/tests/xhr/responsetext-decoding.htm @@ -1143,6 +1143,30 @@ " text / +plain +; +charset += +bogus +" +" +% +C2 +" +" +\ +uFFFD +" +" +text +" +) +; +request +( +" +text +/ xml " "