| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #include "core/fetch/FetchContext.h" | 33 #include "core/fetch/FetchContext.h" |
| 34 #include "core/fetch/ImageResource.h" | |
| 35 #include "core/fetch/MemoryCache.h" | 34 #include "core/fetch/MemoryCache.h" |
| 36 #include "core/fetch/RawResource.h" | 35 #include "core/fetch/RawResource.h" |
| 37 #include "core/fetch/Resource.h" | 36 #include "core/fetch/Resource.h" |
| 38 #include "core/fetch/ResourceFetcher.h" | 37 #include "core/fetch/ResourceFetcher.h" |
| 39 #include "core/fetch/ResourcePtr.h" | 38 #include "core/fetch/ResourcePtr.h" |
| 40 #include "platform/network/ResourceRequest.h" | 39 #include "platform/network/ResourceRequest.h" |
| 41 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 42 #include "wtf/OwnPtr.h" | 41 #include "wtf/OwnPtr.h" |
| 43 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 44 #include <gtest/gtest.h> | 43 #include <gtest/gtest.h> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 | 65 |
| 67 ~MockFetchContext() { } | 66 ~MockFetchContext() { } |
| 68 | 67 |
| 69 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } | 68 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru
e; } |
| 70 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } | 69 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R
esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o
verride { return true; } |
| 71 | 70 |
| 72 private: | 71 private: |
| 73 MockFetchContext() { } | 72 MockFetchContext() { } |
| 74 }; | 73 }; |
| 75 | 74 |
| 75 class MockImageFactory : public ResourceFactory { |
| 76 public: |
| 77 MockImageFactory() : ResourceFactory(Resource::Image) { } |
| 78 |
| 79 Resource* create(const ResourceRequest& request, const String&) const overri
de |
| 80 { |
| 81 return new Resource(request, Resource::Image); |
| 82 } |
| 83 }; |
| 84 |
| 76 class CachingCorrectnessTest : public ::testing::Test { | 85 class CachingCorrectnessTest : public ::testing::Test { |
| 77 protected: | 86 protected: |
| 78 void advanceClock(double seconds) | 87 void advanceClock(double seconds) |
| 79 { | 88 { |
| 80 m_proxyPlatform.advanceClock(seconds); | 89 m_proxyPlatform.advanceClock(seconds); |
| 81 } | 90 } |
| 82 | 91 |
| 83 ResourcePtr<Resource> resourceFromResourceResponse(ResourceResponse response
, Resource::Type type = Resource::Raw) | 92 ResourcePtr<Resource> resourceFromResourceResponse(ResourceResponse response
, Resource::Type type = Resource::Raw) |
| 84 { | 93 { |
| 85 if (response.url().isNull()) | 94 if (response.url().isNull()) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 106 | 115 |
| 107 ResourcePtr<Resource> fetch() | 116 ResourcePtr<Resource> fetch() |
| 108 { | 117 { |
| 109 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); | 118 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); |
| 110 return RawResource::fetchSynchronously(fetchRequest, fetcher()); | 119 return RawResource::fetchSynchronously(fetchRequest, fetcher()); |
| 111 } | 120 } |
| 112 | 121 |
| 113 ResourcePtr<Resource> fetchImage() | 122 ResourcePtr<Resource> fetchImage() |
| 114 { | 123 { |
| 115 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); | 124 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); |
| 116 return ImageResource::fetch(fetchRequest, fetcher()); | 125 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R
equestContextInternal); |
| 126 return fetcher()->requestResource(fetchRequest, MockImageFactory()); |
| 117 } | 127 } |
| 118 | 128 |
| 119 ResourceFetcher* fetcher() const { return m_fetcher.get(); } | 129 ResourceFetcher* fetcher() const { return m_fetcher.get(); } |
| 120 | 130 |
| 121 private: | 131 private: |
| 122 // A simple platform that mocks out the clock, for cache freshness testing. | 132 // A simple platform that mocks out the clock, for cache freshness testing. |
| 123 class ProxyPlatform : public blink::Platform { | 133 class ProxyPlatform : public blink::Platform { |
| 124 public: | 134 public: |
| 125 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon
ds(0.) { } | 135 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon
ds(0.) { } |
| 126 | 136 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 firstResource->setResponse(fresh200Response); | 584 firstResource->setResponse(fresh200Response); |
| 575 memoryCache()->add(firstResource.get()); | 585 memoryCache()->add(firstResource.get()); |
| 576 | 586 |
| 577 advanceClock(500.); | 587 advanceClock(500.); |
| 578 | 588 |
| 579 ResourcePtr<Resource> fetched = fetch(); | 589 ResourcePtr<Resource> fetched = fetch(); |
| 580 EXPECT_EQ(firstResource, fetched); | 590 EXPECT_EQ(firstResource, fetched); |
| 581 } | 591 } |
| 582 | 592 |
| 583 } // namespace blink | 593 } // namespace blink |
| OLD | NEW |