From 2422c5a84691d3666c885243a4aaebe92012c77a Mon Sep 17 00:00:00 2001 From: Yoichi Osato Date: Thu, 25 Mar 2021 13:02:26 +0900 Subject: [PATCH 1/2] init --- fetch/api/basic/request-upload.any.js | 61 ----------------- fetch/api/basic/request-upload.h2.any.js | 83 ++++++++++++++++++++++++ fetch/api/resources/echo-content.h2.py | 9 +++ 3 files changed, 92 insertions(+), 61 deletions(-) create mode 100644 fetch/api/basic/request-upload.h2.any.js create mode 100644 fetch/api/resources/echo-content.h2.py diff --git a/fetch/api/basic/request-upload.any.js b/fetch/api/basic/request-upload.any.js index 82b1ac93c996dc..2b7c9bcf90e774 100644 --- a/fetch/api/basic/request-upload.any.js +++ b/fetch/api/basic/request-upload.any.js @@ -18,17 +18,6 @@ function testUpload(desc, url, method, createBody, expectedBody) { }, desc); } -function testUploadFailure(desc, url, method, createBody) { - const requestInit = {"method": method}; - promise_test(t => { - const body = createBody(); - if (body) { - requestInit["body"] = body; - } - return promise_rejects_js(t, TypeError, fetch(url, requestInit)); - }, desc); -} - const url = RESOURCES_DIR + "echo-content.py" testUpload("Fetch with PUT with body", url, @@ -75,56 +64,6 @@ testUpload("Fetch with POST with Blob body with mime type", url, "POST", () => new Blob(["Test"], { type: "text/maybe" }), "Test"); -testUpload("Fetch with POST with ReadableStream", url, - "POST", - () => { - return new ReadableStream({start: controller => { - const encoder = new TextEncoder(); - controller.enqueue(encoder.encode("Test")); - controller.close(); - }}) - }, - "Test"); -testUploadFailure("Fetch with POST with ReadableStream containing String", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue("Test"); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing null", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(null); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing number", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(99); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing ArrayBuffer", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(new ArrayBuffer()); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing Blob", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(new Blob()); - controller.close(); - }}) - }); promise_test(async (test) => { const resp = await fetch( diff --git a/fetch/api/basic/request-upload.h2.any.js b/fetch/api/basic/request-upload.h2.any.js new file mode 100644 index 00000000000000..23042ad3a1a539 --- /dev/null +++ b/fetch/api/basic/request-upload.h2.any.js @@ -0,0 +1,83 @@ +// META: global=window,worker +// META: script=../resources/utils.js +// META: script=/common/utils.js +// META: script=/common/get-host-info.sub.js + +function testUpload(desc, url, method, createBody, expectedBody) { + const requestInit = {"method": method} + promise_test(function(test){ + const body = createBody(); + if (body) { + requestInit["body"] = body; + } + return fetch(url, requestInit).then(function(resp) { + return resp.text().then((text)=> { + assert_equals(text, expectedBody); + }); + }); + }, desc); +} + +function testUploadFailure(desc, url, method, createBody) { + const requestInit = {"method": method}; + promise_test(t => { + const body = createBody(); + if (body) { + requestInit["body"] = body; + } + return promise_rejects_js(t, TypeError, fetch(url, requestInit)); + }, desc); +} + +const url = RESOURCES_DIR + "echo-content.h2.py" + +testUpload("Fetch with POST with ReadableStream", url, + "POST", + () => { + return new ReadableStream({start: controller => { + const encoder = new TextEncoder(); + controller.enqueue(encoder.encode("Test")); + controller.close(); + }}) + }, + "Test"); +testUploadFailure("Fetch with POST with ReadableStream containing String", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue("Test"); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing null", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(null); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing number", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(99); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing ArrayBuffer", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(new ArrayBuffer()); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing Blob", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(new Blob()); + controller.close(); + }}) + }); diff --git a/fetch/api/resources/echo-content.h2.py b/fetch/api/resources/echo-content.h2.py new file mode 100644 index 00000000000000..d3dcf596baeceb --- /dev/null +++ b/fetch/api/resources/echo-content.h2.py @@ -0,0 +1,9 @@ +from wptserve.utils import isomorphic_encode + +def handle_headers(frame, request, response): + response.status = 200 + response.headers.update([('Content-Type', 'text/plain')]) + response.write_status_headers() + +def handle_data(frame, request, response): + response.writer.write_data(frame.data) From 000e997b68373ac3856b52c3ec3d5f154a5f2526 Mon Sep 17 00:00:00 2001 From: Yoichi Osato Date: Mon, 29 Mar 2021 16:34:35 +0900 Subject: [PATCH 2/2] fix nit. Revert failure tests --- fetch/api/basic/request-upload.any.js | 54 +++++++++++++++++- fetch/api/basic/request-upload.h2.any.js | 70 +++++------------------- 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/fetch/api/basic/request-upload.any.js b/fetch/api/basic/request-upload.any.js index 2b7c9bcf90e774..ac2345d0eb91ab 100644 --- a/fetch/api/basic/request-upload.any.js +++ b/fetch/api/basic/request-upload.any.js @@ -4,7 +4,7 @@ // META: script=/common/get-host-info.sub.js function testUpload(desc, url, method, createBody, expectedBody) { - const requestInit = {"method": method} + const requestInit = {method}; promise_test(function(test){ const body = createBody(); if (body) { @@ -18,6 +18,17 @@ function testUpload(desc, url, method, createBody, expectedBody) { }, desc); } +function testUploadFailure(desc, url, method, createBody) { + const requestInit = {method}; + promise_test(t => { + const body = createBody(); + if (body) { + requestInit["body"] = body; + } + return promise_rejects_js(t, TypeError, fetch(url, requestInit)); + }, desc); +} + const url = RESOURCES_DIR + "echo-content.py" testUpload("Fetch with PUT with body", url, @@ -65,6 +76,47 @@ testUpload("Fetch with POST with Blob body with mime type", url, () => new Blob(["Test"], { type: "text/maybe" }), "Test"); +testUploadFailure("Fetch with POST with ReadableStream containing String", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue("Test"); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing null", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(null); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing number", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(99); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing ArrayBuffer", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(new ArrayBuffer()); + controller.close(); + }}) + }); +testUploadFailure("Fetch with POST with ReadableStream containing Blob", url, + "POST", + () => { + return new ReadableStream({start: controller => { + controller.enqueue(new Blob()); + controller.close(); + }}) + }); + promise_test(async (test) => { const resp = await fetch( "/fetch/connection-pool/resources/network-partition-key.py?" diff --git a/fetch/api/basic/request-upload.h2.any.js b/fetch/api/basic/request-upload.h2.any.js index 23042ad3a1a539..00b54150d6f2d9 100644 --- a/fetch/api/basic/request-upload.h2.any.js +++ b/fetch/api/basic/request-upload.h2.any.js @@ -4,80 +4,36 @@ // META: script=/common/get-host-info.sub.js function testUpload(desc, url, method, createBody, expectedBody) { - const requestInit = {"method": method} - promise_test(function(test){ + const requestInit = {method}; + promise_test(async function(){ const body = createBody(); if (body) { requestInit["body"] = body; } - return fetch(url, requestInit).then(function(resp) { - return resp.text().then((text)=> { - assert_equals(text, expectedBody); - }); - }); - }, desc); -} - -function testUploadFailure(desc, url, method, createBody) { - const requestInit = {"method": method}; - promise_test(t => { - const body = createBody(); - if (body) { - requestInit["body"] = body; - } - return promise_rejects_js(t, TypeError, fetch(url, requestInit)); + const resp = await fetch(url, requestInit); + const text = await resp.text(); + assert_equals(text, expectedBody); }, desc); } const url = RESOURCES_DIR + "echo-content.h2.py" -testUpload("Fetch with POST with ReadableStream", url, +testUpload("Fetch with POST with empty ReadableStream", url, "POST", () => { return new ReadableStream({start: controller => { - const encoder = new TextEncoder(); - controller.enqueue(encoder.encode("Test")); controller.close(); }}) }, - "Test"); -testUploadFailure("Fetch with POST with ReadableStream containing String", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue("Test"); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing null", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(null); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing number", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(99); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing ArrayBuffer", url, - "POST", - () => { - return new ReadableStream({start: controller => { - controller.enqueue(new ArrayBuffer()); - controller.close(); - }}) - }); -testUploadFailure("Fetch with POST with ReadableStream containing Blob", url, + ""); + +testUpload("Fetch with POST with ReadableStream", url, "POST", () => { return new ReadableStream({start: controller => { - controller.enqueue(new Blob()); + const encoder = new TextEncoder(); + controller.enqueue(encoder.encode("Test")); controller.close(); }}) - }); + }, + "Test");