Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/resources/cache-storage-worker.js |
| diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-storage-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-storage-worker.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..309fa33991a1c63f77ad03008551b9eb36f6c9cd |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/resources/cache-storage-worker.js |
| @@ -0,0 +1,168 @@ |
| +importScripts('worker-test-harness.js'); |
| + |
| +promise_test(function(t) { |
| + var cache_name = 'cache-storage/foo'; |
| + return self.caches.delete(cache_name) |
| + .then(function() { |
| + return self.caches.create(cache_name); |
| + }) |
| + .then(function(cache) { |
| + assert_true(cache instanceof Cache, |
| + 'CacheStorage.create should return a Cache.'); |
| + }); |
| + }, 'CacheStorage.create'); |
| + |
| +promise_test(function(t) { |
| + // Note that this test may collide with other tests running in the same |
| + // origin that also uses an empty cache name. |
| + var cache_name = ''; |
| + return self.caches.delete(cache_name) |
| + .then(function() { |
| + 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.
|
| + }) |
| + .then(function(cache) { |
| + assert_true(cache instanceof Cache, |
| + '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.
|
| + }); |
| + }, 'CacheStorage.create with an empty name'); |
| + |
| +promise_test(function(t) { |
| + var cache_name = 'cache-storage/there can be only one'; |
| + return self.caches(delete(cache_name)) |
| + .then(function() { |
| + return self.caches.create(cache_name); |
| + }) |
| + .then(function() { |
| + return assert_promise_throws( |
| + self.caches.create(cache_name), |
| + 'InvalidAccessError', |
| + 'CacheStorage.create should throw InvalidAccessError if called ' + |
| + 'with existing cache name.'); |
| + }); |
| + }, 'CacheStorage.create with an existing cache name'); |
| + |
| +promise_test(function(t) { |
| + var test_cases = [ |
| + { |
| + name: 'cache-storage/lowercase', |
| + should_not_match: |
| + [ |
| + 'cache-storage/Lowercase', |
| + ' cache-storage/lowercase', |
| + 'cache-storage/lowercase ' |
| + ] |
| + }, |
| + { |
| + name: 'cache-storage/has a space', |
| + should_not_match: |
| + [ |
| + 'cache-storage/has' |
| + ] |
| + }, |
| + { |
| + name: 'cache-storage/has\000_in_the_name', |
| + should_not_match: |
| + [ |
| + 'cache-storage/has', |
| + 'cache-storage/has_in_the_name' |
| + ] |
| + } |
| + ]; |
| + return Promise.all(test_cases.map(function(testcase) { |
| + var cache_name = testcase.name; |
| + return self.caches.delete(cache_name) |
| + .then(function() { |
| + return self.caches.create(cache_name); |
| + }) |
| + .then(function() { |
| + return self.caches.has(cache_name); |
| + }) |
| + .then(function(result) { |
| + assert_true(result, |
| + 'CacheStorage.has should return true for existing ' + |
| + 'cache.'); |
| + }) |
| + .then(function() { |
| + return Promise.all( |
| + testcase.should_not_match.map(function(cache_name) { |
| + return self.caches.has(cache_name) |
| + .then(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.has should only perform ' + |
| + 'exact matches on cache names.'); |
| + }); |
| + })); |
| + }) |
| + .then(function() { |
| + return self.caches.delete(cache_name); |
| + }); |
| + })); |
| + }, 'CacheStorage.has with existing cache'); |
| + |
| +promise_test(function(t) { |
| + return self.caches.has('cheezburger') |
| + .then(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.has should return false for ' + |
| + 'nonexistent cache.'); |
| + }); |
| + }, 'CacheStorage.has with nonexistent cache'); |
| + |
| +promise_test(function(t) { |
| + var cache_name = 'cache-storage/get'; |
| + var cache; |
| + return self.caches.create(cache_name) |
| + .then(function(result) { |
| + cache = result; |
| + return self.caches.get(cache_name); |
| + }) |
| + .then(function(result) { |
| + assert_equals(result, cache, |
| + 'CacheStorage.get should return the named Cache ' + |
| + 'object if it exists.'); |
| + return self.caches.get(cache_name); |
| + }) |
| + .then(function(result) { |
| + assert_equals(result, cache, |
| + 'CacheStorage.get should return the same ' + |
| + 'instance of an existing Cache object.'); |
| + }); |
| + }, 'CacheStorage.get with existing cache'); |
| + |
| +promise_test(function(t) { |
| + return self.caches.get('cheezburger') |
| + .then(function(result) { |
| + assert_equals(result, undefined, |
| + 'CacheStorage.get should return undefined for a ' + |
| + 'nonexistent cache.'); |
| + }); |
| + }, 'CacheStorage.get with nonexistent cache'); |
| + |
| +promise_test(function(t) { |
| + var cache_name = 'cache-storage/delete'; |
| + |
| + return self.caches.create(cache_name) |
| + .then(function() { return self.caches.delete(cache_name); }) |
| + .then(function(result) { |
| + assert_true(result, |
| + 'CacheStorage.delete should return true after ' + |
| + 'deleting an existing cache.'); |
| + }) |
| + |
| + .then(function() { return self.caches.has(cache_name); }) |
| + .then(function(cache_exists) { |
| + assert_false(cache_exists, |
| + 'CacheStorage.has should not return true after ' + |
| + 'fulfilment of CacheStorage.delete promise.'); |
| + }); |
| + }, 'CacheStorage.delete with existing cache'); |
| + |
| +promise_test(function(t) { |
| + return self.caches.delete('cheezburger') |
| + .then(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.delete should return false for a ' + |
| + 'nonexistent cache.'); |
| + }); |
| + }, 'CacheStorage.delete with nonexistent cache'); |
| + |