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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after 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'); |
| 384 |
| 385 function evalJsonp(text) { |
| 386 return new Promise(function(resolve) { |
| 387 var report = resolve; |
| 388 // text must contain report() call. |
| 389 eval(text); |
| 390 }); |
| 391 } |
| 392 |
| 393 async_test(function(t) { |
| 394 var request = |
| 395 new Request('fetch-access-control.php', |
| 396 { |
| 397 method: 'POST', |
| 398 body: new Blob(['Test Blob'], {type: 'test/type'}) |
| 399 }); |
| 400 fetch(request) |
| 401 .then(function(response) { return response.body.asText(); }) |
| 402 .then(evalJsonp) |
| 403 .then(function(result) { |
| 404 assert_equals(result.method, 'POST'); |
| 405 assert_equals(result.body, 'Test Blob'); |
| 406 t.done(); |
| 407 }) |
| 408 .catch(unreached_rejection(t)); |
| 409 }, 'Fetch with Blob body test in ServiceWorkerGlobalScope'); |
| 410 |
| 411 async_test(function(t) { |
| 412 var request = new Request('fetch-access-control.php', |
| 413 {method: 'POST', body: 'Test String'}); |
| 414 fetch(request) |
| 415 .then(function(response) { return response.body.asText(); }) |
| 416 .then(evalJsonp) |
| 417 .then(function(result) { |
| 418 assert_equals(result.method, 'POST'); |
| 419 assert_equals(result.body, 'Test String'); |
| 420 t.done(); |
| 421 }) |
| 422 .catch(unreached_rejection(t)); |
| 423 }, 'Fetch with string body test in ServiceWorkerGlobalScope'); |
| 424 |
| 425 async_test(function(t) { |
| 426 var text = "Test ArrayBuffer"; |
| 427 var array = new Uint8Array(text.length); |
| 428 for (var i = 0; i < text.length; ++i) |
| 429 array[i] = text.charCodeAt(i); |
| 430 var request = new Request('fetch-access-control.php', |
| 431 {method: 'POST', body: array.buffer}); |
| 432 fetch(request) |
| 433 .then(function(response) { return response.body.asText(); }) |
| 434 .then(evalJsonp) |
| 435 .then(function(result) { |
| 436 assert_equals(result.method, 'POST'); |
| 437 assert_equals(result.body, 'Test ArrayBuffer'); |
| 438 t.done(); |
| 439 }) |
| 440 .catch(unreached_rejection(t)); |
| 441 }, 'Fetch with ArrayBuffer body test in ServiceWorkerGlobalScope'); |
| 442 |
| 443 async_test(function(t) { |
| 444 var text = "Test ArrayBufferView"; |
| 445 var array = new Uint8Array(text.length); |
| 446 for (var i = 0; i < text.length; ++i) |
| 447 array[i] = text.charCodeAt(i); |
| 448 var request = new Request('fetch-access-control.php', |
| 449 {method: 'POST', body: array}); |
| 450 fetch(request) |
| 451 .then(function(response) { return response.body.asText(); }) |
| 452 .then(evalJsonp) |
| 453 .then(function(result) { |
| 454 assert_equals(result.method, 'POST'); |
| 455 assert_equals(result.body, 'Test ArrayBufferView'); |
| 456 t.done(); |
| 457 }) |
| 458 .catch(unreached_rejection(t)); |
| 459 }, 'Fetch with ArrayBufferView body test in ServiceWorkerGlobalScope'); |
| 460 |
| 461 async_test(function(t) { |
| 462 var formData = new FormData(); |
| 463 formData.append('StringKey1', '1234567890'); |
| 464 formData.append('StringKey2', 'ABCDEFGHIJ'); |
| 465 formData.append('BlobKey', new Blob(['blob content'])); |
| 466 formData.append('FileKey', |
| 467 new File(['file content'], 'file.dat')); |
| 468 var request = new Request('fetch-access-control.php', |
| 469 {method: 'POST', body: formData}); |
| 470 fetch(request) |
| 471 .then(function(response) { return response.body.asText(); }) |
| 472 .then(evalJsonp) |
| 473 .then(function(result) { |
| 474 assert_equals(result.method, 'POST'); |
| 475 assert_equals(result.post['StringKey1'], '1234567890'); |
| 476 assert_equals(result.post['StringKey2'], 'ABCDEFGHIJ'); |
| 477 var files = []; |
| 478 for (var i = 0; i < result.files.length; ++i) { |
| 479 files[result.files[i].key] = result.files[i]; |
| 480 } |
| 481 assert_equals(files['BlobKey'].content, 'blob content'); |
| 482 assert_equals(files['BlobKey'].name, 'blob'); |
| 483 assert_equals(files['BlobKey'].size, 12); |
| 484 assert_equals(files['FileKey'].content, 'file content'); |
| 485 assert_equals(files['FileKey'].name, 'file.dat'); |
| 486 assert_equals(files['FileKey'].size, 12); |
| 487 t.done(); |
| 488 }) |
| 489 .catch(unreached_rejection(t)); |
| 490 }, 'Fetch with FormData body test in ServiceWorkerGlobalScope'); |
OLD | NEW |