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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/request-worker.js

Issue 516603004: [ServiceWorker] Support setting body to Request object in ServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated yhirano's comment 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/modules/modules.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 importScripts('worker-test-harness.js'); 1 importScripts('worker-test-harness.js');
2 importScripts('test-helpers.js');
2 3
3 var URL = 'https://www.example.com/test.html'; 4 var URL = 'https://www.example.com/test.html';
4 5
5 test(function() { 6 test(function() {
6 var headers = new Headers; 7 var headers = new Headers;
7 headers.set('User-Agent', 'Mozilla/5.0'); 8 headers.set('User-Agent', 'Mozilla/5.0');
8 headers.set('Accept', 'text/html'); 9 headers.set('Accept', 'text/html');
9 headers.set('X-ServiceWorker-Test', 'request test field'); 10 headers.set('X-ServiceWorker-Test', 'request test field');
10 11
11 var request = new Request(URL, {method: 'GET', headers: headers}); 12 var request = new Request(URL, {method: 'GET', headers: headers});
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 }); 276 });
276 277
277 ['PATCH', 'MKCOL', 'CUSTOM', 'X-FILES'].forEach(function(method) { 278 ['PATCH', 'MKCOL', 'CUSTOM', 'X-FILES'].forEach(function(method) {
278 assert_equals(new Request(url, {method: method}).method, method, 279 assert_equals(new Request(url, {method: method}).method, method,
279 'method should not be changed when normalized: ' + method); 280 'method should not be changed when normalized: ' + method);
280 method = method.toLowerCase(); 281 method = method.toLowerCase();
281 assert_equals(new Request(url, {method: method}).method, method, 282 assert_equals(new Request(url, {method: method}).method, method,
282 'method should not be changed when normalized: ' + method); 283 'method should not be changed when normalized: ' + method);
283 }); 284 });
284 }, 'Request method names are normalized'); 285 }, 'Request method names are normalized');
286
287 async_test(function(t) {
288 var getContentType = function(headers) {
289 var content_type = '';
290 headers.forEach(function(value, key) {
291 if (key == 'content-type') {
292 content_type = value;
293 }
294 });
295 return content_type;
296 };
297 var request =
298 new Request(URL,
299 {
300 method: 'POST',
301 body: new Blob(['Test Blob'], {type: 'test/type'})
302 });
303 assert_equals(
304 getContentType(request.headers), 'test/type',
305 'ContentType header of Request created with Blob body must be set.');
306 request.body.asText()
307 .then(function(result) {
308 assert_equals(result, 'Test Blob',
309 'Creating a Request with Blob body should success.');
310
311 request = new Request(URL, {method: 'POST', body: 'Test String'});
312 assert_equals(
313 getContentType(request.headers), 'text/plain;charset=UTF-8',
314 'ContentType header of Request created with string must be set.');
315 return request.body.asText();
316 })
317 .then(function(result) {
318 assert_equals(result, 'Test String',
319 'Creating a Request with string body should success.');
320
321 var text = "Test ArrayBuffer";
322 var array = new Uint8Array(text.length);
323 for (var i = 0; i < text.length; ++i)
324 array[i] = text.charCodeAt(i);
325 request = new Request(URL, {method: 'POST', body: array.buffer});
326 return request.body.asText();
327 })
328 .then(function(result) {
329 assert_equals(
330 result, 'Test ArrayBuffer',
331 'Creating a Request with ArrayBuffer body should success.');
332
333 var text = "Test ArrayBufferView";
334 var array = new Uint8Array(text.length);
335 for (var i = 0; i < text.length; ++i)
336 array[i] = text.charCodeAt(i);
337 request = new Request(URL, {method: 'POST', body: array});
338 return request.body.asText();
339 })
340 .then(function(result) {
341 assert_equals(
342 result, 'Test ArrayBufferView',
343 'Creating a Request with ArrayBuffer body should success.');
344
345 var formData = new FormData();
346 formData.append('sample string', '1234567890');
347 formData.append('sample blob', new Blob(['blob content']));
348 formData.append('sample file',
349 new File(['file content'], 'file.dat'));
350 request = new Request(URL, {method: 'POST', body: formData});
351 return request.body.asText();
352 })
353 .then(function(result) {
354 var reg = new RegExp('multipart\/form-data; boundary=(.*)');
355 var regResult = reg.exec(getContentType(request.headers));
356 var boundary = regResult[1];
357 var expected_body =
358 '--' + boundary + '\r\n' +
359 'Content-Disposition: form-data; name="sample string"\r\n' +
360 '\r\n' +
361 '1234567890\r\n' +
362 '--' + boundary + '\r\n' +
363 'Content-Disposition: form-data; name="sample blob"; ' +
364 'filename="blob"\r\n' +
365 'Content-Type: application/octet-stream\r\n' +
366 '\r\n' +
367 'blob content\r\n' +
368 '--' + boundary + '\r\n' +
369 'Content-Disposition: form-data; name="sample file"; ' +
370 'filename="file.dat"\r\n' +
371 'Content-Type: application/octet-stream\r\n' +
372 '\r\n' +
373 'file content\r\n' +
374 '--' + boundary + '--\r\n';
375 assert_equals(
376 result, expected_body,
377 'Creating a Request with FormData body should success.');
378 })
379 .then(function() {
380 t.done();
381 })
382 .catch(unreached_rejection(t));
383 }, 'Request body test in ServiceWorkerGlobalScope');
OLDNEW
« no previous file with comments | « no previous file | Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698