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..d0fc3ab48cb382d3bc40148bea7fae008c2484d6 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-storage-test-worker.js |
@@ -0,0 +1,78 @@ |
+importScripts('worker-test-harness.js'); |
+ |
+promise_test(function(test) { |
+ return caches.create('foo') |
+ .then(test.step_func(function(cache) { |
+ assert_true(cache, |
dominicc (has gone to gerrit)
2014/08/11 01:57:36
Maybe omit this assertion? You'll get a reasonable
asanka
2014/08/13 01:22:51
Done.
|
+ 'CacheStorage.create should return a valid Cache.'); |
+ assert_true(cache instanceof Cache, |
+ 'CacheStorage.create should return a valid Cache.'); |
+ })); |
+ }, 'CacheStorage.create'); |
+ |
+promise_test(function(test) { |
+ return caches.create() |
+ // FIXME: Define the behavior for .create() with an empty or |
dominicc (has gone to gerrit)
2014/08/11 01:57:36
I do not see any bias in the spec against '' as a
asanka
2014/08/13 01:22:51
Thanks for the reference! I've updated the tests.
|
+ // non-string cache name. |
+ .then(test.unreached_func( |
+ 'CacheStorage.create should reject invalid name.'), |
+ function() {}); |
+ }, 'CacheStorage.create with invalid cache name'); |
+ |
+promise_test(function(test) { |
+ return caches.create('bar') |
+ .then(test.step_func(function() { return caches.has('bar'); })) |
+ .then(test.step_func(function(result) { |
+ assert_true(result, |
+ 'CacheStorage.has should return true for ' + |
+ 'existing cache'); |
+ })); |
+ }, 'CacheStorage.has with existing cache'); |
+ |
+promise_test(function(test) { |
+ return caches.has('cheezburger') |
dominicc (has gone to gerrit)
2014/08/11 01:57:36
Huge +1 to the modest sense of humor.
asanka
2014/08/13 01:22:51
Acknowledged.
|
+ .then(test.step_func(function(result) { |
+ assert_false(result, |
+ 'CacheStorage.has should return false for ' + |
+ 'non-existent cache'); |
+ })); |
+ }, 'CacheStorage.has with non-existent cache'); |
+ |
+promise_test(function(test) { |
+ return caches.has() |
+ // FIXME: Define the behavior for .has() with an invalid or undefined |
+ // name. Perhaps it should reject instead of returning false. |
+ .then(test.step_func(function(result) { |
+ // FIXME: Could fail due to the cache creation with an undefined name |
+ // above. Tests shouldn't interact since these are all async_tests. |
+ assert_false(result, |
+ 'CacheStorage.has should return false for invalid ' + |
+ 'cache name.'); |
+ })); |
+ }, 'CacheStorage.has with invalid cache name'); |
+ |
+promise_test(function(test) { |
+ var cache_name = 'to-be-deleted'; |
+ |
+ return caches.create(cache_name) |
+ .then(function() { return caches.delete(cache_name); }) |
+ .then(function() {}, |
+ test.unreached_func('CacheStorage.delete should not reject ' + |
+ 'existing cache')) |
+ |
+ .then(function() { return caches.has(cache_name); }) |
+ .then(test.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(test) { |
+ return caches.delete('cheezburger') |
+ .then(test.unreached_func('CacheStorage.delete should not fulfil ' + |
+ 'promise to delete non-existent cache.'), |
+ function() {}); |
+ }, 'CacheStorage.delete with non-existent cache'); |
+ |
+// FIXME: Define and test behavior for invalid cache name with delete(). |
dominicc (has gone to gerrit)
2014/08/11 01:57:36
You're free to file GitHub issues against the spec
jsbell
2014/08/11 22:48:34
Yeah, I'm not clear what 'invalid' might mean here
asanka
2014/08/13 01:22:51
Thanks! I'll wait for gavinp to comment.
|