| Index: third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js
|
| index 107c0daaa3d5d130ddbc5c804a7d6f2f4721c2de..601a4bd6cb05c70e22e5a02fc81ec55c948ee6da 100644
|
| --- a/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js
|
| @@ -37,6 +37,7 @@ test(function() {
|
| 'http://localhost/' + encodeURIComponent('\uFFFD'),
|
| 'Request.url should have unmatched surrogates replaced.');
|
|
|
| + assert_equals(request.body, null, 'null body');
|
| request.method = 'POST';
|
| assert_equals(request.method, 'GET', 'Request.method should be readonly');
|
| }, 'Request basic test');
|
| @@ -355,26 +356,34 @@ test(function() {
|
| 'consumed.');
|
| }, 'Request construction without body behavior regardning "bodyUsed"');
|
|
|
| -test(function() {
|
| +promise_test(function() {
|
| var req = new Request(URL, {method: 'POST', body: 'hello'});
|
| assert_false(req.bodyUsed,
|
| 'Request should not be flagged as used if it has not been ' +
|
| 'consumed.');
|
| + const originalBody = req.body;
|
| + assert_not_equals(req.body, null, 'Request body');
|
| var req2 = new Request(req);
|
| assert_true(req.bodyUsed,
|
| 'Request should be flagged as used if it has been consumed.');
|
| assert_false(req2.bodyUsed,
|
| 'Request should not be flagged as used if it has not been ' +
|
| 'consumed.');
|
| + assert_equals(req.body, originalBody,
|
| + 'The body property must not change.');
|
| + assert_not_equals(req.body, req2.body,
|
| + 'A new Request has a new body property');
|
| // See https://crbug.com/501195.
|
| assert_throws(
|
| {name: 'TypeError'},
|
| function() { new Request(req); },
|
| 'Request construction should throw if used.');
|
| - }, 'Request construction without body behavior regardning "bodyUsed"');
|
| + }, 'Request construction regarding "body" and "bodyUsed"');
|
|
|
| test(function() {
|
| var req = new Request(URL, {method: 'POST', body: 'hello'});
|
| + const originalBody = req.body;
|
| + assert_not_equals(req.body, null, 'Request body');
|
| assert_false(req.bodyUsed,
|
| 'Request should not be flagged as used if it has not been ' +
|
| 'consumed.');
|
| @@ -384,6 +393,8 @@ test(function() {
|
| 'A get request may not have body.');
|
|
|
| assert_false(req.bodyUsed, 'After the GET case');
|
| + assert_equals(req.body, originalBody,
|
| + 'After the GET case: The body property must not change.');
|
|
|
| assert_throws(
|
| {name: 'TypeError'},
|
| @@ -391,6 +402,9 @@ test(function() {
|
| 'Request() with a forbidden method must throw.');
|
|
|
| assert_false(req.bodyUsed, 'After the forbidden method case');
|
| + assert_equals(req.body, originalBody,
|
| + 'After the forbidden method case: ' +
|
| + 'The body property must not change.');
|
|
|
| var req2 = new Request(req);
|
| assert_true(req.bodyUsed,
|
| @@ -742,7 +756,6 @@ promise_test(function(t) {
|
| assert_equals(req.headers.get('Content-Type'), 'text/plain');
|
| });
|
| }, 'MIME type for Blob with non-empty type');
|
| -
|
| promise_test(function(t) {
|
| var req = new Request('http://localhost/',
|
| {method: 'POST', body: new FormData()});
|
| @@ -819,4 +832,97 @@ promise_test(function(t) {
|
| });
|
| }, 'Credentials and body can both be set.');
|
|
|
| +promise_test(() => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
|
| + controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
|
| + controller.close();
|
| + assert_false(stream.locked);
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + assert_equals(request.body, stream, 'body property');
|
| + var p = request.text().then(t => {
|
| + assert_equals(t, 'helloworld');
|
| + });
|
| + assert_true(stream.locked);
|
| + return p;
|
| + }, 'Request constructed with a stream');
|
| +
|
| +promise_test(() => {
|
| + const request = new Request(URL, {method: 'POST', body: 'hello'});
|
| + return readableStreamToArray(request.body).then(chunks => {
|
| + const decoder = new TextDecoder('utf-8');
|
| + let r = '';
|
| + for (const chunk of chunks) {
|
| + r += decoder.decode(chunk, {stream: true});
|
| + }
|
| + r += decoder.decode();
|
| + assert_equals(r, 'hello');
|
| + });
|
| + }, 'Request constructed with a String / Read from body stream');
|
| +
|
| +promise_test(() => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
|
| + controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
|
| + controller.close();
|
| +
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + return readableStreamToArray(request.body).then(chunks => {
|
| + var decoder = new TextDecoder('utf-8');
|
| + var r = '';
|
| + for (var chunk of chunks) {
|
| + r += decoder.decode(chunk, {stream: true});
|
| + }
|
| + r += decoder.decode();
|
| + assert_equals(r, 'helloworld');
|
| + });
|
| + }, 'Request constructed with a stream / Read from body stream');
|
| +
|
| +promise_test(t => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + setTimeout(() => {
|
| + controller.enqueue(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
|
| + controller.enqueue(new Uint8Array([0x77, 0x6f, 0x72, 0x6c, 0x64]));
|
| + controller.error();
|
| + }, 1);
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + return promise_rejects(t, TypeError(), request.text());
|
| + }, 'Response constructed with an errored stream');
|
| +
|
| +promise_test(t => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + stream.getReader();
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + return promise_rejects(t, TypeError(), request.text());
|
| + }, 'Request constructed with a locked stream');
|
| +
|
| +promise_test(t => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + setTimeout(() => controller.enqueue(), 1);
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + return promise_rejects(t, TypeError(), request.text());
|
| + }, 'Request constructed stream with an undefined chunk');
|
| +
|
| +promise_test(t => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + setTimeout(() => controller.enqueue(null), 1);
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + return promise_rejects(t, TypeError(), request.text());
|
| + }, 'Request constructed stream with a null chunk');
|
| +
|
| +promise_test(t => {
|
| + var controller;
|
| + var stream = new ReadableStream({start: c => controller = c});
|
| + setTimeout(() => controller.enqueue('hello'), 1);
|
| + var request = new Request(URL, {method: 'POST', body: stream});
|
| + return promise_rejects(t, TypeError(), request.text());
|
| + }, 'Request constructed stream with a string chunk');
|
| +
|
| +
|
| done();
|
|
|