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

Unified Diff: Source/modules/serviceworkers/CacheTest.cpp

Issue 433793002: Introducing the WebServiceWorkerCache. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: test isn't quite working Created 6 years, 4 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
« no previous file with comments | « Source/modules/serviceworkers/CacheStorage.cpp ('k') | public/platform/WebServiceWorkerCache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/CacheTest.cpp
diff --git a/Source/modules/serviceworkers/CacheTest.cpp b/Source/modules/serviceworkers/CacheTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..217a1a92e3d340f17303119f108e00b243d3c83f
--- /dev/null
+++ b/Source/modules/serviceworkers/CacheTest.cpp
@@ -0,0 +1,90 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "core/testing/DummyPageHolder.h"
+#include "modules/serviceworkers/Cache.h"
+#include "modules/serviceworkers/Request.h"
+#include "public/platform/WebServiceWorkerCache.h"
+#include "wtf/OwnPtr.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+namespace {
+
+class TestWebCache : public WebServiceWorkerCache {
+public:
+
+ // From WebServiceWorkerCache:
+ virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE
+ {
+ fprintf(stderr, "dispatchMatch()\n");
+ OwnPtr<CacheMatchCallbacks> own_callbacks(adoptPtr(callbacks));
+ WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemented;
+ return callbacks->onError(&error);
+ }
+
+ virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE
+ {
+ OwnPtr<CacheWithResponsesCallbacks> own_callbacks(adoptPtr(callbacks));
+ WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemented;
+ return callbacks->onError(&error);
+ }
+
+ virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWorkerRequest* webRequest, const QueryParams& queryParams) OVERRIDE
+ {
+ OwnPtr<CacheWithRequestsCallbacks> own_callbacks(adoptPtr(callbacks));
+ WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemented;
+ return callbacks->onError(&error);
+ }
+
+ virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const WebVector<BatchOperation>& batchOperations) OVERRIDE
+ {
+ OwnPtr<CacheWithResponsesCallbacks> own_callbacks(adoptPtr(callbacks));
+ WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemented;
+ return callbacks->onError(&error);
+ }
+
+};
+
+class ServiceWorkerCacheTest : public ::testing::Test {
+public:
+ ServiceWorkerCacheTest() : m_page(DummyPageHolder::create(IntSize(1, 1))) { }
+
+ ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->document().frame()); }
+ ExecutionContext* executionContext() { return scriptState()->executionContext(); }
+
+ PassRefPtrWillBeRawPtr<Request> createRequest(const String& url)
+ {
+ TrackExceptionState exceptionState;
+ RefPtrWillBeRawPtr<Request> request = Request::create(executionContext(), url, exceptionState);
+ EXPECT_FALSE(exceptionState.hadException());
+ EXPECT_TRUE(request);
+ return request;
+ }
+
+private:
+ OwnPtr<DummyPageHolder> m_page;
+};
+
+TEST_F(ServiceWorkerCacheTest, Basics)
+{
+ TestWebCache testWebCache;
+ fprintf(stderr, "one\n");
+ RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(&testWebCache);
+ fprintf(stderr, "two\n");
+ ASSERT(cache);
+ fprintf(stderr, "three\n");
+
+ const String url = "http://www.cachetest.org/";
+ scriptState()->isolate();
+
+ ScriptPromise blah = cache->match(scriptState(), url, Dictionary());
gavinp 2014/08/29 20:03:26 This line crashes. It's during construction of Scr
jsbell 2014/08/29 21:26:43 Toss ScriptState::Scope scriptScope(scriptState())
gavinp 2014/09/02 14:42:48 And I found it. Thanks Josh, I'll be uploading a r
+}
+
+
+} // namespace
+} // namespace blink
« no previous file with comments | « Source/modules/serviceworkers/CacheStorage.cpp ('k') | public/platform/WebServiceWorkerCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698