OLD | NEW |
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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 ASSERT_EQ(memoryCache()->deadSize(), 0u); | 280 ASSERT_EQ(memoryCache()->deadSize(), 0u); |
281 ASSERT_EQ(memoryCache()->liveSize(), resource1->size() + resource2->size()); | 281 ASSERT_EQ(memoryCache()->liveSize(), resource1->size() + resource2->size()); |
282 | 282 |
283 // Removing the client from resource1 should result in all resources | 283 // Removing the client from resource1 should result in all resources |
284 // remaining in cache since the prune is deferred. | 284 // remaining in cache since the prune is deferred. |
285 resource1->removeClient(&client1); | 285 resource1->removeClient(&client1); |
286 ASSERT_GT(resource1->decodedSize(), 0u); | 286 ASSERT_GT(resource1->decodedSize(), 0u); |
287 ASSERT_GT(resource2->decodedSize(), 0u); | 287 ASSERT_GT(resource2->decodedSize(), 0u); |
288 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); | 288 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); |
289 ASSERT_EQ(memoryCache()->liveSize(), resource2->size()); | 289 ASSERT_EQ(memoryCache()->liveSize(), resource2->size()); |
290 ASSERT_TRUE(resource1->inCache()); | 290 ASSERT_TRUE(memoryCache()->contains(resource1.get())); |
291 ASSERT_TRUE(resource2->inCache()); | 291 ASSERT_TRUE(memoryCache()->contains(resource2.get())); |
292 | 292 |
293 // Removing the client from resource2 should result in immediate | 293 // Removing the client from resource2 should result in immediate |
294 // eviction of resource2 because we are over the prune deferral limit. | 294 // eviction of resource2 because we are over the prune deferral limit. |
295 resource2->removeClient(&client2); | 295 resource2->removeClient(&client2); |
296 ASSERT_GT(resource1->decodedSize(), 0u); | 296 ASSERT_GT(resource1->decodedSize(), 0u); |
297 ASSERT_GT(resource2->decodedSize(), 0u); | 297 ASSERT_GT(resource2->decodedSize(), 0u); |
298 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); | 298 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); |
299 ASSERT_EQ(memoryCache()->liveSize(), 0u); | 299 ASSERT_EQ(memoryCache()->liveSize(), 0u); |
300 ASSERT_TRUE(resource1->inCache()); | 300 ASSERT_TRUE(memoryCache()->contains(resource1.get())); |
301 ASSERT_FALSE(resource2->inCache()); | 301 ASSERT_FALSE(memoryCache()->contains(resource2.get())); |
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("http://foo.com"), Resource::Raw
); | 311 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw
); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 369 |
370 TEST_F(MemoryCacheTest, MultipleReplace) | 370 TEST_F(MemoryCacheTest, MultipleReplace) |
371 { | 371 { |
372 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest(""),
Resource::Raw); | 372 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest(""),
Resource::Raw); |
373 memoryCache()->add(resource1.get()); | 373 memoryCache()->add(resource1.get()); |
374 EXPECT_EQ(1U, resource1->accessCount()); | |
375 | 374 |
376 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest(""),
Resource::Raw); | 375 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest(""),
Resource::Raw); |
377 memoryCache()->replace(resource2.get(), resource1.get()); | 376 memoryCache()->replace(resource2.get(), resource1.get()); |
378 EXPECT_TRUE(resource2->inCache()); | 377 EXPECT_TRUE(memoryCache()->contains(resource2.get())); |
379 EXPECT_FALSE(resource1->inCache()); | 378 EXPECT_FALSE(memoryCache()->contains(resource1.get())); |
380 EXPECT_EQ(0U, resource2->accessCount()); | |
381 | 379 |
382 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest(""),
Resource::Raw); | 380 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest(""),
Resource::Raw); |
383 memoryCache()->replace(resource3.get(), resource2.get()); | 381 memoryCache()->replace(resource3.get(), resource2.get()); |
384 EXPECT_TRUE(resource3->inCache()); | 382 EXPECT_TRUE(memoryCache()->contains(resource3.get())); |
385 EXPECT_FALSE(resource2->inCache()); | 383 EXPECT_FALSE(memoryCache()->contains(resource2.get())); |
386 EXPECT_EQ(0U, resource3->accessCount()); | |
387 } | 384 } |
388 | 385 |
389 } // namespace | 386 } // namespace |
OLD | NEW |