| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 memoryCache()->add(resource1); | 305 memoryCache()->add(resource1); |
| 306 memoryCache()->add(resource2); | 306 memoryCache()->add(resource2); |
| 307 // Call prune. There is nothing to prune, but this will initialize | 307 // Call prune. There is nothing to prune, but this will initialize |
| 308 // the prune timestamp, allowing future prunes to be deferred. | 308 // the prune timestamp, allowing future prunes to be deferred. |
| 309 memoryCache()->prune(); | 309 memoryCache()->prune(); |
| 310 EXPECT_GT(resource1->decodedSize(), 0u); | 310 EXPECT_GT(resource1->decodedSize(), 0u); |
| 311 EXPECT_GT(resource2->decodedSize(), 0u); | 311 EXPECT_GT(resource2->decodedSize(), 0u); |
| 312 EXPECT_EQ(0u, memoryCache()->deadSize()); | 312 EXPECT_EQ(0u, memoryCache()->deadSize()); |
| 313 EXPECT_EQ(resource1->size() + resource2->size(), memoryCache()->liveSize()); | 313 EXPECT_EQ(resource1->size() + resource2->size(), memoryCache()->liveSize()); |
| 314 | 314 |
| 315 // Removing the client from resource1 should result in all resources | 315 // Removing the client from resource1 should not trigger pruning. |
| 316 // remaining in cache since the prune is deferred. | |
| 317 client1->removeAsClient(); | 316 client1->removeAsClient(); |
| 318 EXPECT_GT(resource1->decodedSize(), 0u); | 317 EXPECT_GT(resource1->decodedSize(), 0u); |
| 319 EXPECT_GT(resource2->decodedSize(), 0u); | 318 EXPECT_GT(resource2->decodedSize(), 0u); |
| 320 EXPECT_EQ(resource1->size(), memoryCache()->deadSize()); | 319 EXPECT_EQ(resource1->size(), memoryCache()->deadSize()); |
| 321 EXPECT_EQ(resource2->size(), memoryCache()->liveSize()); | 320 EXPECT_EQ(resource2->size(), memoryCache()->liveSize()); |
| 322 EXPECT_TRUE(memoryCache()->contains(resource1)); | 321 EXPECT_TRUE(memoryCache()->contains(resource1)); |
| 323 EXPECT_TRUE(memoryCache()->contains(resource2)); | 322 EXPECT_TRUE(memoryCache()->contains(resource2)); |
| 324 | 323 |
| 325 // Removing the client from resource2 should result in immediate | 324 // Removing the client from resource2 should not trigger pruning. |
| 326 // eviction of resource2 because we are over the prune deferral limit. | |
| 327 client2->removeAsClient(); | 325 client2->removeAsClient(); |
| 328 EXPECT_GT(resource1->decodedSize(), 0u); | 326 EXPECT_GT(resource1->decodedSize(), 0u); |
| 329 EXPECT_GT(resource2->decodedSize(), 0u); | 327 EXPECT_GT(resource2->decodedSize(), 0u); |
| 330 EXPECT_EQ(resource1->size(), memoryCache()->deadSize()); | 328 EXPECT_EQ(resource1->size() + resource2->size(), memoryCache()->deadSize()); |
| 331 EXPECT_EQ(0u, memoryCache()->liveSize()); | 329 EXPECT_EQ(0u, memoryCache()->liveSize()); |
| 332 EXPECT_TRUE(memoryCache()->contains(resource1)); | 330 EXPECT_TRUE(memoryCache()->contains(resource1)); |
| 333 EXPECT_FALSE(memoryCache()->contains(resource2)); | 331 EXPECT_TRUE(memoryCache()->contains(resource2)); |
| 332 |
| 333 WeakPersistent<Resource> resource1Weak = resource1; |
| 334 WeakPersistent<Resource> resource2Weak = resource2; |
| 335 |
| 336 ThreadState::current()->collectGarbage(BlinkGC::NoHeapPointersOnStack, Blink
GC::GCWithSweep, BlinkGC::ForcedGC); |
| 337 // Resources are garbage-collected (WeakMemoryCache) and thus removed |
| 338 // from MemoryCache. |
| 339 EXPECT_FALSE(resource1Weak); |
| 340 EXPECT_FALSE(resource2Weak); |
| 341 EXPECT_EQ(0u, memoryCache()->deadSize()); |
| 342 EXPECT_EQ(0u, memoryCache()->liveSize()); |
| 334 } | 343 } |
| 335 | 344 |
| 336 TEST_F(MemoryCacheTest, ClientRemoval_Basic) | 345 TEST_F(MemoryCacheTest, ClientRemoval_Basic) |
| 337 { | 346 { |
| 338 Resource* resource1 = | 347 Resource* resource1 = |
| 339 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resource:
:Raw); | 348 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resource:
:Raw); |
| 340 Resource* resource2 = | 349 Resource* resource2 = |
| 341 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res
ource::Raw); | 350 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 342 TestClientRemoval(resource1, resource2); | 351 TestClientRemoval(resource1, resource2); |
| 343 } | 352 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 const KURL url2 = KURL(ParsedURLString, "http://test/resource2#foo"); | 479 const KURL url2 = KURL(ParsedURLString, "http://test/resource2#foo"); |
| 471 FakeResource* resource2 = FakeResource::create(ResourceRequest(url2), Resour
ce::Raw); | 480 FakeResource* resource2 = FakeResource::create(ResourceRequest(url2), Resour
ce::Raw); |
| 472 memoryCache()->add(resource2); | 481 memoryCache()->add(resource2); |
| 473 EXPECT_TRUE(memoryCache()->contains(resource2)); | 482 EXPECT_TRUE(memoryCache()->contains(resource2)); |
| 474 | 483 |
| 475 memoryCache()->removeURLFromCache(url2); | 484 memoryCache()->removeURLFromCache(url2); |
| 476 EXPECT_FALSE(memoryCache()->contains(resource2)); | 485 EXPECT_FALSE(memoryCache()->contains(resource2)); |
| 477 } | 486 } |
| 478 | 487 |
| 479 } // namespace blink | 488 } // namespace blink |
| OLD | NEW |