From 5aa2a30f6011f0a2f53f669867102dd6b85b5b3b Mon Sep 17 00:00:00 2001 From: Harris Hancock Date: Mon, 9 Apr 2018 17:15:49 +0000 Subject: [PATCH] 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 | 2 +- .../fetch/api/request/request-disturbed.html | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index c2ccb6249e64a..d750f5da10f20 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -550837,7 +550837,7 @@ "testharness" ], "fetch/api/request/request-disturbed.html": [ - "47a1771e5ce32b63cf4b378a87c5d53ee486c246", + "62d53aaa3cefd7f76f315ab3f3aa1cd5d5a4e4a0", "testharness" ], "fetch/api/request/request-error.html": [ diff --git a/testing/web-platform/tests/fetch/api/request/request-disturbed.html b/testing/web-platform/tests/fetch/api/request/request-disturbed.html index 83a1a1f0e0c59..d247a7ff2db3b 100644 --- a/testing/web-platform/tests/fetch/api/request/request-disturbed.html +++ b/testing/web-platform/tests/fetch/api/request/request-disturbed.html @@ -48,6 +48,17 @@ 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; @@ -58,7 +69,7 @@ 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"); @@ -74,7 +85,7 @@ 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");