diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/fetch/api/response/response-clone.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/fetch/api/response/response-clone.html')
-rw-r--r-- | testing/web-platform/tests/fetch/api/response/response-clone.html | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/api/response/response-clone.html b/testing/web-platform/tests/fetch/api/response/response-clone.html new file mode 100644 index 000000000..1efb4da5e --- /dev/null +++ b/testing/web-platform/tests/fetch/api/response/response-clone.html @@ -0,0 +1,98 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title>Response clone</title> + <meta name="help" href="https://fetch.spec.whatwg.org/#response"> + <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + </head> + <body> + <script src="../resources/utils.js"></script> + <script> + var defaultValues = { "type" : "default", + "url" : "", + "ok" : true, + "status" : 200, + "statusText" : "OK" + }; + + var response = new Response(); + var clonedResponse = response.clone(); + test(function() { + for (var attributeName in defaultValues) { + var expectedValue = defaultValues[attributeName]; + assert_equals(clonedResponse[attributeName], expectedValue, + "Expect default response." + attributeName + " is " + expectedValue); + } + }, "Check Response's clone with default values, without body"); + + var body = "This is response body"; + var headersInit = { "name" : "value" }; + var responseInit = { "status" : 200, + "statusText" : "GOOD", + "headers" : headersInit + }; + var response = new Response(body, responseInit); + var clonedResponse = response.clone(); + test(function() { + assert_equals(clonedResponse.status, responseInit["status"], + "Expect response.status is " + responseInit["status"]); + assert_equals(clonedResponse.statusText, responseInit["statusText"], + "Expect response.statusText is " + responseInit["statusText"]); + assert_equals(clonedResponse.headers.get("name"), "value", + "Expect response.headers has name:value header"); + }, "Check Response's clone has the expected attribute values"); + + promise_test(function(test) { + return validateStreamFromString(response.body.getReader(), body); + }, "Check orginal response's body after cloning"); + + promise_test(function(test) { + return validateStreamFromString(clonedResponse.body.getReader(), body); + }, "Check cloned response's body"); + + promise_test(function(test) { + var disturbedResponse = new Response("data"); + return disturbedResponse.text().then(function() { + assert_true(disturbedResponse.bodyUsed, "response is disturbed"); + assert_throws(new TypeError() , function() { disturbedResponse.clone(); }, + "Expect TypeError exception"); + }); + }, "Cannot clone a disturbed response"); + + promise_test(function(t) { + var clone; + var result; + var response; + return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) { + clone = res.clone(); + response = res; + return clone.arrayBuffer(); + }).then(function(r) { + assert_equals(r.byteLength, 26); + result = r; + return response.arrayBuffer(); + }).then(function(r) { + assert_array_equals(r, result, "cloned responses should provide the same data"); + }); + }, 'Cloned responses should provide the same data'); + + promise_test(function(t) { + var clone; + return fetch('../resources/trickle.py?count=2&delay=100').then(function(res) { + clone = res.clone(); + res.body.cancel(); + assert_true(res.bodyUsed); + assert_false(clone.bodyUsed); + return clone.arrayBuffer(); + }).then(function(r) { + assert_equals(r.byteLength, 26); + assert_true(clone.bodyUsed); + }); + }, 'Cancelling stream should not affect cloned one'); + + </script> + </body> +</html> |