Commit 74030662 authored by jkarlin@chromium.org's avatar jkarlin@chromium.org

[ServiceWorkerCacheStorage] Blink changes to remove create/get and add open function

As per recent spec changes, remove create and get and replace it with open.

CLs in this three-legged-patch:

1. Add open to browser - https://codereview.chromium.org/664433003/
*2. Add open (remove get/create) to Blink - https://codereview.chromium.org/638023003
3. Remove get/create from browser - https://codereview.chromium.org/663503002/

BUG=423942

Review URL: https://codereview.chromium.org/638023003

git-svn-id: svn://svn.chromium.org/blink/trunk@183895 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 420021cc
...@@ -15,7 +15,7 @@ promise_test(function(test) { ...@@ -15,7 +15,7 @@ promise_test(function(test) {
}) })
.then(function() { .then(function() {
return Promise.all(test_cache_list.map(function(key) { return Promise.all(test_cache_list.map(function(key) {
return self.caches.create(key); return self.caches.open(key);
})); }));
}) })
......
...@@ -5,13 +5,13 @@ promise_test(function(t) { ...@@ -5,13 +5,13 @@ promise_test(function(t) {
var cache_name = 'cache-storage/foo'; var cache_name = 'cache-storage/foo';
return self.caches.delete(cache_name) return self.caches.delete(cache_name)
.then(function() { .then(function() {
return self.caches.create(cache_name); return self.caches.open(cache_name);
}) })
.then(function(cache) { .then(function(cache) {
assert_true(cache instanceof Cache, assert_true(cache instanceof Cache,
'CacheStorage.create should return a Cache.'); 'CacheStorage.open should return a Cache.');
}); });
}, 'CacheStorage.create'); }, 'CacheStorage.open');
promise_test(function(t) { promise_test(function(t) {
// Note that this test may collide with other tests running in the same // Note that this test may collide with other tests running in the same
...@@ -19,35 +19,20 @@ promise_test(function(t) { ...@@ -19,35 +19,20 @@ promise_test(function(t) {
var cache_name = ''; var cache_name = '';
return self.caches.delete(cache_name) return self.caches.delete(cache_name)
.then(function() { .then(function() {
return self.caches.create(cache_name); return self.caches.open(cache_name);
}) })
.then(function(cache) { .then(function(cache) {
assert_true(cache instanceof Cache, assert_true(cache instanceof Cache,
'CacheStorage.create should accept an empty name.'); 'CacheStorage.open should accept an empty name.');
}); });
}, 'CacheStorage.create with an empty name'); }, 'CacheStorage.open with an empty name');
promise_test(function(t) { promise_test(function(t) {
return assert_promise_rejects( return assert_promise_rejects(
self.caches.create(), self.caches.open(),
new TypeError(), new TypeError(),
'CacheStorage.create should throw TypeError if called with no arguments.'); 'CacheStorage.open should throw TypeError if called with no arguments.');
}, 'CacheStorage.create with no arguments'); }, 'CacheStorage.open with no arguments');
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_rejects(
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) { promise_test(function(t) {
var test_cases = [ var test_cases = [
...@@ -80,7 +65,7 @@ promise_test(function(t) { ...@@ -80,7 +65,7 @@ promise_test(function(t) {
var cache_name = testcase.name; var cache_name = testcase.name;
return self.caches.delete(cache_name) return self.caches.delete(cache_name)
.then(function() { .then(function() {
return self.caches.create(cache_name); return self.caches.open(cache_name);
}) })
.then(function() { .then(function() {
return self.caches.has(cache_name); return self.caches.has(cache_name);
...@@ -117,48 +102,39 @@ promise_test(function(t) { ...@@ -117,48 +102,39 @@ promise_test(function(t) {
}, 'CacheStorage.has with nonexistent cache'); }, 'CacheStorage.has with nonexistent cache');
promise_test(function(t) { promise_test(function(t) {
var cache_name = 'cache-storage/get'; var cache_name = 'cache-storage/open';
var cache; var cache;
return self.caches.delete(cache_name) return self.caches.delete(cache_name)
.then(function() { .then(function() {
return self.caches.create(cache_name); return self.caches.open(cache_name);
}) })
.then(function(result) { .then(function(result) {
cache = result; cache = result;
}) })
.then(function() { .then(function() {
return self.caches.get(cache_name); return self.caches.open(cache_name);
}) })
.then(function(result) { .then(function(result) {
assert_equals(result, cache, assert_equals(result, cache,
'CacheStorage.get should return the named Cache ' + 'CacheStorage.open should return the named Cache ' +
'object if it exists.'); 'object if it exists.');
}) })
.then(function() { .then(function() {
return self.caches.get(cache_name); return self.caches.open(cache_name);
}) })
.then(function(result) { .then(function(result) {
assert_equals(result, cache, assert_equals(result, cache,
'CacheStorage.get should return the same ' + 'CacheStorage.open should return the same ' +
'instance of an existing Cache object.'); 'instance of an existing Cache object.');
}); });
}, 'CacheStorage.get with existing cache'); }, 'CacheStorage.open 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) { promise_test(function(t) {
var cache_name = 'cache-storage/delete'; var cache_name = 'cache-storage/delete';
return self.caches.delete(cache_name) return self.caches.delete(cache_name)
.then(function() { .then(function() {
return self.caches.create(cache_name); return self.caches.open(cache_name);
}) })
.then(function() { return self.caches.delete(cache_name); }) .then(function() { return self.caches.delete(cache_name); })
.then(function(result) { .then(function(result) {
......
...@@ -148,7 +148,7 @@ CacheStorage* CacheStorage::create(WebServiceWorkerCacheStorage* webCacheStorage ...@@ -148,7 +148,7 @@ CacheStorage* CacheStorage::create(WebServiceWorkerCacheStorage* webCacheStorage
return new CacheStorage(webCacheStorage); return new CacheStorage(webCacheStorage);
} }
ScriptPromise CacheStorage::get(ScriptState* scriptState, const String& cacheName) ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheName)
{ {
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise(); const ScriptPromise promise = resolver->promise();
...@@ -160,7 +160,7 @@ ScriptPromise CacheStorage::get(ScriptState* scriptState, const String& cacheNam ...@@ -160,7 +160,7 @@ ScriptPromise CacheStorage::get(ScriptState* scriptState, const String& cacheNam
} }
if (m_webCacheStorage) if (m_webCacheStorage)
m_webCacheStorage->dispatchGet(new WithCacheCallbacks(cacheName, this, resolver), cacheName); m_webCacheStorage->dispatchOpen(new WithCacheCallbacks(cacheName, this, resolver), cacheName);
else else
resolver->reject(createNoImplementationException()); resolver->reject(createNoImplementationException());
...@@ -185,19 +185,6 @@ ScriptPromise CacheStorage::has(ScriptState* scriptState, const String& cacheNam ...@@ -185,19 +185,6 @@ ScriptPromise CacheStorage::has(ScriptState* scriptState, const String& cacheNam
return promise; return promise;
} }
ScriptPromise CacheStorage::createFunction(ScriptState* scriptState, const String& cacheName)
{
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise();
if (m_webCacheStorage)
m_webCacheStorage->dispatchCreate(new WithCacheCallbacks(cacheName, this, resolver), cacheName);
else
resolver->reject(createNoImplementationException());
return promise;
}
ScriptPromise CacheStorage::deleteFunction(ScriptState* scriptState, const String& cacheName) ScriptPromise CacheStorage::deleteFunction(ScriptState* scriptState, const String& cacheName)
{ {
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
......
...@@ -23,9 +23,8 @@ class CacheStorage final : public GarbageCollected<CacheStorage>, public ScriptW ...@@ -23,9 +23,8 @@ class CacheStorage final : public GarbageCollected<CacheStorage>, public ScriptW
public: public:
static CacheStorage* create(WebServiceWorkerCacheStorage*); static CacheStorage* create(WebServiceWorkerCacheStorage*);
ScriptPromise get(ScriptState*, const String& cacheName); ScriptPromise open(ScriptState*, const String& cacheName);
ScriptPromise has(ScriptState*, const String& cacheName); ScriptPromise has(ScriptState*, const String& cacheName);
ScriptPromise createFunction(ScriptState*, const String& cacheName);
ScriptPromise deleteFunction(ScriptState*, const String& cacheName); ScriptPromise deleteFunction(ScriptState*, const String& cacheName);
ScriptPromise keys(ScriptState*); ScriptPromise keys(ScriptState*);
......
...@@ -8,9 +8,8 @@ ...@@ -8,9 +8,8 @@
Exposed=ServiceWorker, Exposed=ServiceWorker,
RuntimeEnabled=ServiceWorkerCache, RuntimeEnabled=ServiceWorkerCache,
] interface CacheStorage { ] interface CacheStorage {
[CallWith=ScriptState] Promise get(ScalarValueString cacheName);
[CallWith=ScriptState] Promise has(ScalarValueString cacheName); [CallWith=ScriptState] Promise has(ScalarValueString cacheName);
[CallWith=ScriptState, ImplementedAs=createFunction] Promise create(ScalarValueString cacheName); [CallWith=ScriptState] Promise open(ScalarValueString cacheName);
[CallWith=ScriptState, ImplementedAs=deleteFunction] Promise delete(ScalarValueString cacheName); [CallWith=ScriptState, ImplementedAs=deleteFunction] Promise delete(ScalarValueString cacheName);
[CallWith=ScriptState] Promise keys(); [CallWith=ScriptState] Promise keys();
// FIXME: From https://github.com/slightlyoff/ServiceWorker/issues/372 and the updated // FIXME: From https://github.com/slightlyoff/ServiceWorker/issues/372 and the updated
......
...@@ -29,11 +29,11 @@ public: ...@@ -29,11 +29,11 @@ public:
// Ownership of the CacheStorage*Callbacks methods passes to the WebServiceWorkerCacheStorage instance, which // Ownership of the CacheStorage*Callbacks methods passes to the WebServiceWorkerCacheStorage instance, which
// will delete it after calling onSuccess or onFailure. // will delete it after calling onSuccess or onFailure.
// dispatchGet() or dispatchCreate() can return a WebServiceWorkerCache object, and these objects are owned by // dispatchOpen() can return a WebServiceWorkerCache object. These
// Blink, and should be destroyed when they are no longer needed. // objects are owned by Blink and should be destroyed when they are no
virtual void dispatchGet(CacheStorageWithCacheCallbacks*, const WebString& cacheName) = 0; // longer needed.
virtual void dispatchHas(CacheStorageCallbacks*, const WebString& cacheName) = 0; virtual void dispatchHas(CacheStorageCallbacks*, const WebString& cacheName) = 0;
virtual void dispatchCreate(CacheStorageWithCacheCallbacks*, const WebString& cacheName) = 0; virtual void dispatchOpen(CacheStorageWithCacheCallbacks*, const WebString& cacheName) = 0;
virtual void dispatchDelete(CacheStorageCallbacks*, const WebString& cacheName) = 0; virtual void dispatchDelete(CacheStorageCallbacks*, const WebString& cacheName) = 0;
virtual void dispatchKeys(CacheStorageKeysCallbacks*) = 0; virtual void dispatchKeys(CacheStorageKeysCallbacks*) = 0;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment