Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: Source/core/fetch/MemoryCacheTest.cpp

Issue 1115553002: Removing blink::prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/fetch/MemoryCache.cpp ('k') | Source/core/fetch/MockImageResourceClient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 #include "platform/testing/UnitTestHelpers.h" 38 #include "platform/testing/UnitTestHelpers.h"
39 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
40 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
41 41
42 #include <gtest/gtest.h> 42 #include <gtest/gtest.h>
43 43
44 namespace blink { 44 namespace blink {
45 45
46 class MemoryCacheTest : public ::testing::Test { 46 class MemoryCacheTest : public ::testing::Test {
47 public: 47 public:
48 class FakeDecodedResource : public blink::Resource { 48 class FakeDecodedResource : public Resource {
49 public: 49 public:
50 FakeDecodedResource(const ResourceRequest& request, Type type) 50 FakeDecodedResource(const ResourceRequest& request, Type type)
51 : Resource(request, type) 51 : Resource(request, type)
52 { 52 {
53 } 53 }
54 54
55 virtual void appendData(const char* data, unsigned len) 55 virtual void appendData(const char* data, unsigned len)
56 { 56 {
57 Resource::appendData(data, len); 57 Resource::appendData(data, len);
58 setDecodedSize(this->size()); 58 setDecodedSize(this->size());
59 } 59 }
60 60
61 protected: 61 protected:
62 virtual void destroyDecodedDataIfPossible() override 62 virtual void destroyDecodedDataIfPossible() override
63 { 63 {
64 setDecodedSize(0); 64 setDecodedSize(0);
65 } 65 }
66 }; 66 };
67 67
68 class FakeResource : public blink::Resource { 68 class FakeResource : public Resource {
69 public: 69 public:
70 FakeResource(const ResourceRequest& request, Type type) 70 FakeResource(const ResourceRequest& request, Type type)
71 : Resource(request, type) 71 : Resource(request, type)
72 { 72 {
73 } 73 }
74 74
75 void fakeEncodedSize(size_t size) 75 void fakeEncodedSize(size_t size)
76 { 76 {
77 setEncodedSize(size); 77 setEncodedSize(size);
78 } 78 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 const unsigned totalCapacity = 1; 198 const unsigned totalCapacity = 1;
199 const unsigned minDeadCapacity = 0; 199 const unsigned minDeadCapacity = 0;
200 const unsigned maxDeadCapacity = 0; 200 const unsigned maxDeadCapacity = 0;
201 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity ); 201 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity );
202 const char data[6] = "abcde"; 202 const char data[6] = "abcde";
203 cachedDeadResource->appendData(data, 3u); 203 cachedDeadResource->appendData(data, 3u);
204 MockImageResourceClient client; 204 MockImageResourceClient client;
205 cachedLiveResource->addClient(&client); 205 cachedLiveResource->addClient(&client);
206 cachedLiveResource->appendData(data, 4u); 206 cachedLiveResource->appendData(data, 4u);
207 207
208 class Task1 : public blink::WebThread::Task { 208 class Task1 : public WebThread::Task {
209 public: 209 public:
210 Task1(const ResourcePtr<Resource>& live, Resource* dead) 210 Task1(const ResourcePtr<Resource>& live, Resource* dead)
211 : m_live(live) 211 : m_live(live)
212 , m_dead(dead) 212 , m_dead(dead)
213 { } 213 { }
214 214
215 virtual void run() override 215 virtual void run() override
216 { 216 {
217 // The resource size has to be nonzero for this test to be meaningfu l, but 217 // The resource size has to be nonzero for this test to be meaningfu l, but
218 // we do not rely on it having any particular value. 218 // we do not rely on it having any particular value.
(...skipping 14 matching lines...) Expand all
233 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize()); 233 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize());
234 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); 234 ASSERT_EQ(m_live->size(), memoryCache()->liveSize());
235 ASSERT_GT(m_live->decodedSize(), 0u); 235 ASSERT_GT(m_live->decodedSize(), 0u);
236 } 236 }
237 237
238 private: 238 private:
239 ResourcePtr<Resource> m_live; 239 ResourcePtr<Resource> m_live;
240 Resource* m_dead; 240 Resource* m_dead;
241 }; 241 };
242 242
243 class Task2 : public blink::WebThread::Task { 243 class Task2 : public WebThread::Task {
244 public: 244 public:
245 Task2(unsigned liveSizeWithoutDecode) 245 Task2(unsigned liveSizeWithoutDecode)
246 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } 246 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { }
247 247
248 virtual void run() override 248 virtual void run() override
249 { 249 {
250 // Next task: now, the live resource was evicted. 250 // Next task: now, the live resource was evicted.
251 ASSERT_EQ(0u, memoryCache()->deadSize()); 251 ASSERT_EQ(0u, memoryCache()->deadSize());
252 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); 252 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize());
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 Platform::current()->currentThread()->postTask(FROM_HERE, new Task1(cachedLi veResource, cachedDeadResource));
261 blink::Platform::current()->currentThread()->postTask(FROM_HERE, new Task2(c achedLiveResource->encodedSize() + cachedLiveResource->overheadSize())); 261 Platform::current()->currentThread()->postTask(FROM_HERE, new Task2(cachedLi veResource->encodedSize() + cachedLiveResource->overheadSize()));
262 testing::runPendingTasks(); 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);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « Source/core/fetch/MemoryCache.cpp ('k') | Source/core/fetch/MockImageResourceClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698