Bug 1444166 [wpt PR 9931] - Add used body replacement test for Request constructor, a=testonly
authorHarris Hancock <harris.hancock@gmail.com>
Mon, 09 Apr 2018 17:15:49 +0000
changeset 467104 ad7b8e6c381646d827339d34e4ac9db07654bcc8
parent 467103 bf9a721325b80509bdbbf23067255551986cb588
child 467105 56277a5c9dfd4865be0ea8fb74a10e156425de48
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1444166
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1444166 [wpt PR 9931] - Add used body replacement test for Request constructor, a=testonly Automatic update from web-platform-testsFetch: add used body replacement test for Request constructor See Fetch change https://github.com/whatwg/fetch/pull/675. Specifically, that PR allows Requests with disturbed bodies to be used as the first parameter to the Request constructor, as long as the RequestInit dictionary contains a body member with which to replace the used body. As of this writing, no browser implements this change. wpt-commits: e87f38097902e16348d4e17f4fe3bc2d0112bff1 wpt-pr: 9931 wpt-commits: e87f38097902e16348d4e17f4fe3bc2d0112bff1 wpt-pr: 9931
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/fetch/api/request/request-disturbed.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -550832,17 +550832,17 @@
    "0b7f4d7e51825b125b9ebcc56f6bcaf0b6791faf",
    "testharness"
   ],
   "fetch/api/request/request-consume.html": [
    "9525e1c130e6660020c5fedb434fa0efdf62db81",
    "testharness"
   ],
   "fetch/api/request/request-disturbed.html": [
-   "47a1771e5ce32b63cf4b378a87c5d53ee486c246",
+   "62d53aaa3cefd7f76f315ab3f3aa1cd5d5a4e4a0",
    "testharness"
   ],
   "fetch/api/request/request-error.html": [
    "ec4b12f1eca0a0c64c04269f67194cdc90571e0a",
    "testharness"
   ],
   "fetch/api/request/request-error.js": [
    "8a4d36d8d179473c04b1f640ebc898c1b10c4b1d",
--- a/testing/web-platform/tests/fetch/api/request/request-disturbed.html
+++ b/testing/web-platform/tests/fetch/api/request/request-disturbed.html
@@ -44,42 +44,53 @@
       }, "Check cloning a disturbed request");
 
       test(function() {
         assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
         assert_throws(new TypeError(), function() { new Request(bodyConsumed); });
       }, "Check creating a new request from a disturbed request");
 
       promise_test(function() {
+        assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
+        const originalBody = bodyConsumed.body;
+        const bodyReplaced = new Request(bodyConsumed, { body: "Replaced body" });
+        assert_not_equals(bodyReplaced.body, originalBody, "new request's body is new");
+        assert_false(bodyReplaced.bodyUsed, "bodyUsed is false when request is not disturbed");
+        return bodyReplaced.text().then(text => {
+          assert_equals(text, "Replaced body");
+        });
+      }, "Check creating a new request with a new body from a disturbed request");
+
+      promise_test(function() {
         var bodyRequest = new Request("", initValuesDict);
         const originalBody = bodyRequest.body;
         assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");
         var requestFromRequest = new Request(bodyRequest);
         assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");
         assert_equals(bodyRequest.body, originalBody, "body should not change");
         assert_not_equals(originalBody, undefined, "body should not be undefined");
         assert_not_equals(originalBody, null, "body should not be null");
         assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
-        return requestFromRequest.text(text => {
+        return requestFromRequest.text().then(text => {
           assert_equals(text, "Request's body");
         });
       }, "Input request used for creating new request became disturbed");
 
       promise_test(() => {
         const bodyRequest = new Request("", initValuesDict);
         const originalBody = bodyRequest.body;
         assert_false(bodyRequest.bodyUsed , "bodyUsed is false when request is not disturbed");
         const requestFromRequest = new Request(bodyRequest, { body : "init body" });
         assert_true(bodyRequest.bodyUsed , "bodyUsed is true when request is disturbed");
         assert_equals(bodyRequest.body, originalBody, "body should not change");
         assert_not_equals(originalBody, undefined, "body should not be undefined");
         assert_not_equals(originalBody, null, "body should not be null");
         assert_not_equals(requestFromRequest.body, originalBody, "new request's body is new");
 
-        return requestFromRequest.text(text => {
+        return requestFromRequest.text().then(text => {
           assert_equals(text, "init body");
         });
       }, "Input request used for creating new request became disturbed even if body is not used");
 
       promise_test(function(test) {
         assert_true(bodyConsumed.bodyUsed , "bodyUsed is true when request is disturbed");
         return promise_rejects(test, new TypeError(), bodyConsumed.blob());
       }, "Check consuming a disturbed request");