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 async_test(function(t) { | 4 async_test(function(t) { |
5 fetch('http://') | 5 fetch('http://') |
6 .then( | 6 .then( |
7 unreached_rejection(t, 'fetch of invalid URL must fail'), | 7 unreached_rejection(t, 'fetch of invalid URL must fail'), |
8 function(e) { | 8 function(e) { |
9 assert_equals(e.message, 'Invalid URL'); | 9 assert_equals(e.message, 'Invalid URL'); |
10 t.done(); | 10 t.done(); |
(...skipping 14 matching lines...) Expand all Loading... |
25 async_test(function(t) { | 25 async_test(function(t) { |
26 fetch('fetch-status.php?status=404') | 26 fetch('fetch-status.php?status=404') |
27 .then(function(response) { | 27 .then(function(response) { |
28 assert_equals(response.status, 404); | 28 assert_equals(response.status, 404); |
29 assert_equals(response.statusText, 'Not Found'); | 29 assert_equals(response.statusText, 'Not Found'); |
30 t.done(); | 30 t.done(); |
31 }) | 31 }) |
32 .catch(unreached_rejection(t)); | 32 .catch(unreached_rejection(t)); |
33 }, 'Fetch result of 404 response in ServiceWorkerGlobalScope'); | 33 }, 'Fetch result of 404 response in ServiceWorkerGlobalScope'); |
34 | 34 |
| 35 function evalJsonp(text) { |
| 36 return new Promise(function(resolve) { |
| 37 var report = resolve; |
| 38 // text must contain report() call. |
| 39 eval(text); |
| 40 }); |
| 41 } |
| 42 |
| 43 async_test(function(t) { |
| 44 var request = |
| 45 new Request('fetch-access-control.php', |
| 46 { |
| 47 method: 'POST', |
| 48 body: new Blob(['Test Blob'], {type: 'test/type'}) |
| 49 }); |
| 50 fetch(request) |
| 51 .then(function(response) { return response.body.asText(); }) |
| 52 .then(evalJsonp) |
| 53 .then(function(result) { |
| 54 assert_equals(result.method, 'POST'); |
| 55 assert_equals(result.body, 'Test Blob'); |
| 56 t.done(); |
| 57 }) |
| 58 .catch(unreached_rejection(t)); |
| 59 }, 'Fetch with Blob body test in ServiceWorkerGlobalScope'); |
| 60 |
| 61 async_test(function(t) { |
| 62 var request = new Request('fetch-access-control.php', |
| 63 {method: 'POST', body: 'Test String'}); |
| 64 fetch(request) |
| 65 .then(function(response) { return response.body.asText(); }) |
| 66 .then(evalJsonp) |
| 67 .then(function(result) { |
| 68 assert_equals(result.method, 'POST'); |
| 69 assert_equals(result.body, 'Test String'); |
| 70 t.done(); |
| 71 }) |
| 72 .catch(unreached_rejection(t)); |
| 73 }, 'Fetch with string body test in ServiceWorkerGlobalScope'); |
| 74 |
| 75 async_test(function(t) { |
| 76 var text = "Test ArrayBuffer"; |
| 77 var array = new Uint8Array(text.length); |
| 78 for (var i = 0; i < text.length; ++i) |
| 79 array[i] = text.charCodeAt(i); |
| 80 var request = new Request('fetch-access-control.php', |
| 81 {method: 'POST', body: array.buffer}); |
| 82 fetch(request) |
| 83 .then(function(response) { return response.body.asText(); }) |
| 84 .then(evalJsonp) |
| 85 .then(function(result) { |
| 86 assert_equals(result.method, 'POST'); |
| 87 assert_equals(result.body, 'Test ArrayBuffer'); |
| 88 t.done(); |
| 89 }) |
| 90 .catch(unreached_rejection(t)); |
| 91 }, 'Fetch with ArrayBuffer body test in ServiceWorkerGlobalScope'); |
| 92 |
| 93 async_test(function(t) { |
| 94 var text = "Test ArrayBufferView"; |
| 95 var array = new Uint8Array(text.length); |
| 96 for (var i = 0; i < text.length; ++i) |
| 97 array[i] = text.charCodeAt(i); |
| 98 var request = new Request('fetch-access-control.php', |
| 99 {method: 'POST', body: array}); |
| 100 fetch(request) |
| 101 .then(function(response) { return response.body.asText(); }) |
| 102 .then(evalJsonp) |
| 103 .then(function(result) { |
| 104 assert_equals(result.method, 'POST'); |
| 105 assert_equals(result.body, 'Test ArrayBufferView'); |
| 106 t.done(); |
| 107 }) |
| 108 .catch(unreached_rejection(t)); |
| 109 }, 'Fetch with ArrayBufferView body test in ServiceWorkerGlobalScope'); |
| 110 |
| 111 async_test(function(t) { |
| 112 var formData = new FormData(); |
| 113 formData.append('StringKey1', '1234567890'); |
| 114 formData.append('StringKey2', 'ABCDEFGHIJ'); |
| 115 formData.append('BlobKey', new Blob(['blob content'])); |
| 116 formData.append('FileKey', |
| 117 new File(['file content'], 'file.dat')); |
| 118 var request = new Request('fetch-access-control.php', |
| 119 {method: 'POST', body: formData}); |
| 120 fetch(request) |
| 121 .then(function(response) { return response.body.asText(); }) |
| 122 .then(evalJsonp) |
| 123 .then(function(result) { |
| 124 assert_equals(result.method, 'POST'); |
| 125 assert_equals(result.post['StringKey1'], '1234567890'); |
| 126 assert_equals(result.post['StringKey2'], 'ABCDEFGHIJ'); |
| 127 var files = []; |
| 128 for (var i = 0; i < result.files.length; ++i) { |
| 129 files[result.files[i].key] = result.files[i]; |
| 130 } |
| 131 assert_equals(files['BlobKey'].content, 'blob content'); |
| 132 assert_equals(files['BlobKey'].name, 'blob'); |
| 133 assert_equals(files['BlobKey'].size, 12); |
| 134 assert_equals(files['FileKey'].content, 'file content'); |
| 135 assert_equals(files['FileKey'].name, 'file.dat'); |
| 136 assert_equals(files['FileKey'].size, 12); |
| 137 t.done(); |
| 138 }) |
| 139 .catch(unreached_rejection(t)); |
| 140 }, 'Fetch with FormData body test in ServiceWorkerGlobalScope'); |
| 141 |
35 test(function(t) { | 142 test(function(t) { |
36 function runInfiniteFetchLoop() { | 143 function runInfiniteFetchLoop() { |
37 fetch('dummy.html') | 144 fetch('dummy.html') |
38 .then(function() { runInfiniteFetchLoop(); }); | 145 .then(function() { runInfiniteFetchLoop(); }); |
39 } | 146 } |
40 runInfiniteFetchLoop(); | 147 runInfiniteFetchLoop(); |
41 }, | 148 }, |
42 'Destroying the execution context while fetch is happening should not ' + | 149 'Destroying the execution context while fetch is happening should not ' + |
43 'cause a crash.'); | 150 'cause a crash.'); |
OLD | NEW |