OLD | NEW |
(Empty) | |
| 1 importScripts('worker-test-harness.js'); |
| 2 |
| 3 promise_test(function(t) { |
| 4 var cache_name = 'cache-storage/foo'; |
| 5 return self.caches.delete(cache_name) |
| 6 .then(function() { |
| 7 return self.caches.create(cache_name); |
| 8 }) |
| 9 .then(function(cache) { |
| 10 assert_true(cache instanceof Cache, |
| 11 'CacheStorage.create should return a Cache.'); |
| 12 }); |
| 13 }, 'CacheStorage.create'); |
| 14 |
| 15 promise_test(function(t) { |
| 16 // Note that this test may collide with other tests running in the same |
| 17 // origin that also uses an empty cache name. |
| 18 var cache_name = ''; |
| 19 return self.caches.delete(cache_name) |
| 20 .then(function() { |
| 21 return self.caches.create(cache_name); |
| 22 }) |
| 23 .then(function(cache) { |
| 24 assert_true(cache instanceof Cache, |
| 25 'CacheStorage.create should accept an empty name.'); |
| 26 }); |
| 27 }, 'CacheStorage.create with an empty name'); |
| 28 |
| 29 promise_test(function(t) { |
| 30 return assert_promise_throws( |
| 31 self.caches.create(), |
| 32 new TypeError(), |
| 33 'CacheStorage.create should throw TypeError if called with no arguments.')
; |
| 34 }, 'CacheStorage.create with no arguments'); |
| 35 |
| 36 promise_test(function(t) { |
| 37 var cache_name = 'cache-storage/there can be only one'; |
| 38 return self.caches.delete(cache_name) |
| 39 .then(function() { |
| 40 return self.caches.create(cache_name); |
| 41 }) |
| 42 .then(function() { |
| 43 return assert_promise_throws( |
| 44 self.caches.create(cache_name), |
| 45 'InvalidAccessError', |
| 46 'CacheStorage.create should throw InvalidAccessError if called ' + |
| 47 'with existing cache name.'); |
| 48 }); |
| 49 }, 'CacheStorage.create with an existing cache name'); |
| 50 |
| 51 promise_test(function(t) { |
| 52 var test_cases = [ |
| 53 { |
| 54 name: 'cache-storage/lowercase', |
| 55 should_not_match: |
| 56 [ |
| 57 'cache-storage/Lowercase', |
| 58 ' cache-storage/lowercase', |
| 59 'cache-storage/lowercase ' |
| 60 ] |
| 61 }, |
| 62 { |
| 63 name: 'cache-storage/has a space', |
| 64 should_not_match: |
| 65 [ |
| 66 'cache-storage/has' |
| 67 ] |
| 68 }, |
| 69 { |
| 70 name: 'cache-storage/has\000_in_the_name', |
| 71 should_not_match: |
| 72 [ |
| 73 'cache-storage/has', |
| 74 'cache-storage/has_in_the_name' |
| 75 ] |
| 76 } |
| 77 ]; |
| 78 return Promise.all(test_cases.map(function(testcase) { |
| 79 var cache_name = testcase.name; |
| 80 return self.caches.delete(cache_name) |
| 81 .then(function() { |
| 82 return self.caches.create(cache_name); |
| 83 }) |
| 84 .then(function() { |
| 85 return self.caches.has(cache_name); |
| 86 }) |
| 87 .then(function(result) { |
| 88 assert_true(result, |
| 89 'CacheStorage.has should return true for existing ' + |
| 90 'cache.'); |
| 91 }) |
| 92 .then(function() { |
| 93 return Promise.all( |
| 94 testcase.should_not_match.map(function(cache_name) { |
| 95 return self.caches.has(cache_name) |
| 96 .then(function(result) { |
| 97 assert_false(result, |
| 98 'CacheStorage.has should only perform ' + |
| 99 'exact matches on cache names.'); |
| 100 }); |
| 101 })); |
| 102 }) |
| 103 .then(function() { |
| 104 return self.caches.delete(cache_name); |
| 105 }); |
| 106 })); |
| 107 }, 'CacheStorage.has with existing cache'); |
| 108 |
| 109 promise_test(function(t) { |
| 110 return self.caches.has('cheezburger') |
| 111 .then(function(result) { |
| 112 assert_false(result, |
| 113 'CacheStorage.has should return false for ' + |
| 114 'nonexistent cache.'); |
| 115 }); |
| 116 }, 'CacheStorage.has with nonexistent cache'); |
| 117 |
| 118 promise_test(function(t) { |
| 119 var cache_name = 'cache-storage/get'; |
| 120 var cache; |
| 121 return self.caches.delete(cache_name) |
| 122 .then(function() { |
| 123 return self.caches.create(cache_name); |
| 124 }) |
| 125 .then(function(result) { |
| 126 cache = result; |
| 127 }) |
| 128 .then(function() { |
| 129 return self.caches.get(cache_name); |
| 130 }) |
| 131 .then(function(result) { |
| 132 assert_equals(result, cache, |
| 133 'CacheStorage.get should return the named Cache ' + |
| 134 'object if it exists.'); |
| 135 }) |
| 136 .then(function() { |
| 137 return self.caches.get(cache_name); |
| 138 }) |
| 139 .then(function(result) { |
| 140 assert_equals(result, cache, |
| 141 'CacheStorage.get should return the same ' + |
| 142 'instance of an existing Cache object.'); |
| 143 }); |
| 144 }, 'CacheStorage.get with existing cache'); |
| 145 |
| 146 promise_test(function(t) { |
| 147 return self.caches.get('cheezburger') |
| 148 .then(function(result) { |
| 149 assert_equals(result, undefined, |
| 150 'CacheStorage.get should return undefined for a ' + |
| 151 'nonexistent cache.'); |
| 152 }); |
| 153 }, 'CacheStorage.get with nonexistent cache'); |
| 154 |
| 155 promise_test(function(t) { |
| 156 var cache_name = 'cache-storage/delete'; |
| 157 |
| 158 return self.caches.delete(cache_name) |
| 159 .then(function() { |
| 160 return self.caches.create(cache_name); |
| 161 }) |
| 162 .then(function() { return self.caches.delete(cache_name); }) |
| 163 .then(function(result) { |
| 164 assert_true(result, |
| 165 'CacheStorage.delete should return true after ' + |
| 166 'deleting an existing cache.'); |
| 167 }) |
| 168 |
| 169 .then(function() { return self.caches.has(cache_name); }) |
| 170 .then(function(cache_exists) { |
| 171 assert_false(cache_exists, |
| 172 'CacheStorage.has should return false after ' + |
| 173 'fulfillment of CacheStorage.delete promise.'); |
| 174 }); |
| 175 }, 'CacheStorage.delete with existing cache'); |
| 176 |
| 177 promise_test(function(t) { |
| 178 return self.caches.delete('cheezburger') |
| 179 .then(function(result) { |
| 180 assert_false(result, |
| 181 'CacheStorage.delete should return false for a ' + |
| 182 'nonexistent cache.'); |
| 183 }); |
| 184 }, 'CacheStorage.delete with nonexistent cache'); |
| 185 |
OLD | NEW |