Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp

Issue 1852663002: Oilpan: Remove WillBe types (part 9) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 }; 73 };
74 74
75 class ResourceFetcherTest : public ::testing::Test { 75 class ResourceFetcherTest : public ::testing::Test {
76 }; 76 };
77 77
78 class TestResourceFactory : public ResourceFactory { 78 class TestResourceFactory : public ResourceFactory {
79 public: 79 public:
80 TestResourceFactory(Resource::Type type = Resource::Raw) 80 TestResourceFactory(Resource::Type type = Resource::Raw)
81 : ResourceFactory(type) { } 81 : ResourceFactory(type) { }
82 82
83 PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest& request, cons t ResourceLoaderOptions& options, const String& charset) const override 83 RawPtr<Resource> create(const ResourceRequest& request, const ResourceLoader Options& options, const String& charset) const override
84 { 84 {
85 return Resource::create(request, type(), options); 85 return Resource::create(request, type(), options);
86 } 86 }
87 }; 87 };
88 88
89 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) 89 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach)
90 { 90 {
91 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); 91 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png");
92 // Try to request a url. The request should fail, no resource should be retu rned, 92 // Try to request a url. The request should fail, no resource should be retu rned,
93 // and no resource should be present in the cache. 93 // and no resource should be present in the cache.
94 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 94 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
95 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo()); 95 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo());
96 RefPtrWillBeRawPtr<Resource> resource = fetcher->requestResource(fetchReques t, TestResourceFactory()); 96 RawPtr<Resource> resource = fetcher->requestResource(fetchRequest, TestResou rceFactory());
97 EXPECT_EQ(resource.get(), static_cast<Resource*>(nullptr)); 97 EXPECT_EQ(resource.get(), static_cast<Resource*>(nullptr));
98 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr)); 98 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr));
99 } 99 }
100 100
101 TEST_F(ResourceFetcherTest, UseExistingResource) 101 TEST_F(ResourceFetcherTest, UseExistingResource)
102 { 102 {
103 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 103 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
104 104
105 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 105 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
106 RefPtrWillBeRawPtr<Resource> resource = Resource::create(url, Resource::Imag e); 106 RawPtr<Resource> resource = Resource::create(url, Resource::Image);
107 memoryCache()->add(resource.get()); 107 memoryCache()->add(resource.get());
108 ResourceResponse response; 108 ResourceResponse response;
109 response.setURL(url); 109 response.setURL(url);
110 response.setHTTPStatusCode(200); 110 response.setHTTPStatusCode(200);
111 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 111 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
112 resource->responseReceived(response, nullptr); 112 resource->responseReceived(response, nullptr);
113 resource->finish(); 113 resource->finish();
114 114
115 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 115 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
116 RefPtrWillBeRawPtr<Resource> newResource = fetcher->requestResource(fetchReq uest, TestResourceFactory(Resource::Image)); 116 RawPtr<Resource> newResource = fetcher->requestResource(fetchRequest, TestRe sourceFactory(Resource::Image));
117 EXPECT_EQ(resource, newResource); 117 EXPECT_EQ(resource, newResource);
118 memoryCache()->remove(resource.get()); 118 memoryCache()->remove(resource.get());
119 } 119 }
120 120
121 TEST_F(ResourceFetcherTest, Vary) 121 TEST_F(ResourceFetcherTest, Vary)
122 { 122 {
123 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 123 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
124 RefPtrWillBeRawPtr<Resource> resource = Resource::create(url, Resource::Raw) ; 124 RawPtr<Resource> resource = Resource::create(url, Resource::Raw);
125 memoryCache()->add(resource.get()); 125 memoryCache()->add(resource.get());
126 ResourceResponse response; 126 ResourceResponse response;
127 response.setURL(url); 127 response.setURL(url);
128 response.setHTTPStatusCode(200); 128 response.setHTTPStatusCode(200);
129 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 129 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
130 response.setHTTPHeaderField(HTTPNames::Vary, "*"); 130 response.setHTTPHeaderField(HTTPNames::Vary, "*");
131 resource->responseReceived(response, nullptr); 131 resource->responseReceived(response, nullptr);
132 resource->finish(); 132 resource->finish();
133 ASSERT_TRUE(resource->hasVaryHeader()); 133 ASSERT_TRUE(resource->hasVaryHeader());
134 134
135 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 135 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
136 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 136 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
137 Platform::current()->unitTestSupport()->registerMockedURL(url, WebURLRespons e(), ""); 137 Platform::current()->unitTestSupport()->registerMockedURL(url, WebURLRespons e(), "");
138 RefPtrWillBeRawPtr<Resource> newResource = fetcher->requestResource(fetchReq uest, TestResourceFactory()); 138 RawPtr<Resource> newResource = fetcher->requestResource(fetchRequest, TestRe sourceFactory());
139 EXPECT_NE(resource, newResource); 139 EXPECT_NE(resource, newResource);
140 newResource->loader()->cancel(); 140 newResource->loader()->cancel();
141 memoryCache()->remove(newResource.get()); 141 memoryCache()->remove(newResource.get());
142 Platform::current()->unitTestSupport()->unregisterMockedURL(url); 142 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
143 143
144 memoryCache()->remove(resource.get()); 144 memoryCache()->remove(resource.get());
145 } 145 }
146 146
147 TEST_F(ResourceFetcherTest, VaryOnBack) 147 TEST_F(ResourceFetcherTest, VaryOnBack)
148 { 148 {
149 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); 149 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create();
150 context->setCachePolicy(CachePolicyHistoryBuffer); 150 context->setCachePolicy(CachePolicyHistoryBuffer);
151 ResourceFetcher* fetcher = ResourceFetcher::create(context); 151 ResourceFetcher* fetcher = ResourceFetcher::create(context);
152 152
153 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 153 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
154 RefPtrWillBeRawPtr<Resource> resource = Resource::create(url, Resource::Raw) ; 154 RawPtr<Resource> resource = Resource::create(url, Resource::Raw);
155 memoryCache()->add(resource.get()); 155 memoryCache()->add(resource.get());
156 ResourceResponse response; 156 ResourceResponse response;
157 response.setURL(url); 157 response.setURL(url);
158 response.setHTTPStatusCode(200); 158 response.setHTTPStatusCode(200);
159 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 159 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
160 response.setHTTPHeaderField(HTTPNames::Vary, "*"); 160 response.setHTTPHeaderField(HTTPNames::Vary, "*");
161 resource->responseReceived(response, nullptr); 161 resource->responseReceived(response, nullptr);
162 resource->finish(); 162 resource->finish();
163 ASSERT_TRUE(resource->hasVaryHeader()); 163 ASSERT_TRUE(resource->hasVaryHeader());
164 164
165 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 165 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
166 RefPtrWillBeRawPtr<Resource> newResource = fetcher->requestResource(fetchReq uest, TestResourceFactory()); 166 RawPtr<Resource> newResource = fetcher->requestResource(fetchRequest, TestRe sourceFactory());
167 EXPECT_EQ(resource, newResource); 167 EXPECT_EQ(resource, newResource);
168 168
169 memoryCache()->remove(newResource.get()); 169 memoryCache()->remove(newResource.get());
170 } 170 }
171 171
172 TEST_F(ResourceFetcherTest, VaryImage) 172 TEST_F(ResourceFetcherTest, VaryImage)
173 { 173 {
174 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 174 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
175 175
176 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 176 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
177 ResourceResponse response; 177 ResourceResponse response;
178 response.setURL(url); 178 response.setURL(url);
179 response.setHTTPStatusCode(200); 179 response.setHTTPStatusCode(200);
180 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 180 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
181 response.setHTTPHeaderField(HTTPNames::Vary, "*"); 181 response.setHTTPHeaderField(HTTPNames::Vary, "*");
182 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png" , WebString::fromUTF8(""), WrappedResourceResponse(response)); 182 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png" , WebString::fromUTF8(""), WrappedResourceResponse(response));
183 183
184 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); 184 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo());
185 RefPtrWillBeRawPtr<Resource> resource = fetcher->requestResource(fetchReques tOriginal, TestResourceFactory(Resource::Image)); 185 RawPtr<Resource> resource = fetcher->requestResource(fetchRequestOriginal, T estResourceFactory(Resource::Image));
186 ASSERT_TRUE(resource.get()); 186 ASSERT_TRUE(resource.get());
187 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); 187 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
188 ASSERT_TRUE(resource->hasVaryHeader()); 188 ASSERT_TRUE(resource->hasVaryHeader());
189 189
190 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 190 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
191 RefPtrWillBeRawPtr<Resource> newResource = fetcher->requestResource(fetchReq uest, TestResourceFactory(Resource::Image)); 191 RawPtr<Resource> newResource = fetcher->requestResource(fetchRequest, TestRe sourceFactory(Resource::Image));
192 EXPECT_EQ(resource, newResource); 192 EXPECT_EQ(resource, newResource);
193 193
194 memoryCache()->remove(newResource.get()); 194 memoryCache()->remove(newResource.get());
195 Platform::current()->unitTestSupport()->unregisterMockedURL(url); 195 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
196 } 196 }
197 197
198 TEST_F(ResourceFetcherTest, RevalidateWhileLoading) 198 TEST_F(ResourceFetcherTest, RevalidateWhileLoading)
199 { 199 {
200 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 200 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
201 Platform::current()->unitTestSupport()->registerMockedURL(url, WebURLRespons e(), ""); 201 Platform::current()->unitTestSupport()->registerMockedURL(url, WebURLRespons e(), "");
202 202
203 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF etchContext::create()); 203 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF etchContext::create());
204 ResourceRequest request1(url); 204 ResourceRequest request1(url);
205 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); 205 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache");
206 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); 206 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo());
207 RefPtrWillBeRawPtr<Resource> resource1 = fetcher1->requestResource(fetchRequ est1, TestResourceFactory(Resource::Image)); 207 RawPtr<Resource> resource1 = fetcher1->requestResource(fetchRequest1, TestRe sourceFactory(Resource::Image));
208 ResourceResponse response; 208 ResourceResponse response;
209 response.setURL(url); 209 response.setURL(url);
210 response.setHTTPStatusCode(200); 210 response.setHTTPStatusCode(200);
211 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 211 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
212 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); 212 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890");
213 resource1->responseReceived(response, nullptr); 213 resource1->responseReceived(response, nullptr);
214 resource1->finish(); 214 resource1->finish();
215 215
216 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); 216 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create();
217 context->setCachePolicy(CachePolicyRevalidate); 217 context->setCachePolicy(CachePolicyRevalidate);
218 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); 218 ResourceFetcher* fetcher2 = ResourceFetcher::create(context);
219 FetchRequest fetchRequest2(url, FetchInitiatorInfo()); 219 FetchRequest fetchRequest2(url, FetchInitiatorInfo());
220 RefPtrWillBeRawPtr<Resource> resource2 = fetcher2->requestResource(fetchRequ est2, TestResourceFactory(Resource::Image)); 220 RawPtr<Resource> resource2 = fetcher2->requestResource(fetchRequest2, TestRe sourceFactory(Resource::Image));
221 EXPECT_EQ(resource1, resource2); 221 EXPECT_EQ(resource1, resource2);
222 222
223 // Tidily(?) shut down the ResourceLoader. 223 // Tidily(?) shut down the ResourceLoader.
224 resource1->loader()->cancel(); 224 resource1->loader()->cancel();
225 Platform::current()->unitTestSupport()->unregisterMockedURL(url); 225 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
226 } 226 }
227 227
228 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) 228 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl)
229 { 229 {
230 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 230 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
231 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); 231 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo"));
232 ResourceLoaderOptions options; 232 ResourceLoaderOptions options;
233 options.dataBufferingPolicy = DoNotBufferData; 233 options.dataBufferingPolicy = DoNotBufferData;
234 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i nternal, options); 234 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i nternal, options);
235 RefPtrWillBeRawPtr<Resource> resource1 = fetcher->requestResource(fetchReque st, TestResourceFactory(Resource::Media)); 235 RawPtr<Resource> resource1 = fetcher->requestResource(fetchRequest, TestReso urceFactory(Resource::Media));
236 RefPtrWillBeRawPtr<Resource> resource2 = fetcher->requestResource(fetchReque st, TestResourceFactory(Resource::Media)); 236 RawPtr<Resource> resource2 = fetcher->requestResource(fetchRequest, TestReso urceFactory(Resource::Media));
237 EXPECT_NE(resource1.get(), resource2.get()); 237 EXPECT_NE(resource1.get(), resource2.get());
238 memoryCache()->remove(resource2.get()); 238 memoryCache()->remove(resource2.get());
239 } 239 }
240 240
241 class ServeRequestsOnCompleteClient : public RawResourceClient { 241 class ServeRequestsOnCompleteClient : public RawResourceClient {
242 public: 242 public:
243 void notifyFinished(Resource*) override 243 void notifyFinished(Resource*) override
244 { 244 {
245 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); 245 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( );
246 } 246 }
(...skipping 19 matching lines...) Expand all
266 TEST_F(ResourceFetcherTest, ResponseOnCancel) 266 TEST_F(ResourceFetcherTest, ResponseOnCancel)
267 { 267 {
268 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 268 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
269 ResourceResponse response; 269 ResourceResponse response;
270 response.setURL(url); 270 response.setURL(url);
271 response.setHTTPStatusCode(200); 271 response.setHTTPStatusCode(200);
272 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png" , WebString::fromUTF8(""), WrappedResourceResponse(response)); 272 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png" , WebString::fromUTF8(""), WrappedResourceResponse(response));
273 273
274 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 274 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
275 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 275 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
276 RefPtrWillBeRawPtr<Resource> resource = fetcher->requestResource(fetchReques t, TestResourceFactory(Resource::Raw)); 276 RawPtr<Resource> resource = fetcher->requestResource(fetchRequest, TestResou rceFactory(Resource::Raw));
277 ServeRequestsOnCompleteClient client; 277 ServeRequestsOnCompleteClient client;
278 resource->addClient(&client); 278 resource->addClient(&client);
279 resource->loader()->cancel(); 279 resource->loader()->cancel();
280 Platform::current()->unitTestSupport()->unregisterMockedURL(url); 280 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
281 } 281 }
282 282
283 } // namespace blink 283 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp ('k') | third_party/WebKit/Source/core/fetch/ResourceLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698