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

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

Issue 1889973002: Refactoring starting a resource load (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a browser_test Created 4 years, 6 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 { 110 {
111 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); 111 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png");
112 // Try to request a url. The request should fail, no resource should be retu rned, 112 // Try to request a url. The request should fail, no resource should be retu rned,
113 // and no resource should be present in the cache. 113 // and no resource should be present in the cache.
114 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 114 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
115 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo()); 115 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo());
116 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory()); 116 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory());
117 EXPECT_EQ(resource, static_cast<Resource*>(nullptr)); 117 EXPECT_EQ(resource, static_cast<Resource*>(nullptr));
118 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr)); 118 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr));
119 119
120 // Try calling Resource::load directly. This shouldn't crash. 120 // Start by calling startLoad() directly, rather than via requestResource().
121 Resource* resource2 = Resource::create(secureURL, Resource::Raw); 121 // This shouldn't crash.
122 resource2->load(fetcher); 122 fetcher->startLoad(Resource::create(secureURL, Resource::Raw));
123 } 123 }
124 124
125 TEST_F(ResourceFetcherTest, UseExistingResource) 125 TEST_F(ResourceFetcherTest, UseExistingResource)
126 { 126 {
127 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 127 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
128 128
129 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 129 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
130 Resource* resource = Resource::create(url, Resource::Image); 130 Resource* resource = Resource::create(url, Resource::Image);
131 memoryCache()->add(resource); 131 memoryCache()->add(resource);
132 ResourceResponse response; 132 ResourceResponse response;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WrappedReso urceResponse(response), ""); 286 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WrappedReso urceResponse(response), "");
287 287
288 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); 288 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create();
289 ResourceFetcher* fetcher = ResourceFetcher::create(context); 289 ResourceFetcher* fetcher = ResourceFetcher::create(context);
290 290
291 // Fetch to cache a resource. 291 // Fetch to cache a resource.
292 ResourceRequest request1(url); 292 ResourceRequest request1(url);
293 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); 293 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo());
294 Resource* resource1 = fetcher->requestResource(fetchRequest1, TestResourceFa ctory(Resource::Font)); 294 Resource* resource1 = fetcher->requestResource(fetchRequest1, TestResourceFa ctory(Resource::Font));
295 ASSERT_TRUE(resource1); 295 ASSERT_TRUE(resource1);
296 resource1->load(fetcher); 296 fetcher->startLoad(resource1);
297 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 297 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
298 EXPECT_TRUE(resource1->isLoaded()); 298 EXPECT_TRUE(resource1->isLoaded());
299 EXPECT_FALSE(resource1->errorOccurred()); 299 EXPECT_FALSE(resource1->errorOccurred());
300 300
301 // Set the context as it is on reloads. 301 // Set the context as it is on reloads.
302 context->setLoadComplete(true); 302 context->setLoadComplete(true);
303 context->setCachePolicy(CachePolicyRevalidate); 303 context->setCachePolicy(CachePolicyRevalidate);
304 304
305 // Revalidate the resource. 305 // Revalidate the resource.
306 ResourceRequest request2(url); 306 ResourceRequest request2(url);
307 FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo()); 307 FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo());
308 Resource* resource2 = fetcher->requestResource(fetchRequest2, TestResourceFa ctory(Resource::Font)); 308 Resource* resource2 = fetcher->requestResource(fetchRequest2, TestResourceFa ctory(Resource::Font));
309 ASSERT_TRUE(resource2); 309 ASSERT_TRUE(resource2);
310 EXPECT_EQ(resource1, resource2); 310 EXPECT_EQ(resource1, resource2);
311 EXPECT_TRUE(resource2->isCacheValidator()); 311 EXPECT_TRUE(resource2->isCacheValidator());
312 EXPECT_TRUE(resource2->stillNeedsLoad()); 312 EXPECT_TRUE(resource2->stillNeedsLoad());
313 313
314 // Fetch the same resource again before actual load operation starts. 314 // Fetch the same resource again before actual load operation starts.
315 ResourceRequest request3(url); 315 ResourceRequest request3(url);
316 FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo()); 316 FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo());
317 Resource* resource3 = fetcher->requestResource(fetchRequest3, TestResourceFa ctory(Resource::Font)); 317 Resource* resource3 = fetcher->requestResource(fetchRequest3, TestResourceFa ctory(Resource::Font));
318 ASSERT_TRUE(resource3); 318 ASSERT_TRUE(resource3);
319 EXPECT_EQ(resource2, resource3); 319 EXPECT_EQ(resource2, resource3);
320 EXPECT_TRUE(resource3->isCacheValidator()); 320 EXPECT_TRUE(resource3->isCacheValidator());
321 EXPECT_TRUE(resource3->stillNeedsLoad()); 321 EXPECT_TRUE(resource3->stillNeedsLoad());
322 322
323 // load() can be called from any initiator. Here, call it from the latter. 323 // startLoad() can be called from any initiator. Here, call it from the latt er.
324 resource3->load(fetcher); 324 fetcher->startLoad(resource3);
325 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 325 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
326 EXPECT_TRUE(resource3->isLoaded()); 326 EXPECT_TRUE(resource3->isLoaded());
327 EXPECT_FALSE(resource3->errorOccurred()); 327 EXPECT_FALSE(resource3->errorOccurred());
328 EXPECT_TRUE(resource2->isLoaded()); 328 EXPECT_TRUE(resource2->isLoaded());
329 EXPECT_FALSE(resource2->errorOccurred()); 329 EXPECT_FALSE(resource2->errorOccurred());
330 330
331 memoryCache()->remove(resource1); 331 memoryCache()->remove(resource1);
332 } 332 }
333 333
334 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) 334 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 383 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
384 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw)); 384 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw));
385 Persistent<ServeRequestsOnCompleteClient> client = new ServeRequestsOnComple teClient(); 385 Persistent<ServeRequestsOnCompleteClient> client = new ServeRequestsOnComple teClient();
386 resource->addClient(client); 386 resource->addClient(client);
387 resource->loader()->cancel(); 387 resource->loader()->cancel();
388 resource->removeClient(client); 388 resource->removeClient(client);
389 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 389 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
390 } 390 }
391 391
392 } // namespace blink 392 } // 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