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

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

Issue 1327653004: Have uses of MockImageResourceClient leak less. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Clean up MockImageResourceClient somewhat Created 5 years, 3 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
« no previous file with comments | « Source/core/fetch/RawResourceTest.cpp ('k') | Source/core/frame/ImageBitmapTest.cpp » ('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) 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 16 matching lines...) Expand all
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 #include "core/fetch/ResourceFetcher.h" 32 #include "core/fetch/ResourceFetcher.h"
33 33
34 #include "core/fetch/FetchInitiatorInfo.h" 34 #include "core/fetch/FetchInitiatorInfo.h"
35 #include "core/fetch/FetchRequest.h" 35 #include "core/fetch/FetchRequest.h"
36 #include "core/fetch/MemoryCache.h" 36 #include "core/fetch/MemoryCache.h"
37 #include "core/fetch/ResourceLoader.h"
37 #include "core/fetch/ResourcePtr.h" 38 #include "core/fetch/ResourcePtr.h"
38 #include "platform/exported/WrappedResourceResponse.h" 39 #include "platform/exported/WrappedResourceResponse.h"
39 #include "platform/heap/Handle.h" 40 #include "platform/heap/Handle.h"
40 #include "platform/network/ResourceRequest.h" 41 #include "platform/network/ResourceRequest.h"
41 #include "platform/testing/URLTestHelpers.h" 42 #include "platform/testing/URLTestHelpers.h"
42 #include "platform/weborigin/KURL.h" 43 #include "platform/weborigin/KURL.h"
43 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
44 #include "public/platform/WebURLResponse.h" 45 #include "public/platform/WebURLResponse.h"
45 #include "public/platform/WebUnitTestSupport.h" 46 #include "public/platform/WebUnitTestSupport.h"
46 #include <gtest/gtest.h> 47 #include <gtest/gtest.h>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 response.setHTTPHeaderField("Cache-Control", "max-age=3600"); 111 response.setHTTPHeaderField("Cache-Control", "max-age=3600");
111 resource->responseReceived(response, nullptr); 112 resource->responseReceived(response, nullptr);
112 resource->finish(); 113 resource->finish();
113 114
114 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 115 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
115 ResourcePtr<Resource> newResource = fetcher->requestResource(fetchRequest, T estResourceFactory(Resource::Image)); 116 ResourcePtr<Resource> newResource = fetcher->requestResource(fetchRequest, T estResourceFactory(Resource::Image));
116 EXPECT_EQ(resource, newResource); 117 EXPECT_EQ(resource, newResource);
117 memoryCache()->remove(resource.get()); 118 memoryCache()->remove(resource.get());
118 } 119 }
119 120
120
121 TEST_F(ResourceFetcherTest, Vary) 121 TEST_F(ResourceFetcherTest, Vary)
122 { 122 {
123 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
124
125 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 123 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
126 ResourcePtr<Resource> resource = new Resource(url, Resource::Raw); 124 ResourcePtr<Resource> resource = new Resource(url, Resource::Raw);
127 memoryCache()->add(resource.get()); 125 memoryCache()->add(resource.get());
128 ResourceResponse response; 126 ResourceResponse response;
129 response.setURL(url); 127 response.setURL(url);
130 response.setHTTPStatusCode(200); 128 response.setHTTPStatusCode(200);
131 response.setHTTPHeaderField("Cache-Control", "max-age=3600"); 129 response.setHTTPHeaderField("Cache-Control", "max-age=3600");
132 response.setHTTPHeaderField("Vary", "*"); 130 response.setHTTPHeaderField("Vary", "*");
133 resource->responseReceived(response, nullptr); 131 resource->responseReceived(response, nullptr);
134 resource->finish(); 132 resource->finish();
135 ASSERT_TRUE(resource->hasVaryHeader()); 133 ASSERT_TRUE(resource->hasVaryHeader());
136 134
135 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
137 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 136 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
138 Platform::current()->unitTestSupport()->registerMockedURL(url, WebURLRespons e(), ""); 137 Platform::current()->unitTestSupport()->registerMockedURL(url, WebURLRespons e(), "");
139 ResourcePtr<Resource> newResource = fetcher->requestResource(fetchRequest, T estResourceFactory()); 138 ResourcePtr<Resource> newResource = fetcher->requestResource(fetchRequest, T estResourceFactory());
140 EXPECT_NE(resource, newResource); 139 EXPECT_NE(resource, newResource);
141 140 newResource->loader()->cancel();
142 memoryCache()->remove(newResource.get()); 141 memoryCache()->remove(newResource.get());
143 Platform::current()->unitTestSupport()->unregisterMockedURL(url); 142 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
143
144 memoryCache()->remove(resource.get());
144 } 145 }
145 146
146 TEST_F(ResourceFetcherTest, VaryOnBack) 147 TEST_F(ResourceFetcherTest, VaryOnBack)
147 { 148 {
148 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); 149 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create();
149 context->setCachePolicy(CachePolicyHistoryBuffer); 150 context->setCachePolicy(CachePolicyHistoryBuffer);
150 ResourceFetcher* fetcher = ResourceFetcher::create(context); 151 ResourceFetcher* fetcher = ResourceFetcher::create(context);
151 152
152 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 153 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
153 ResourcePtr<Resource> resource = new Resource(url, Resource::Raw); 154 ResourcePtr<Resource> resource = new Resource(url, Resource::Raw);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 response.setHTTPHeaderField("etag", "1234567890"); 212 response.setHTTPHeaderField("etag", "1234567890");
212 resource1->responseReceived(response, nullptr); 213 resource1->responseReceived(response, nullptr);
213 resource1->finish(); 214 resource1->finish();
214 215
215 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); 216 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create();
216 context->setCachePolicy(CachePolicyRevalidate); 217 context->setCachePolicy(CachePolicyRevalidate);
217 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); 218 ResourceFetcher* fetcher2 = ResourceFetcher::create(context);
218 FetchRequest fetchRequest2(url, FetchInitiatorInfo()); 219 FetchRequest fetchRequest2(url, FetchInitiatorInfo());
219 ResourcePtr<Resource> resource2 = fetcher2->requestResource(fetchRequest2, T estResourceFactory(Resource::Image)); 220 ResourcePtr<Resource> resource2 = fetcher2->requestResource(fetchRequest2, T estResourceFactory(Resource::Image));
220 EXPECT_EQ(resource1, resource2); 221 EXPECT_EQ(resource1, resource2);
222
223 // Tidily(?) shut down the ResourceLoader.
224 resource1->loader()->cancel();
225 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
221 } 226 }
222 227
223 } // namespace blink 228 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/fetch/RawResourceTest.cpp ('k') | Source/core/frame/ImageBitmapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698