| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 *m_expectedBatchOperations; | 187 *m_expectedBatchOperations; |
| 188 EXPECT_EQ(expectedBatchOperations.size(), batchOperations.size()); | 188 EXPECT_EQ(expectedBatchOperations.size(), batchOperations.size()); |
| 189 for (int i = 0, minsize = std::min(expectedBatchOperations.size(), | 189 for (int i = 0, minsize = std::min(expectedBatchOperations.size(), |
| 190 batchOperations.size()); | 190 batchOperations.size()); |
| 191 i < minsize; ++i) { | 191 i < minsize; ++i) { |
| 192 EXPECT_EQ(expectedBatchOperations[i].operationType, | 192 EXPECT_EQ(expectedBatchOperations[i].operationType, |
| 193 batchOperations[i].operationType); | 193 batchOperations[i].operationType); |
| 194 const String expectedRequestUrl = | 194 const String expectedRequestUrl = |
| 195 KURL(expectedBatchOperations[i].request.url()); | 195 KURL(expectedBatchOperations[i].request.url()); |
| 196 EXPECT_EQ(expectedRequestUrl, KURL(batchOperations[i].request.url())); | 196 EXPECT_EQ(expectedRequestUrl, KURL(batchOperations[i].request.url())); |
| 197 const String expectedResponseUrl = | 197 EXPECT_EQ(expectedBatchOperations[i].response.urlList().size(), |
| 198 KURL(expectedBatchOperations[i].response.url()); | 198 batchOperations[i].response.urlList().size()); |
| 199 EXPECT_EQ(expectedResponseUrl, KURL(batchOperations[i].response.url())); | 199 for (size_t j = 0; |
| 200 j < expectedBatchOperations[i].response.urlList().size(); ++j) { |
| 201 EXPECT_EQ(expectedBatchOperations[i].response.urlList()[j], |
| 202 batchOperations[i].response.urlList()[j]); |
| 203 } |
| 200 CompareQueryParamsForTest(expectedBatchOperations[i].matchParams, | 204 CompareQueryParamsForTest(expectedBatchOperations[i].matchParams, |
| 201 batchOperations[i].matchParams); | 205 batchOperations[i].matchParams); |
| 202 } | 206 } |
| 203 } | 207 } |
| 204 | 208 |
| 205 private: | 209 private: |
| 206 static void CompareQueryParamsForTest(const QueryParams& expectedQueryParams, | 210 static void CompareQueryParamsForTest(const QueryParams& expectedQueryParams, |
| 207 const QueryParams& queryParams) { | 211 const QueryParams& queryParams) { |
| 208 EXPECT_EQ(expectedQueryParams.ignoreSearch, queryParams.ignoreSearch); | 212 EXPECT_EQ(expectedQueryParams.ignoreSearch, queryParams.ignoreSearch); |
| 209 EXPECT_EQ(expectedQueryParams.ignoreMethod, queryParams.ignoreMethod); | 213 EXPECT_EQ(expectedQueryParams.ignoreMethod, queryParams.ignoreMethod); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 testCache->setExpectedQueryParams(&expectedQueryParams); | 464 testCache->setExpectedQueryParams(&expectedQueryParams); |
| 461 | 465 |
| 462 CacheQueryOptions options; | 466 CacheQueryOptions options; |
| 463 options.setCacheName(expectedQueryParams.cacheName); | 467 options.setCacheName(expectedQueryParams.cacheName); |
| 464 | 468 |
| 465 const String url = "http://batch.operations.test/"; | 469 const String url = "http://batch.operations.test/"; |
| 466 Request* request = newRequestFromUrl(url); | 470 Request* request = newRequestFromUrl(url); |
| 467 ASSERT(request); | 471 ASSERT(request); |
| 468 | 472 |
| 469 WebServiceWorkerResponse webResponse; | 473 WebServiceWorkerResponse webResponse; |
| 470 webResponse.setURL(KURL(ParsedURLString, url)); | 474 std::vector<KURL> urlList; |
| 475 urlList.push_back(KURL(ParsedURLString, url)); |
| 476 webResponse.setURLList(urlList); |
| 471 Response* response = Response::create(getScriptState(), webResponse); | 477 Response* response = Response::create(getScriptState(), webResponse); |
| 472 | 478 |
| 473 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations( | 479 WebVector<WebServiceWorkerCache::BatchOperation> expectedDeleteOperations( |
| 474 size_t(1)); | 480 size_t(1)); |
| 475 { | 481 { |
| 476 WebServiceWorkerCache::BatchOperation deleteOperation; | 482 WebServiceWorkerCache::BatchOperation deleteOperation; |
| 477 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDelete; | 483 deleteOperation.operationType = WebServiceWorkerCache::OperationTypeDelete; |
| 478 request->populateWebServiceWorkerRequest(deleteOperation.request); | 484 request->populateWebServiceWorkerRequest(deleteOperation.request); |
| 479 deleteOperation.matchParams = expectedQueryParams; | 485 deleteOperation.matchParams = expectedQueryParams; |
| 480 expectedDeleteOperations[0] = deleteOperation; | 486 expectedDeleteOperations[0] = deleteOperation; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 }; | 544 }; |
| 539 | 545 |
| 540 TEST_F(CacheStorageTest, MatchResponseTest) { | 546 TEST_F(CacheStorageTest, MatchResponseTest) { |
| 541 ScriptState::Scope scope(getScriptState()); | 547 ScriptState::Scope scope(getScriptState()); |
| 542 NonThrowableExceptionState exceptionState; | 548 NonThrowableExceptionState exceptionState; |
| 543 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 549 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 544 const String requestUrl = "http://request.url/"; | 550 const String requestUrl = "http://request.url/"; |
| 545 const String responseUrl = "http://match.response.test/"; | 551 const String responseUrl = "http://match.response.test/"; |
| 546 | 552 |
| 547 WebServiceWorkerResponse webResponse; | 553 WebServiceWorkerResponse webResponse; |
| 548 webResponse.setURL(KURL(ParsedURLString, responseUrl)); | 554 std::vector<KURL> urlList; |
| 555 urlList.push_back(KURL(ParsedURLString, responseUrl)); |
| 556 webResponse.setURLList(urlList); |
| 549 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); | 557 webResponse.setResponseType(WebServiceWorkerResponseTypeDefault); |
| 550 | 558 |
| 551 Cache* cache = createCache(fetcher, new MatchTestCache(webResponse)); | 559 Cache* cache = createCache(fetcher, new MatchTestCache(webResponse)); |
| 552 CacheQueryOptions options; | 560 CacheQueryOptions options; |
| 553 | 561 |
| 554 ScriptPromise result = | 562 ScriptPromise result = |
| 555 cache->match(getScriptState(), stringToRequestInfo(requestUrl), options, | 563 cache->match(getScriptState(), stringToRequestInfo(requestUrl), options, |
| 556 exceptionState); | 564 exceptionState); |
| 557 ScriptValue scriptValue = getResolveValue(result); | 565 ScriptValue scriptValue = getResolveValue(result); |
| 558 Response* response = | 566 Response* response = |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 NonThrowableExceptionState exceptionState; | 643 NonThrowableExceptionState exceptionState; |
| 636 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); | 644 ScopedFetcherForTests* fetcher = ScopedFetcherForTests::create(); |
| 637 const String url1 = "http://first.response/"; | 645 const String url1 = "http://first.response/"; |
| 638 const String url2 = "http://second.response/"; | 646 const String url2 = "http://second.response/"; |
| 639 | 647 |
| 640 Vector<String> expectedUrls(size_t(2)); | 648 Vector<String> expectedUrls(size_t(2)); |
| 641 expectedUrls[0] = url1; | 649 expectedUrls[0] = url1; |
| 642 expectedUrls[1] = url2; | 650 expectedUrls[1] = url2; |
| 643 | 651 |
| 644 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); | 652 WebVector<WebServiceWorkerResponse> webResponses(size_t(2)); |
| 645 webResponses[0].setURL(KURL(ParsedURLString, url1)); | 653 std::vector<KURL> urlList1; |
| 654 urlList1.push_back(KURL(ParsedURLString, url1)); |
| 655 webResponses[0].setURLList(urlList1); |
| 646 webResponses[0].setResponseType(WebServiceWorkerResponseTypeDefault); | 656 webResponses[0].setResponseType(WebServiceWorkerResponseTypeDefault); |
| 647 webResponses[1].setURL(KURL(ParsedURLString, url2)); | 657 std::vector<KURL> urlList2; |
| 658 urlList2.push_back(KURL(ParsedURLString, url2)); |
| 659 webResponses[1].setURLList(urlList2); |
| 648 webResponses[1].setResponseType(WebServiceWorkerResponseTypeDefault); | 660 webResponses[1].setResponseType(WebServiceWorkerResponseTypeDefault); |
| 649 | 661 |
| 650 Cache* cache = | 662 Cache* cache = |
| 651 createCache(fetcher, new MatchAllAndBatchTestCache(webResponses)); | 663 createCache(fetcher, new MatchAllAndBatchTestCache(webResponses)); |
| 652 | 664 |
| 653 CacheQueryOptions options; | 665 CacheQueryOptions options; |
| 654 ScriptPromise result = | 666 ScriptPromise result = |
| 655 cache->matchAll(getScriptState(), stringToRequestInfo("http://some.url/"), | 667 cache->matchAll(getScriptState(), stringToRequestInfo("http://some.url/"), |
| 656 options, exceptionState); | 668 options, exceptionState); |
| 657 ScriptValue scriptValue = getResolveValue(result); | 669 ScriptValue scriptValue = getResolveValue(result); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 | 727 |
| 716 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); | 728 EXPECT_EQ(kNotImplementedString, getRejectString(addResult)); |
| 717 EXPECT_EQ(1, fetcher->fetchCount()); | 729 EXPECT_EQ(1, fetcher->fetchCount()); |
| 718 EXPECT_EQ("dispatchBatch", | 730 EXPECT_EQ("dispatchBatch", |
| 719 testCache->getAndClearLastErrorWebCacheMethodCalled()); | 731 testCache->getAndClearLastErrorWebCacheMethodCalled()); |
| 720 } | 732 } |
| 721 | 733 |
| 722 } // namespace | 734 } // namespace |
| 723 | 735 |
| 724 } // namespace blink | 736 } // namespace blink |
| OLD | NEW |