| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 131 |
| 132 cachedResource->fakeEncodedSize(resourceSize2); | 132 cachedResource->fakeEncodedSize(resourceSize2); |
| 133 ASSERT_EQ(0u, memoryCache()->deadSize()); | 133 ASSERT_EQ(0u, memoryCache()->deadSize()); |
| 134 ASSERT_EQ(cachedResource->size(), memoryCache()->liveSize()); | 134 ASSERT_EQ(cachedResource->size(), memoryCache()->liveSize()); |
| 135 | 135 |
| 136 cachedResource->removeClient(&client); | 136 cachedResource->removeClient(&client); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Verifies that dead resources that exceed dead resource capacity are evicted | 139 // Verifies that dead resources that exceed dead resource capacity are evicted |
| 140 // from cache when pruning. | 140 // from cache when pruning. |
| 141 TEST_F(MemoryCacheTest, DeadResourceEviction) | 141 static void TestDeadResourceEviction(Resource* resource1, Resource* resource2) |
| 142 { | 142 { |
| 143 memoryCache()->setDelayBeforeLiveDecodedPrune(0); | 143 memoryCache()->setDelayBeforeLiveDecodedPrune(0); |
| 144 memoryCache()->setMaxPruneDeferralDelay(0); | 144 memoryCache()->setMaxPruneDeferralDelay(0); |
| 145 const unsigned totalCapacity = 1000000; | 145 const unsigned totalCapacity = 1000000; |
| 146 const unsigned minDeadCapacity = 0; | 146 const unsigned minDeadCapacity = 0; |
| 147 const unsigned maxDeadCapacity = 0; | 147 const unsigned maxDeadCapacity = 0; |
| 148 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); | 148 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); |
| 149 | 149 |
| 150 Resource* cachedResource = | |
| 151 new Resource(ResourceRequest("http://test/resource"), Resource::Raw); | |
| 152 const char data[5] = "abcd"; | 150 const char data[5] = "abcd"; |
| 153 cachedResource->appendData(data, 3u); | 151 resource1->appendData(data, 3u); |
| 152 resource2->appendData(data, 2u); |
| 153 |
| 154 // The resource size has to be nonzero for this test to be meaningful, but | 154 // The resource size has to be nonzero for this test to be meaningful, but |
| 155 // we do not rely on it having any particular value. | 155 // we do not rely on it having any particular value. |
| 156 ASSERT_GT(cachedResource->size(), 0u); | 156 ASSERT_GT(resource1->size(), 0u); |
| 157 ASSERT_GT(resource2->size(), 0u); |
| 157 | 158 |
| 158 ASSERT_EQ(0u, memoryCache()->deadSize()); | 159 ASSERT_EQ(0u, memoryCache()->deadSize()); |
| 159 ASSERT_EQ(0u, memoryCache()->liveSize()); | 160 ASSERT_EQ(0u, memoryCache()->liveSize()); |
| 160 | 161 |
| 161 memoryCache()->add(cachedResource); | 162 memoryCache()->add(resource1); |
| 162 ASSERT_EQ(cachedResource->size(), memoryCache()->deadSize()); | 163 ASSERT_EQ(resource1->size(), memoryCache()->deadSize()); |
| 164 ASSERT_EQ(0u, memoryCache()->liveSize()); |
| 165 |
| 166 memoryCache()->add(resource2); |
| 167 ASSERT_EQ(resource1->size() + resource2->size(), memoryCache()->deadSize()); |
| 163 ASSERT_EQ(0u, memoryCache()->liveSize()); | 168 ASSERT_EQ(0u, memoryCache()->liveSize()); |
| 164 | 169 |
| 165 memoryCache()->prune(); | 170 memoryCache()->prune(); |
| 166 ASSERT_EQ(0u, memoryCache()->deadSize()); | 171 ASSERT_EQ(0u, memoryCache()->deadSize()); |
| 167 ASSERT_EQ(0u, memoryCache()->liveSize()); | 172 ASSERT_EQ(0u, memoryCache()->liveSize()); |
| 168 } | 173 } |
| 169 | 174 |
| 170 // Verified that when ordering a prune in a runLoop task, the prune | 175 TEST_F(MemoryCacheTest, DeadResourceEviction_Basic) |
| 171 // is deferred to the end of the task. | 176 { |
| 172 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask) | 177 Resource* resource1 = |
| 178 new Resource(ResourceRequest("http://test/resource1"), Resource::Raw); |
| 179 Resource* resource2 = |
| 180 new Resource(ResourceRequest("http://test/resource2"), Resource::Raw); |
| 181 TestDeadResourceEviction(resource1, resource2); |
| 182 } |
| 183 |
| 184 TEST_F(MemoryCacheTest, DeadResourceEviction_MultipleResourceMaps) |
| 185 { |
| 186 Resource* resource1 = |
| 187 new Resource(ResourceRequest("http://test/resource1"), Resource::Raw); |
| 188 Resource* resource2 = |
| 189 new Resource(ResourceRequest("http://test/resource2"), Resource::Raw); |
| 190 resource2->setCacheIdentifier("foo"); |
| 191 TestDeadResourceEviction(resource1, resource2); |
| 192 } |
| 193 |
| 194 static void TestLiveResourceEvictionAtEndOfTask(Resource* cachedDeadResource, co
nst ResourcePtr<Resource>& cachedLiveResource) |
| 173 { | 195 { |
| 174 memoryCache()->setDelayBeforeLiveDecodedPrune(0); | 196 memoryCache()->setDelayBeforeLiveDecodedPrune(0); |
| 175 const unsigned totalCapacity = 1; | 197 const unsigned totalCapacity = 1; |
| 176 const unsigned minDeadCapacity = 0; | 198 const unsigned minDeadCapacity = 0; |
| 177 const unsigned maxDeadCapacity = 0; | 199 const unsigned maxDeadCapacity = 0; |
| 178 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); | 200 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); |
| 179 const char data[6] = "abcde"; | 201 const char data[6] = "abcde"; |
| 180 Resource* cachedDeadResource = | |
| 181 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); | |
| 182 cachedDeadResource->appendData(data, 3u); | 202 cachedDeadResource->appendData(data, 3u); |
| 183 ResourcePtr<Resource> cachedLiveResource = | |
| 184 new FakeDecodedResource(ResourceRequest("http://test/resource"), Resourc
e::Raw); | |
| 185 MockImageResourceClient client; | 203 MockImageResourceClient client; |
| 186 cachedLiveResource->addClient(&client); | 204 cachedLiveResource->addClient(&client); |
| 187 cachedLiveResource->appendData(data, 4u); | 205 cachedLiveResource->appendData(data, 4u); |
| 188 | 206 |
| 189 class Task1 : public blink::WebThread::Task { | 207 class Task1 : public blink::WebThread::Task { |
| 190 public: | 208 public: |
| 191 Task1(const ResourcePtr<Resource>& live, Resource* dead) | 209 Task1(const ResourcePtr<Resource>& live, Resource* dead) |
| 192 : m_live(live) | 210 : m_live(live) |
| 193 , m_dead(dead) | 211 , m_dead(dead) |
| 194 { } | 212 { } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 unsigned m_liveSizeWithoutDecode; | 256 unsigned m_liveSizeWithoutDecode; |
| 239 }; | 257 }; |
| 240 | 258 |
| 241 | 259 |
| 242 blink::Platform::current()->currentThread()->postTask(new Task1(cachedLiveRe
source, cachedDeadResource)); | 260 blink::Platform::current()->currentThread()->postTask(new Task1(cachedLiveRe
source, cachedDeadResource)); |
| 243 blink::Platform::current()->currentThread()->postTask(new Task2(cachedLiveRe
source->encodedSize() + cachedLiveResource->overheadSize())); | 261 blink::Platform::current()->currentThread()->postTask(new Task2(cachedLiveRe
source->encodedSize() + cachedLiveResource->overheadSize())); |
| 244 blink::Platform::current()->currentThread()->enterRunLoop(); | 262 blink::Platform::current()->currentThread()->enterRunLoop(); |
| 245 cachedLiveResource->removeClient(&client); | 263 cachedLiveResource->removeClient(&client); |
| 246 } | 264 } |
| 247 | 265 |
| 266 // Verified that when ordering a prune in a runLoop task, the prune |
| 267 // is deferred to the end of the task. |
| 268 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) |
| 269 { |
| 270 Resource* cachedDeadResource = |
| 271 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); |
| 272 ResourcePtr<Resource> cachedLiveResource = |
| 273 new FakeDecodedResource(ResourceRequest("http://test/resource"), Resourc
e::Raw); |
| 274 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResource); |
| 275 } |
| 276 |
| 277 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_MultipleResourceMaps) |
| 278 { |
| 279 { |
| 280 Resource* cachedDeadResource = |
| 281 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); |
| 282 cachedDeadResource->setCacheIdentifier("foo"); |
| 283 ResourcePtr<Resource> cachedLiveResource = |
| 284 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 285 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResour
ce); |
| 286 memoryCache()->evictResources(); |
| 287 } |
| 288 { |
| 289 Resource* cachedDeadResource = |
| 290 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); |
| 291 ResourcePtr<Resource> cachedLiveResource = |
| 292 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 293 cachedLiveResource->setCacheIdentifier("foo"); |
| 294 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResour
ce); |
| 295 memoryCache()->evictResources(); |
| 296 } |
| 297 { |
| 298 Resource* cachedDeadResource = |
| 299 new Resource(ResourceRequest("hhtp://test/resource"), Resource::Raw)
; |
| 300 cachedDeadResource->setCacheIdentifier("foo"); |
| 301 ResourcePtr<Resource> cachedLiveResource = |
| 302 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 303 cachedLiveResource->setCacheIdentifier("bar"); |
| 304 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource, cachedLiveResour
ce); |
| 305 memoryCache()->evictResources(); |
| 306 } |
| 307 } |
| 308 |
| 248 // Verifies that cached resources are evicted immediately after release when | 309 // Verifies that cached resources are evicted immediately after release when |
| 249 // the total dead resource size is more than double the dead resource capacity. | 310 // the total dead resource size is more than double the dead resource capacity. |
| 250 TEST_F(MemoryCacheTest, ClientRemoval) | 311 static void TestClientRemoval(const ResourcePtr<Resource>& resource1, const Reso
urcePtr<Resource>& resource2) |
| 251 { | 312 { |
| 252 const char data[6] = "abcde"; | 313 const char data[6] = "abcde"; |
| 253 ResourcePtr<Resource> resource1 = | |
| 254 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw
); | |
| 255 MockImageResourceClient client1; | 314 MockImageResourceClient client1; |
| 256 resource1->addClient(&client1); | 315 resource1->addClient(&client1); |
| 257 resource1->appendData(data, 4u); | 316 resource1->appendData(data, 4u); |
| 258 ResourcePtr<Resource> resource2 = | |
| 259 new FakeDecodedResource(ResourceRequest("http://test/resource"), Resourc
e::Raw); | |
| 260 MockImageResourceClient client2; | 317 MockImageResourceClient client2; |
| 261 resource2->addClient(&client2); | 318 resource2->addClient(&client2); |
| 262 resource2->appendData(data, 4u); | 319 resource2->appendData(data, 4u); |
| 263 | 320 |
| 264 const unsigned minDeadCapacity = 0; | 321 const unsigned minDeadCapacity = 0; |
| 265 const unsigned maxDeadCapacity = ((resource1->size() + resource2->size()) /
2) - 1; | 322 const unsigned maxDeadCapacity = ((resource1->size() + resource2->size()) /
2) - 1; |
| 266 const unsigned totalCapacity = maxDeadCapacity; | 323 const unsigned totalCapacity = maxDeadCapacity; |
| 267 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); | 324 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); |
| 268 memoryCache()->add(resource1.get()); | 325 memoryCache()->add(resource1.get()); |
| 269 memoryCache()->add(resource2.get()); | 326 memoryCache()->add(resource2.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 289 // eviction of resource2 because we are over the prune deferral limit. | 346 // eviction of resource2 because we are over the prune deferral limit. |
| 290 resource2->removeClient(&client2); | 347 resource2->removeClient(&client2); |
| 291 ASSERT_GT(resource1->decodedSize(), 0u); | 348 ASSERT_GT(resource1->decodedSize(), 0u); |
| 292 ASSERT_GT(resource2->decodedSize(), 0u); | 349 ASSERT_GT(resource2->decodedSize(), 0u); |
| 293 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); | 350 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); |
| 294 ASSERT_EQ(memoryCache()->liveSize(), 0u); | 351 ASSERT_EQ(memoryCache()->liveSize(), 0u); |
| 295 ASSERT_TRUE(memoryCache()->contains(resource1.get())); | 352 ASSERT_TRUE(memoryCache()->contains(resource1.get())); |
| 296 ASSERT_FALSE(memoryCache()->contains(resource2.get())); | 353 ASSERT_FALSE(memoryCache()->contains(resource2.get())); |
| 297 } | 354 } |
| 298 | 355 |
| 356 TEST_F(MemoryCacheTest, ClientRemoval_Basic) |
| 357 { |
| 358 ResourcePtr<Resource> resource1 = |
| 359 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw
); |
| 360 ResourcePtr<Resource> resource2 = |
| 361 new FakeDecodedResource(ResourceRequest("http://test/resource"), Resourc
e::Raw); |
| 362 TestClientRemoval(resource1, resource2); |
| 363 } |
| 364 |
| 365 TEST_F(MemoryCacheTest, ClientRemoval_MultipleResourceMaps) |
| 366 { |
| 367 { |
| 368 ResourcePtr<Resource> resource1 = |
| 369 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource:
:Raw); |
| 370 resource1->setCacheIdentifier("foo"); |
| 371 ResourcePtr<Resource> resource2 = |
| 372 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 373 TestClientRemoval(resource1, resource2); |
| 374 memoryCache()->evictResources(); |
| 375 } |
| 376 { |
| 377 ResourcePtr<Resource> resource1 = |
| 378 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource:
:Raw); |
| 379 ResourcePtr<Resource> resource2 = |
| 380 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 381 resource2->setCacheIdentifier("foo"); |
| 382 TestClientRemoval(resource1, resource2); |
| 383 memoryCache()->evictResources(); |
| 384 } |
| 385 { |
| 386 ResourcePtr<Resource> resource1 = |
| 387 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 388 resource1->setCacheIdentifier("foo"); |
| 389 ResourcePtr<Resource> resource2 = |
| 390 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 391 resource2->setCacheIdentifier("bar"); |
| 392 TestClientRemoval(resource1, resource2); |
| 393 memoryCache()->evictResources(); |
| 394 } |
| 395 } |
| 396 |
| 299 // Verifies that CachedResources are evicted from the decode cache | 397 // Verifies that CachedResources are evicted from the decode cache |
| 300 // according to their DecodeCachePriority. | 398 // according to their DecodeCachePriority. |
| 301 TEST_F(MemoryCacheTest, DecodeCacheOrder) | 399 static void TestDecodeCacheOrder(const ResourcePtr<Resource>& cachedImageLowPrio
rity, const ResourcePtr<Resource>& cachedImageHighPriority) |
| 302 { | 400 { |
| 303 memoryCache()->setDelayBeforeLiveDecodedPrune(0); | 401 memoryCache()->setDelayBeforeLiveDecodedPrune(0); |
| 304 memoryCache()->setMaxPruneDeferralDelay(0); | 402 memoryCache()->setMaxPruneDeferralDelay(0); |
| 305 ResourcePtr<FakeDecodedResource> cachedImageLowPriority = | |
| 306 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw
); | |
| 307 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = | |
| 308 new FakeDecodedResource(ResourceRequest("http://test/resource"), Resourc
e::Raw); | |
| 309 | 403 |
| 310 MockImageResourceClient clientLowPriority; | 404 MockImageResourceClient clientLowPriority; |
| 311 MockImageResourceClient clientHighPriority; | 405 MockImageResourceClient clientHighPriority; |
| 312 cachedImageLowPriority->addClient(&clientLowPriority); | 406 cachedImageLowPriority->addClient(&clientLowPriority); |
| 313 cachedImageHighPriority->addClient(&clientHighPriority); | 407 cachedImageHighPriority->addClient(&clientHighPriority); |
| 314 | 408 |
| 315 const char data[5] = "abcd"; | 409 const char data[5] = "abcd"; |
| 316 cachedImageLowPriority->appendData(data, 1u); | 410 cachedImageLowPriority->appendData(data, 1u); |
| 317 cachedImageHighPriority->appendData(data, 4u); | 411 cachedImageHighPriority->appendData(data, 4u); |
| 318 const unsigned lowPrioritySize = cachedImageLowPriority->size(); | 412 const unsigned lowPrioritySize = cachedImageLowPriority->size(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // Should prune the HighPriority item. | 452 // Should prune the HighPriority item. |
| 359 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()
->liveSize() - 10, memoryCache()->liveSize() - 10); | 453 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()
->liveSize() - 10, memoryCache()->liveSize() - 10); |
| 360 memoryCache()->prune(); | 454 memoryCache()->prune(); |
| 361 ASSERT_EQ(memoryCache()->deadSize(), 0u); | 455 ASSERT_EQ(memoryCache()->deadSize(), 0u); |
| 362 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize -
highPriorityMockDecodeSize); | 456 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize -
highPriorityMockDecodeSize); |
| 363 | 457 |
| 364 cachedImageLowPriority->removeClient(&clientLowPriority); | 458 cachedImageLowPriority->removeClient(&clientLowPriority); |
| 365 cachedImageHighPriority->removeClient(&clientHighPriority); | 459 cachedImageHighPriority->removeClient(&clientHighPriority); |
| 366 } | 460 } |
| 367 | 461 |
| 462 TEST_F(MemoryCacheTest, DecodeCacheOrder_Basic) |
| 463 { |
| 464 ResourcePtr<FakeDecodedResource> cachedImageLowPriority = |
| 465 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource::Raw
); |
| 466 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = |
| 467 new FakeDecodedResource(ResourceRequest("http://test/resource"), Resourc
e::Raw); |
| 468 TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority); |
| 469 } |
| 470 |
| 471 TEST_F(MemoryCacheTest, DecodeCacheOrder_MultipleResourceMaps) |
| 472 { |
| 473 { |
| 474 ResourcePtr<FakeDecodedResource> cachedImageLowPriority = |
| 475 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource:
:Raw); |
| 476 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = |
| 477 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 478 cachedImageLowPriority->setCacheIdentifier("foo"); |
| 479 TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority); |
| 480 memoryCache()->evictResources(); |
| 481 } |
| 482 { |
| 483 ResourcePtr<FakeDecodedResource> cachedImageLowPriority = |
| 484 new FakeDecodedResource(ResourceRequest("http://foo.com"), Resource:
:Raw); |
| 485 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = |
| 486 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 487 cachedImageHighPriority->setCacheIdentifier("foo"); |
| 488 TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority); |
| 489 memoryCache()->evictResources(); |
| 490 } |
| 491 { |
| 492 ResourcePtr<FakeDecodedResource> cachedImageLowPriority = |
| 493 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 494 cachedImageLowPriority->setCacheIdentifier("foo"); |
| 495 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = |
| 496 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res
ource::Raw); |
| 497 cachedImageHighPriority->setCacheIdentifier("bar"); |
| 498 TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority); |
| 499 memoryCache()->evictResources(); |
| 500 } |
| 501 } |
| 502 |
| 368 TEST_F(MemoryCacheTest, MultipleReplace) | 503 TEST_F(MemoryCacheTest, MultipleReplace) |
| 369 { | 504 { |
| 370 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); | 505 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); |
| 371 memoryCache()->add(resource1.get()); | 506 memoryCache()->add(resource1.get()); |
| 372 | 507 |
| 373 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); | 508 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); |
| 374 memoryCache()->replace(resource2.get(), resource1.get()); | 509 memoryCache()->replace(resource2.get(), resource1.get()); |
| 375 EXPECT_TRUE(memoryCache()->contains(resource2.get())); | 510 EXPECT_TRUE(memoryCache()->contains(resource2.get())); |
| 376 EXPECT_FALSE(memoryCache()->contains(resource1.get())); | 511 EXPECT_FALSE(memoryCache()->contains(resource1.get())); |
| 377 | 512 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 397 memoryCache()->add(resource3.get()); | 532 memoryCache()->add(resource3.get()); |
| 398 EXPECT_TRUE(memoryCache()->contains(resource3.get())); | 533 EXPECT_TRUE(memoryCache()->contains(resource3.get())); |
| 399 EXPECT_FALSE(memoryCache()->contains(resource2.get())); | 534 EXPECT_FALSE(memoryCache()->contains(resource2.get())); |
| 400 | 535 |
| 401 memoryCache()->replace(resource1.get(), resource2.get()); | 536 memoryCache()->replace(resource1.get(), resource2.get()); |
| 402 EXPECT_TRUE(memoryCache()->contains(resource1.get())); | 537 EXPECT_TRUE(memoryCache()->contains(resource1.get())); |
| 403 EXPECT_FALSE(memoryCache()->contains(resource2.get())); | 538 EXPECT_FALSE(memoryCache()->contains(resource2.get())); |
| 404 EXPECT_FALSE(memoryCache()->contains(resource3.get())); | 539 EXPECT_FALSE(memoryCache()->contains(resource3.get())); |
| 405 } | 540 } |
| 406 | 541 |
| 542 TEST_F(MemoryCacheTest, ResourceMapIsolation) |
| 543 { |
| 544 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); |
| 545 memoryCache()->add(resource1.get()); |
| 546 |
| 547 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); |
| 548 resource2->setCacheIdentifier("foo"); |
| 549 memoryCache()->add(resource2.get()); |
| 550 EXPECT_TRUE(memoryCache()->contains(resource1.get())); |
| 551 EXPECT_TRUE(memoryCache()->contains(resource2.get())); |
| 552 |
| 553 const KURL url = KURL(ParsedURLString, "http://test/resource"); |
| 554 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url)); |
| 555 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url, memoryCache()-
>defaultCacheIdentifier())); |
| 556 EXPECT_EQ(resource2.get(), memoryCache()->resourceForURL(url, "foo")); |
| 557 |
| 558 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); |
| 559 resource3->setCacheIdentifier("foo"); |
| 560 memoryCache()->remove(resource2.get()); |
| 561 memoryCache()->add(resource3.get()); |
| 562 EXPECT_TRUE(memoryCache()->contains(resource1.get())); |
| 563 EXPECT_FALSE(memoryCache()->contains(resource2.get())); |
| 564 EXPECT_TRUE(memoryCache()->contains(resource3.get())); |
| 565 |
| 566 ResourcePtr<FakeResource> resource4 = new FakeResource(ResourceRequest("http
://test/resource"), Resource::Raw); |
| 567 resource4->setCacheIdentifier("foo"); |
| 568 memoryCache()->replace(resource4.get(), resource3.get()); |
| 569 EXPECT_TRUE(memoryCache()->contains(resource1.get())); |
| 570 EXPECT_FALSE(memoryCache()->contains(resource3.get())); |
| 571 EXPECT_TRUE(memoryCache()->contains(resource4.get())); |
| 572 |
| 573 WillBeHeapVector<Member<Resource>> resources = memoryCache()->resourcesForUR
L(url); |
| 574 EXPECT_EQ(2u, resources.size()); |
| 575 |
| 576 memoryCache()->evictResources(); |
| 577 EXPECT_FALSE(memoryCache()->contains(resource1.get())); |
| 578 EXPECT_FALSE(memoryCache()->contains(resource3.get())); |
| 579 } |
| 580 |
| 407 } // namespace | 581 } // namespace |
| OLD | NEW |