OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/loader/resource/FontResource.h" | 5 #include "core/loader/resource/FontResource.h" |
6 | 6 |
7 #include "core/loader/resource/MockFontResourceClient.h" | 7 #include "core/loader/resource/MockFontResourceClient.h" |
8 #include "platform/exported/WrappedResourceResponse.h" | 8 #include "platform/exported/WrappedResourceResponse.h" |
9 #include "platform/loader/fetch/FetchInitiatorInfo.h" | 9 #include "platform/loader/fetch/FetchInitiatorInfo.h" |
10 #include "platform/loader/fetch/FetchRequest.h" | 10 #include "platform/loader/fetch/FetchRequest.h" |
11 #include "platform/loader/fetch/MemoryCache.h" | 11 #include "platform/loader/fetch/MemoryCache.h" |
12 #include "platform/loader/fetch/ResourceFetcher.h" | 12 #include "platform/loader/fetch/ResourceFetcher.h" |
13 #include "platform/loader/fetch/ResourceLoader.h" | 13 #include "platform/loader/fetch/ResourceLoader.h" |
14 #include "platform/loader/testing/MockFetchContext.h" | 14 #include "platform/loader/testing/MockFetchContext.h" |
15 #include "platform/loader/testing/MockResourceClient.h" | 15 #include "platform/loader/testing/MockResourceClient.h" |
16 #include "platform/network/ResourceError.h" | 16 #include "platform/network/ResourceError.h" |
17 #include "platform/network/ResourceRequest.h" | 17 #include "platform/network/ResourceRequest.h" |
18 #include "platform/network/ResourceResponse.h" | 18 #include "platform/network/ResourceResponse.h" |
19 #include "platform/weborigin/KURL.h" | 19 #include "platform/weborigin/KURL.h" |
20 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
| 21 #include "public/platform/WebCachePolicy.h" |
21 #include "public/platform/WebURLLoaderMockFactory.h" | 22 #include "public/platform/WebURLLoaderMockFactory.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace blink { | 25 namespace blink { |
25 | 26 |
26 class FontResourceTest : public ::testing::Test { | 27 class FontResourceTest : public ::testing::Test { |
27 void TearDown() override { | 28 void TearDown() override { |
28 Platform::current() | 29 Platform::current() |
29 ->getURLLoaderMockFactory() | 30 ->getURLLoaderMockFactory() |
30 ->unregisterAllURLsAndClearMemoryCache(); | 31 ->unregisterAllURLsAndClearMemoryCache(); |
(...skipping 21 matching lines...) Expand all Loading... |
52 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); | 53 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); |
53 Resource* resource1 = FontResource::fetch(fetchRequest1, fetcher); | 54 Resource* resource1 = FontResource::fetch(fetchRequest1, fetcher); |
54 ASSERT_TRUE(resource1); | 55 ASSERT_TRUE(resource1); |
55 fetcher->startLoad(resource1); | 56 fetcher->startLoad(resource1); |
56 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); | 57 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
57 EXPECT_TRUE(resource1->isLoaded()); | 58 EXPECT_TRUE(resource1->isLoaded()); |
58 EXPECT_FALSE(resource1->errorOccurred()); | 59 EXPECT_FALSE(resource1->errorOccurred()); |
59 | 60 |
60 // Set the context as it is on reloads. | 61 // Set the context as it is on reloads. |
61 context->setLoadComplete(true); | 62 context->setLoadComplete(true); |
62 context->setCachePolicy(CachePolicyRevalidate); | |
63 | 63 |
64 // Revalidate the resource. | 64 // Revalidate the resource. |
65 ResourceRequest request2(url); | 65 ResourceRequest request2(url); |
| 66 request2.setCachePolicy(WebCachePolicy::ValidatingCacheData); |
66 FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo()); | 67 FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo()); |
67 Resource* resource2 = FontResource::fetch(fetchRequest2, fetcher); | 68 Resource* resource2 = FontResource::fetch(fetchRequest2, fetcher); |
68 ASSERT_TRUE(resource2); | 69 ASSERT_TRUE(resource2); |
69 EXPECT_EQ(resource1, resource2); | 70 EXPECT_EQ(resource1, resource2); |
70 EXPECT_TRUE(resource2->isCacheValidator()); | 71 EXPECT_TRUE(resource2->isCacheValidator()); |
71 EXPECT_TRUE(resource2->stillNeedsLoad()); | 72 EXPECT_TRUE(resource2->stillNeedsLoad()); |
72 | 73 |
73 // Fetch the same resource again before actual load operation starts. | 74 // Fetch the same resource again before actual load operation starts. |
74 ResourceRequest request3(url); | 75 ResourceRequest request3(url); |
| 76 request3.setCachePolicy(WebCachePolicy::ValidatingCacheData); |
75 FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo()); | 77 FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo()); |
76 Resource* resource3 = FontResource::fetch(fetchRequest3, fetcher); | 78 Resource* resource3 = FontResource::fetch(fetchRequest3, fetcher); |
77 ASSERT_TRUE(resource3); | 79 ASSERT_TRUE(resource3); |
78 EXPECT_EQ(resource2, resource3); | 80 EXPECT_EQ(resource2, resource3); |
79 EXPECT_TRUE(resource3->isCacheValidator()); | 81 EXPECT_TRUE(resource3->isCacheValidator()); |
80 EXPECT_TRUE(resource3->stillNeedsLoad()); | 82 EXPECT_TRUE(resource3->stillNeedsLoad()); |
81 | 83 |
82 // startLoad() can be called from any initiator. Here, call it from the | 84 // startLoad() can be called from any initiator. Here, call it from the |
83 // latter. | 85 // latter. |
84 fetcher->startLoad(resource3); | 86 fetcher->startLoad(resource3); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Persistent<MockFontResourceClient> client3 = | 143 Persistent<MockFontResourceClient> client3 = |
142 new MockFontResourceClient(resource); | 144 new MockFontResourceClient(resource); |
143 EXPECT_TRUE(client3->fontLoadShortLimitExceededCalled()); | 145 EXPECT_TRUE(client3->fontLoadShortLimitExceededCalled()); |
144 EXPECT_TRUE(client3->fontLoadLongLimitExceededCalled()); | 146 EXPECT_TRUE(client3->fontLoadLongLimitExceededCalled()); |
145 | 147 |
146 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); | 148 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
147 memoryCache()->remove(resource); | 149 memoryCache()->remove(resource); |
148 } | 150 } |
149 | 151 |
150 } // namespace blink | 152 } // namespace blink |
OLD | NEW |