| 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'); | |
| 4 importScripts('../resources/test-helpers.js'); | 3 importScripts('../resources/test-helpers.js'); |
| 5 } | 4 } |
| 6 | 5 |
| 7 cache_test(function(cache) { | 6 cache_test(function(cache, test) { |
| 8 return assert_promise_rejects( | 7 return promise_rejects( |
| 8 test, |
| 9 new TypeError(), |
| 9 cache.add(), | 10 cache.add(), |
| 10 new TypeError(), | |
| 11 'Cache.add should throw a TypeError when no arguments are given.'); | 11 'Cache.add should throw a TypeError when no arguments are given.'); |
| 12 }, 'Cache.add called with no arguments'); | 12 }, 'Cache.add called with no arguments'); |
| 13 | 13 |
| 14 cache_test(function(cache) { | 14 cache_test(function(cache) { |
| 15 return cache.add('../resources/simple.txt') | 15 return cache.add('../resources/simple.txt') |
| 16 .then(function(result) { | 16 .then(function(result) { |
| 17 assert_equals(result, undefined, | 17 assert_equals(result, undefined, |
| 18 'Cache.add should resolve with undefined on success.'); | 18 'Cache.add should resolve with undefined on success.'); |
| 19 return cache.match('../resources/simple.txt'); | 19 return cache.match('../resources/simple.txt'); |
| 20 }) | 20 }) |
| 21 .then(function(response) { | 21 .then(function(response) { |
| 22 assert_class_string(response, 'Response', | 22 assert_class_string(response, 'Response', |
| 23 'Cache.add should put a resource in the cache.'); | 23 'Cache.add should put a resource in the cache.'); |
| 24 return response.text(); | 24 return response.text(); |
| 25 }) | 25 }) |
| 26 .then(function(body) { | 26 .then(function(body) { |
| 27 assert_equals(body, 'a simple text file\n', | 27 assert_equals(body, 'a simple text file\n', |
| 28 'Cache.add should retrieve the correct body.'); | 28 'Cache.add should retrieve the correct body.'); |
| 29 }); | 29 }); |
| 30 }, 'Cache.add called with relative URL specified as a string'); | 30 }, 'Cache.add called with relative URL specified as a string'); |
| 31 | 31 |
| 32 cache_test(function(cache) { | 32 cache_test(function(cache, test) { |
| 33 return assert_promise_rejects( | 33 return promise_rejects( |
| 34 test, |
| 35 new TypeError(), |
| 34 cache.add('javascript://this-is-not-http-mmkay'), | 36 cache.add('javascript://this-is-not-http-mmkay'), |
| 35 new TypeError(), | |
| 36 'Cache.add should throw a TypeError for non-HTTP/HTTPS URLs.'); | 37 'Cache.add should throw a TypeError for non-HTTP/HTTPS URLs.'); |
| 37 }, 'Cache.add called with non-HTTP/HTTPS URL'); | 38 }, 'Cache.add called with non-HTTP/HTTPS URL'); |
| 38 | 39 |
| 39 cache_test(function(cache) { | 40 cache_test(function(cache) { |
| 40 var request = new Request('../resources/simple.txt'); | 41 var request = new Request('../resources/simple.txt'); |
| 41 return cache.add(request) | 42 return cache.add(request) |
| 42 .then(function(result) { | 43 .then(function(result) { |
| 43 assert_equals(result, undefined, | 44 assert_equals(result, undefined, |
| 44 'Cache.add should resolve with undefined on success.'); | 45 'Cache.add should resolve with undefined on success.'); |
| 45 }); | 46 }); |
| 46 }, 'Cache.add called with Request object'); | 47 }, 'Cache.add called with Request object'); |
| 47 | 48 |
| 48 cache_test(function(cache) { | 49 cache_test(function(cache, test) { |
| 49 var request = new Request('../resources/simple.txt', | 50 var request = new Request('../resources/simple.txt', |
| 50 {method: 'POST', body: 'This is a body.'}); | 51 {method: 'POST', body: 'This is a body.'}); |
| 51 return assert_promise_rejects( | 52 return promise_rejects( |
| 53 test, |
| 54 new TypeError(), |
| 52 cache.add(request), | 55 cache.add(request), |
| 53 new TypeError(), | |
| 54 'Cache.add should throw a TypeError for non-GET requests.'); | 56 'Cache.add should throw a TypeError for non-GET requests.'); |
| 55 }, 'Cache.add called with POST request'); | 57 }, 'Cache.add called with POST request'); |
| 56 | 58 |
| 57 cache_test(function(cache) { | 59 cache_test(function(cache) { |
| 58 var request = new Request('../resources/simple.txt'); | 60 var request = new Request('../resources/simple.txt'); |
| 59 return cache.add(request) | 61 return cache.add(request) |
| 60 .then(function(result) { | 62 .then(function(result) { |
| 61 assert_equals(result, undefined, | 63 assert_equals(result, undefined, |
| 62 'Cache.add should resolve with undefined on success.'); | 64 'Cache.add should resolve with undefined on success.'); |
| 63 }) | 65 }) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 var request = new Request('../resources/simple.txt'); | 76 var request = new Request('../resources/simple.txt'); |
| 75 return request.text() | 77 return request.text() |
| 76 .then(function() { | 78 .then(function() { |
| 77 assert_false(request.bodyUsed); | 79 assert_false(request.bodyUsed); |
| 78 }) | 80 }) |
| 79 .then(function() { | 81 .then(function() { |
| 80 return cache.add(request); | 82 return cache.add(request); |
| 81 }); | 83 }); |
| 82 }, 'Cache.add called with Request object with a used body'); | 84 }, 'Cache.add called with Request object with a used body'); |
| 83 | 85 |
| 84 cache_test(function(cache) { | 86 cache_test(function(cache, test) { |
| 85 return assert_promise_rejects( | 87 return promise_rejects( |
| 88 test, |
| 89 new TypeError(), |
| 86 cache.add('this-does-not-exist-please-dont-create-it'), | 90 cache.add('this-does-not-exist-please-dont-create-it'), |
| 87 new TypeError(), | |
| 88 'Cache.add should reject if response is !ok'); | 91 'Cache.add should reject if response is !ok'); |
| 89 }, 'Cache.add with request that results in a status of 404'); | 92 }, 'Cache.add with request that results in a status of 404'); |
| 90 | 93 |
| 91 cache_test(function(cache) { | 94 cache_test(function(cache, test) { |
| 92 return assert_promise_rejects( | 95 return promise_rejects( |
| 96 test, |
| 97 new TypeError(), |
| 93 cache.add('../resources/fetch-status.php?status=500'), | 98 cache.add('../resources/fetch-status.php?status=500'), |
| 94 new TypeError(), | |
| 95 'Cache.add should reject if response is !ok'); | 99 'Cache.add should reject if response is !ok'); |
| 96 }, 'Cache.add with request that results in a status of 500'); | 100 }, 'Cache.add with request that results in a status of 500'); |
| 97 | 101 |
| 98 cache_test(function(cache) { | 102 cache_test(function(cache, test) { |
| 99 return assert_promise_rejects( | 103 return promise_rejects( |
| 104 test, |
| 105 new TypeError(), |
| 100 cache.addAll(), | 106 cache.addAll(), |
| 101 new TypeError(), | |
| 102 'Cache.addAll with no arguments should throw TypeError.'); | 107 'Cache.addAll with no arguments should throw TypeError.'); |
| 103 }, 'Cache.addAll with no arguments'); | 108 }, 'Cache.addAll with no arguments'); |
| 104 | 109 |
| 105 cache_test(function(cache) { | 110 cache_test(function(cache, test) { |
| 106 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h
tml | 111 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h
tml |
| 107 var urls = ['../resources/simple.txt', undefined, '../resources/blank.html']
; | 112 var urls = ['../resources/simple.txt', undefined, '../resources/blank.html']
; |
| 108 return assert_promise_rejects( | 113 return promise_rejects( |
| 114 test, |
| 115 new TypeError(), |
| 109 cache.addAll(), | 116 cache.addAll(), |
| 110 new TypeError(), | |
| 111 'Cache.addAll should throw TypeError for an undefined argument.'); | 117 'Cache.addAll should throw TypeError for an undefined argument.'); |
| 112 }, 'Cache.addAll with a mix of valid and undefined arguments'); | 118 }, 'Cache.addAll with a mix of valid and undefined arguments'); |
| 113 | 119 |
| 114 cache_test(function(cache) { | 120 cache_test(function(cache) { |
| 115 return cache.addAll([]) | 121 return cache.addAll([]) |
| 116 .then(function(result) { | 122 .then(function(result) { |
| 117 assert_equals(result, undefined, | 123 assert_equals(result, undefined, |
| 118 'Cache.addAll should resolve with undefined on ' + | 124 'Cache.addAll should resolve with undefined on ' + |
| 119 'success.'); | 125 'success.'); |
| 120 return cache.keys(); | 126 return cache.keys(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 .then(function(bodies) { | 201 .then(function(bodies) { |
| 196 assert_equals( | 202 assert_equals( |
| 197 bodies[0], 'a simple text file\n', | 203 bodies[0], 'a simple text file\n', |
| 198 'Cache.add should retrieve the correct body.'); | 204 'Cache.add should retrieve the correct body.'); |
| 199 assert_equals( | 205 assert_equals( |
| 200 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', | 206 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', |
| 201 'Cache.add should retrieve the correct body.'); | 207 'Cache.add should retrieve the correct body.'); |
| 202 }); | 208 }); |
| 203 }, 'Cache.addAll with Request arguments'); | 209 }, 'Cache.addAll with Request arguments'); |
| 204 | 210 |
| 205 cache_test(function(cache) { | 211 cache_test(function(cache, test) { |
| 206 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. | 212 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. |
| 207 // The second resource does not. | 213 // The second resource does not. |
| 208 var urls = ['../resources/simple.txt', | 214 var urls = ['../resources/simple.txt', |
| 209 'this-resource-should-not-exist', | 215 'this-resource-should-not-exist', |
| 210 '../resources/blank.html']; | 216 '../resources/blank.html']; |
| 211 var requests = urls.map(function(url) { | 217 var requests = urls.map(function(url) { |
| 212 return new Request(url); | 218 return new Request(url); |
| 213 }); | 219 }); |
| 214 return assert_promise_rejects( | 220 return promise_rejects( |
| 221 test, |
| 222 new TypeError(), |
| 215 cache.addAll(requests), | 223 cache.addAll(requests), |
| 216 new TypeError(), | |
| 217 'Cache.addAll should reject with TypeError if any request fails') | 224 'Cache.addAll should reject with TypeError if any request fails') |
| 218 .then(function() { | 225 .then(function() { |
| 219 return Promise.all(urls.map(function(url) { | 226 return Promise.all(urls.map(function(url) { |
| 220 return cache.match(url); | 227 return cache.match(url); |
| 221 })); | 228 })); |
| 222 }) | 229 }) |
| 223 .then(function(matches) { | 230 .then(function(matches) { |
| 224 assert_array_equals( | 231 assert_array_equals( |
| 225 matches, | 232 matches, |
| 226 [undefined, undefined, undefined], | 233 [undefined, undefined, undefined], |
| 227 'If any response fails, no response should be added to cache'); | 234 'If any response fails, no response should be added to cache'); |
| 228 }); | 235 }); |
| 229 }, 'Cache.addAll with a mix of succeeding and failing requests'); | 236 }, 'Cache.addAll with a mix of succeeding and failing requests'); |
| 230 | 237 |
| 231 cache_test(function(cache) { | 238 cache_test(function(cache, test) { |
| 232 var request = new Request('../resources/simple.txt'); | 239 var request = new Request('../resources/simple.txt'); |
| 233 return assert_promise_rejects( | 240 return promise_rejects( |
| 241 test, |
| 242 'InvalidStateError', |
| 234 cache.addAll([request, request]), | 243 cache.addAll([request, request]), |
| 235 'InvalidStateError', | |
| 236 'Cache.addAll should throw InvalidStateError if the same request is added
' + | 244 'Cache.addAll should throw InvalidStateError if the same request is added
' + |
| 237 'twice.'); | 245 'twice.'); |
| 238 }, 'Cache.addAll called with the same Request object specified twice'); | 246 }, 'Cache.addAll called with the same Request object specified twice'); |
| 239 | 247 |
| 240 done(); | 248 done(); |
| OLD | NEW |