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

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

Issue 1475003002: Remove an unused function from MemoryCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « third_party/WebKit/Source/core/fetch/MemoryCache.cpp ('k') | no next file » | 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res ource::Raw); 480 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res ource::Raw);
481 cachedImageLowPriority->setCacheIdentifier("foo"); 481 cachedImageLowPriority->setCacheIdentifier("foo");
482 ResourcePtr<FakeDecodedResource> cachedImageHighPriority = 482 ResourcePtr<FakeDecodedResource> cachedImageHighPriority =
483 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res ource::Raw); 483 new FakeDecodedResource(ResourceRequest("http://test/resource"), Res ource::Raw);
484 cachedImageHighPriority->setCacheIdentifier("bar"); 484 cachedImageHighPriority->setCacheIdentifier("bar");
485 TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority); 485 TestDecodeCacheOrder(cachedImageLowPriority, cachedImageHighPriority);
486 memoryCache()->evictResources(); 486 memoryCache()->evictResources();
487 } 487 }
488 } 488 }
489 489
490 TEST_F(MemoryCacheTest, MultipleReplace)
491 {
492 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
493 memoryCache()->add(resource1.get());
494
495 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
496 memoryCache()->replace(resource2.get(), resource1.get());
497 EXPECT_TRUE(memoryCache()->contains(resource2.get()));
498 EXPECT_FALSE(memoryCache()->contains(resource1.get()));
499
500 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
501 memoryCache()->replace(resource3.get(), resource2.get());
502 EXPECT_TRUE(memoryCache()->contains(resource3.get()));
503 EXPECT_FALSE(memoryCache()->contains(resource2.get()));
504 }
505
506 TEST_F(MemoryCacheTest, RemoveDuringRevalidation) 490 TEST_F(MemoryCacheTest, RemoveDuringRevalidation)
507 { 491 {
508 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw); 492 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
509 memoryCache()->add(resource1.get()); 493 memoryCache()->add(resource1.get());
510 494
511 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw); 495 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
512 memoryCache()->remove(resource1.get()); 496 memoryCache()->remove(resource1.get());
513 memoryCache()->add(resource2.get()); 497 memoryCache()->add(resource2.get());
514 EXPECT_TRUE(memoryCache()->contains(resource2.get())); 498 EXPECT_TRUE(memoryCache()->contains(resource2.get()));
515 EXPECT_FALSE(memoryCache()->contains(resource1.get())); 499 EXPECT_FALSE(memoryCache()->contains(resource1.get()));
516 500
517 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw); 501 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
518 memoryCache()->remove(resource2.get()); 502 memoryCache()->remove(resource2.get());
519 memoryCache()->add(resource3.get()); 503 memoryCache()->add(resource3.get());
520 EXPECT_TRUE(memoryCache()->contains(resource3.get())); 504 EXPECT_TRUE(memoryCache()->contains(resource3.get()));
521 EXPECT_FALSE(memoryCache()->contains(resource2.get())); 505 EXPECT_FALSE(memoryCache()->contains(resource2.get()));
522
523 memoryCache()->replace(resource1.get(), resource2.get());
524 EXPECT_TRUE(memoryCache()->contains(resource1.get()));
525 EXPECT_FALSE(memoryCache()->contains(resource2.get()));
526 EXPECT_FALSE(memoryCache()->contains(resource3.get()));
527 } 506 }
528 507
529 TEST_F(MemoryCacheTest, ResourceMapIsolation) 508 TEST_F(MemoryCacheTest, ResourceMapIsolation)
530 { 509 {
531 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw); 510 ResourcePtr<FakeResource> resource1 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
532 memoryCache()->add(resource1.get()); 511 memoryCache()->add(resource1.get());
533 512
534 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw); 513 ResourcePtr<FakeResource> resource2 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
535 resource2->setCacheIdentifier("foo"); 514 resource2->setCacheIdentifier("foo");
536 memoryCache()->add(resource2.get()); 515 memoryCache()->add(resource2.get());
537 EXPECT_TRUE(memoryCache()->contains(resource1.get())); 516 EXPECT_TRUE(memoryCache()->contains(resource1.get()));
538 EXPECT_TRUE(memoryCache()->contains(resource2.get())); 517 EXPECT_TRUE(memoryCache()->contains(resource2.get()));
539 518
540 const KURL url = KURL(ParsedURLString, "http://test/resource"); 519 const KURL url = KURL(ParsedURLString, "http://test/resource");
541 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url)); 520 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url));
542 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url, memoryCache()- >defaultCacheIdentifier())); 521 EXPECT_EQ(resource1.get(), memoryCache()->resourceForURL(url, memoryCache()- >defaultCacheIdentifier()));
543 EXPECT_EQ(resource2.get(), memoryCache()->resourceForURL(url, "foo")); 522 EXPECT_EQ(resource2.get(), memoryCache()->resourceForURL(url, "foo"));
544 EXPECT_EQ(0, memoryCache()->resourceForURL(KURL())); 523 EXPECT_EQ(0, memoryCache()->resourceForURL(KURL()));
545 524
546 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw); 525 ResourcePtr<FakeResource> resource3 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
547 resource3->setCacheIdentifier("foo"); 526 resource3->setCacheIdentifier("foo");
548 memoryCache()->remove(resource2.get()); 527 memoryCache()->remove(resource2.get());
549 memoryCache()->add(resource3.get()); 528 memoryCache()->add(resource3.get());
550 EXPECT_TRUE(memoryCache()->contains(resource1.get())); 529 EXPECT_TRUE(memoryCache()->contains(resource1.get()));
551 EXPECT_FALSE(memoryCache()->contains(resource2.get())); 530 EXPECT_FALSE(memoryCache()->contains(resource2.get()));
552 EXPECT_TRUE(memoryCache()->contains(resource3.get())); 531 EXPECT_TRUE(memoryCache()->contains(resource3.get()));
553 532
554 ResourcePtr<FakeResource> resource4 = new FakeResource(ResourceRequest("http ://test/resource"), Resource::Raw);
555 resource4->setCacheIdentifier("foo");
556 memoryCache()->replace(resource4.get(), resource3.get());
557 EXPECT_TRUE(memoryCache()->contains(resource1.get()));
558 EXPECT_FALSE(memoryCache()->contains(resource3.get()));
559 EXPECT_TRUE(memoryCache()->contains(resource4.get()));
560
561 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = memoryCache()->re sourcesForURL(url); 533 WillBeHeapVector<RawPtrWillBeMember<Resource>> resources = memoryCache()->re sourcesForURL(url);
562 EXPECT_EQ(2u, resources.size()); 534 EXPECT_EQ(2u, resources.size());
563 535
564 memoryCache()->evictResources(); 536 memoryCache()->evictResources();
565 EXPECT_FALSE(memoryCache()->contains(resource1.get())); 537 EXPECT_FALSE(memoryCache()->contains(resource1.get()));
566 EXPECT_FALSE(memoryCache()->contains(resource3.get())); 538 EXPECT_FALSE(memoryCache()->contains(resource3.get()));
567 } 539 }
568 540
569 } // namespace 541 } // namespace
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698