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

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

Issue 2399473002: Remove Resource::create() to ensure proper subclasses of Resource are created (Closed)
Patch Set: Rebase Created 4 years, 2 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 memoryCache()->add(resource2); 159 memoryCache()->add(resource2);
160 EXPECT_EQ(resource1->size() + resource2->size(), memoryCache()->deadSize()); 160 EXPECT_EQ(resource1->size() + resource2->size(), memoryCache()->deadSize());
161 EXPECT_EQ(0u, memoryCache()->liveSize()); 161 EXPECT_EQ(0u, memoryCache()->liveSize());
162 162
163 memoryCache()->prune(); 163 memoryCache()->prune();
164 EXPECT_EQ(0u, memoryCache()->deadSize()); 164 EXPECT_EQ(0u, memoryCache()->deadSize());
165 EXPECT_EQ(0u, memoryCache()->liveSize()); 165 EXPECT_EQ(0u, memoryCache()->liveSize());
166 } 166 }
167 167
168 TEST_F(MemoryCacheTest, DeadResourceEviction_Basic) { 168 TEST_F(MemoryCacheTest, DeadResourceEviction_Basic) {
169 Resource* resource1 = 169 Resource* resource1 = RawResource::create(
170 Resource::create(ResourceRequest("http://test/resource1"), Resource::Raw); 170 ResourceRequest("http://test/resource1"), Resource::Raw);
171 Resource* resource2 = 171 Resource* resource2 = RawResource::create(
172 Resource::create(ResourceRequest("http://test/resource2"), Resource::Raw); 172 ResourceRequest("http://test/resource2"), Resource::Raw);
173 TestDeadResourceEviction(resource1, resource2); 173 TestDeadResourceEviction(resource1, resource2);
174 } 174 }
175 175
176 TEST_F(MemoryCacheTest, DeadResourceEviction_MultipleResourceMaps) { 176 TEST_F(MemoryCacheTest, DeadResourceEviction_MultipleResourceMaps) {
177 Resource* resource1 = 177 Resource* resource1 = RawResource::create(
178 Resource::create(ResourceRequest("http://test/resource1"), Resource::Raw); 178 ResourceRequest("http://test/resource1"), Resource::Raw);
179 Resource* resource2 = 179 Resource* resource2 = RawResource::create(
180 Resource::create(ResourceRequest("http://test/resource2"), Resource::Raw); 180 ResourceRequest("http://test/resource2"), Resource::Raw);
181 resource2->setCacheIdentifier("foo"); 181 resource2->setCacheIdentifier("foo");
182 TestDeadResourceEviction(resource1, resource2); 182 TestDeadResourceEviction(resource1, resource2);
183 } 183 }
184 184
185 static void runTask1(Resource* live, Resource* dead) { 185 static void runTask1(Resource* live, Resource* dead) {
186 // The resource size has to be nonzero for this test to be meaningful, but 186 // The resource size has to be nonzero for this test to be meaningful, but
187 // we do not rely on it having any particular value. 187 // we do not rely on it having any particular value.
188 EXPECT_GT(live->size(), 0u); 188 EXPECT_GT(live->size(), 0u);
189 EXPECT_GT(dead->size(), 0u); 189 EXPECT_GT(dead->size(), 0u);
190 190
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 BLINK_FROM_HERE, 232 BLINK_FROM_HERE,
233 WTF::bind(&runTask2, cachedLiveResource->encodedSize() + 233 WTF::bind(&runTask2, cachedLiveResource->encodedSize() +
234 cachedLiveResource->overheadSize())); 234 cachedLiveResource->overheadSize()));
235 testing::runPendingTasks(); 235 testing::runPendingTasks();
236 } 236 }
237 237
238 // Verified that when ordering a prune in a runLoop task, the prune 238 // Verified that when ordering a prune in a runLoop task, the prune
239 // is deferred to the end of the task. 239 // is deferred to the end of the task.
240 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) { 240 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) {
241 Resource* cachedDeadResource = 241 Resource* cachedDeadResource =
242 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw); 242 RawResource::create(ResourceRequest("hhtp://foo"), Resource::Raw);
243 Resource* cachedLiveResource = FakeDecodedResource::create( 243 Resource* cachedLiveResource = FakeDecodedResource::create(
244 ResourceRequest("http://test/resource"), Resource::Raw); 244 ResourceRequest("http://test/resource"), Resource::Raw);
245 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource); 245 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
246 } 246 }
247 247
248 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_MultipleResourceMaps) { 248 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_MultipleResourceMaps) {
249 { 249 {
250 Resource* cachedDeadResource = 250 Resource* cachedDeadResource =
251 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw); 251 RawResource::create(ResourceRequest("hhtp://foo"), Resource::Raw);
252 cachedDeadResource->setCacheIdentifier("foo"); 252 cachedDeadResource->setCacheIdentifier("foo");
253 Resource* cachedLiveResource = FakeDecodedResource::create( 253 Resource* cachedLiveResource = FakeDecodedResource::create(
254 ResourceRequest("http://test/resource"), Resource::Raw); 254 ResourceRequest("http://test/resource"), Resource::Raw);
255 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource); 255 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
256 memoryCache()->evictResources(); 256 memoryCache()->evictResources();
257 } 257 }
258 { 258 {
259 Resource* cachedDeadResource = 259 Resource* cachedDeadResource =
260 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw); 260 RawResource::create(ResourceRequest("hhtp://foo"), Resource::Raw);
261 Resource* cachedLiveResource = FakeDecodedResource::create( 261 Resource* cachedLiveResource = FakeDecodedResource::create(
262 ResourceRequest("http://test/resource"), Resource::Raw); 262 ResourceRequest("http://test/resource"), Resource::Raw);
263 cachedLiveResource->setCacheIdentifier("foo"); 263 cachedLiveResource->setCacheIdentifier("foo");
264 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource); 264 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
265 memoryCache()->evictResources(); 265 memoryCache()->evictResources();
266 } 266 }
267 { 267 {
268 Resource* cachedDeadResource = Resource::create( 268 Resource* cachedDeadResource = RawResource::create(
269 ResourceRequest("hhtp://test/resource"), Resource::Raw); 269 ResourceRequest("hhtp://test/resource"), Resource::Raw);
270 cachedDeadResource->setCacheIdentifier("foo"); 270 cachedDeadResource->setCacheIdentifier("foo");
271 Resource* cachedLiveResource = FakeDecodedResource::create( 271 Resource* cachedLiveResource = FakeDecodedResource::create(
272 ResourceRequest("http://test/resource"), Resource::Raw); 272 ResourceRequest("http://test/resource"), Resource::Raw);
273 cachedLiveResource->setCacheIdentifier("bar"); 273 cachedLiveResource->setCacheIdentifier("bar");
274 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource); 274 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource);
275 memoryCache()->evictResources(); 275 memoryCache()->evictResources();
276 } 276 }
277 } 277 }
278 278
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 FakeResource* resource2 = 472 FakeResource* resource2 =
473 FakeResource::create(ResourceRequest(url2), Resource::Raw); 473 FakeResource::create(ResourceRequest(url2), Resource::Raw);
474 memoryCache()->add(resource2); 474 memoryCache()->add(resource2);
475 EXPECT_TRUE(memoryCache()->contains(resource2)); 475 EXPECT_TRUE(memoryCache()->contains(resource2));
476 476
477 memoryCache()->removeURLFromCache(url2); 477 memoryCache()->removeURLFromCache(url2);
478 EXPECT_FALSE(memoryCache()->contains(resource2)); 478 EXPECT_FALSE(memoryCache()->contains(resource2));
479 } 479 }
480 480
481 } // namespace blink 481 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/FontResource.h ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698