Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ExceptionState.h" | |
| 8 #include "core/testing/DummyPageHolder.h" | |
| 9 #include "modules/serviceworkers/Cache.h" | |
| 10 #include "modules/serviceworkers/Request.h" | |
| 11 #include "public/platform/WebServiceWorkerCache.h" | |
| 12 #include "wtf/OwnPtr.h" | |
| 13 #include <gtest/gtest.h> | |
| 14 | |
| 15 namespace blink { | |
| 16 namespace { | |
| 17 | |
| 18 class TestWebCache : public WebServiceWorkerCache { | |
| 19 public: | |
| 20 | |
| 21 // From WebServiceWorkerCache: | |
| 22 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW orkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE | |
| 23 { | |
| 24 fprintf(stderr, "dispatchMatch()\n"); | |
| 25 OwnPtr<CacheMatchCallbacks> own_callbacks(adoptPtr(callbacks)); | |
| 26 WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemen ted; | |
| 27 return callbacks->onError(&error); | |
| 28 } | |
| 29 | |
| 30 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE | |
| 31 { | |
| 32 OwnPtr<CacheWithResponsesCallbacks> own_callbacks(adoptPtr(callbacks)); | |
| 33 WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemen ted; | |
| 34 return callbacks->onError(&error); | |
| 35 } | |
| 36 | |
| 37 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe rviceWorkerRequest* webRequest, const QueryParams& queryParams) OVERRIDE | |
| 38 { | |
| 39 OwnPtr<CacheWithRequestsCallbacks> own_callbacks(adoptPtr(callbacks)); | |
| 40 WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemen ted; | |
| 41 return callbacks->onError(&error); | |
| 42 } | |
| 43 | |
| 44 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web Vector<BatchOperation>& batchOperations) OVERRIDE | |
| 45 { | |
| 46 OwnPtr<CacheWithResponsesCallbacks> own_callbacks(adoptPtr(callbacks)); | |
| 47 WebServiceWorkerCacheError error = WebServiceWorkerCacheErrorNotImplemen ted; | |
| 48 return callbacks->onError(&error); | |
| 49 } | |
| 50 | |
| 51 }; | |
| 52 | |
| 53 class ServiceWorkerCacheTest : public ::testing::Test { | |
| 54 public: | |
| 55 ServiceWorkerCacheTest() : m_page(DummyPageHolder::create(IntSize(1, 1))) { } | |
| 56 | |
| 57 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume nt().frame()); } | |
| 58 ExecutionContext* executionContext() { return scriptState()->executionContex t(); } | |
| 59 | |
| 60 PassRefPtrWillBeRawPtr<Request> createRequest(const String& url) | |
| 61 { | |
| 62 TrackExceptionState exceptionState; | |
| 63 RefPtrWillBeRawPtr<Request> request = Request::create(executionContext() , url, exceptionState); | |
| 64 EXPECT_FALSE(exceptionState.hadException()); | |
| 65 EXPECT_TRUE(request); | |
| 66 return request; | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 OwnPtr<DummyPageHolder> m_page; | |
| 71 }; | |
| 72 | |
| 73 TEST_F(ServiceWorkerCacheTest, Basics) | |
| 74 { | |
| 75 TestWebCache testWebCache; | |
| 76 fprintf(stderr, "one\n"); | |
| 77 RefPtrWillBeRawPtr<Cache> cache = Cache::fromWebServiceWorkerCache(&testWebC ache); | |
| 78 fprintf(stderr, "two\n"); | |
| 79 ASSERT(cache); | |
| 80 fprintf(stderr, "three\n"); | |
| 81 | |
| 82 const String url = "http://www.cachetest.org/"; | |
| 83 scriptState()->isolate(); | |
| 84 | |
| 85 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
| |
| 86 } | |
| 87 | |
| 88 | |
| 89 } // namespace | |
| 90 } // namespace blink | |
| OLD | NEW |