| 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> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #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" |
| 11 #include "bindings/core/v8/ScriptFunction.h" | 13 #include "bindings/core/v8/ScriptFunction.h" |
| 12 #include "bindings/core/v8/ScriptPromise.h" | 14 #include "bindings/core/v8/ScriptPromise.h" |
| 13 #include "bindings/core/v8/ScriptPromiseResolver.h" | 15 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 14 #include "bindings/core/v8/ScriptValue.h" | 16 #include "bindings/core/v8/ScriptValue.h" |
| 15 #include "bindings/core/v8/V8Binding.h" | 17 #include "bindings/core/v8/V8Binding.h" |
| 16 #include "bindings/modules/v8/V8Request.h" | 18 #include "bindings/modules/v8/V8Request.h" |
| 17 #include "bindings/modules/v8/V8Response.h" | 19 #include "bindings/modules/v8/V8Response.h" |
| 18 #include "core/dom/Document.h" | 20 #include "core/dom/Document.h" |
| 19 #include "core/dom/ExecutionContext.h" | 21 #include "core/dom/ExecutionContext.h" |
| 20 #include "core/frame/Frame.h" | 22 #include "core/frame/Frame.h" |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 606 |
| 605 WebVector<WebServiceWorkerRequest> web_requests(size_t(2)); | 607 WebVector<WebServiceWorkerRequest> web_requests(size_t(2)); |
| 606 web_requests[0].SetURL(KURL(kParsedURLString, url1)); | 608 web_requests[0].SetURL(KURL(kParsedURLString, url1)); |
| 607 web_requests[1].SetURL(KURL(kParsedURLString, url2)); | 609 web_requests[1].SetURL(KURL(kParsedURLString, url2)); |
| 608 | 610 |
| 609 Cache* cache = CreateCache(fetcher, new KeysTestCache(web_requests)); | 611 Cache* cache = CreateCache(fetcher, new KeysTestCache(web_requests)); |
| 610 | 612 |
| 611 ScriptPromise result = cache->keys(GetScriptState(), exception_state); | 613 ScriptPromise result = cache->keys(GetScriptState(), exception_state); |
| 612 ScriptValue script_value = GetResolveValue(result); | 614 ScriptValue script_value = GetResolveValue(result); |
| 613 | 615 |
| 614 Vector<v8::Local<v8::Value>> requests = | 616 HeapVector<Member<Request>> requests = |
| 615 ToImplArray<Vector<v8::Local<v8::Value>>>(script_value.V8Value(), 0, | 617 NativeValueTraits<IDLSequence<Request>>::NativeValue( |
| 616 GetIsolate(), exception_state); | 618 GetIsolate(), script_value.V8Value(), exception_state); |
| 617 EXPECT_EQ(expected_urls.size(), requests.size()); | 619 EXPECT_EQ(expected_urls.size(), requests.size()); |
| 618 for (int i = 0, minsize = std::min(expected_urls.size(), requests.size()); | 620 for (int i = 0, minsize = std::min(expected_urls.size(), requests.size()); |
| 619 i < minsize; ++i) { | 621 i < minsize; ++i) { |
| 620 Request* request = | 622 Request* request = requests[i]; |
| 621 V8Request::toImplWithTypeCheck(GetIsolate(), requests[i]); | |
| 622 EXPECT_TRUE(request); | 623 EXPECT_TRUE(request); |
| 623 if (request) | 624 if (request) |
| 624 EXPECT_EQ(expected_urls[i], request->url()); | 625 EXPECT_EQ(expected_urls[i], request->url()); |
| 625 } | 626 } |
| 626 } | 627 } |
| 627 | 628 |
| 628 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 629 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
| 629 public: | 630 public: |
| 630 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) | 631 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) |
| 631 : responses_(responses) {} | 632 : responses_(responses) {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 668 |
| 668 Cache* cache = | 669 Cache* cache = |
| 669 CreateCache(fetcher, new MatchAllAndBatchTestCache(web_responses)); | 670 CreateCache(fetcher, new MatchAllAndBatchTestCache(web_responses)); |
| 670 | 671 |
| 671 CacheQueryOptions options; | 672 CacheQueryOptions options; |
| 672 ScriptPromise result = | 673 ScriptPromise result = |
| 673 cache->matchAll(GetScriptState(), StringToRequestInfo("http://some.url/"), | 674 cache->matchAll(GetScriptState(), StringToRequestInfo("http://some.url/"), |
| 674 options, exception_state); | 675 options, exception_state); |
| 675 ScriptValue script_value = GetResolveValue(result); | 676 ScriptValue script_value = GetResolveValue(result); |
| 676 | 677 |
| 677 Vector<v8::Local<v8::Value>> responses = | 678 HeapVector<Member<Response>> responses = |
| 678 ToImplArray<Vector<v8::Local<v8::Value>>>(script_value.V8Value(), 0, | 679 NativeValueTraits<IDLSequence<Response>>::NativeValue( |
| 679 GetIsolate(), exception_state); | 680 GetIsolate(), script_value.V8Value(), exception_state); |
| 680 EXPECT_EQ(expected_urls.size(), responses.size()); | 681 EXPECT_EQ(expected_urls.size(), responses.size()); |
| 681 for (int i = 0, minsize = std::min(expected_urls.size(), responses.size()); | 682 for (int i = 0, minsize = std::min(expected_urls.size(), responses.size()); |
| 682 i < minsize; ++i) { | 683 i < minsize; ++i) { |
| 683 Response* response = | 684 Response* response = responses[i]; |
| 684 V8Response::toImplWithTypeCheck(GetIsolate(), responses[i]); | |
| 685 EXPECT_TRUE(response); | 685 EXPECT_TRUE(response); |
| 686 if (response) | 686 if (response) |
| 687 EXPECT_EQ(expected_urls[i], response->url()); | 687 EXPECT_EQ(expected_urls[i], response->url()); |
| 688 } | 688 } |
| 689 | 689 |
| 690 result = cache->deleteFunction(GetScriptState(), | 690 result = cache->deleteFunction(GetScriptState(), |
| 691 StringToRequestInfo("http://some.url/"), | 691 StringToRequestInfo("http://some.url/"), |
| 692 options, exception_state); | 692 options, exception_state); |
| 693 script_value = GetResolveValue(result); | 693 script_value = GetResolveValue(result); |
| 694 EXPECT_TRUE(script_value.V8Value()->IsBoolean()); | 694 EXPECT_TRUE(script_value.V8Value()->IsBoolean()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 733 |
| 734 EXPECT_EQ(kNotImplementedString, GetRejectString(add_result)); | 734 EXPECT_EQ(kNotImplementedString, GetRejectString(add_result)); |
| 735 EXPECT_EQ(1, fetcher->FetchCount()); | 735 EXPECT_EQ(1, fetcher->FetchCount()); |
| 736 EXPECT_EQ("dispatchBatch", | 736 EXPECT_EQ("dispatchBatch", |
| 737 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); | 737 test_cache->GetAndClearLastErrorWebCacheMethodCalled()); |
| 738 } | 738 } |
| 739 | 739 |
| 740 } // namespace | 740 } // namespace |
| 741 | 741 |
| 742 } // namespace blink | 742 } // namespace blink |
| OLD | NEW |