Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: LayoutTests/http/tests/serviceworker/resources/cache-storage-test-worker.js

Issue 430993002: [ServiceWorker] CacheStorage tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix typo and formatting Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698