Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Unified Diff: LayoutTests/http/tests/serviceworker/resources/fetch-worker.js

Issue 533123002: [ServiceWorker] Send the body of Request in fetch() API. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: move tests to fetch-worker.js Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js b/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
index 6f29ce3df315b27dd94d95be37669013ac521bf2..c9433e606eacaeb61fc1910b25fcfe2b809aeaca 100644
--- a/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
+++ b/LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
@@ -32,6 +32,113 @@ async_test(function(t) {
.catch(unreached_rejection(t));
}, 'Fetch result of 404 response in ServiceWorkerGlobalScope');
+function evalJsonp(text) {
+ return new Promise(function(resolve) {
+ var report = resolve;
+ // text must contain report() call.
+ eval(text);
+ });
+}
+
+async_test(function(t) {
+ var request =
+ new Request('fetch-access-control.php',
+ {
+ method: 'POST',
+ body: new Blob(['Test Blob'], {type: 'test/type'})
+ });
+ fetch(request)
+ .then(function(response) { return response.body.asText(); })
+ .then(evalJsonp)
+ .then(function(result) {
+ assert_equals(result.method, 'POST');
+ assert_equals(result.body, 'Test Blob');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch with Blob body test in ServiceWorkerGlobalScope');
+
+async_test(function(t) {
+ var request = new Request('fetch-access-control.php',
+ {method: 'POST', body: 'Test String'});
+ fetch(request)
+ .then(function(response) { return response.body.asText(); })
+ .then(evalJsonp)
+ .then(function(result) {
+ assert_equals(result.method, 'POST');
+ assert_equals(result.body, 'Test String');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch with string body test in ServiceWorkerGlobalScope');
+
+async_test(function(t) {
+ var text = "Test ArrayBuffer";
+ var array = new Uint8Array(text.length);
+ for (var i = 0; i < text.length; ++i)
+ array[i] = text.charCodeAt(i);
+ var request = new Request('fetch-access-control.php',
+ {method: 'POST', body: array.buffer});
+ fetch(request)
+ .then(function(response) { return response.body.asText(); })
+ .then(evalJsonp)
+ .then(function(result) {
+ assert_equals(result.method, 'POST');
+ assert_equals(result.body, 'Test ArrayBuffer');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch with ArrayBuffer body test in ServiceWorkerGlobalScope');
+
+async_test(function(t) {
+ var text = "Test ArrayBufferView";
+ var array = new Uint8Array(text.length);
+ for (var i = 0; i < text.length; ++i)
+ array[i] = text.charCodeAt(i);
+ var request = new Request('fetch-access-control.php',
+ {method: 'POST', body: array});
+ fetch(request)
+ .then(function(response) { return response.body.asText(); })
+ .then(evalJsonp)
+ .then(function(result) {
+ assert_equals(result.method, 'POST');
+ assert_equals(result.body, 'Test ArrayBufferView');
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch with ArrayBufferView body test in ServiceWorkerGlobalScope');
+
+async_test(function(t) {
+ var formData = new FormData();
+ formData.append('StringKey1', '1234567890');
+ formData.append('StringKey2', 'ABCDEFGHIJ');
+ formData.append('BlobKey', new Blob(['blob content']));
+ formData.append('FileKey',
+ new File(['file content'], 'file.dat'));
+ var request = new Request('fetch-access-control.php',
+ {method: 'POST', body: formData});
+ fetch(request)
+ .then(function(response) { return response.body.asText(); })
+ .then(evalJsonp)
+ .then(function(result) {
+ assert_equals(result.method, 'POST');
+ assert_equals(result.post['StringKey1'], '1234567890');
+ assert_equals(result.post['StringKey2'], 'ABCDEFGHIJ');
+ var files = [];
+ for (var i = 0; i < result.files.length; ++i) {
+ files[result.files[i].key] = result.files[i];
+ }
+ assert_equals(files['BlobKey'].content, 'blob content');
+ assert_equals(files['BlobKey'].name, 'blob');
+ assert_equals(files['BlobKey'].size, 12);
+ assert_equals(files['FileKey'].content, 'file content');
+ assert_equals(files['FileKey'].name, 'file.dat');
+ assert_equals(files['FileKey'].size, 12);
+ t.done();
+ })
+ .catch(unreached_rejection(t));
+ }, 'Fetch with FormData body test in ServiceWorkerGlobalScope');
+
test(function(t) {
function runInfiniteFetchLoop() {
fetch('dummy.html')

Powered by Google App Engine
This is Rietveld 408576698