Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 if (self.importScripts) { | 1 if (self.importScripts) { |
| 2 importScripts('/resources/testharness.js'); | 2 importScripts('/resources/testharness.js'); |
| 3 importScripts('/resources/testharness-helpers.js'); | 3 importScripts('/resources/testharness-helpers.js'); |
| 4 importScripts('../resources/test-helpers.js'); | 4 importScripts('../resources/test-helpers.js'); |
| 5 } | 5 } |
| 6 | 6 |
| 7 cache_test(function(cache) { | 7 cache_test(function(cache) { |
| 8 return assert_promise_rejects( | 8 return assert_promise_rejects( |
| 9 cache.add(), | 9 cache.add(), |
| 10 new TypeError(), | 10 new TypeError(), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 cache_test(function(cache) { | 91 cache_test(function(cache) { |
| 92 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h tml | 92 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h tml |
| 93 var urls = ['../resources/simple.txt', undefined, '../resources/blank.html'] ; | 93 var urls = ['../resources/simple.txt', undefined, '../resources/blank.html'] ; |
| 94 return assert_promise_rejects( | 94 return assert_promise_rejects( |
| 95 cache.addAll(), | 95 cache.addAll(), |
| 96 new TypeError(), | 96 new TypeError(), |
| 97 'Cache.addAll should throw TypeError for an undefined argument.'); | 97 'Cache.addAll should throw TypeError for an undefined argument.'); |
| 98 }, 'Cache.addAll with a mix of valid and undefined arguments'); | 98 }, 'Cache.addAll with a mix of valid and undefined arguments'); |
| 99 | 99 |
| 100 cache_test(function(cache) { | 100 cache_test(function(cache) { |
| 101 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h tml | 101 // Assumes the existence of ../resources/simple.txt and |
| 102 var urls = ['../resources/simple.txt', self.location.href, '../resources/bla nk.html']; | 102 // ../resources/blank.html |
| 103 var urls = ['../resources/simple.txt', | |
| 104 self.location.href, | |
| 105 '../resources/blank.html']; | |
| 103 return cache.addAll(urls) | 106 return cache.addAll(urls) |
| 104 .then(function(result) { | 107 .then(function(result) { |
| 105 assert_equals(result, undefined, | 108 assert_equals(result, undefined, |
| 106 'Cache.addAll should resolve with undefined on ' + | 109 'Cache.addAll should resolve with undefined on ' + |
| 107 'success.'); | 110 'success.'); |
| 111 return Promise.all( | |
| 112 urls.map(function(url) { return cache.match(url); })); | |
|
jkarlin
2015/06/26 19:40:28
This and all of the Promise.all( lines, 2 space in
nhiroki
2015/07/02 09:31:54
Right. Fixed.
| |
| 113 }) | |
| 114 .then(function(responses) { | |
| 115 assert_class_string( | |
| 116 responses[0], 'Response', | |
| 117 'Cache.addAll should put a resource in the cache.'); | |
| 118 assert_class_string( | |
| 119 responses[1], 'Response', | |
| 120 'Cache.addAll should put a resource in the cache.'); | |
| 121 assert_class_string( | |
| 122 responses[2], 'Response', | |
| 123 'Cache.addAll should put a resource in the cache.'); | |
| 124 return Promise.all( | |
| 125 responses.map(function(response) { return response.text(); })); | |
| 126 }) | |
| 127 .then(function(bodies) { | |
| 128 assert_equals( | |
| 129 bodies[0], 'a simple text file\n', | |
| 130 'Cache.add should retrieve the correct body.'); | |
| 131 assert_equals( | |
| 132 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', | |
| 133 'Cache.add should retrieve the correct body.'); | |
| 108 }); | 134 }); |
| 109 }, 'Cache.addAll with string URL arguments'); | 135 }, 'Cache.addAll with string URL arguments'); |
| 110 | 136 |
| 111 cache_test(function(cache) { | 137 cache_test(function(cache) { |
| 112 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h tml | 138 // Assumes the existence of ../resources/simple.txt and |
| 113 var urls = ['../resources/simple.txt', self.location.href, '../resources/bla nk.html']; | 139 // ../resources/blank.html |
| 114 var requests = urls.map(function(url) { | 140 var urls = ['../resources/simple.txt', |
| 115 return new Request(url); | 141 self.location.href, |
| 116 }); | 142 '../resources/blank.html']; |
| 143 var requests = urls.map(function(url) { return new Request(url); }); | |
| 117 return cache.addAll(requests) | 144 return cache.addAll(requests) |
| 118 .then(function(result) { | 145 .then(function(result) { |
| 119 assert_equals(result, undefined, | 146 assert_equals(result, undefined, |
| 120 'Cache.addAll should resolve with undefined on ' + | 147 'Cache.addAll should resolve with undefined on ' + |
| 121 'success.'); | 148 'success.'); |
| 149 return Promise.all( | |
| 150 urls.map(function(url) { return cache.match(url); })); | |
| 151 }) | |
| 152 .then(function(responses) { | |
| 153 assert_class_string( | |
| 154 responses[0], 'Response', | |
| 155 'Cache.addAll should put a resource in the cache.'); | |
| 156 assert_class_string( | |
| 157 responses[1], 'Response', | |
| 158 'Cache.addAll should put a resource in the cache.'); | |
| 159 assert_class_string( | |
| 160 responses[2], 'Response', | |
| 161 'Cache.addAll should put a resource in the cache.'); | |
| 162 return Promise.all( | |
| 163 responses.map(function(response) { return response.text(); })); | |
| 164 }) | |
| 165 .then(function(bodies) { | |
| 166 assert_equals( | |
| 167 bodies[0], 'a simple text file\n', | |
| 168 'Cache.add should retrieve the correct body.'); | |
| 169 assert_equals( | |
| 170 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', | |
| 171 'Cache.add should retrieve the correct body.'); | |
| 122 }); | 172 }); |
| 123 }, 'Cache.addAll with Request arguments'); | 173 }, 'Cache.addAll with Request arguments'); |
| 124 | 174 |
| 125 cache_test(function(cache) { | 175 cache_test(function(cache) { |
| 126 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. T he second | 176 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. |
| 127 // resource does not. | 177 // The second resource does not. |
| 128 var urls = ['../resources/simple.txt', 'this-resource-should-not-exist', '.. /resources/blank.html']; | 178 var urls = ['../resources/simple.txt', |
| 129 var requests = urls.map(function(url) { | 179 'this-resource-should-not-exist', |
| 130 return new Request(url); | 180 '../resources/blank.html']; |
| 131 }); | 181 var requests = urls.map(function(url) { return new Request(url); }); |
| 132 return cache.addAll(requests) | 182 return cache.addAll(requests) |
| 133 .then(function(result) { | 183 .then(function(result) { |
| 134 assert_equals(result, undefined, | 184 assert_equals(result, undefined, |
| 135 'Cache.addAll should resolve with undefined on ' + | 185 'Cache.addAll should resolve with undefined on ' + |
| 136 'success.'); | 186 'success.'); |
| 187 return Promise.all( | |
| 188 urls.map(function(url) { return cache.match(url); })); | |
| 189 }) | |
| 190 .then(function(responses) { | |
| 191 assert_class_string( | |
| 192 responses[0], 'Response', | |
| 193 'Cache.addAll should put a resource in the cache.'); | |
| 194 assert_class_string( | |
| 195 responses[1], 'Response', | |
| 196 'Cache.addAll should put a resource in the cache.'); | |
| 197 assert_equals( | |
| 198 responses[1].status, 404, | |
| 199 'Cache.addAll should put a 404 resource in the cache.'); | |
| 200 assert_class_string( | |
| 201 responses[2], 'Response', | |
| 202 'Cache.addAll should put a resource in the cache.'); | |
| 203 return Promise.all( | |
| 204 responses.map(function(response) { return response.text(); })); | |
| 205 }) | |
| 206 .then(function(bodies) { | |
| 207 assert_equals( | |
| 208 bodies[0], 'a simple text file\n', | |
| 209 'Cache.add should retrieve the correct body.'); | |
| 210 assert_equals( | |
| 211 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', | |
| 212 'Cache.add should retrieve the correct body.'); | |
| 137 }); | 213 }); |
| 138 }, 'Cache.addAll with a mix of succeeding and failing requests'); | 214 }, 'Cache.addAll with a mix of succeeding and failing requests'); |
| 139 | 215 |
| 140 done(); | 216 done(); |
| OLD | NEW |