| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 var request = new Request('../resources/simple.txt', | 49 var request = new Request('../resources/simple.txt', |
| 50 {method: 'POST', body: 'This is a body.'}); | 50 {method: 'POST', body: 'This is a body.'}); |
| 51 return assert_promise_rejects( | 51 return assert_promise_rejects( |
| 52 cache.add(request), | 52 cache.add(request), |
| 53 new TypeError(), | 53 new TypeError(), |
| 54 'Cache.add should throw a TypeError for non-GET requests.'); | 54 'Cache.add should throw a TypeError for non-GET requests.'); |
| 55 }, 'Cache.add called with POST request'); | 55 }, 'Cache.add called with POST request'); |
| 56 | 56 |
| 57 cache_test(function(cache) { | 57 cache_test(function(cache) { |
| 58 var request = new Request('../resources/simple.txt'); | 58 var request = new Request('../resources/simple.txt'); |
| 59 return cache.add(request) |
| 60 .then(function(result) { |
| 61 assert_equals(result, undefined, |
| 62 'Cache.add should resolve with undefined on success.'); |
| 63 }) |
| 64 .then(function() { |
| 65 return cache.add(request); |
| 66 }) |
| 67 .then(function(result) { |
| 68 assert_equals(result, undefined, |
| 69 'Cache.add should resolve with undefined on success.'); |
| 70 }); |
| 71 }, 'Cache.add called twice with the same Request object'); |
| 72 |
| 73 cache_test(function(cache) { |
| 74 var request = new Request('../resources/simple.txt'); |
| 59 return request.text() | 75 return request.text() |
| 60 .then(function() { | 76 .then(function() { |
| 61 assert_false(request.bodyUsed); | 77 assert_false(request.bodyUsed); |
| 62 }) | 78 }) |
| 63 .then(function() { | 79 .then(function() { |
| 64 return cache.add(request); | 80 return cache.add(request); |
| 65 }); | 81 }); |
| 66 }, 'Cache.add called with Request object with a used body'); | 82 }, 'Cache.add called with Request object with a used body'); |
| 67 | 83 |
| 68 cache_test(function(cache) { | 84 cache_test(function(cache) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 'Cache.add should retrieve the correct body.'); | 163 'Cache.add should retrieve the correct body.'); |
| 148 }); | 164 }); |
| 149 }, 'Cache.addAll with string URL arguments'); | 165 }, 'Cache.addAll with string URL arguments'); |
| 150 | 166 |
| 151 cache_test(function(cache) { | 167 cache_test(function(cache) { |
| 152 // Assumes the existence of ../resources/simple.txt and | 168 // Assumes the existence of ../resources/simple.txt and |
| 153 // ../resources/blank.html | 169 // ../resources/blank.html |
| 154 var urls = ['../resources/simple.txt', | 170 var urls = ['../resources/simple.txt', |
| 155 self.location.href, | 171 self.location.href, |
| 156 '../resources/blank.html']; | 172 '../resources/blank.html']; |
| 157 var requests = urls.map(function(url) { return new Request(url); }); | 173 var requests = urls.map(function(url) { |
| 174 return new Request(url); |
| 175 }); |
| 158 return cache.addAll(requests) | 176 return cache.addAll(requests) |
| 159 .then(function(result) { | 177 .then(function(result) { |
| 160 assert_equals(result, undefined, | 178 assert_equals(result, undefined, |
| 161 'Cache.addAll should resolve with undefined on ' + | 179 'Cache.addAll should resolve with undefined on ' + |
| 162 'success.'); | 180 'success.'); |
| 163 return Promise.all( | 181 return Promise.all( |
| 164 urls.map(function(url) { return cache.match(url); })); | 182 urls.map(function(url) { return cache.match(url); })); |
| 165 }) | 183 }) |
| 166 .then(function(responses) { | 184 .then(function(responses) { |
| 167 assert_class_string( | 185 assert_class_string( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 'Cache.add should retrieve the correct body.'); | 203 'Cache.add should retrieve the correct body.'); |
| 186 }); | 204 }); |
| 187 }, 'Cache.addAll with Request arguments'); | 205 }, 'Cache.addAll with Request arguments'); |
| 188 | 206 |
| 189 cache_test(function(cache) { | 207 cache_test(function(cache) { |
| 190 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. | 208 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. |
| 191 // The second resource does not. | 209 // The second resource does not. |
| 192 var urls = ['../resources/simple.txt', | 210 var urls = ['../resources/simple.txt', |
| 193 'this-resource-should-not-exist', | 211 'this-resource-should-not-exist', |
| 194 '../resources/blank.html']; | 212 '../resources/blank.html']; |
| 195 var requests = urls.map(function(url) { return new Request(url); }); | 213 var requests = urls.map(function(url) { |
| 214 return new Request(url); |
| 215 }); |
| 196 return cache.addAll(requests) | 216 return cache.addAll(requests) |
| 197 .then(function(result) { | 217 .then(function(result) { |
| 198 assert_equals(result, undefined, | 218 assert_equals(result, undefined, |
| 199 'Cache.addAll should resolve with undefined on ' + | 219 'Cache.addAll should resolve with undefined on ' + |
| 200 'success.'); | 220 'success.'); |
| 201 return Promise.all( | 221 return Promise.all( |
| 202 urls.map(function(url) { return cache.match(url); })); | 222 urls.map(function(url) { return cache.match(url); })); |
| 203 }) | 223 }) |
| 204 .then(function(responses) { | 224 .then(function(responses) { |
| 205 assert_class_string( | 225 assert_class_string( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 220 .then(function(bodies) { | 240 .then(function(bodies) { |
| 221 assert_equals( | 241 assert_equals( |
| 222 bodies[0], 'a simple text file\n', | 242 bodies[0], 'a simple text file\n', |
| 223 'Cache.add should retrieve the correct body.'); | 243 'Cache.add should retrieve the correct body.'); |
| 224 assert_equals( | 244 assert_equals( |
| 225 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', | 245 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', |
| 226 'Cache.add should retrieve the correct body.'); | 246 'Cache.add should retrieve the correct body.'); |
| 227 }); | 247 }); |
| 228 }, 'Cache.addAll with a mix of succeeding and failing requests'); | 248 }, 'Cache.addAll with a mix of succeeding and failing requests'); |
| 229 | 249 |
| 250 cache_test(function(cache) { |
| 251 var request = new Request('../resources/simple.txt'); |
| 252 return assert_promise_rejects( |
| 253 cache.addAll([request, request]), |
| 254 'InvalidStateError', |
| 255 'Cache.addAll should throw InvalidStateError if the same request is added
' + |
| 256 'twice.'); |
| 257 }, 'Cache.addAll called with the same Request object specified twice'); |
| 258 |
| 230 done(); | 259 done(); |
| OLD | NEW |