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