| 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 <algorithm> |
| 8 #include <memory> |
| 9 #include <string> |
| 7 #include "bindings/core/v8/ExceptionState.h" | 10 #include "bindings/core/v8/ExceptionState.h" |
| 11 #include "bindings/core/v8/IDLTypes.h" |
| 12 #include "bindings/core/v8/NativeValueTraitsImpl.h" |
| 8 #include "bindings/core/v8/ScriptFunction.h" | 13 #include "bindings/core/v8/ScriptFunction.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 14 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 15 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "bindings/core/v8/ScriptValue.h" | 16 #include "bindings/core/v8/ScriptValue.h" |
| 12 #include "bindings/core/v8/V8Binding.h" | 17 #include "bindings/core/v8/V8Binding.h" |
| 13 #include "bindings/modules/v8/V8Request.h" | 18 #include "bindings/modules/v8/V8Request.h" |
| 14 #include "bindings/modules/v8/V8Response.h" | 19 #include "bindings/modules/v8/V8Response.h" |
| 15 #include "core/dom/Document.h" | 20 #include "core/dom/Document.h" |
| 16 #include "core/frame/Frame.h" | 21 #include "core/frame/Frame.h" |
| 17 #include "core/testing/DummyPageHolder.h" | 22 #include "core/testing/DummyPageHolder.h" |
| 18 #include "modules/fetch/BodyStreamBuffer.h" | 23 #include "modules/fetch/BodyStreamBuffer.h" |
| 19 #include "modules/fetch/FormDataBytesConsumer.h" | 24 #include "modules/fetch/FormDataBytesConsumer.h" |
| 20 #include "modules/fetch/GlobalFetch.h" | 25 #include "modules/fetch/GlobalFetch.h" |
| 21 #include "modules/fetch/Request.h" | 26 #include "modules/fetch/Request.h" |
| 22 #include "modules/fetch/Response.h" | 27 #include "modules/fetch/Response.h" |
| 23 #include "modules/fetch/ResponseInit.h" | 28 #include "modules/fetch/ResponseInit.h" |
| 24 #include "public/platform/WebURLResponse.h" | 29 #include "public/platform/WebURLResponse.h" |
| 25 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" | 30 #include "public/platform/modules/serviceworker/WebServiceWorkerCache.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "wtf/PtrUtil.h" | 32 #include "wtf/PtrUtil.h" |
| 28 #include <algorithm> | |
| 29 #include <memory> | |
| 30 #include <string> | |
| 31 | 33 |
| 32 namespace blink { | 34 namespace blink { |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 const char kNotImplementedString[] = | 38 const char kNotImplementedString[] = |
| 37 "NotSupportedError: Method is not implemented."; | 39 "NotSupportedError: Method is not implemented."; |
| 38 | 40 |
| 39 class ScopedFetcherForTests final | 41 class ScopedFetcherForTests final |
| 40 : public GarbageCollectedFinalized<ScopedFetcherForTests>, | 42 : public GarbageCollectedFinalized<ScopedFetcherForTests>, |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 605 |
| 604 WebVector<WebServiceWorkerRequest> web_requests(size_t(2)); | 606 WebVector<WebServiceWorkerRequest> web_requests(size_t(2)); |
| 605 web_requests[0].SetURL(KURL(kParsedURLString, url1)); | 607 web_requests[0].SetURL(KURL(kParsedURLString, url1)); |
| 606 web_requests[1].SetURL(KURL(kParsedURLString, url2)); | 608 web_requests[1].SetURL(KURL(kParsedURLString, url2)); |
| 607 | 609 |
| 608 Cache* cache = CreateCache(fetcher, new KeysTestCache(web_requests)); | 610 Cache* cache = CreateCache(fetcher, new KeysTestCache(web_requests)); |
| 609 | 611 |
| 610 ScriptPromise result = cache->keys(GetScriptState(), exception_state); | 612 ScriptPromise result = cache->keys(GetScriptState(), exception_state); |
| 611 ScriptValue script_value = GetResolveValue(result); | 613 ScriptValue script_value = GetResolveValue(result); |
| 612 | 614 |
| 613 Vector<v8::Local<v8::Value>> requests = | 615 HeapVector<Member<Request>> requests = |
| 614 ToImplArray<Vector<v8::Local<v8::Value>>>(script_value.V8Value(), 0, | 616 NativeValueTraits<IDLSequence<Request>>::NativeValue( |
| 615 GetIsolate(), exception_state); | 617 GetIsolate(), script_value.V8Value(), exception_state); |
| 616 EXPECT_EQ(expected_urls.size(), requests.size()); | 618 EXPECT_EQ(expected_urls.size(), requests.size()); |
| 617 for (int i = 0, minsize = std::min(expected_urls.size(), requests.size()); | 619 for (int i = 0, minsize = std::min(expected_urls.size(), requests.size()); |
| 618 i < minsize; ++i) { | 620 i < minsize; ++i) { |
| 619 Request* request = | 621 Request* request = requests[i]; |
| 620 V8Request::toImplWithTypeCheck(GetIsolate(), requests[i]); | |
| 621 EXPECT_TRUE(request); | 622 EXPECT_TRUE(request); |
| 622 if (request) | 623 if (request) |
| 623 EXPECT_EQ(expected_urls[i], request->url()); | 624 EXPECT_EQ(expected_urls[i], request->url()); |
| 624 } | 625 } |
| 625 } | 626 } |
| 626 | 627 |
| 627 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 628 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
| 628 public: | 629 public: |
| 629 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) | 630 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) |
| 630 : responses_(responses) {} | 631 : responses_(responses) {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 | 667 |
| 667 Cache* cache = | 668 Cache* cache = |
| 668 CreateCache(fetcher, new MatchAllAndBatchTestCache(web_responses)); | 669 CreateCache(fetcher, new MatchAllAndBatchTestCache(web_responses)); |
| 669 | 670 |
| 670 CacheQueryOptions options; | 671 CacheQueryOptions options; |
| 671 ScriptPromise result = | 672 ScriptPromise result = |
| 672 cache->matchAll(GetScriptState(), StringToRequestInfo("http://some.url/"), | 673 cache->matchAll(GetScriptState(), StringToRequestInfo("http://some.url/"), |
| 673 options, exception_state); | 674 options, exception_state); |
| 674 ScriptValue script_value = GetResolveValue(result); | 675 ScriptValue script_value = GetResolveValue(result); |
| 675 | 676 |
| 676 Vector<v8::Local<v8::Value>> responses = | 677 HeapVector<Member<Response>> responses = |
| 677 ToImplArray<Vector<v8::Local<v8::Value>>>(script_value.V8Value(), 0, | 678 NativeValueTraits<IDLSequence<Response>>::NativeValue( |
| 678 GetIsolate(), exception_state); | 679 GetIsolate(), script_value.V8Value(), exception_state); |
| 679 EXPECT_EQ(expected_urls.size(), responses.size()); | 680 EXPECT_EQ(expected_urls.size(), responses.size()); |
| 680 for (int i = 0, minsize = std::min(expected_urls.size(), responses.size()); | 681 for (int i = 0, minsize = std::min(expected_urls.size(), responses.size()); |
| 681 i < minsize; ++i) { | 682 i < minsize; ++i) { |
| 682 Response* response = | 683 Response* response = responses[i]; |
| 683 V8Response::toImplWithTypeCheck(GetIsolate(), responses[i]); | |
| 684 EXPECT_TRUE(response); | 684 EXPECT_TRUE(response); |
| 685 if (response) | 685 if (response) |
| 686 EXPECT_EQ(expected_urls[i], response->url()); | 686 EXPECT_EQ(expected_urls[i], response->url()); |
| 687 } | 687 } |
| 688 | 688 |
| 689 result = cache->deleteFunction(GetScriptState(), | 689 result = cache->deleteFunction(GetScriptState(), |
| 690 StringToRequestInfo("http://some.url/"), | 690 StringToRequestInfo("http://some.url/"), |
| 691 options, exception_state); | 691 options, exception_state); |
| 692 script_value = GetResolveValue(result); | 692 script_value = GetResolveValue(result); |
| 693 EXPECT_TRUE(script_value.V8Value()->IsBoolean()); | 693 EXPECT_TRUE(script_value.V8Value()->IsBoolean()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 | 732 |
| 733 EXPECT_EQ(kNotImplementedString, GetRejectString(add_result)); | 733 EXPECT_EQ(kNotImplementedString, GetRejectString(add_result)); |
| 734 EXPECT_EQ(1, fetcher->FetchCount()); | 734 EXPECT_EQ(1, fetcher->FetchCount()); |
| 735 EXPECT_EQ("dispatchBatch", | 735 EXPECT_EQ("dispatchBatch", |
| 736 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); | 736 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); |
| 737 } | 737 } |
| 738 | 738 |
| 739 } // namespace | 739 } // namespace |
| 740 | 740 |
| 741 } // namespace blink | 741 } // namespace blink |
| OLD | NEW |