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

Side by Side Diff: Source/modules/cachestorage/CacheTest.cpp

Issue 1227783004: Fix virtual/override/final usage in Source/modules/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/cachestorage/Cache.h" 6 #include "modules/cachestorage/Cache.h"
7 7
8 #include "bindings/core/v8/ExceptionState.h" 8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptFunction.h" 9 #include "bindings/core/v8/ScriptFunction.h"
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 m_lastErrorWebCacheMethodCalled.clear(); 98 m_lastErrorWebCacheMethodCalled.clear();
99 return old; 99 return old;
100 } 100 }
101 101
102 // These methods do not take ownership of their parameter. They provide an o ptional sample object to check parameters against. 102 // These methods do not take ownership of their parameter. They provide an o ptional sample object to check parameters against.
103 void setExpectedUrl(const String* expectedUrl) { m_expectedUrl = expectedUrl ; } 103 void setExpectedUrl(const String* expectedUrl) { m_expectedUrl = expectedUrl ; }
104 void setExpectedQueryParams(const QueryParams* expectedQueryParams) { m_expe ctedQueryParams = expectedQueryParams; } 104 void setExpectedQueryParams(const QueryParams* expectedQueryParams) { m_expe ctedQueryParams = expectedQueryParams; }
105 void setExpectedBatchOperations(const WebVector<BatchOperation>* expectedBat chOperations) { m_expectedBatchOperations = expectedBatchOperations; } 105 void setExpectedBatchOperations(const WebVector<BatchOperation>* expectedBat chOperations) { m_expectedBatchOperations = expectedBatchOperations; }
106 106
107 // From WebServiceWorkerCache: 107 // From WebServiceWorkerCache:
108 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW orkerRequest& webRequest, const QueryParams& queryParams) override 108 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq uest& webRequest, const QueryParams& queryParams) override
109 { 109 {
110 m_lastErrorWebCacheMethodCalled = "dispatchMatch"; 110 m_lastErrorWebCacheMethodCalled = "dispatchMatch";
111 checkUrlIfProvided(webRequest.url()); 111 checkUrlIfProvided(webRequest.url());
112 checkQueryParamsIfProvided(queryParams); 112 checkQueryParamsIfProvided(queryParams);
113 113
114 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); 114 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks));
115 return callbacks->onError(new WebServiceWorkerCacheError(m_error)); 115 return callbacks->onError(new WebServiceWorkerCacheError(m_error));
116 } 116 }
117 117
118 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) override 118 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServi ceWorkerRequest& webRequest, const QueryParams& queryParams) override
119 { 119 {
120 m_lastErrorWebCacheMethodCalled = "dispatchMatchAll"; 120 m_lastErrorWebCacheMethodCalled = "dispatchMatchAll";
121 checkUrlIfProvided(webRequest.url()); 121 checkUrlIfProvided(webRequest.url());
122 checkQueryParamsIfProvided(queryParams); 122 checkQueryParamsIfProvided(queryParams);
123 123
124 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); 124 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks));
125 return callbacks->onError(new WebServiceWorkerCacheError(m_error)); 125 return callbacks->onError(new WebServiceWorkerCacheError(m_error));
126 } 126 }
127 127
128 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe rviceWorkerRequest* webRequest, const QueryParams& queryParams) override 128 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor kerRequest* webRequest, const QueryParams& queryParams) override
129 { 129 {
130 m_lastErrorWebCacheMethodCalled = "dispatchKeys"; 130 m_lastErrorWebCacheMethodCalled = "dispatchKeys";
131 if (webRequest) { 131 if (webRequest) {
132 checkUrlIfProvided(webRequest->url()); 132 checkUrlIfProvided(webRequest->url());
133 checkQueryParamsIfProvided(queryParams); 133 checkQueryParamsIfProvided(queryParams);
134 } 134 }
135 135
136 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); 136 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks));
137 return callbacks->onError(new WebServiceWorkerCacheError(m_error)); 137 return callbacks->onError(new WebServiceWorkerCacheError(m_error));
138 } 138 }
139 139
140 virtual void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<B atchOperation>& batchOperations) override 140 void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<BatchOper ation>& batchOperations) override
141 { 141 {
142 m_lastErrorWebCacheMethodCalled = "dispatchBatch"; 142 m_lastErrorWebCacheMethodCalled = "dispatchBatch";
143 checkBatchOperationsIfProvided(batchOperations); 143 checkBatchOperationsIfProvided(batchOperations);
144 144
145 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); 145 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks));
146 return callbacks->onError(new WebServiceWorkerCacheError(m_error)); 146 return callbacks->onError(new WebServiceWorkerCacheError(m_error));
147 } 147 }
148 148
149 protected: 149 protected:
150 void checkUrlIfProvided(const KURL& url) 150 void checkUrlIfProvided(const KURL& url)
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 private: 261 private:
262 // A ScriptFunction that creates a test failure if it is ever called. 262 // A ScriptFunction that creates a test failure if it is ever called.
263 class UnreachableFunction : public ScriptFunction { 263 class UnreachableFunction : public ScriptFunction {
264 public: 264 public:
265 static v8::Local<v8::Function> create(ScriptState* scriptState) 265 static v8::Local<v8::Function> create(ScriptState* scriptState)
266 { 266 {
267 UnreachableFunction* self = new UnreachableFunction(scriptState); 267 UnreachableFunction* self = new UnreachableFunction(scriptState);
268 return self->bindToV8Function(); 268 return self->bindToV8Function();
269 } 269 }
270 270
271 virtual ScriptValue call(ScriptValue value) override 271 ScriptValue call(ScriptValue value) override
272 { 272 {
273 ADD_FAILURE() << "Unexpected call to a null ScriptFunction."; 273 ADD_FAILURE() << "Unexpected call to a null ScriptFunction.";
274 return value; 274 return value;
275 } 275 }
276 private: 276 private:
277 UnreachableFunction(ScriptState* scriptState) : ScriptFunction(scriptSta te) { } 277 UnreachableFunction(ScriptState* scriptState) : ScriptFunction(scriptSta te) { }
278 }; 278 };
279 279
280 // A ScriptFunction that saves its parameter; used by tests to assert on cor rect 280 // A ScriptFunction that saves its parameter; used by tests to assert on cor rect
281 // values being passed. 281 // values being passed.
282 class TestFunction : public ScriptFunction { 282 class TestFunction : public ScriptFunction {
283 public: 283 public:
284 static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptVa lue* outValue) 284 static v8::Local<v8::Function> create(ScriptState* scriptState, ScriptVa lue* outValue)
285 { 285 {
286 TestFunction* self = new TestFunction(scriptState, outValue); 286 TestFunction* self = new TestFunction(scriptState, outValue);
287 return self->bindToV8Function(); 287 return self->bindToV8Function();
288 } 288 }
289 289
290 virtual ScriptValue call(ScriptValue value) override 290 ScriptValue call(ScriptValue value) override
291 { 291 {
292 ASSERT(!value.isEmpty()); 292 ASSERT(!value.isEmpty());
293 *m_value = value; 293 *m_value = value;
294 return value; 294 return value;
295 } 295 }
296 296
297 private: 297 private:
298 TestFunction(ScriptState* scriptState, ScriptValue* outValue) : ScriptFu nction(scriptState), m_value(outValue) { } 298 TestFunction(ScriptState* scriptState, ScriptValue* outValue) : ScriptFu nction(scriptState), m_value(outValue) { }
299 299
300 ScriptValue* m_value; 300 ScriptValue* m_value;
301 }; 301 };
302 302
303 // From ::testing::Test: 303 // From ::testing::Test:
304 virtual void SetUp() override 304 void SetUp() override
305 { 305 {
306 EXPECT_FALSE(m_scopedFetcherForTests); 306 EXPECT_FALSE(m_scopedFetcherForTests);
307 m_scopedFetcherForTests = adoptPtr(new ScopedFetcherForTests()); 307 m_scopedFetcherForTests = adoptPtr(new ScopedFetcherForTests());
308 EXPECT_FALSE(m_scriptScope); 308 EXPECT_FALSE(m_scriptScope);
309 m_scriptScope = adoptPtr(new ScriptState::Scope(scriptState())); 309 m_scriptScope = adoptPtr(new ScriptState::Scope(scriptState()));
310 } 310 }
311 311
312 virtual void TearDown() override 312 void TearDown() override
313 { 313 {
314 m_scopedFetcherForTests = nullptr; 314 m_scopedFetcherForTests = nullptr;
315 m_scriptScope = 0; 315 m_scriptScope = 0;
316 } 316 }
317 317
318 OwnPtr<ScopedFetcherForTests> m_scopedFetcherForTests; 318 OwnPtr<ScopedFetcherForTests> m_scopedFetcherForTests;
319 319
320 // Lifetime is that of the text fixture. 320 // Lifetime is that of the text fixture.
321 OwnPtr<DummyPageHolder> m_page; 321 OwnPtr<DummyPageHolder> m_page;
322 322
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 // FIXME: test add & addAll. 480 // FIXME: test add & addAll.
481 } 481 }
482 482
483 class MatchTestCache : public NotImplementedErrorCache { 483 class MatchTestCache : public NotImplementedErrorCache {
484 public: 484 public:
485 MatchTestCache(WebServiceWorkerResponse& response) 485 MatchTestCache(WebServiceWorkerResponse& response)
486 : m_response(response) { } 486 : m_response(response) { }
487 487
488 // From WebServiceWorkerCache: 488 // From WebServiceWorkerCache:
489 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW orkerRequest& webRequest, const QueryParams& queryParams) override 489 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq uest& webRequest, const QueryParams& queryParams) override
490 { 490 {
491 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); 491 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks));
492 return callbacks->onSuccess(&m_response); 492 return callbacks->onSuccess(&m_response);
493 } 493 }
494 494
495 private: 495 private:
496 WebServiceWorkerResponse& m_response; 496 WebServiceWorkerResponse& m_response;
497 }; 497 };
498 498
499 TEST_F(CacheStorageTest, MatchResponseTest) 499 TEST_F(CacheStorageTest, MatchResponseTest)
(...skipping 13 matching lines...) Expand all
513 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue. v8Value()); 513 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue. v8Value());
514 ASSERT_TRUE(response); 514 ASSERT_TRUE(response);
515 EXPECT_EQ(responseUrl, response->url()); 515 EXPECT_EQ(responseUrl, response->url());
516 } 516 }
517 517
518 class KeysTestCache : public NotImplementedErrorCache { 518 class KeysTestCache : public NotImplementedErrorCache {
519 public: 519 public:
520 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) 520 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests)
521 : m_requests(requests) { } 521 : m_requests(requests) { }
522 522
523 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe rviceWorkerRequest* webRequest, const QueryParams& queryParams) override 523 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor kerRequest* webRequest, const QueryParams& queryParams) override
524 { 524 {
525 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); 525 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks));
526 return callbacks->onSuccess(&m_requests); 526 return callbacks->onSuccess(&m_requests);
527 } 527 }
528 528
529 private: 529 private:
530 WebVector<WebServiceWorkerRequest>& m_requests; 530 WebVector<WebServiceWorkerRequest>& m_requests;
531 }; 531 };
532 532
533 TEST_F(CacheStorageTest, KeysResponseTest) 533 TEST_F(CacheStorageTest, KeysResponseTest)
(...skipping 22 matching lines...) Expand all
556 if (request) 556 if (request)
557 EXPECT_EQ(expectedUrls[i], request->url()); 557 EXPECT_EQ(expectedUrls[i], request->url());
558 } 558 }
559 } 559 }
560 560
561 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { 561 class MatchAllAndBatchTestCache : public NotImplementedErrorCache {
562 public: 562 public:
563 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) 563 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses)
564 : m_responses(responses) { } 564 : m_responses(responses) { }
565 565
566 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) override 566 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServi ceWorkerRequest& webRequest, const QueryParams& queryParams) override
567 { 567 {
568 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); 568 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks));
569 return callbacks->onSuccess(&m_responses); 569 return callbacks->onSuccess(&m_responses);
570 } 570 }
571 571
572 virtual void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<B atchOperation>& batchOperations) override 572 void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<BatchOper ation>& batchOperations) override
573 { 573 {
574 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); 574 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks));
575 return callbacks->onSuccess(); 575 return callbacks->onSuccess();
576 } 576 }
577 577
578 private: 578 private:
579 WebVector<WebServiceWorkerResponse>& m_responses; 579 WebVector<WebServiceWorkerResponse>& m_responses;
580 }; 580 };
581 581
582 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) 582 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 643
644 ScriptPromise addResult = cache->add(scriptState(), requestToRequestInfo(req uest), exceptionState()); 644 ScriptPromise addResult = cache->add(scriptState(), requestToRequestInfo(req uest), exceptionState());
645 645
646 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); 646 EXPECT_EQ(kNotImplementedString, getRejectString(addResult));
647 EXPECT_EQ(1, fetcher()->fetchCount()); 647 EXPECT_EQ(1, fetcher()->fetchCount());
648 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall ed()); 648 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall ed());
649 } 649 }
650 650
651 } // namespace 651 } // namespace
652 } // namespace blink 652 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/cachestorage/CacheStorage.cpp ('k') | Source/modules/cachestorage/InspectorCacheStorageAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698