| 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/fetch/MemoryCache.h" | 32 #include "core/fetch/MemoryCache.h" |
| 33 | 33 |
| 34 #include "core/fetch/MockImageResourceClient.h" | 34 #include "core/fetch/MockImageResourceClient.h" |
| 35 #include "core/fetch/RawResource.h" | 35 #include "core/fetch/RawResource.h" |
| 36 #include "core/fetch/ResourcePtr.h" | 36 #include "core/fetch/ResourcePtr.h" |
| 37 #include "core/testing/UnitTestHelpers.h" |
| 37 #include "platform/network/ResourceRequest.h" | 38 #include "platform/network/ResourceRequest.h" |
| 38 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 39 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
| 40 | 41 |
| 41 #include <gtest/gtest.h> | 42 #include <gtest/gtest.h> |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 class MemoryCacheTest : public ::testing::Test { | 46 class MemoryCacheTest : public ::testing::Test { |
| 46 public: | 47 public: |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 class Task2 : public blink::WebThread::Task { | 243 class Task2 : public blink::WebThread::Task { |
| 243 public: | 244 public: |
| 244 Task2(unsigned liveSizeWithoutDecode) | 245 Task2(unsigned liveSizeWithoutDecode) |
| 245 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } | 246 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } |
| 246 | 247 |
| 247 virtual void run() override | 248 virtual void run() override |
| 248 { | 249 { |
| 249 // Next task: now, the live resource was evicted. | 250 // Next task: now, the live resource was evicted. |
| 250 ASSERT_EQ(0u, memoryCache()->deadSize()); | 251 ASSERT_EQ(0u, memoryCache()->deadSize()); |
| 251 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); | 252 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); |
| 252 blink::Platform::current()->currentThread()->exitRunLoop(); | |
| 253 } | 253 } |
| 254 | 254 |
| 255 private: | 255 private: |
| 256 unsigned m_liveSizeWithoutDecode; | 256 unsigned m_liveSizeWithoutDecode; |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 | 259 |
| 260 blink::Platform::current()->currentThread()->postTask(FROM_HERE, new Task1(c
achedLiveResource, cachedDeadResource)); | 260 blink::Platform::current()->currentThread()->postTask(FROM_HERE, new Task1(c
achedLiveResource, cachedDeadResource)); |
| 261 blink::Platform::current()->currentThread()->postTask(FROM_HERE, new Task2(c
achedLiveResource->encodedSize() + cachedLiveResource->overheadSize())); | 261 blink::Platform::current()->currentThread()->postTask(FROM_HERE, new Task2(c
achedLiveResource->encodedSize() + cachedLiveResource->overheadSize())); |
| 262 blink::Platform::current()->currentThread()->enterRunLoop(); | 262 testing::runPendingTasks(); |
| 263 cachedLiveResource->removeClient(&client); | 263 cachedLiveResource->removeClient(&client); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Verified that when ordering a prune in a runLoop task, the prune | 266 // Verified that when ordering a prune in a runLoop task, the prune |
| 267 // is deferred to the end of the task. | 267 // is deferred to the end of the task. |
| 268 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) | 268 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) |
| 269 { | 269 { |
| 270 Resource* cachedDeadResource = | 270 Resource* cachedDeadResource = |
| 271 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); | 271 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); |
| 272 ResourcePtr<Resource> cachedLiveResource = | 272 ResourcePtr<Resource> cachedLiveResource = |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 572 |
| 573 WillBeHeapVector<Member<Resource>> resources = memoryCache()->resourcesForUR
L(url); | 573 WillBeHeapVector<Member<Resource>> resources = memoryCache()->resourcesForUR
L(url); |
| 574 EXPECT_EQ(2u, resources.size()); | 574 EXPECT_EQ(2u, resources.size()); |
| 575 | 575 |
| 576 memoryCache()->evictResources(); | 576 memoryCache()->evictResources(); |
| 577 EXPECT_FALSE(memoryCache()->contains(resource1.get())); | 577 EXPECT_FALSE(memoryCache()->contains(resource1.get())); |
| 578 EXPECT_FALSE(memoryCache()->contains(resource3.get())); | 578 EXPECT_FALSE(memoryCache()->contains(resource3.get())); |
| 579 } | 579 } |
| 580 | 580 |
| 581 } // namespace | 581 } // namespace |
| OLD | NEW |