OLD | NEW |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& 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(m_error); |
116 } | 116 } |
117 | 117 |
118 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServi
ceWorkerRequest& 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(m_error); |
126 } | 126 } |
127 | 127 |
128 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest* 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(m_error); |
138 } | 138 } |
139 | 139 |
140 void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<BatchOper
ation>& 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(m_error); | 146 return callbacks->onError(m_error); |
147 } | 147 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 class MatchTestCache : public NotImplementedErrorCache { | 468 class MatchTestCache : public NotImplementedErrorCache { |
469 public: | 469 public: |
470 MatchTestCache(WebServiceWorkerResponse& response) | 470 MatchTestCache(WebServiceWorkerResponse& response) |
471 : m_response(response) { } | 471 : m_response(response) { } |
472 | 472 |
473 // From WebServiceWorkerCache: | 473 // From WebServiceWorkerCache: |
474 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& webRequest, const QueryParams& queryParams) override | 474 void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceWorkerReq
uest& webRequest, const QueryParams& queryParams) override |
475 { | 475 { |
476 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 476 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
477 return callbacks->onSuccess(&m_response); | 477 return callbacks->onSuccess(m_response); |
478 } | 478 } |
479 | 479 |
480 private: | 480 private: |
481 WebServiceWorkerResponse& m_response; | 481 WebServiceWorkerResponse& m_response; |
482 }; | 482 }; |
483 | 483 |
484 TEST_F(CacheStorageTest, MatchResponseTest) | 484 TEST_F(CacheStorageTest, MatchResponseTest) |
485 { | 485 { |
486 ScriptState::Scope scope(scriptState()); | 486 ScriptState::Scope scope(scriptState()); |
487 OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests()
); | 487 OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests()
); |
(...skipping 15 matching lines...) Expand all Loading... |
503 } | 503 } |
504 | 504 |
505 class KeysTestCache : public NotImplementedErrorCache { | 505 class KeysTestCache : public NotImplementedErrorCache { |
506 public: | 506 public: |
507 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) | 507 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) |
508 : m_requests(requests) { } | 508 : m_requests(requests) { } |
509 | 509 |
510 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest* webRequest, const QueryParams& queryParams) override | 510 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebServiceWor
kerRequest* webRequest, const QueryParams& queryParams) override |
511 { | 511 { |
512 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 512 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
513 return callbacks->onSuccess(&m_requests); | 513 return callbacks->onSuccess(m_requests); |
514 } | 514 } |
515 | 515 |
516 private: | 516 private: |
517 WebVector<WebServiceWorkerRequest>& m_requests; | 517 WebVector<WebServiceWorkerRequest>& m_requests; |
518 }; | 518 }; |
519 | 519 |
520 TEST_F(CacheStorageTest, KeysResponseTest) | 520 TEST_F(CacheStorageTest, KeysResponseTest) |
521 { | 521 { |
522 ScriptState::Scope scope(scriptState()); | 522 ScriptState::Scope scope(scriptState()); |
523 OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests()
); | 523 OwnPtr<ScopedFetcherForTests> fetcher = adoptPtr(new ScopedFetcherForTests()
); |
(...skipping 24 matching lines...) Expand all Loading... |
548 } | 548 } |
549 | 549 |
550 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 550 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
551 public: | 551 public: |
552 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) | 552 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) |
553 : m_responses(responses) { } | 553 : m_responses(responses) { } |
554 | 554 |
555 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServi
ceWorkerRequest& webRequest, const QueryParams& queryParams) override | 555 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const WebServi
ceWorkerRequest& webRequest, const QueryParams& queryParams) override |
556 { | 556 { |
557 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 557 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
558 return callbacks->onSuccess(&m_responses); | 558 return callbacks->onSuccess(m_responses); |
559 } | 559 } |
560 | 560 |
561 void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<BatchOper
ation>& batchOperations) override | 561 void dispatchBatch(CacheBatchCallbacks* callbacks, const WebVector<BatchOper
ation>& batchOperations) override |
562 { | 562 { |
563 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 563 OwnPtr<CacheBatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
564 return callbacks->onSuccess(); | 564 return callbacks->onSuccess(); |
565 } | 565 } |
566 | 566 |
567 private: | 567 private: |
568 WebVector<WebServiceWorkerResponse>& m_responses; | 568 WebVector<WebServiceWorkerResponse>& m_responses; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 | 636 |
637 ScriptPromise addResult = cache->add(scriptState(), requestToRequestInfo(req
uest), exceptionState()); | 637 ScriptPromise addResult = cache->add(scriptState(), requestToRequestInfo(req
uest), exceptionState()); |
638 | 638 |
639 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); | 639 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); |
640 EXPECT_EQ(1, fetcher->fetchCount()); | 640 EXPECT_EQ(1, fetcher->fetchCount()); |
641 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); | 641 EXPECT_EQ("dispatchBatch", testCache->getAndClearLastErrorWebCacheMethodCall
ed()); |
642 } | 642 } |
643 | 643 |
644 } // namespace | 644 } // namespace |
645 } // namespace blink | 645 } // namespace blink |
OLD | NEW |