Commit d68bf519 authored by jsbell@chromium.org's avatar jsbell@chromium.org

Service Workers: Cache.put() should resolve to undefined

Spec was updated with the determination that add(), addAll() and put()
should resolve to `undefined`, not the response(s). Only put() is
currently implemented; update the resolution type.

BUG=425469
R=jkarlin@chromium.org

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

git-svn-id: svn://svn.chromium.org/blink/trunk@184307 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a31c7538
This is a testharness.js-based test. This is a testharness.js-based test.
PASS Service Worker: Cache.put PASS Service Worker: Cache.put
FAIL Cache.put called with simple Request and Response assert_equals: Cache.put should resolve with undefined on success. expected (undefined) undefined but got (object) object "[object Response]" PASS Cache.put called with simple Request and Response
PASS Cache.put called with Request and Response from fetch() PASS Cache.put called with Request and Response from fetch()
FAIL Cache.put with Request containing a body assert_false: Cache.put should not consume Request body. expected false got true FAIL Cache.put with Request containing a body assert_false: Cache.put should not consume Request body. expected false got true
FAIL Cache.put with a Response containing an empty URL assert_equals: Cache.put should update the cache with new Request and Response. :[object].url expected "" but got "https://example.com/foo" FAIL Cache.put with a Response containing an empty URL assert_equals: Cache.put should update the cache with new Request and Response. :[object].url expected "" but got "https://example.com/foo"
......
...@@ -78,16 +78,16 @@ protected: ...@@ -78,16 +78,16 @@ protected:
}; };
// FIXME: Consider using CallbackPromiseAdapter. // FIXME: Consider using CallbackPromiseAdapter.
class CacheWithOneResponseCallbacks : public CacheWithResponsesCallbacks { class CacheAddOrPutCallbacks : public CacheWithResponsesCallbacks {
WTF_MAKE_NONCOPYABLE(CacheWithOneResponseCallbacks); WTF_MAKE_NONCOPYABLE(CacheAddOrPutCallbacks);
public: public:
CacheWithOneResponseCallbacks(PassRefPtr<ScriptPromiseResolver> resolver) CacheAddOrPutCallbacks(PassRefPtr<ScriptPromiseResolver> resolver)
: CacheWithResponsesCallbacks(resolver) { } : CacheWithResponsesCallbacks(resolver) { }
virtual void onSuccess(WebVector<WebServiceWorkerResponse>* webResponses) override virtual void onSuccess(WebVector<WebServiceWorkerResponse>* webResponses) override
{ {
ASSERT(webResponses->size() == 1); // FIXME: Since response is ignored, consider simplifying public API.
m_resolver->resolve(Response::create(m_resolver->scriptState()->executionContext(), (*webResponses)[0])); m_resolver->resolve();
m_resolver.clear(); m_resolver.clear();
} }
}; };
...@@ -101,6 +101,7 @@ public: ...@@ -101,6 +101,7 @@ public:
virtual void onSuccess(WebVector<WebServiceWorkerResponse>* webResponses) override virtual void onSuccess(WebVector<WebServiceWorkerResponse>* webResponses) override
{ {
// FIXME: Since response is ignored, consider simplifying public API.
m_resolver->resolve(true); m_resolver->resolve(true);
m_resolver.clear(); m_resolver.clear();
} }
...@@ -378,7 +379,7 @@ ScriptPromise Cache::putImpl(ScriptState* scriptState, Request* request, Respons ...@@ -378,7 +379,7 @@ ScriptPromise Cache::putImpl(ScriptState* scriptState, Request* request, Respons
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise(); const ScriptPromise promise = resolver->promise();
m_webCache->dispatchBatch(new CacheWithOneResponseCallbacks(resolver), batchOperations); m_webCache->dispatchBatch(new CacheAddOrPutCallbacks(resolver), batchOperations);
return promise; return promise;
} }
......
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