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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 const char data[6] = "abcde"; | 142 const char data[6] = "abcde"; |
143 ResourcePtr<Resource> cachedDeadResource = | 143 ResourcePtr<Resource> cachedDeadResource = |
144 new Resource(ResourceRequest(""), Resource::Raw); | 144 new Resource(ResourceRequest(""), Resource::Raw); |
145 cachedDeadResource->appendData(data, 3); | 145 cachedDeadResource->appendData(data, 3); |
146 ResourcePtr<Resource> cachedLiveResource = | 146 ResourcePtr<Resource> cachedLiveResource = |
147 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); | 147 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); |
148 MockImageResourceClient client; | 148 MockImageResourceClient client; |
149 cachedLiveResource->addClient(&client); | 149 cachedLiveResource->addClient(&client); |
150 cachedLiveResource->appendData(data, 4); | 150 cachedLiveResource->appendData(data, 4); |
151 | 151 |
152 class Task1 : public WebKit::WebThread::Task { | 152 class Task1 : public blink::WebThread::Task { |
153 public: | 153 public: |
154 Task1(const ResourcePtr<Resource>& live, const ResourcePtr<Resource>& de
ad) | 154 Task1(const ResourcePtr<Resource>& live, const ResourcePtr<Resource>& de
ad) |
155 : m_live(live) | 155 : m_live(live) |
156 , m_dead(dead) | 156 , m_dead(dead) |
157 { } | 157 { } |
158 | 158 |
159 virtual void run() OVERRIDE | 159 virtual void run() OVERRIDE |
160 { | 160 { |
161 // The resource size has to be nonzero for this test to be meaningfu
l, but | 161 // The resource size has to be nonzero for this test to be meaningfu
l, but |
162 // we do not rely on it having any particular value. | 162 // we do not rely on it having any particular value. |
(...skipping 13 matching lines...) Expand all Loading... |
176 memoryCache()->prune(); // Dead resources are pruned immediately | 176 memoryCache()->prune(); // Dead resources are pruned immediately |
177 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize()); | 177 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize()); |
178 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); | 178 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); |
179 ASSERT_GT(m_live->decodedSize(), 0u); | 179 ASSERT_GT(m_live->decodedSize(), 0u); |
180 } | 180 } |
181 | 181 |
182 private: | 182 private: |
183 ResourcePtr<Resource> m_live, m_dead; | 183 ResourcePtr<Resource> m_live, m_dead; |
184 }; | 184 }; |
185 | 185 |
186 class Task2 : public WebKit::WebThread::Task { | 186 class Task2 : public blink::WebThread::Task { |
187 public: | 187 public: |
188 Task2(unsigned liveSizeWithoutDecode) | 188 Task2(unsigned liveSizeWithoutDecode) |
189 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } | 189 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } |
190 | 190 |
191 virtual void run() OVERRIDE | 191 virtual void run() OVERRIDE |
192 { | 192 { |
193 // Next task: now, the live resource was evicted. | 193 // Next task: now, the live resource was evicted. |
194 ASSERT_EQ(0u, memoryCache()->deadSize()); | 194 ASSERT_EQ(0u, memoryCache()->deadSize()); |
195 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); | 195 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); |
196 WebKit::Platform::current()->currentThread()->exitRunLoop(); | 196 blink::Platform::current()->currentThread()->exitRunLoop(); |
197 } | 197 } |
198 | 198 |
199 private: | 199 private: |
200 unsigned m_liveSizeWithoutDecode; | 200 unsigned m_liveSizeWithoutDecode; |
201 }; | 201 }; |
202 | 202 |
203 | 203 |
204 WebKit::Platform::current()->currentThread()->postTask(new Task1(cachedLiveR
esource, cachedDeadResource)); | 204 blink::Platform::current()->currentThread()->postTask(new Task1(cachedLiveRe
source, cachedDeadResource)); |
205 WebKit::Platform::current()->currentThread()->postTask(new Task2(cachedLiveR
esource->encodedSize() + cachedLiveResource->overheadSize())); | 205 blink::Platform::current()->currentThread()->postTask(new Task2(cachedLiveRe
source->encodedSize() + cachedLiveResource->overheadSize())); |
206 WebKit::Platform::current()->currentThread()->enterRunLoop(); | 206 blink::Platform::current()->currentThread()->enterRunLoop(); |
207 cachedLiveResource->removeClient(&client); | 207 cachedLiveResource->removeClient(&client); |
208 } | 208 } |
209 | 209 |
210 // Verifies that cached resources are evicted immediately after release when | 210 // Verifies that cached resources are evicted immediately after release when |
211 // the total dead resource size is more than double the dead resource capacity. | 211 // the total dead resource size is more than double the dead resource capacity. |
212 TEST_F(MemoryCacheTest, ClientRemoval) | 212 TEST_F(MemoryCacheTest, ClientRemoval) |
213 { | 213 { |
214 const char data[6] = "abcde"; | 214 const char data[6] = "abcde"; |
215 ResourcePtr<Resource> resource1 = | 215 ResourcePtr<Resource> resource1 = |
216 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); | 216 new FakeDecodedResource(ResourceRequest(""), Resource::Raw); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ASSERT_EQ(memoryCache()->deadSize(), 0u); | 317 ASSERT_EQ(memoryCache()->deadSize(), 0u); |
318 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize); | 318 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize); |
319 | 319 |
320 // Should prune the HighPriority item. | 320 // Should prune the HighPriority item. |
321 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()
->liveSize() - 10, memoryCache()->liveSize() - 10); | 321 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()
->liveSize() - 10, memoryCache()->liveSize() - 10); |
322 memoryCache()->prune(); | 322 memoryCache()->prune(); |
323 ASSERT_EQ(memoryCache()->deadSize(), 0u); | 323 ASSERT_EQ(memoryCache()->deadSize(), 0u); |
324 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize -
highPriorityMockDecodeSize); | 324 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize -
highPriorityMockDecodeSize); |
325 } | 325 } |
326 } // namespace | 326 } // namespace |
OLD | NEW |