Chromium Code Reviews| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 EXPECT_TRUE(memoryCache()->contains(resource3)); | 418 EXPECT_TRUE(memoryCache()->contains(resource3)); |
| 419 | 419 |
| 420 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url) ; | 420 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url) ; |
| 421 EXPECT_EQ(2u, resources.size()); | 421 EXPECT_EQ(2u, resources.size()); |
| 422 | 422 |
| 423 memoryCache()->evictResources(); | 423 memoryCache()->evictResources(); |
| 424 EXPECT_FALSE(memoryCache()->contains(resource1)); | 424 EXPECT_FALSE(memoryCache()->contains(resource1)); |
| 425 EXPECT_FALSE(memoryCache()->contains(resource3)); | 425 EXPECT_FALSE(memoryCache()->contains(resource3)); |
| 426 } | 426 } |
| 427 | 427 |
| 428 TEST_F(MemoryCacheTest, FragmentIdentifier) | |
| 429 { | |
| 430 const KURL url1 = KURL(ParsedURLString, "http://test/resource#foo"); | |
| 431 FakeResource* resource = FakeResource::create(ResourceRequest(url1), Resourc e::Raw); | |
| 432 memoryCache()->add(resource); | |
| 433 ASSERT_TRUE(memoryCache()->contains(resource)); | |
| 434 | |
| 435 EXPECT_EQ(resource, memoryCache()->resourceForURL(url1)); | |
| 436 | |
| 437 const KURL url2 = KURL(ParsedURLString, "http://test/resource"); | |
|
Nate Chapin
2016/07/26 19:14:18
Optional: url2 = url1.removeFragmentIdentifier();
Nate Chapin
2016/07/26 19:15:22
Sorry, I meant MemoryCache::removeFragmentIdentifi
HyungwookLee
2016/07/27 00:53:24
Done.
| |
| 438 EXPECT_EQ(resource, memoryCache()->resourceForURL(url2)); | |
| 439 } | |
| 440 | |
| 441 TEST_F(MemoryCacheTest, MakeLiveAndDead) | |
| 442 { | |
| 443 FakeResource* resource = FakeResource::create(ResourceRequest("http://test/r esource"), Resource::Raw); | |
| 444 const char data[6] = "abcde"; | |
| 445 resource->appendData(data, 5u); | |
| 446 memoryCache()->add(resource); | |
| 447 | |
| 448 const size_t deadSize = memoryCache()->deadSize(); | |
| 449 const size_t liveSize = memoryCache()->liveSize(); | |
| 450 | |
| 451 memoryCache()->makeLive(resource); | |
| 452 ASSERT_EQ(deadSize, memoryCache()->deadSize() + resource->size()); | |
| 453 ASSERT_EQ(liveSize, memoryCache()->liveSize() - resource->size()); | |
| 454 | |
| 455 memoryCache()->makeDead(resource); | |
| 456 ASSERT_EQ(deadSize, memoryCache()->deadSize()); | |
| 457 ASSERT_EQ(liveSize, memoryCache()->liveSize()); | |
| 458 } | |
| 459 | |
| 460 TEST_F(MemoryCacheTest, RemoveURLFromCache) | |
| 461 { | |
| 462 const KURL url1 = KURL(ParsedURLString, "http://test/resource1"); | |
| 463 FakeResource* resource1 = FakeResource::create(ResourceRequest(url1), Resour ce::Raw); | |
| 464 memoryCache()->add(resource1); | |
| 465 ASSERT_TRUE(memoryCache()->contains(resource1)); | |
| 466 | |
| 467 memoryCache()->removeURLFromCache(url1); | |
| 468 EXPECT_FALSE(memoryCache()->contains(resource1)); | |
| 469 | |
| 470 const KURL url2 = KURL(ParsedURLString, "http://test/resource2#foo"); | |
| 471 FakeResource* resource2 = FakeResource::create(ResourceRequest(url2), Resour ce::Raw); | |
| 472 memoryCache()->add(resource2); | |
| 473 ASSERT_TRUE(memoryCache()->contains(resource2)); | |
| 474 | |
| 475 memoryCache()->removeURLFromCache(url2); | |
| 476 EXPECT_FALSE(memoryCache()->contains(resource2)); | |
| 477 } | |
| 478 | |
| 428 } // namespace blink | 479 } // namespace blink |
| OLD | NEW |