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

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: 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
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 44
44 #include <gtest/gtest.h> 45 #include <gtest/gtest.h>
45 46
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 new Resource(request, type); 103 new Resource(request, type);
103 resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceUR L), "text/html", 0, nullAtom, String())); 104 resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceUR L), "text/html", 0, nullAtom, String()));
104 memoryCache()->add(resource.get()); 105 memoryCache()->add(resource.get());
105 106
106 return resource; 107 return resource;
107 } 108 }
108 109
109 ResourcePtr<Resource> fetch() 110 ResourcePtr<Resource> fetch()
110 { 111 {
111 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo()); 112 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo());
112 return m_fetcher->fetchSynchronously(fetchRequest); 113 return RawResource::fetchSynchronously(fetchRequest, fetcher());
113 } 114 }
114 115
115 ResourcePtr<Resource> fetchImage() 116 ResourcePtr<Resource> fetchImage()
116 { 117 {
117 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo()); 118 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo());
118 return m_fetcher->fetchImage(fetchRequest); 119 return ImageResource::fetch(fetchRequest, fetcher());
119 } 120 }
120 121
121 ResourceFetcher* fetcher() const { return m_fetcher.get(); } 122 ResourceFetcher* fetcher() const { return m_fetcher.get(); }
122 123
123 private: 124 private:
124 // A simple platform that mocks out the clock, for cache freshness testing. 125 // A simple platform that mocks out the clock, for cache freshness testing.
125 class ProxyPlatform : public blink::Platform { 126 class ProxyPlatform : public blink::Platform {
126 public: 127 public:
127 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon ds(0.) { } 128 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon ds(0.) { }
128 129
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 { 465 {
465 ResourceRequest request1(KURL(ParsedURLString, kResourceURL)); 466 ResourceRequest request1(KURL(ParsedURLString, kResourceURL));
466 request1.setHTTPMethod("POST"); 467 request1.setHTTPMethod("POST");
467 ResourcePtr<Resource> resource1 = new Resource(ResourceRequest(request1.url( )), Resource::Raw); 468 ResourcePtr<Resource> resource1 = new Resource(ResourceRequest(request1.url( )), Resource::Raw);
468 resource1->setLoading(true); 469 resource1->setLoading(true);
469 memoryCache()->add(resource1.get()); 470 memoryCache()->add(resource1.get());
470 471
471 ResourceRequest request2(KURL(ParsedURLString, kResourceURL)); 472 ResourceRequest request2(KURL(ParsedURLString, kResourceURL));
472 request2.setHTTPMethod("POST"); 473 request2.setHTTPMethod("POST");
473 FetchRequest fetch2(request2, FetchInitiatorInfo()); 474 FetchRequest fetch2(request2, FetchInitiatorInfo());
474 ResourcePtr<Resource> resource2 = fetcher()->fetchSynchronously(fetch2); 475 ResourcePtr<Resource> resource2 = RawResource::fetchSynchronously(fetch2, fe tcher());
475 476
476 EXPECT_EQ(resource2, memoryCache()->resourceForURL(request2.url())); 477 EXPECT_EQ(resource2, memoryCache()->resourceForURL(request2.url()));
477 EXPECT_NE(resource1, resource2); 478 EXPECT_NE(resource1, resource2);
478 } 479 }
479 480
480 TEST_F(CachingCorrectnessTest, 302RedirectNotImplicitlyFresh) 481 TEST_F(CachingCorrectnessTest, 302RedirectNotImplicitlyFresh)
481 { 482 {
482 KURL redirectUrl(ParsedURLString, kResourceURL); 483 KURL redirectUrl(ParsedURLString, kResourceURL);
483 const char redirectTargetUrlString[] = "http://redirect-target.com"; 484 const char redirectTargetUrlString[] = "http://redirect-target.com";
484 KURL redirectTargetUrl(ParsedURLString, redirectTargetUrlString); 485 KURL redirectTargetUrl(ParsedURLString, redirectTargetUrlString);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 firstResource->setResponse(fresh200Response); 577 firstResource->setResponse(fresh200Response);
577 memoryCache()->add(firstResource.get()); 578 memoryCache()->add(firstResource.get());
578 579
579 advanceClock(500.); 580 advanceClock(500.);
580 581
581 ResourcePtr<Resource> fetched = fetch(); 582 ResourcePtr<Resource> fetched = fetch();
582 EXPECT_EQ(firstResource, fetched); 583 EXPECT_EQ(firstResource, fetched);
583 } 584 }
584 585
585 } // namespace 586 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698