Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/resources/cache-storage-test-worker.js |
| diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-storage-test-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-storage-test-worker.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..40d1653cc156e62b595e4aab69aa4d0df8b50c3a |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/resources/cache-storage-test-worker.js |
| @@ -0,0 +1,130 @@ |
| +importScripts('worker-test-harness.js'); |
| + |
| +promise_test(function(t) { |
| + return caches.create('foo') |
|
jsbell
2014/08/15 21:36:13
IIUC, Caches are scoped to an origin, not to a SW
asanka
2014/08/20 03:10:29
I see. This was a bit of a head scratcher for me s
|
| + .then(t.step_func(function(cache) { |
|
jsbell
2014/08/15 21:36:13
Should not need t.step_func in a promise_test (her
asanka
2014/08/20 03:10:29
Ah. Good point! Changed.
|
| + assert_true(cache instanceof Cache, |
| + 'CacheStorage.create should return a Cache.'); |
| + })); |
| + }, 'CacheStorage.create'); |
| + |
| +promise_test(function(t) { |
| + return caches.create() |
| + .then(t.step_func(function(cache) { |
| + assert_true(cache instanceof Cache, |
| + 'CacheStorage.create should accept an empty name.'); |
| + })); |
| + }, 'CacheStorage.create with an empty name'); |
| + |
| +promise_test(function(t) { |
| + var cache_name = 'there can be only one'; |
| + |
| + return caches.create(cache_name) |
| + .then(function() { |
| + return expect_promise_throws( |
| + t, |
| + caches.create(cache_name), |
| + 'InvalidAccessError', |
| + 'CacheStorage.create should throw InvalidAccessError if called ' + |
| + 'with existing cache name.'); |
| + }); |
| + }, 'CacheStorage.create'); |
| + |
| +promise_test(function(t) { |
| + return caches.create('bar') |
| + .then(t.step_func(function() { return caches.has('bar'); })) |
| + .then(t.step_func(function(result) { |
| + assert_true(result, |
| + 'CacheStorage.has should return true for ' + |
| + 'existing cache.'); |
| + })) |
| + |
| + .then(function() { return caches.has('Bar'); }) |
| + .then(t.step_func(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.has should not match a cache name that ' + |
| + 'differs in case.'); |
| + })) |
| + |
| + .then(function() { return caches.has(' bar'); }) |
| + .then(t.step_func(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.has should not ignore leading ' + |
| + 'whitespace in name.'); |
| + })) |
| + |
| + .then(function() { return caches.has('bar '); }) |
| + .then(t.step_func(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.has should not ignore trailing ' + |
|
jsbell
2014/08/15 21:36:13
Any particular reason to worry about leading/trail
asanka
2014/08/20 03:10:29
I added a test case for an embedded NUL. I didn't
|
| + 'whitespace in name.'); |
| + })); |
| + }, 'CacheStorage.has with existing cache'); |
| + |
| +promise_test(function(t) { |
| + return caches.has('cheezburger') |
| + .then(t.step_func(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 = 'get-test'; |
| + var cache; |
| + return caches.create(cache_name) |
| + .then(t.step_func(function(result) { |
| + cache = result; |
| + return caches.get(cache_name); |
| + })) |
| + .then(t.step_func(function(result) { |
| + assert_equals(result, cache, |
| + 'CacheStorage.get should return the named Cache object ' + |
|
jsbell
2014/08/15 21:36:13
nit: line length (80 cols)
asanka
2014/08/20 03:10:29
Done.
|
| + 'if it exists.'); |
| + return caches.get(cache_name); |
| + })) |
| + .then(t.step_func(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 caches.get('cheezburger') |
| + .then(t.step_func(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 = 'to-be-deleted'; |
| + |
| + return caches.create(cache_name) |
| + .then(function() { return caches.delete(cache_name); }) |
| + .then(t.step_func(function(result) { |
| + assert_true(result, |
| + 'CacheStorage.delete should return true after ' + |
| + 'deleting an existing cache.'); |
| + })) |
| + |
| + .then(function() { return caches.has(cache_name); }) |
| + .then(t.step_func(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 caches.delete('cheezburger') |
| + .then(t.step_func(function(result) { |
| + assert_false(result, |
| + 'CacheStorage.delete should return false for a ' + |
| + 'nonexistent cache.'); |
| + })); |
| + }, 'CacheStorage.delete with nonexistent cache'); |
| + |