| OLD | NEW |
| 1 importScripts('worker-test-harness.js'); | 1 importScripts('worker-test-harness.js'); |
| 2 importScripts('test-helpers.js'); | 2 importScripts('test-helpers.js'); |
| 3 | 3 |
| 4 var URL = 'https://www.example.com/test.html'; | 4 var URL = 'https://www.example.com/test.html'; |
| 5 | 5 |
| 6 test(function() { | 6 test(function() { |
| 7 var headers = new Headers; | 7 var headers = new Headers; |
| 8 headers.set('User-Agent', 'Mozilla/5.0'); | 8 headers.set('User-Agent', 'Mozilla/5.0'); |
| 9 headers.set('Accept', 'text/html'); | 9 headers.set('Accept', 'text/html'); |
| 10 headers.set('X-ServiceWorker-Test', 'request test field'); | 10 headers.set('X-ServiceWorker-Test', 'request test field'); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 }; | 296 }; |
| 297 var request = | 297 var request = |
| 298 new Request(URL, | 298 new Request(URL, |
| 299 { | 299 { |
| 300 method: 'POST', | 300 method: 'POST', |
| 301 body: new Blob(['Test Blob'], {type: 'test/type'}) | 301 body: new Blob(['Test Blob'], {type: 'test/type'}) |
| 302 }); | 302 }); |
| 303 assert_equals( | 303 assert_equals( |
| 304 getContentType(request.headers), 'test/type', | 304 getContentType(request.headers), 'test/type', |
| 305 'ContentType header of Request created with Blob body must be set.'); | 305 'ContentType header of Request created with Blob body must be set.'); |
| 306 request.body.asText() | 306 request.text() |
| 307 .then(function(result) { | 307 .then(function(result) { |
| 308 assert_equals(result, 'Test Blob', | 308 assert_equals(result, 'Test Blob', |
| 309 'Creating a Request with Blob body should success.'); | 309 'Creating a Request with Blob body should success.'); |
| 310 | 310 |
| 311 request = new Request(URL, {method: 'POST', body: 'Test String'}); | 311 request = new Request(URL, {method: 'POST', body: 'Test String'}); |
| 312 assert_equals( | 312 assert_equals( |
| 313 getContentType(request.headers), 'text/plain;charset=UTF-8', | 313 getContentType(request.headers), 'text/plain;charset=UTF-8', |
| 314 'ContentType header of Request created with string must be set.'); | 314 'ContentType header of Request created with string must be set.'); |
| 315 return request.body.asText(); | 315 return request.text(); |
| 316 }) | 316 }) |
| 317 .then(function(result) { | 317 .then(function(result) { |
| 318 assert_equals(result, 'Test String', | 318 assert_equals(result, 'Test String', |
| 319 'Creating a Request with string body should success.'); | 319 'Creating a Request with string body should success.'); |
| 320 | 320 |
| 321 var text = "Test ArrayBuffer"; | 321 var text = "Test ArrayBuffer"; |
| 322 var array = new Uint8Array(text.length); | 322 var array = new Uint8Array(text.length); |
| 323 for (var i = 0; i < text.length; ++i) | 323 for (var i = 0; i < text.length; ++i) |
| 324 array[i] = text.charCodeAt(i); | 324 array[i] = text.charCodeAt(i); |
| 325 request = new Request(URL, {method: 'POST', body: array.buffer}); | 325 request = new Request(URL, {method: 'POST', body: array.buffer}); |
| 326 return request.body.asText(); | 326 return request.text(); |
| 327 }) | 327 }) |
| 328 .then(function(result) { | 328 .then(function(result) { |
| 329 assert_equals( | 329 assert_equals( |
| 330 result, 'Test ArrayBuffer', | 330 result, 'Test ArrayBuffer', |
| 331 'Creating a Request with ArrayBuffer body should success.'); | 331 'Creating a Request with ArrayBuffer body should success.'); |
| 332 | 332 |
| 333 var text = "Test ArrayBufferView"; | 333 var text = "Test ArrayBufferView"; |
| 334 var array = new Uint8Array(text.length); | 334 var array = new Uint8Array(text.length); |
| 335 for (var i = 0; i < text.length; ++i) | 335 for (var i = 0; i < text.length; ++i) |
| 336 array[i] = text.charCodeAt(i); | 336 array[i] = text.charCodeAt(i); |
| 337 request = new Request(URL, {method: 'POST', body: array}); | 337 request = new Request(URL, {method: 'POST', body: array}); |
| 338 return request.body.asText(); | 338 return request.text(); |
| 339 }) | 339 }) |
| 340 .then(function(result) { | 340 .then(function(result) { |
| 341 assert_equals( | 341 assert_equals( |
| 342 result, 'Test ArrayBufferView', | 342 result, 'Test ArrayBufferView', |
| 343 'Creating a Request with ArrayBuffer body should success.'); | 343 'Creating a Request with ArrayBuffer body should success.'); |
| 344 | 344 |
| 345 var formData = new FormData(); | 345 var formData = new FormData(); |
| 346 formData.append('sample string', '1234567890'); | 346 formData.append('sample string', '1234567890'); |
| 347 formData.append('sample blob', new Blob(['blob content'])); | 347 formData.append('sample blob', new Blob(['blob content'])); |
| 348 formData.append('sample file', | 348 formData.append('sample file', |
| 349 new File(['file content'], 'file.dat')); | 349 new File(['file content'], 'file.dat')); |
| 350 request = new Request(URL, {method: 'POST', body: formData}); | 350 request = new Request(URL, {method: 'POST', body: formData}); |
| 351 return request.body.asText(); | 351 return request.text(); |
| 352 }) | 352 }) |
| 353 .then(function(result) { | 353 .then(function(result) { |
| 354 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); | 354 var reg = new RegExp('multipart\/form-data; boundary=(.*)'); |
| 355 var regResult = reg.exec(getContentType(request.headers)); | 355 var regResult = reg.exec(getContentType(request.headers)); |
| 356 var boundary = regResult[1]; | 356 var boundary = regResult[1]; |
| 357 var expected_body = | 357 var expected_body = |
| 358 '--' + boundary + '\r\n' + | 358 '--' + boundary + '\r\n' + |
| 359 'Content-Disposition: form-data; name="sample string"\r\n' + | 359 'Content-Disposition: form-data; name="sample string"\r\n' + |
| 360 '\r\n' + | 360 '\r\n' + |
| 361 '1234567890\r\n' + | 361 '1234567890\r\n' + |
| (...skipping 12 matching lines...) Expand all Loading... |
| 374 '--' + boundary + '--\r\n'; | 374 '--' + boundary + '--\r\n'; |
| 375 assert_equals( | 375 assert_equals( |
| 376 result, expected_body, | 376 result, expected_body, |
| 377 'Creating a Request with FormData body should success.'); | 377 'Creating a Request with FormData body should success.'); |
| 378 }) | 378 }) |
| 379 .then(function() { | 379 .then(function() { |
| 380 t.done(); | 380 t.done(); |
| 381 }) | 381 }) |
| 382 .catch(unreached_rejection(t)); | 382 .catch(unreached_rejection(t)); |
| 383 }, 'Request body test in ServiceWorkerGlobalScope'); | 383 }, 'Request body test in ServiceWorkerGlobalScope'); |
| OLD | NEW |