Chromium Code Reviews| 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(); | |
|
jsbell
2014/08/21 19:07:47
I missed that this is calling create() with no arg
asanka
2014/08/21 21:50:59
Done.
| |
| 22 }) | |
| 23 .then(function(cache) { | |
| 24 assert_true(cache instanceof Cache, | |
| 25 'CacheStorage.create should accept an empty name.'); | |
|
jsbell
2014/08/21 19:07:48
I interpreted this as "empty string" rather than "
asanka
2014/08/21 21:50:59
Acknowledged.
| |
| 26 }); | |
| 27 }, 'CacheStorage.create with an empty name'); | |
| 28 | |
| 29 promise_test(function(t) { | |
| 30 var cache_name = 'cache-storage/there can be only one'; | |
| 31 return self.caches(delete(cache_name)) | |
| 32 .then(function() { | |
| 33 return self.caches.create(cache_name); | |
| 34 }) | |
| 35 .then(function() { | |
| 36 return assert_promise_throws( | |
| 37 self.caches.create(cache_name), | |
| 38 'InvalidAccessError', | |
| 39 'CacheStorage.create should throw InvalidAccessError if called ' + | |
| 40 'with existing cache name.'); | |
| 41 }); | |
| 42 }, 'CacheStorage.create with an existing cache name'); | |
| 43 | |
| 44 promise_test(function(t) { | |
| 45 var test_cases = [ | |
| 46 { | |
| 47 name: 'cache-storage/lowercase', | |
| 48 should_not_match: | |
| 49 [ | |
| 50 'cache-storage/Lowercase', | |
| 51 ' cache-storage/lowercase', | |
| 52 'cache-storage/lowercase ' | |
| 53 ] | |
| 54 }, | |
| 55 { | |
| 56 name: 'cache-storage/has a space', | |
| 57 should_not_match: | |
| 58 [ | |
| 59 'cache-storage/has' | |
| 60 ] | |
| 61 }, | |
| 62 { | |
| 63 name: 'cache-storage/has\000_in_the_name', | |
| 64 should_not_match: | |
| 65 [ | |
| 66 'cache-storage/has', | |
| 67 'cache-storage/has_in_the_name' | |
| 68 ] | |
| 69 } | |
| 70 ]; | |
| 71 return Promise.all(test_cases.map(function(testcase) { | |
| 72 var cache_name = testcase.name; | |
| 73 return self.caches.delete(cache_name) | |
| 74 .then(function() { | |
| 75 return self.caches.create(cache_name); | |
| 76 }) | |
| 77 .then(function() { | |
| 78 return self.caches.has(cache_name); | |
| 79 }) | |
| 80 .then(function(result) { | |
| 81 assert_true(result, | |
| 82 'CacheStorage.has should return true for existing ' + | |
| 83 'cache.'); | |
| 84 }) | |
| 85 .then(function() { | |
| 86 return Promise.all( | |
| 87 testcase.should_not_match.map(function(cache_name) { | |
| 88 return self.caches.has(cache_name) | |
| 89 .then(function(result) { | |
| 90 assert_false(result, | |
| 91 'CacheStorage.has should only perform ' + | |
| 92 'exact matches on cache names.'); | |
| 93 }); | |
| 94 })); | |
| 95 }) | |
| 96 .then(function() { | |
| 97 return self.caches.delete(cache_name); | |
| 98 }); | |
| 99 })); | |
| 100 }, 'CacheStorage.has with existing cache'); | |
| 101 | |
| 102 promise_test(function(t) { | |
| 103 return self.caches.has('cheezburger') | |
| 104 .then(function(result) { | |
| 105 assert_false(result, | |
| 106 'CacheStorage.has should return false for ' + | |
| 107 'nonexistent cache.'); | |
| 108 }); | |
| 109 }, 'CacheStorage.has with nonexistent cache'); | |
| 110 | |
| 111 promise_test(function(t) { | |
| 112 var cache_name = 'cache-storage/get'; | |
| 113 var cache; | |
| 114 return self.caches.create(cache_name) | |
| 115 .then(function(result) { | |
| 116 cache = result; | |
| 117 return self.caches.get(cache_name); | |
| 118 }) | |
| 119 .then(function(result) { | |
| 120 assert_equals(result, cache, | |
| 121 'CacheStorage.get should return the named Cache ' + | |
| 122 'object if it exists.'); | |
| 123 return self.caches.get(cache_name); | |
| 124 }) | |
| 125 .then(function(result) { | |
| 126 assert_equals(result, cache, | |
| 127 'CacheStorage.get should return the same ' + | |
| 128 'instance of an existing Cache object.'); | |
| 129 }); | |
| 130 }, 'CacheStorage.get with existing cache'); | |
| 131 | |
| 132 promise_test(function(t) { | |
| 133 return self.caches.get('cheezburger') | |
| 134 .then(function(result) { | |
| 135 assert_equals(result, undefined, | |
| 136 'CacheStorage.get should return undefined for a ' + | |
| 137 'nonexistent cache.'); | |
| 138 }); | |
| 139 }, 'CacheStorage.get with nonexistent cache'); | |
| 140 | |
| 141 promise_test(function(t) { | |
| 142 var cache_name = 'cache-storage/delete'; | |
| 143 | |
| 144 return self.caches.create(cache_name) | |
| 145 .then(function() { return self.caches.delete(cache_name); }) | |
| 146 .then(function(result) { | |
| 147 assert_true(result, | |
| 148 'CacheStorage.delete should return true after ' + | |
| 149 'deleting an existing cache.'); | |
| 150 }) | |
| 151 | |
| 152 .then(function() { return self.caches.has(cache_name); }) | |
| 153 .then(function(cache_exists) { | |
| 154 assert_false(cache_exists, | |
| 155 'CacheStorage.has should not return true after ' + | |
| 156 'fulfilment of CacheStorage.delete promise.'); | |
| 157 }); | |
| 158 }, 'CacheStorage.delete with existing cache'); | |
| 159 | |
| 160 promise_test(function(t) { | |
| 161 return self.caches.delete('cheezburger') | |
| 162 .then(function(result) { | |
| 163 assert_false(result, | |
| 164 'CacheStorage.delete should return false for a ' + | |
| 165 'nonexistent cache.'); | |
| 166 }); | |
| 167 }, 'CacheStorage.delete with nonexistent cache'); | |
| 168 | |
| OLD | NEW |