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

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

Issue 1686483002: Oilpan: Remove most WillBe types from the code base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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 26 matching lines...) Expand all
37 #include "public/platform/Platform.h" 37 #include "public/platform/Platform.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "wtf/OwnPtr.h" 39 #include "wtf/OwnPtr.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 class MemoryCacheTest : public ::testing::Test { 43 class MemoryCacheTest : public ::testing::Test {
44 public: 44 public:
45 class FakeDecodedResource : public Resource { 45 class FakeDecodedResource : public Resource {
46 public: 46 public:
47 static RefPtrWillBeRawPtr<FakeDecodedResource> create(const ResourceRequ est& request, Type type) 47 static RawPtr<FakeDecodedResource> create(const ResourceRequest& request , Type type)
48 { 48 {
49 return adoptRefWillBeNoop(new FakeDecodedResource(request, type)); 49 return (new FakeDecodedResource(request, type));
50 } 50 }
51 51
52 virtual void appendData(const char* data, size_t len) 52 virtual void appendData(const char* data, size_t len)
53 { 53 {
54 Resource::appendData(data, len); 54 Resource::appendData(data, len);
55 setDecodedSize(this->size()); 55 setDecodedSize(this->size());
56 } 56 }
57 57
58 protected: 58 protected:
59 FakeDecodedResource(const ResourceRequest& request, Type type) 59 FakeDecodedResource(const ResourceRequest& request, Type type)
60 : Resource(request, type) 60 : Resource(request, type)
61 { 61 {
62 } 62 }
63 63
64 void destroyDecodedDataIfPossible() override 64 void destroyDecodedDataIfPossible() override
65 { 65 {
66 setDecodedSize(0); 66 setDecodedSize(0);
67 } 67 }
68 }; 68 };
69 69
70 class FakeResource : public Resource { 70 class FakeResource : public Resource {
71 public: 71 public:
72 static RefPtrWillBeRawPtr<FakeResource> create(const ResourceRequest& re quest, Type type) 72 static RawPtr<FakeResource> create(const ResourceRequest& request, Type type)
73 { 73 {
74 return adoptRefWillBeNoop(new FakeResource(request, type)); 74 return (new FakeResource(request, type));
75 } 75 }
76 76
77 void fakeEncodedSize(size_t size) 77 void fakeEncodedSize(size_t size)
78 { 78 {
79 setEncodedSize(size); 79 setEncodedSize(size);
80 } 80 }
81 81
82 private: 82 private:
83 FakeResource(const ResourceRequest& request, Type type) 83 FakeResource(const ResourceRequest& request, Type type)
84 : Resource(request, type) 84 : Resource(request, type)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 TEST_F(MemoryCacheTest, VeryLargeResourceAccounting) 117 TEST_F(MemoryCacheTest, VeryLargeResourceAccounting)
118 { 118 {
119 const size_t sizeMax = ~static_cast<size_t>(0); 119 const size_t sizeMax = ~static_cast<size_t>(0);
120 const size_t totalCapacity = sizeMax / 4; 120 const size_t totalCapacity = sizeMax / 4;
121 const size_t minDeadCapacity = sizeMax / 16; 121 const size_t minDeadCapacity = sizeMax / 16;
122 const size_t maxDeadCapacity = sizeMax / 8; 122 const size_t maxDeadCapacity = sizeMax / 8;
123 const size_t resourceSize1 = sizeMax / 16; 123 const size_t resourceSize1 = sizeMax / 16;
124 const size_t resourceSize2 = sizeMax / 20; 124 const size_t resourceSize2 = sizeMax / 20;
125 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity ); 125 memoryCache()->setCapacities(minDeadCapacity, maxDeadCapacity, totalCapacity );
126 RefPtrWillBeRawPtr<FakeResource> cachedResource = 126 RawPtr<FakeResource> cachedResource =
127 FakeResource::create(ResourceRequest("http://test/resource"), Resource:: Raw); 127 FakeResource::create(ResourceRequest("http://test/resource"), Resource:: Raw);
128 cachedResource->fakeEncodedSize(resourceSize1); 128 cachedResource->fakeEncodedSize(resourceSize1);
129 129
130 ASSERT_EQ(0u, memoryCache()->deadSize()); 130 ASSERT_EQ(0u, memoryCache()->deadSize());
131 ASSERT_EQ(0u, memoryCache()->liveSize()); 131 ASSERT_EQ(0u, memoryCache()->liveSize());
132 memoryCache()->add(cachedResource.get()); 132 memoryCache()->add(cachedResource.get());
133 ASSERT_EQ(cachedResource->size(), memoryCache()->deadSize()); 133 ASSERT_EQ(cachedResource->size(), memoryCache()->deadSize());
134 ASSERT_EQ(0u, memoryCache()->liveSize()); 134 ASSERT_EQ(0u, memoryCache()->liveSize());
135 135
136 MockImageResourceClient client(cachedResource); 136 MockImageResourceClient client(cachedResource);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ASSERT_EQ(resource1->size() + resource2->size(), memoryCache()->deadSize()); 173 ASSERT_EQ(resource1->size() + resource2->size(), memoryCache()->deadSize());
174 ASSERT_EQ(0u, memoryCache()->liveSize()); 174 ASSERT_EQ(0u, memoryCache()->liveSize());
175 175
176 memoryCache()->prune(); 176 memoryCache()->prune();
177 ASSERT_EQ(0u, memoryCache()->deadSize()); 177 ASSERT_EQ(0u, memoryCache()->deadSize());
178 ASSERT_EQ(0u, memoryCache()->liveSize()); 178 ASSERT_EQ(0u, memoryCache()->liveSize());
179 } 179 }
180 180
181 TEST_F(MemoryCacheTest, DeadResourceEviction_Basic) 181 TEST_F(MemoryCacheTest, DeadResourceEviction_Basic)
182 { 182 {
183 RefPtrWillBeRawPtr<Resource> resource1 = 183 RawPtr<Resource> resource1 =
184 Resource::create(ResourceRequest("http://test/resource1"), Resource::Raw ); 184 Resource::create(ResourceRequest("http://test/resource1"), Resource::Raw );
185 RefPtrWillBeRawPtr<Resource> resource2 = 185 RawPtr<Resource> resource2 =
186 Resource::create(ResourceRequest("http://test/resource2"), Resource::Raw ); 186 Resource::create(ResourceRequest("http://test/resource2"), Resource::Raw );
187 TestDeadResourceEviction(resource1.get(), resource2.get()); 187 TestDeadResourceEviction(resource1.get(), resource2.get());
188 } 188 }
189 189
190 TEST_F(MemoryCacheTest, DeadResourceEviction_MultipleResourceMaps) 190 TEST_F(MemoryCacheTest, DeadResourceEviction_MultipleResourceMaps)
191 { 191 {
192 RefPtrWillBeRawPtr<Resource> resource1 = 192 RawPtr<Resource> resource1 =
193 Resource::create(ResourceRequest("http://test/resource1"), Resource::Raw ); 193 Resource::create(ResourceRequest("http://test/resource1"), Resource::Raw );
194 RefPtrWillBeRawPtr<Resource> resource2 = 194 RawPtr<Resource> resource2 =
195 Resource::create(ResourceRequest("http://test/resource2"), Resource::Raw ); 195 Resource::create(ResourceRequest("http://test/resource2"), Resource::Raw );
196 resource2->setCacheIdentifier("foo"); 196 resource2->setCacheIdentifier("foo");
197 TestDeadResourceEviction(resource1.get(), resource2.get()); 197 TestDeadResourceEviction(resource1.get(), resource2.get());
198 } 198 }
199 199
200 static void TestLiveResourceEvictionAtEndOfTask(Resource* cachedDeadResource, Re source* cachedLiveResource) 200 static void TestLiveResourceEvictionAtEndOfTask(Resource* cachedDeadResource, Re source* cachedLiveResource)
201 { 201 {
202 memoryCache()->setDelayBeforeLiveDecodedPrune(0); 202 memoryCache()->setDelayBeforeLiveDecodedPrune(0);
203 const unsigned totalCapacity = 1; 203 const unsigned totalCapacity = 1;
204 const unsigned minDeadCapacity = 0; 204 const unsigned minDeadCapacity = 0;
(...skipping 28 matching lines...) Expand all
233 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); 233 ASSERT_EQ(m_live->size(), memoryCache()->liveSize());
234 ASSERT_GT(m_live->decodedSize(), 0u); 234 ASSERT_GT(m_live->decodedSize(), 0u);
235 235
236 memoryCache()->prune(); // Dead resources are pruned immediately 236 memoryCache()->prune(); // Dead resources are pruned immediately
237 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize()); 237 ASSERT_EQ(m_dead->size(), memoryCache()->deadSize());
238 ASSERT_EQ(m_live->size(), memoryCache()->liveSize()); 238 ASSERT_EQ(m_live->size(), memoryCache()->liveSize());
239 ASSERT_GT(m_live->decodedSize(), 0u); 239 ASSERT_GT(m_live->decodedSize(), 0u);
240 } 240 }
241 241
242 private: 242 private:
243 RefPtrWillBePersistent<Resource> m_live; 243 Persistent<Resource> m_live;
244 RefPtrWillBePersistent<Resource> m_dead; 244 Persistent<Resource> m_dead;
245 }; 245 };
246 246
247 class Task2 : public WebTaskRunner::Task { 247 class Task2 : public WebTaskRunner::Task {
248 public: 248 public:
249 Task2(unsigned liveSizeWithoutDecode) 249 Task2(unsigned liveSizeWithoutDecode)
250 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { } 250 : m_liveSizeWithoutDecode(liveSizeWithoutDecode) { }
251 251
252 void run() override 252 void run() override
253 { 253 {
254 // Next task: now, the live resource was evicted. 254 // Next task: now, the live resource was evicted.
255 ASSERT_EQ(0u, memoryCache()->deadSize()); 255 ASSERT_EQ(0u, memoryCache()->deadSize());
256 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize()); 256 ASSERT_EQ(m_liveSizeWithoutDecode, memoryCache()->liveSize());
257 } 257 }
258 258
259 private: 259 private:
260 unsigned m_liveSizeWithoutDecode; 260 unsigned m_liveSizeWithoutDecode;
261 }; 261 };
262 262
263 263
264 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE , new Task1(cachedLiveResource, cachedDeadResource)); 264 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE , new Task1(cachedLiveResource, cachedDeadResource));
265 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE , new Task2(cachedLiveResource->encodedSize() + cachedLiveResource->overheadSize ())); 265 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE , new Task2(cachedLiveResource->encodedSize() + cachedLiveResource->overheadSize ()));
266 testing::runPendingTasks(); 266 testing::runPendingTasks();
267 } 267 }
268 268
269 // Verified that when ordering a prune in a runLoop task, the prune 269 // Verified that when ordering a prune in a runLoop task, the prune
270 // is deferred to the end of the task. 270 // is deferred to the end of the task.
271 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic) 271 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_Basic)
272 { 272 {
273 RefPtrWillBeRawPtr<Resource> cachedDeadResource = 273 RawPtr<Resource> cachedDeadResource =
274 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw); 274 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw);
275 RefPtrWillBeRawPtr<Resource> cachedLiveResource = 275 RawPtr<Resource> cachedLiveResource =
276 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res ource::Raw); 276 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res ource::Raw);
277 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLiveReso urce.get()); 277 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLiveReso urce.get());
278 } 278 }
279 279
280 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_MultipleResourceMaps) 280 TEST_F(MemoryCacheTest, LiveResourceEvictionAtEndOfTask_MultipleResourceMaps)
281 { 281 {
282 { 282 {
283 RefPtrWillBeRawPtr<Resource> cachedDeadResource = 283 RawPtr<Resource> cachedDeadResource =
284 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw); 284 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw);
285 cachedDeadResource->setCacheIdentifier("foo"); 285 cachedDeadResource->setCacheIdentifier("foo");
286 RefPtrWillBeRawPtr<Resource> cachedLiveResource = 286 RawPtr<Resource> cachedLiveResource =
287 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 287 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
288 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLive Resource.get()); 288 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLive Resource.get());
289 memoryCache()->evictResources(); 289 memoryCache()->evictResources();
290 } 290 }
291 { 291 {
292 RefPtrWillBeRawPtr<Resource> cachedDeadResource = 292 RawPtr<Resource> cachedDeadResource =
293 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw); 293 Resource::create(ResourceRequest("hhtp://foo"), Resource::Raw);
294 RefPtrWillBeRawPtr<Resource> cachedLiveResource = 294 RawPtr<Resource> cachedLiveResource =
295 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 295 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
296 cachedLiveResource->setCacheIdentifier("foo"); 296 cachedLiveResource->setCacheIdentifier("foo");
297 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLive Resource.get()); 297 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLive Resource.get());
298 memoryCache()->evictResources(); 298 memoryCache()->evictResources();
299 } 299 }
300 { 300 {
301 RefPtrWillBeRawPtr<Resource> cachedDeadResource = 301 RawPtr<Resource> cachedDeadResource =
302 Resource::create(ResourceRequest("hhtp://test/resource"), Resource:: Raw); 302 Resource::create(ResourceRequest("hhtp://test/resource"), Resource:: Raw);
303 cachedDeadResource->setCacheIdentifier("foo"); 303 cachedDeadResource->setCacheIdentifier("foo");
304 RefPtrWillBeRawPtr<Resource> cachedLiveResource = 304 RawPtr<Resource> cachedLiveResource =
305 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 305 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
306 cachedLiveResource->setCacheIdentifier("bar"); 306 cachedLiveResource->setCacheIdentifier("bar");
307 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLive Resource.get()); 307 TestLiveResourceEvictionAtEndOfTask(cachedDeadResource.get(), cachedLive Resource.get());
308 memoryCache()->evictResources(); 308 memoryCache()->evictResources();
309 } 309 }
310 } 310 }
311 311
312 // Verifies that cached resources are evicted immediately after release when 312 // Verifies that cached resources are evicted immediately after release when
313 // the total dead resource size is more than double the dead resource capacity. 313 // the total dead resource size is more than double the dead resource capacity.
314 static void TestClientRemoval(Resource* resource1, Resource* resource2) 314 static void TestClientRemoval(Resource* resource1, Resource* resource2)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 ASSERT_GT(resource1->decodedSize(), 0u); 349 ASSERT_GT(resource1->decodedSize(), 0u);
350 ASSERT_GT(resource2->decodedSize(), 0u); 350 ASSERT_GT(resource2->decodedSize(), 0u);
351 ASSERT_EQ(memoryCache()->deadSize(), resource1->size()); 351 ASSERT_EQ(memoryCache()->deadSize(), resource1->size());
352 ASSERT_EQ(memoryCache()->liveSize(), 0u); 352 ASSERT_EQ(memoryCache()->liveSize(), 0u);
353 ASSERT_TRUE(memoryCache()->contains(resource1)); 353 ASSERT_TRUE(memoryCache()->contains(resource1));
354 ASSERT_FALSE(memoryCache()->contains(resource2)); 354 ASSERT_FALSE(memoryCache()->contains(resource2));
355 } 355 }
356 356
357 TEST_F(MemoryCacheTest, ClientRemoval_Basic) 357 TEST_F(MemoryCacheTest, ClientRemoval_Basic)
358 { 358 {
359 RefPtrWillBeRawPtr<Resource> resource1 = 359 RawPtr<Resource> resource1 =
360 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resource: :Raw); 360 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resource: :Raw);
361 RefPtrWillBeRawPtr<Resource> resource2 = 361 RawPtr<Resource> resource2 =
362 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res ource::Raw); 362 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res ource::Raw);
363 TestClientRemoval(resource1.get(), resource2.get()); 363 TestClientRemoval(resource1.get(), resource2.get());
364 } 364 }
365 365
366 TEST_F(MemoryCacheTest, ClientRemoval_MultipleResourceMaps) 366 TEST_F(MemoryCacheTest, ClientRemoval_MultipleResourceMaps)
367 { 367 {
368 { 368 {
369 RefPtrWillBeRawPtr<Resource> resource1 = 369 RawPtr<Resource> resource1 =
370 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw); 370 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw);
371 resource1->setCacheIdentifier("foo"); 371 resource1->setCacheIdentifier("foo");
372 RefPtrWillBeRawPtr<Resource> resource2 = 372 RawPtr<Resource> resource2 =
373 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 373 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
374 TestClientRemoval(resource1.get(), resource2.get()); 374 TestClientRemoval(resource1.get(), resource2.get());
375 memoryCache()->evictResources(); 375 memoryCache()->evictResources();
376 } 376 }
377 { 377 {
378 RefPtrWillBeRawPtr<Resource> resource1 = 378 RawPtr<Resource> resource1 =
379 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw); 379 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw);
380 RefPtrWillBeRawPtr<Resource> resource2 = 380 RawPtr<Resource> resource2 =
381 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 381 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
382 resource2->setCacheIdentifier("foo"); 382 resource2->setCacheIdentifier("foo");
383 TestClientRemoval(resource1.get(), resource2.get()); 383 TestClientRemoval(resource1.get(), resource2.get());
384 memoryCache()->evictResources(); 384 memoryCache()->evictResources();
385 } 385 }
386 { 386 {
387 RefPtrWillBeRawPtr<Resource> resource1 = 387 RawPtr<Resource> resource1 =
388 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 388 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
389 resource1->setCacheIdentifier("foo"); 389 resource1->setCacheIdentifier("foo");
390 RefPtrWillBeRawPtr<Resource> resource2 = 390 RawPtr<Resource> resource2 =
391 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 391 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
392 resource2->setCacheIdentifier("bar"); 392 resource2->setCacheIdentifier("bar");
393 TestClientRemoval(resource1.get(), resource2.get()); 393 TestClientRemoval(resource1.get(), resource2.get());
394 memoryCache()->evictResources(); 394 memoryCache()->evictResources();
395 } 395 }
396 } 396 }
397 397
398 // Verifies that CachedResources are evicted from the decode cache 398 // Verifies that CachedResources are evicted from the decode cache
399 // according to their DecodeCachePriority. 399 // according to their DecodeCachePriority.
400 static void TestDecodeCacheOrder(Resource* cachedImageLowPriority, Resource* cac hedImageHighPriority) 400 static void TestDecodeCacheOrder(Resource* cachedImageLowPriority, Resource* cac hedImageHighPriority)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 // Should prune the HighPriority item. 451 // Should prune the HighPriority item.
452 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache() ->liveSize() - 10, memoryCache()->liveSize() - 10); 452 memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache() ->liveSize() - 10, memoryCache()->liveSize() - 10);
453 memoryCache()->prune(); 453 memoryCache()->prune();
454 ASSERT_EQ(memoryCache()->deadSize(), 0u); 454 ASSERT_EQ(memoryCache()->deadSize(), 0u);
455 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - highPriorityMockDecodeSize); 455 ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - highPriorityMockDecodeSize);
456 } 456 }
457 457
458 TEST_F(MemoryCacheTest, DecodeCacheOrder_Basic) 458 TEST_F(MemoryCacheTest, DecodeCacheOrder_Basic)
459 { 459 {
460 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageLowPriority = 460 RawPtr<FakeDecodedResource> cachedImageLowPriority =
461 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resource: :Raw); 461 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resource: :Raw);
462 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageHighPriority = 462 RawPtr<FakeDecodedResource> cachedImageHighPriority =
463 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res ource::Raw); 463 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Res ource::Raw);
464 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriority.g et()); 464 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriority.g et());
465 } 465 }
466 466
467 TEST_F(MemoryCacheTest, DecodeCacheOrder_MultipleResourceMaps) 467 TEST_F(MemoryCacheTest, DecodeCacheOrder_MultipleResourceMaps)
468 { 468 {
469 { 469 {
470 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageLowPriority = 470 RawPtr<FakeDecodedResource> cachedImageLowPriority =
471 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw); 471 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw);
472 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageHighPriority = 472 RawPtr<FakeDecodedResource> cachedImageHighPriority =
473 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 473 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
474 cachedImageLowPriority->setCacheIdentifier("foo"); 474 cachedImageLowPriority->setCacheIdentifier("foo");
475 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriori ty.get()); 475 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriori ty.get());
476 memoryCache()->evictResources(); 476 memoryCache()->evictResources();
477 } 477 }
478 { 478 {
479 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageLowPriority = 479 RawPtr<FakeDecodedResource> cachedImageLowPriority =
480 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw); 480 FakeDecodedResource::create(ResourceRequest("http://foo.com"), Resou rce::Raw);
481 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageHighPriority = 481 RawPtr<FakeDecodedResource> cachedImageHighPriority =
482 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 482 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
483 cachedImageHighPriority->setCacheIdentifier("foo"); 483 cachedImageHighPriority->setCacheIdentifier("foo");
484 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriori ty.get()); 484 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriori ty.get());
485 memoryCache()->evictResources(); 485 memoryCache()->evictResources();
486 } 486 }
487 { 487 {
488 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageLowPriority = 488 RawPtr<FakeDecodedResource> cachedImageLowPriority =
489 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 489 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
490 cachedImageLowPriority->setCacheIdentifier("foo"); 490 cachedImageLowPriority->setCacheIdentifier("foo");
491 RefPtrWillBeRawPtr<FakeDecodedResource> cachedImageHighPriority = 491 RawPtr<FakeDecodedResource> cachedImageHighPriority =
492 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw); 492 FakeDecodedResource::create(ResourceRequest("http://test/resource"), Resource::Raw);
493 cachedImageHighPriority->setCacheIdentifier("bar"); 493 cachedImageHighPriority->setCacheIdentifier("bar");
494 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriori ty.get()); 494 TestDecodeCacheOrder(cachedImageLowPriority.get(), cachedImageHighPriori ty.get());
495 memoryCache()->evictResources(); 495 memoryCache()->evictResources();
496 } 496 }
497 } 497 }
498 498
499 TEST_F(MemoryCacheTest, RemoveDuringRevalidation) 499 TEST_F(MemoryCacheTest, RemoveDuringRevalidation)
500 { 500 {
501 RefPtrWillBeRawPtr<FakeResource> resource1 = FakeResource::create(ResourceRe quest("http://test/resource"), Resource::Raw); 501 RawPtr<FakeResource> resource1 = FakeResource::create(ResourceRequest("http: //test/resource"), Resource::Raw);
502 memoryCache()->add(resource1.get()); 502 memoryCache()->add(resource1.get());
503 503
504 RefPtrWillBeRawPtr<FakeResource> resource2 = FakeResource::create(ResourceRe quest("http://test/resource"), Resource::Raw); 504 RawPtr<FakeResource> resource2 = FakeResource::create(ResourceRequest("http: //test/resource"), Resource::Raw);
505 memoryCache()->remove(resource1.get()); 505 memoryCache()->remove(resource1.get());
506 memoryCache()->add(resource2.get()); 506 memoryCache()->add(resource2.get());
507 EXPECT_TRUE(memoryCache()->contains(resource2.get())); 507 EXPECT_TRUE(memoryCache()->contains(resource2.get()));
508 EXPECT_FALSE(memoryCache()->contains(resource1.get())); 508 EXPECT_FALSE(memoryCache()->contains(resource1.get()));
509 509
510 RefPtrWillBeRawPtr<FakeResource> resource3 = FakeResource::create(ResourceRe quest("http://test/resource"), Resource::Raw); 510 RawPtr<FakeResource> resource3 = FakeResource::create(ResourceRequest("http: //test/resource"), Resource::Raw);
511 memoryCache()->remove(resource2.get()); 511 memoryCache()->remove(resource2.get());
512 memoryCache()->add(resource3.get()); 512 memoryCache()->add(resource3.get());
513 EXPECT_TRUE(memoryCache()->contains(resource3.get())); 513 EXPECT_TRUE(memoryCache()->contains(resource3.get()));
514 EXPECT_FALSE(memoryCache()->contains(resource2.get())); 514 EXPECT_FALSE(memoryCache()->contains(resource2.get()));
515 } 515 }
516 516
517 TEST_F(MemoryCacheTest, ResourceMapIsolation) 517 TEST_F(MemoryCacheTest, ResourceMapIsolation)
518 { 518 {
519 RefPtrWillBeRawPtr<FakeResource> resource1 = FakeResource::create(ResourceRe quest("http://test/resource"), Resource::Raw); 519 RawPtr<FakeResource> resource1 = FakeResource::create(ResourceRequest("http: //test/resource"), Resource::Raw);
520 memoryCache()->add(resource1.get()); 520 memoryCache()->add(resource1.get());
521 521
522 RefPtrWillBeRawPtr<FakeResource> resource2 = FakeResource::create(ResourceRe quest("http://test/resource"), Resource::Raw); 522 RawPtr<FakeResource> resource2 = FakeResource::create(ResourceRequest("http: //test/resource"), Resource::Raw);
523 resource2->setCacheIdentifier("foo"); 523 resource2->setCacheIdentifier("foo");
524 memoryCache()->add(resource2.get()); 524 memoryCache()->add(resource2.get());
525 EXPECT_TRUE(memoryCache()->contains(resource1.get())); 525 EXPECT_TRUE(memoryCache()->contains(resource1.get()));
526 EXPECT_TRUE(memoryCache()->contains(resource2.get())); 526 EXPECT_TRUE(memoryCache()->contains(resource2.get()));
527 527
528 const KURL url = KURL(ParsedURLString, "http://test/resource"); 528 const KURL url = KURL(ParsedURLString, "http://test/resource");
529 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url)); 529 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url));
530 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url, memoryCache()- >defaultCacheIdentifier())); 530 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url, memoryCache()- >defaultCacheIdentifier()));
531 EXPECT_EQ(resource2.get(), memoryCache()->resourceForURL(url, "foo")); 531 EXPECT_EQ(resource2.get(), memoryCache()->resourceForURL(url, "foo"));
532 EXPECT_EQ(0, memoryCache()->resourceForURL(KURL())); 532 EXPECT_EQ(0, memoryCache()->resourceForURL(KURL()));
533 533
534 RefPtrWillBeRawPtr<FakeResource> resource3 = FakeResource::create(ResourceRe quest("http://test/resource"), Resource::Raw); 534 RawPtr<FakeResource> resource3 = FakeResource::create(ResourceRequest("http: //test/resource"), Resource::Raw);
535 resource3->setCacheIdentifier("foo"); 535 resource3->setCacheIdentifier("foo");
536 memoryCache()->remove(resource2.get()); 536 memoryCache()->remove(resource2.get());
537 memoryCache()->add(resource3.get()); 537 memoryCache()->add(resource3.get());
538 EXPECT_TRUE(memoryCache()->contains(resource1.get())); 538 EXPECT_TRUE(memoryCache()->contains(resource1.get()));
539 EXPECT_FALSE(memoryCache()->contains(resource2.get())); 539 EXPECT_FALSE(memoryCache()->contains(resource2.get()));
540 EXPECT_TRUE(memoryCache()->contains(resource3.get())); 540 EXPECT_TRUE(memoryCache()->contains(resource3.get()));
541 541
542 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = memoryCache()->re sourcesForURL(url); 542 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url) ;
543 EXPECT_EQ(2u, resources.size()); 543 EXPECT_EQ(2u, resources.size());
544 544
545 memoryCache()->evictResources(); 545 memoryCache()->evictResources();
546 EXPECT_FALSE(memoryCache()->contains(resource1.get())); 546 EXPECT_FALSE(memoryCache()->contains(resource1.get()));
547 EXPECT_FALSE(memoryCache()->contains(resource3.get())); 547 EXPECT_FALSE(memoryCache()->contains(resource3.get()));
548 } 548 }
549 549
550 } // namespace blink 550 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698