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

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.');
yhirano 2014/09/01 08:36:30 Please place a blank line between the assertion of
horo 2014/09/01 09:03:17 Done.
310 request = new Request(URL, {method: 'POST', body: 'Test String'});
311 assert_equals(
312 getContentType(request.headers), 'text/plain;charset=UTF-8',
313 'ContentType header of Request created with string must be set.');
314 return request.body.asText();
315 })
316 .then(function(result) {
317 assert_equals(result, 'Test String',
318 'Creating a Request with string body should success.');
319 var text = "Test ArrayBuffer";
320 var array = new Uint8Array(text.length);
321 for (var i = 0; i < text.length; ++i)
322 array[i] = text.charCodeAt(i);
323 request = new Request(URL, {method: 'POST', body: array.buffer});
324 return request.body.asText();
325 })
326 .then(function(result) {
327 assert_equals(
328 result, 'Test ArrayBuffer',
329 'Creating a Request with ArrayBuffer body should success.');
330 var text = "Test ArrayBufferView";
331 var array = new Uint8Array(text.length);
332 for (var i = 0; i < text.length; ++i)
333 array[i] = text.charCodeAt(i);
334 request = new Request(URL, {method: 'POST', body: array});
335 return request.body.asText();
336 })
337 .then(function(result) {
338 assert_equals(
339 result, 'Test ArrayBufferView',
340 'Creating a Request with ArrayBuffer body should success.');
341 var formData = new FormData();
342 formData.append('sample string', '1234567890');
343 formData.append('sample blob', new Blob(['blob content']));
344 formData.append('sample file',
345 new File(['file content'], 'file.dat'));
346 request = new Request(URL, {method: 'POST', body: formData});
347 return request.body.asText();
348 })
349 .then(function(result) {
350 var reg = new RegExp('multipart\/form-data; boundary=(.*)');
351 var regResult = reg.exec(getContentType(request.headers));
352 var boundary = regResult[1];
353 var expected_body =
354 '--' + boundary + '\r\n' +
355 'Content-Disposition: form-data; name="sample string"\r\n' +
356 '\r\n' +
357 '1234567890\r\n' +
358 '--' + boundary + '\r\n' +
359 'Content-Disposition: form-data; name="sample blob"; ' +
360 'filename="blob"\r\n' +
361 'Content-Type: application/octet-stream\r\n' +
362 '\r\n' +
363 'blob content\r\n' +
364 '--' + boundary + '\r\n' +
365 'Content-Disposition: form-data; name="sample file"; ' +
366 'filename="file.dat"\r\n' +
367 'Content-Type: application/octet-stream\r\n' +
368 '\r\n' +
369 'file content\r\n' +
370 '--' + boundary + '--\r\n';
371 assert_equals(
372 result, expected_body,
373 'Creating a Request with FormData body should success.');
374 })
375 .then(function() {
376 t.done();
377 })
378 .catch(unreached_rejection(t));
379 }, '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