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

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

Issue 1998073002: Move some ResourceClients for testing to Oilpan heap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 ASSERT_TRUE(resource->hasVaryHeader()); 208 ASSERT_TRUE(resource->hasVaryHeader());
209 209
210 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 210 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
211 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image)); 211 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image));
212 EXPECT_EQ(resource, newResource); 212 EXPECT_EQ(resource, newResource);
213 213
214 memoryCache()->remove(newResource); 214 memoryCache()->remove(newResource);
215 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 215 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
216 } 216 }
217 217
218 class RequestSameResourceOnComplete : public RawResourceClient { 218 class RequestSameResourceOnComplete : public GarbageCollectedFinalized<RequestSa meResourceOnComplete>, public RawResourceClient {
219 public: 219 public:
220 explicit RequestSameResourceOnComplete(Resource* resource) 220 explicit RequestSameResourceOnComplete(Resource* resource)
221 : m_resource(resource) 221 : m_resource(resource)
222 , m_notifyFinishedCalled(false) 222 , m_notifyFinishedCalled(false)
223 { 223 {
224 } 224 }
225 225
226 void notifyFinished(Resource* resource) override 226 void notifyFinished(Resource* resource) override
227 { 227 {
228 ASSERT_EQ(m_resource, resource); 228 ASSERT_EQ(m_resource, resource);
229 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe tchContext::create(); 229 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe tchContext::create();
230 context->setCachePolicy(CachePolicyRevalidate); 230 context->setCachePolicy(CachePolicyRevalidate);
231 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); 231 ResourceFetcher* fetcher2 = ResourceFetcher::create(context);
232 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); 232 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo());
233 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou rceFactory(Resource::Image)); 233 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou rceFactory(Resource::Image));
234 EXPECT_EQ(m_resource, resource2); 234 EXPECT_EQ(m_resource, resource2);
235 m_notifyFinishedCalled = true; 235 m_notifyFinishedCalled = true;
236 } 236 }
237 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } 237 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; }
238 238
239 DEFINE_INLINE_TRACE()
240 {
241 visitor->trace(m_resource);
242 }
243
239 String debugName() const override { return "RequestSameResourceOnComplete"; } 244 String debugName() const override { return "RequestSameResourceOnComplete"; }
240 245
241 private: 246 private:
242 Persistent<Resource> m_resource; 247 Member<Resource> m_resource;
243 bool m_notifyFinishedCalled; 248 bool m_notifyFinishedCalled;
244 }; 249 };
245 250
246 TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) 251 TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading)
247 { 252 {
248 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 253 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
249 ResourceResponse response; 254 ResourceResponse response;
250 response.setURL(url); 255 response.setURL(url);
251 response.setHTTPStatusCode(200); 256 response.setHTTPStatusCode(200);
252 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 257 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
253 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); 258 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890");
254 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WrappedReso urceResponse(response), ""); 259 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WrappedReso urceResponse(response), "");
255 260
256 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF etchContext::create()); 261 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF etchContext::create());
257 ResourceRequest request1(url); 262 ResourceRequest request1(url);
258 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); 263 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache");
259 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); 264 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo());
260 Resource* resource1 = fetcher1->requestResource(fetchRequest1, TestResourceF actory(Resource::Image)); 265 Resource* resource1 = fetcher1->requestResource(fetchRequest1, TestResourceF actory(Resource::Image));
261 RequestSameResourceOnComplete client(resource1); 266 Persistent<RequestSameResourceOnComplete> client = new RequestSameResourceOn Complete(resource1);
262 resource1->addClient(&client); 267 resource1->addClient(client);
263 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 268 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
264 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 269 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
265 EXPECT_TRUE(client.notifyFinishedCalled()); 270 EXPECT_TRUE(client->notifyFinishedCalled());
266 resource1->removeClient(&client); 271 resource1->removeClient(client);
267 memoryCache()->remove(resource1); 272 memoryCache()->remove(resource1);
268 } 273 }
269 274
270 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) 275 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl)
271 { 276 {
272 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 277 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
273 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); 278 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo"));
274 ResourceLoaderOptions options; 279 ResourceLoaderOptions options;
275 options.dataBufferingPolicy = DoNotBufferData; 280 options.dataBufferingPolicy = DoNotBufferData;
276 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i nternal, options); 281 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i nternal, options);
277 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac tory(Resource::Media)); 282 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac tory(Resource::Media));
278 Resource* resource2 = fetcher->requestResource(fetchRequest, TestResourceFac tory(Resource::Media)); 283 Resource* resource2 = fetcher->requestResource(fetchRequest, TestResourceFac tory(Resource::Media));
279 EXPECT_NE(resource1, resource2); 284 EXPECT_NE(resource1, resource2);
280 memoryCache()->remove(resource2); 285 memoryCache()->remove(resource2);
281 } 286 }
282 287
283 class ServeRequestsOnCompleteClient : public RawResourceClient { 288 class ServeRequestsOnCompleteClient final : public GarbageCollectedFinalized<Ser veRequestsOnCompleteClient>, public RawResourceClient {
284 public: 289 public:
285 void notifyFinished(Resource*) override 290 void notifyFinished(Resource*) override
286 { 291 {
287 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest s(); 292 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest s();
288 } 293 }
289 294
290 // No callbacks should be received except for the notifyFinished() 295 // No callbacks should be received except for the notifyFinished()
291 // triggered by ResourceLoader::cancel(). 296 // triggered by ResourceLoader::cancel().
292 void dataSent(Resource*, unsigned long long, unsigned long long) override { ASSERT_TRUE(false); } 297 void dataSent(Resource*, unsigned long long, unsigned long long) override { ASSERT_TRUE(false); }
293 void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr<WebData ConsumerHandle>) override { ASSERT_TRUE(false); } 298 void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr<WebData ConsumerHandle>) override { ASSERT_TRUE(false); }
294 void setSerializedCachedMetadata(Resource*, const char*, size_t) override { ASSERT_TRUE(false); } 299 void setSerializedCachedMetadata(Resource*, const char*, size_t) override { ASSERT_TRUE(false); }
295 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal se); } 300 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal se); }
296 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&) override { ASSERT_TRUE(false); } 301 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&) override { ASSERT_TRUE(false); }
297 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); } 302 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); }
298 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override { ASSERT_TRUE(false); } 303 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override { ASSERT_TRUE(false); }
299 304
305 DEFINE_INLINE_TRACE() {}
306
300 String debugName() const override { return "ServeRequestsOnCompleteClient"; } 307 String debugName() const override { return "ServeRequestsOnCompleteClient"; }
301 }; 308 };
302 309
303 // Regression test for http://crbug.com/594072. 310 // Regression test for http://crbug.com/594072.
304 // This emulates a modal dialog triggering a nested run loop inside 311 // This emulates a modal dialog triggering a nested run loop inside
305 // ResourceLoader::cancel(). If the ResourceLoader doesn't promptly cancel its 312 // ResourceLoader::cancel(). If the ResourceLoader doesn't promptly cancel its
306 // WebURLLoader before notifying its clients, a nested run loop may send a 313 // WebURLLoader before notifying its clients, a nested run loop may send a
307 // network response, leading to an invalid state transition in ResourceLoader. 314 // network response, leading to an invalid state transition in ResourceLoader.
308 TEST_F(ResourceFetcherTest, ResponseOnCancel) 315 TEST_F(ResourceFetcherTest, ResponseOnCancel)
309 { 316 {
310 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 317 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
311 ResourceResponse response; 318 ResourceResponse response;
312 response.setURL(url); 319 response.setURL(url);
313 response.setHTTPStatusCode(200); 320 response.setHTTPStatusCode(200);
314 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png" , WebString::fromUTF8(""), WrappedResourceResponse(response)); 321 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png" , WebString::fromUTF8(""), WrappedResourceResponse(response));
315 322
316 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 323 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
317 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 324 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
318 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw)); 325 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw));
319 ServeRequestsOnCompleteClient client; 326 Persistent<ServeRequestsOnCompleteClient> client = new ServeRequestsOnComple teClient();
320 resource->addClient(&client); 327 resource->addClient(client);
321 resource->loader()->cancel(); 328 resource->loader()->cancel();
329 resource->removeClient(client);
322 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 330 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
323 } 331 }
324 332
325 } // namespace blink 333 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698