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

Side by Side Diff: Source/core/fetch/CachingCorrectnessTest.cpp

Issue 1170503003: Remove resource type-specific fetching logic from ResourceFetcher (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Null-check Document::loader() before calling startPreload() Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/fetch/CSSStyleSheetResource.cpp ('k') | Source/core/fetch/DocumentResource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
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" 34 #include "core/fetch/ImageResource.h"
35 #include "core/fetch/MemoryCache.h" 35 #include "core/fetch/MemoryCache.h"
36 #include "core/fetch/RawResource.h"
36 #include "core/fetch/Resource.h" 37 #include "core/fetch/Resource.h"
37 #include "core/fetch/ResourceFetcher.h" 38 #include "core/fetch/ResourceFetcher.h"
38 #include "core/fetch/ResourcePtr.h" 39 #include "core/fetch/ResourcePtr.h"
39 #include "platform/network/ResourceRequest.h" 40 #include "platform/network/ResourceRequest.h"
40 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
41 #include "wtf/OwnPtr.h" 42 #include "wtf/OwnPtr.h"
42 #include "wtf/RefPtr.h" 43 #include "wtf/RefPtr.h"
43 #include <gtest/gtest.h> 44 #include <gtest/gtest.h>
44 45
45 namespace blink { 46 namespace blink {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 new Resource(request, type); 100 new Resource(request, type);
100 resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceUR L), "text/html", 0, nullAtom, String())); 101 resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceUR L), "text/html", 0, nullAtom, String()));
101 memoryCache()->add(resource.get()); 102 memoryCache()->add(resource.get());
102 103
103 return resource; 104 return resource;
104 } 105 }
105 106
106 ResourcePtr<Resource> fetch() 107 ResourcePtr<Resource> fetch()
107 { 108 {
108 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo()); 109 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo());
109 return m_fetcher->fetchSynchronously(fetchRequest); 110 return RawResource::fetchSynchronously(fetchRequest, fetcher());
110 } 111 }
111 112
112 ResourcePtr<Resource> fetchImage() 113 ResourcePtr<Resource> fetchImage()
113 { 114 {
114 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo()); 115 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo());
115 return m_fetcher->fetchImage(fetchRequest); 116 return ImageResource::fetch(fetchRequest, fetcher());
116 } 117 }
117 118
118 ResourceFetcher* fetcher() const { return m_fetcher.get(); } 119 ResourceFetcher* fetcher() const { return m_fetcher.get(); }
119 120
120 private: 121 private:
121 // A simple platform that mocks out the clock, for cache freshness testing. 122 // A simple platform that mocks out the clock, for cache freshness testing.
122 class ProxyPlatform : public blink::Platform { 123 class ProxyPlatform : public blink::Platform {
123 public: 124 public:
124 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon ds(0.) { } 125 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon ds(0.) { }
125 126
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 { 462 {
462 ResourceRequest request1(KURL(ParsedURLString, kResourceURL)); 463 ResourceRequest request1(KURL(ParsedURLString, kResourceURL));
463 request1.setHTTPMethod("POST"); 464 request1.setHTTPMethod("POST");
464 ResourcePtr<Resource> resource1 = new Resource(ResourceRequest(request1.url( )), Resource::Raw); 465 ResourcePtr<Resource> resource1 = new Resource(ResourceRequest(request1.url( )), Resource::Raw);
465 resource1->setLoading(true); 466 resource1->setLoading(true);
466 memoryCache()->add(resource1.get()); 467 memoryCache()->add(resource1.get());
467 468
468 ResourceRequest request2(KURL(ParsedURLString, kResourceURL)); 469 ResourceRequest request2(KURL(ParsedURLString, kResourceURL));
469 request2.setHTTPMethod("POST"); 470 request2.setHTTPMethod("POST");
470 FetchRequest fetch2(request2, FetchInitiatorInfo()); 471 FetchRequest fetch2(request2, FetchInitiatorInfo());
471 ResourcePtr<Resource> resource2 = fetcher()->fetchSynchronously(fetch2); 472 ResourcePtr<Resource> resource2 = RawResource::fetchSynchronously(fetch2, fe tcher());
472 473
473 EXPECT_EQ(resource2, memoryCache()->resourceForURL(request2.url())); 474 EXPECT_EQ(resource2, memoryCache()->resourceForURL(request2.url()));
474 EXPECT_NE(resource1, resource2); 475 EXPECT_NE(resource1, resource2);
475 } 476 }
476 477
477 TEST_F(CachingCorrectnessTest, 302RedirectNotImplicitlyFresh) 478 TEST_F(CachingCorrectnessTest, 302RedirectNotImplicitlyFresh)
478 { 479 {
479 KURL redirectUrl(ParsedURLString, kResourceURL); 480 KURL redirectUrl(ParsedURLString, kResourceURL);
480 const char redirectTargetUrlString[] = "http://redirect-target.com"; 481 const char redirectTargetUrlString[] = "http://redirect-target.com";
481 KURL redirectTargetUrl(ParsedURLString, redirectTargetUrlString); 482 KURL redirectTargetUrl(ParsedURLString, redirectTargetUrlString);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 firstResource->setResponse(fresh200Response); 574 firstResource->setResponse(fresh200Response);
574 memoryCache()->add(firstResource.get()); 575 memoryCache()->add(firstResource.get());
575 576
576 advanceClock(500.); 577 advanceClock(500.);
577 578
578 ResourcePtr<Resource> fetched = fetch(); 579 ResourcePtr<Resource> fetched = fetch();
579 EXPECT_EQ(firstResource, fetched); 580 EXPECT_EQ(firstResource, fetched);
580 } 581 }
581 582
582 } // namespace blink 583 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/fetch/CSSStyleSheetResource.cpp ('k') | Source/core/fetch/DocumentResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698