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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 memoryCache()->setDelayBeforeLiveDecodedPrune(0); | 194 memoryCache()->setDelayBeforeLiveDecodedPrune(0); |
195 const unsigned totalCapacity = 1; | 195 const unsigned totalCapacity = 1; |
196 const unsigned minDeadCapacity = 0; | 196 const unsigned minDeadCapacity = 0; |
197 const unsigned maxDeadCapacity = 0; | 197 const unsigned maxDeadCapacity = 0; |
198 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); | 198 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity
); |
199 const char data[6] = "abcde"; | 199 const char data[6] = "abcde"; |
200 cachedDeadResource->appendData(data, 3u); | 200 cachedDeadResource->appendData(data, 3u); |
201 MockImageResourceClient client(cachedLiveResource); | 201 MockImageResourceClient client(cachedLiveResource); |
202 cachedLiveResource->appendData(data, 4u); | 202 cachedLiveResource->appendData(data, 4u); |
203 | 203 |
204 class Task1 : public WebThread::Task { | 204 class Task1 : public WebTaskRunner::Task { |
205 public: | 205 public: |
206 Task1(const ResourcePtr<Resource>& live, Resource* dead) | 206 Task1(const ResourcePtr<Resource>& live, Resource* dead) |
207 : m_live(live) | 207 : m_live(live) |
208 , m_dead(dead) | 208 , m_dead(dead) |
209 { } | 209 { } |
210 | 210 |
211 void run() override | 211 void run() override |
212 { | 212 { |
213 // The resource size has to be nonzero for this test to be meaningfu
l, but | 213 // The resource size has to be nonzero for this test to be meaningfu
l, but |
214 // we do not rely on it having any particular value. | 214 // we do not rely on it having any particular value. |
(...skipping 14 matching lines...) Expand all Loading... |
229 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize()); | 229 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize()); |
230 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); | 230 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); |
231 ASSERT_GT(m_live->decodedSize(), 0u); | 231 ASSERT_GT(m_live->decodedSize(), 0u); |
232 } | 232 } |
233 | 233 |
234 private: | 234 private: |
235 ResourcePtr<Resource> m_live; | 235 ResourcePtr<Resource> m_live; |
236 Resource* m_dead; | 236 Resource* m_dead; |
237 }; | 237 }; |
238 | 238 |
239 class Task2 : public WebThread::Task { | 239 class Task2 : public WebTaskRunner::Task { |
240 public: | 240 public: |
241 Task2(unsigned liveSizeWithoutDecode) | 241 Task2(unsigned liveSizeWithoutDecode) |
242 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } | 242 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } |
243 | 243 |
244 void run() override | 244 void run() override |
245 { | 245 { |
246 // Next task: now, the live resource was evicted. | 246 // Next task: now, the live resource was evicted. |
247 ASSERT_EQ(0u, memoryCache()->deadSize()); | 247 ASSERT_EQ(0u, memoryCache()->deadSize()); |
248 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); | 248 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); |
249 } | 249 } |
250 | 250 |
251 private: | 251 private: |
252 unsigned m_liveSizeWithoutDecode; | 252 unsigned m_liveSizeWithoutDecode; |
253 }; | 253 }; |
254 | 254 |
255 | 255 |
256 Platform::current()->currentThread()->postTask(FROM_HERE, new Task1(cachedLi
veResource, cachedDeadResource)); | 256 Platform::current()->currentThread()->taskRunner()->postTask(FROM_HERE, new
Task1(cachedLiveResource, cachedDeadResource)); |
257 Platform::current()->currentThread()->postTask(FROM_HERE, new Task2(cachedLi
veResource->encodedSize() + cachedLiveResource->overheadSize())); | 257 Platform::current()->currentThread()->taskRunner()->postTask(FROM_HERE, new
Task2(cachedLiveResource->encodedSize() + cachedLiveResource->overheadSize())); |
258 testing::runPendingTasks(); | 258 testing::runPendingTasks(); |
259 } | 259 } |
260 | 260 |
261 // Verified that when ordering a prune in a runLoop task, the prune | 261 // Verified that when ordering a prune in a runLoop task, the prune |
262 // is deferred to the end of the task. | 262 // is deferred to the end of the task. |
263 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) | 263 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) |
264 { | 264 { |
265 Resource* cachedDeadResource = | 265 Resource* cachedDeadResource = |
266 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); | 266 new Resource(ResourceRequest("hhtp://foo"), Resource::Raw); |
267 ResourcePtr<Resource> cachedLiveResource = | 267 ResourcePtr<Resource> cachedLiveResource = |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 561 |
562 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = memoryCache()->re
sourcesForURL(url); | 562 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = memoryCache()->re
sourcesForURL(url); |
563 EXPECT_EQ(2u, resources.size()); | 563 EXPECT_EQ(2u, resources.size()); |
564 | 564 |
565 memoryCache()->evictResources(); | 565 memoryCache()->evictResources(); |
566 EXPECT_FALSE(memoryCache()->contains(resource1.get())); | 566 EXPECT_FALSE(memoryCache()->contains(resource1.get())); |
567 EXPECT_FALSE(memoryCache()->contains(resource3.get())); | 567 EXPECT_FALSE(memoryCache()->contains(resource3.get())); |
568 } | 568 } |
569 | 569 |
570 } // namespace | 570 } // namespace |
OLD | NEW |