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 "modules/cachestorage/Cache.h" | 5 #include "modules/cachestorage/Cache.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 void setExpectedQueryParams(const QueryParams* expectedQueryParams) { | 119 void setExpectedQueryParams(const QueryParams* expectedQueryParams) { |
120 m_expectedQueryParams = expectedQueryParams; | 120 m_expectedQueryParams = expectedQueryParams; |
121 } | 121 } |
122 void setExpectedBatchOperations( | 122 void setExpectedBatchOperations( |
123 const WebVector<BatchOperation>* expectedBatchOperations) { | 123 const WebVector<BatchOperation>* expectedBatchOperations) { |
124 m_expectedBatchOperations = expectedBatchOperations; | 124 m_expectedBatchOperations = expectedBatchOperations; |
125 } | 125 } |
126 | 126 |
127 // From WebServiceWorkerCache: | 127 // From WebServiceWorkerCache: |
128 void dispatchMatch(CacheMatchCallbacks* callbacks, | 128 void dispatchMatch(std::unique_ptr<CacheMatchCallbacks> callbacks, |
129 const WebServiceWorkerRequest& webRequest, | 129 const WebServiceWorkerRequest& webRequest, |
130 const QueryParams& queryParams) override { | 130 const QueryParams& queryParams) override { |
131 m_lastErrorWebCacheMethodCalled = "dispatchMatch"; | 131 m_lastErrorWebCacheMethodCalled = "dispatchMatch"; |
132 checkUrlIfProvided(webRequest.url()); | 132 checkUrlIfProvided(webRequest.url()); |
133 checkQueryParamsIfProvided(queryParams); | 133 checkQueryParamsIfProvided(queryParams); |
134 | 134 |
135 std::unique_ptr<CacheMatchCallbacks> ownedCallbacks(wrapUnique(callbacks)); | |
136 return callbacks->onError(m_error); | 135 return callbacks->onError(m_error); |
137 } | 136 } |
138 | 137 |
139 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, | 138 void dispatchMatchAll(std::unique_ptr<CacheWithResponsesCallbacks> callbacks, |
140 const WebServiceWorkerRequest& webRequest, | 139 const WebServiceWorkerRequest& webRequest, |
141 const QueryParams& queryParams) override { | 140 const QueryParams& queryParams) override { |
142 m_lastErrorWebCacheMethodCalled = "dispatchMatchAll"; | 141 m_lastErrorWebCacheMethodCalled = "dispatchMatchAll"; |
143 checkUrlIfProvided(webRequest.url()); | 142 checkUrlIfProvided(webRequest.url()); |
144 checkQueryParamsIfProvided(queryParams); | 143 checkQueryParamsIfProvided(queryParams); |
145 | 144 |
146 std::unique_ptr<CacheWithResponsesCallbacks> ownedCallbacks( | |
147 wrapUnique(callbacks)); | |
148 return callbacks->onError(m_error); | 145 return callbacks->onError(m_error); |
149 } | 146 } |
150 | 147 |
151 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, | 148 void dispatchKeys(std::unique_ptr<CacheWithRequestsCallbacks> callbacks, |
152 const WebServiceWorkerRequest& webRequest, | 149 const WebServiceWorkerRequest& webRequest, |
153 const QueryParams& queryParams) override { | 150 const QueryParams& queryParams) override { |
154 m_lastErrorWebCacheMethodCalled = "dispatchKeys"; | 151 m_lastErrorWebCacheMethodCalled = "dispatchKeys"; |
155 if (!webRequest.url().isEmpty()) { | 152 if (!webRequest.url().isEmpty()) { |
156 checkUrlIfProvided(webRequest.url()); | 153 checkUrlIfProvided(webRequest.url()); |
157 checkQueryParamsIfProvided(queryParams); | 154 checkQueryParamsIfProvided(queryParams); |
158 } | 155 } |
159 | 156 |
160 std::unique_ptr<CacheWithRequestsCallbacks> ownedCallbacks( | |
161 wrapUnique(callbacks)); | |
162 return callbacks->onError(m_error); | 157 return callbacks->onError(m_error); |
163 } | 158 } |
164 | 159 |
165 void dispatchBatch( | 160 void dispatchBatch( |
166 CacheBatchCallbacks* callbacks, | 161 std::unique_ptr<CacheBatchCallbacks> callbacks, |
167 const WebVector<BatchOperation>& batchOperations) override { | 162 const WebVector<BatchOperation>& batchOperations) override { |
168 m_lastErrorWebCacheMethodCalled = "dispatchBatch"; | 163 m_lastErrorWebCacheMethodCalled = "dispatchBatch"; |
169 checkBatchOperationsIfProvided(batchOperations); | 164 checkBatchOperationsIfProvided(batchOperations); |
170 | 165 |
171 std::unique_ptr<CacheBatchCallbacks> ownedCallbacks(wrapUnique(callbacks)); | |
172 return callbacks->onError(m_error); | 166 return callbacks->onError(m_error); |
173 } | 167 } |
174 | 168 |
175 protected: | 169 protected: |
176 void checkUrlIfProvided(const KURL& url) { | 170 void checkUrlIfProvided(const KURL& url) { |
177 if (!m_expectedUrl) | 171 if (!m_expectedUrl) |
178 return; | 172 return; |
179 EXPECT_EQ(*m_expectedUrl, url); | 173 EXPECT_EQ(*m_expectedUrl, url); |
180 } | 174 } |
181 | 175 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 EXPECT_EQ(kNotImplementedString, getRejectString(stringPutResult)); | 520 EXPECT_EQ(kNotImplementedString, getRejectString(stringPutResult)); |
527 | 521 |
528 // FIXME: test add & addAll. | 522 // FIXME: test add & addAll. |
529 } | 523 } |
530 | 524 |
531 class MatchTestCache : public NotImplementedErrorCache { | 525 class MatchTestCache : public NotImplementedErrorCache { |
532 public: | 526 public: |
533 MatchTestCache(WebServiceWorkerResponse& response) : m_response(response) {} | 527 MatchTestCache(WebServiceWorkerResponse& response) : m_response(response) {} |
534 | 528 |
535 // From WebServiceWorkerCache: | 529 // From WebServiceWorkerCache: |
536 void dispatchMatch(CacheMatchCallbacks* callbacks, | 530 void dispatchMatch(std::unique_ptr<CacheMatchCallbacks> callbacks, |
537 const WebServiceWorkerRequest& webRequest, | 531 const WebServiceWorkerRequest& webRequest, |
538 const QueryParams& queryParams) override { | 532 const QueryParams& queryParams) override { |
539 std::unique_ptr<CacheMatchCallbacks> ownedCallbacks(wrapUnique(callbacks)); | |
540 return callbacks->onSuccess(m_response); | 533 return callbacks->onSuccess(m_response); |
541 } | 534 } |
542 | 535 |
543 private: | 536 private: |
544 WebServiceWorkerResponse& m_response; | 537 WebServiceWorkerResponse& m_response; |
545 }; | 538 }; |
546 | 539 |
547 TEST_F(CacheStorageTest, MatchResponseTest) { | 540 TEST_F(CacheStorageTest, MatchResponseTest) { |
548 ScriptState::Scope scope(getScriptState()); | 541 ScriptState::Scope scope(getScriptState()); |
549 NonThrowableExceptionState exceptionState; | 542 NonThrowableExceptionState exceptionState; |
(...skipping 16 matching lines...) Expand all Loading... |
566 V8Response::toImplWithTypeCheck(isolate(), scriptValue.v8Value()); | 559 V8Response::toImplWithTypeCheck(isolate(), scriptValue.v8Value()); |
567 ASSERT_TRUE(response); | 560 ASSERT_TRUE(response); |
568 EXPECT_EQ(responseUrl, response->url()); | 561 EXPECT_EQ(responseUrl, response->url()); |
569 } | 562 } |
570 | 563 |
571 class KeysTestCache : public NotImplementedErrorCache { | 564 class KeysTestCache : public NotImplementedErrorCache { |
572 public: | 565 public: |
573 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) | 566 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) |
574 : m_requests(requests) {} | 567 : m_requests(requests) {} |
575 | 568 |
576 void dispatchKeys(CacheWithRequestsCallbacks* callbacks, | 569 void dispatchKeys(std::unique_ptr<CacheWithRequestsCallbacks> callbacks, |
577 const WebServiceWorkerRequest& webRequest, | 570 const WebServiceWorkerRequest& webRequest, |
578 const QueryParams& queryParams) override { | 571 const QueryParams& queryParams) override { |
579 std::unique_ptr<CacheWithRequestsCallbacks> ownedCallbacks( | |
580 wrapUnique(callbacks)); | |
581 return callbacks->onSuccess(m_requests); | 572 return callbacks->onSuccess(m_requests); |
582 } | 573 } |
583 | 574 |
584 private: | 575 private: |
585 WebVector<WebServiceWorkerRequest>& m_requests; | 576 WebVector<WebServiceWorkerRequest>& m_requests; |
586 }; | 577 }; |
587 | 578 |
588 TEST_F(CacheStorageTest, KeysResponseTest) { | 579 TEST_F(CacheStorageTest, KeysResponseTest) { |
589 ScriptState::Scope scope(getScriptState()); | 580 ScriptState::Scope scope(getScriptState()); |
590 NonThrowableExceptionState exceptionState; | 581 NonThrowableExceptionState exceptionState; |
(...skipping 25 matching lines...) Expand all Loading... |
616 if (request) | 607 if (request) |
617 EXPECT_EQ(expectedUrls[i], request->url()); | 608 EXPECT_EQ(expectedUrls[i], request->url()); |
618 } | 609 } |
619 } | 610 } |
620 | 611 |
621 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 612 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
622 public: | 613 public: |
623 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) | 614 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) |
624 : m_responses(responses) {} | 615 : m_responses(responses) {} |
625 | 616 |
626 void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, | 617 void dispatchMatchAll(std::unique_ptr<CacheWithResponsesCallbacks> callbacks, |
627 const WebServiceWorkerRequest& webRequest, | 618 const WebServiceWorkerRequest& webRequest, |
628 const QueryParams& queryParams) override { | 619 const QueryParams& queryParams) override { |
629 std::unique_ptr<CacheWithResponsesCallbacks> ownedCallbacks( | |
630 wrapUnique(callbacks)); | |
631 return callbacks->onSuccess(m_responses); | 620 return callbacks->onSuccess(m_responses); |
632 } | 621 } |
633 | 622 |
634 void dispatchBatch( | 623 void dispatchBatch( |
635 CacheBatchCallbacks* callbacks, | 624 std::unique_ptr<CacheBatchCallbacks> callbacks, |
636 const WebVector<BatchOperation>& batchOperations) override { | 625 const WebVector<BatchOperation>& batchOperations) override { |
637 std::unique_ptr<CacheBatchCallbacks> ownedCallbacks(wrapUnique(callbacks)); | |
638 return callbacks->onSuccess(); | 626 return callbacks->onSuccess(); |
639 } | 627 } |
640 | 628 |
641 private: | 629 private: |
642 WebVector<WebServiceWorkerResponse>& m_responses; | 630 WebVector<WebServiceWorkerResponse>& m_responses; |
643 }; | 631 }; |
644 | 632 |
645 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) { | 633 TEST_F(CacheStorageTest, MatchAllAndBatchResponseTest) { |
646 ScriptState::Scope scope(getScriptState()); | 634 ScriptState::Scope scope(getScriptState()); |
647 NonThrowableExceptionState exceptionState; | 635 NonThrowableExceptionState exceptionState; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 715 |
728 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); | 716 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); |
729 EXPECT_EQ(1, fetcher->fetchCount()); | 717 EXPECT_EQ(1, fetcher->fetchCount()); |
730 EXPECT_EQ("dispatchBatch", | 718 EXPECT_EQ("dispatchBatch", |
731 testCache->getAndClearLastErrorWebCacheMethodCalled()); | 719 testCache->getAndClearLastErrorWebCacheMethodCalled()); |
732 } | 720 } |
733 | 721 |
734 } // namespace | 722 } // namespace |
735 | 723 |
736 } // namespace blink | 724 } // namespace blink |
OLD | NEW |