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

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

Issue 174523002: Reland "Move MemoryCache implementation details out of Resource" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 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/MemoryCache.cpp ('k') | Source/core/fetch/Resource.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) 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // is deferred to the end of the task. 177 // is deferred to the end of the task.
178 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask) 178 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask)
179 { 179 {
180 memoryCache()->setDelayBeforeLiveDecodedPrune(0); 180 memoryCache()->setDelayBeforeLiveDecodedPrune(0);
181 const unsigned totalCapacity = 1; 181 const unsigned totalCapacity = 1;
182 const unsigned minDeadCapacity = 0; 182 const unsigned minDeadCapacity = 0;
183 const unsigned maxDeadCapacity = 0; 183 const unsigned maxDeadCapacity = 0;
184 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity ); 184 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity );
185 const char data[6] = "abcde"; 185 const char data[6] = "abcde";
186 ResourcePtr<Resource> cachedDeadResource = 186 ResourcePtr<Resource> cachedDeadResource =
187 new Resource(ResourceRequest(""), Resource::Raw); 187 new Resource(ResourceRequest("http://foo"), Resource::Raw);
188 cachedDeadResource->appendData(data, 3); 188 cachedDeadResource->appendData(data, 3);
189 ResourcePtr<Resource> cachedLiveResource = 189 ResourcePtr<Resource> cachedLiveResource =
190 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); 190 new FakeDecodedResource(ResourceRequest(""), Resource::Raw);
191 MockImageResourceClient client; 191 MockImageResourceClient client;
192 cachedLiveResource->addClient(&client); 192 cachedLiveResource->addClient(&client);
193 cachedLiveResource->appendData(data, 4); 193 cachedLiveResource->appendData(data, 4);
194 194
195 class Task1 : public blink::WebThread::Task { 195 class Task1 : public blink::WebThread::Task {
196 public: 196 public:
197 Task1(const ResourcePtr<Resource>& live, const ResourcePtr<Resource>& de ad) 197 Task1(const ResourcePtr<Resource>& live, const ResourcePtr<Resource>& de ad)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 blink::Platform::current()->currentThread()->enterRunLoop(); 249 blink::Platform::current()->currentThread()->enterRunLoop();
250 cachedLiveResource->removeClient(&client); 250 cachedLiveResource->removeClient(&client);
251 } 251 }
252 252
253 // Verifies that cached resources are evicted immediately after release when 253 // Verifies that cached resources are evicted immediately after release when
254 // the total dead resource size is more than double the dead resource capacity. 254 // the total dead resource size is more than double the dead resource capacity.
255 TEST_F(MemoryCacheTest, ClientRemoval) 255 TEST_F(MemoryCacheTest, ClientRemoval)
256 { 256 {
257 const char data[6] = "abcde"; 257 const char data[6] = "abcde";
258 ResourcePtr<Resource> resource1 = 258 ResourcePtr<Resource> resource1 =
259 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); 259 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw );
260 MockImageResourceClient client1; 260 MockImageResourceClient client1;
261 resource1->addClient(&client1); 261 resource1->addClient(&client1);
262 resource1->appendData(data, 4); 262 resource1->appendData(data, 4);
263 ResourcePtr<Resource> resource2 = 263 ResourcePtr<Resource> resource2 =
264 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); 264 new FakeDecodedResource(ResourceRequest(""), Resource::Raw);
265 MockImageResourceClient client2; 265 MockImageResourceClient client2;
266 resource2->addClient(&client2); 266 resource2->addClient(&client2);
267 resource2->appendData(data, 4); 267 resource2->appendData(data, 4);
268 268
269 const unsigned minDeadCapacity = 0; 269 const unsigned minDeadCapacity = 0;
270 const unsigned maxDeadCapacity = resource1->size() - 1; 270 const unsigned maxDeadCapacity = ((resource1->size() + resource2->size()) / 2) - 1;
271 const unsigned totalCapacity = maxDeadCapacity; 271 const unsigned totalCapacity = maxDeadCapacity;
272 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity ); 272 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity );
273 memoryCache()->add(resource1.get()); 273 memoryCache()->add(resource1.get());
274 memoryCache()->add(resource2.get()); 274 memoryCache()->add(resource2.get());
275 // Call prune. There is nothing to prune, but this will initialize 275 // Call prune. There is nothing to prune, but this will initialize
276 // the prune timestamp, allowing future prunes to be deferred. 276 // the prune timestamp, allowing future prunes to be deferred.
277 memoryCache()->prune(); 277 memoryCache()->prune();
278 ASSERT_GT(resource1->decodedSize(), 0u); 278 ASSERT_GT(resource1->decodedSize(), 0u);
279 ASSERT_GT(resource2->decodedSize(), 0u); 279 ASSERT_GT(resource2->decodedSize(), 0u);
280 ASSERT_EQ(memoryCache()->deadSize(), 0u); 280 ASSERT_EQ(memoryCache()->deadSize(), 0u);
(...skipping 20 matching lines...) Expand all
301 ASSERT_FALSE(resource2->inCache()); 301 ASSERT_FALSE(resource2->inCache());
302 } 302 }
303 303
304 // Verifies that CachedResources are evicted from the decode cache 304 // Verifies that CachedResources are evicted from the decode cache
305 // according to their DecodeCachePriority. 305 // according to their DecodeCachePriority.
306 TEST_F(MemoryCacheTest, DecodeCacheOrder) 306 TEST_F(MemoryCacheTest, DecodeCacheOrder)
307 { 307 {
308 memoryCache()->setDelayBeforeLiveDecodedPrune(0); 308 memoryCache()->setDelayBeforeLiveDecodedPrune(0);
309 memoryCache()->setMaxPruneDeferralDelay(0); 309 memoryCache()->setMaxPruneDeferralDelay(0);
310 ResourcePtr<FakeDecodedResource> cachedImageLowPriority = 310 ResourcePtr<FakeDecodedResource> cachedImageLowPriority =
311 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); 311 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw );
312 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = 312 ResourcePtr<FakeDecodedResource> cachedImageHighPriority =
313 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); 313 new FakeDecodedResource(ResourceRequest(""), Resource::Raw);
314 314
315 MockImageResourceClient clientLowPriority; 315 MockImageResourceClient clientLowPriority;
316 MockImageResourceClient clientHighPriority; 316 MockImageResourceClient clientHighPriority;
317 cachedImageLowPriority->addClient(&clientLowPriority); 317 cachedImageLowPriority->addClient(&clientLowPriority);
318 cachedImageHighPriority->addClient(&clientHighPriority); 318 cachedImageHighPriority->addClient(&clientHighPriority);
319 319
320 const char data[5] = "abcd"; 320 const char data[5] = "abcd";
321 cachedImageLowPriority->appendData(data, 1); 321 cachedImageLowPriority->appendData(data, 1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 ASSERT_EQ(memoryCache()->deadSize(), 0u); 360 ASSERT_EQ(memoryCache()->deadSize(), 0u);
361 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize); 361 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize);
362 362
363 // Should prune the HighPriority item. 363 // Should prune the HighPriority item.
364 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache() ->liveSize() - 10, memoryCache()->liveSize() - 10); 364 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache() ->liveSize() - 10, memoryCache()->liveSize() - 10);
365 memoryCache()->prune(); 365 memoryCache()->prune();
366 ASSERT_EQ(memoryCache()->deadSize(), 0u); 366 ASSERT_EQ(memoryCache()->deadSize(), 0u);
367 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - highPriorityMockDecodeSize); 367 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - highPriorityMockDecodeSize);
368 } 368 }
369 } // namespace 369 } // namespace
OLDNEW
« no previous file with comments | « Source/core/fetch/MemoryCache.cpp ('k') | Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698