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

Unified Diff: Source/core/loader/cache/MemoryCacheTest.cpp

Issue 19393004: Allow eviction of ImageBitmaps that are created from ImageElements. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix drawImage out of bounds src rect. Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/loader/cache/MemoryCacheTest.cpp
diff --git a/Source/core/loader/cache/MemoryCacheTest.cpp b/Source/core/loader/cache/MemoryCacheTest.cpp
index 021c3751d5ca6ef31f9cd944ff4e71b69a76304c..344d761602c4583a7a7951532f3488a2f4debea5 100644
--- a/Source/core/loader/cache/MemoryCacheTest.cpp
+++ b/Source/core/loader/cache/MemoryCacheTest.cpp
@@ -33,6 +33,7 @@
#include "core/loader/cache/CachedRawResource.h"
#include "core/loader/cache/CachedResourceHandle.h"
+#include "core/loader/cache/MockCachedImageClient.h"
#include "core/platform/network/ResourceRequest.h"
#include "wtf/OwnPtr.h"
@@ -41,6 +42,27 @@
namespace WebCore {
class MemoryCacheTest : public ::testing::Test {
+public:
+ class MockCachedImage : public WebCore::CachedResource {
+ public:
+ MockCachedImage(const ResourceRequest& request, Type type)
+ : CachedResource(request, type)
+ {
+ }
+
+ virtual void appendData(const char* data, int len)
+ {
+ CachedResource::appendData(data, len);
+ setDecodedSize(this->size());
+ }
+
+ virtual void destroyDecodedData()
+ {
+ setDecodedSize(0);
+ makePurgeable(true);
+ }
+ };
+
protected:
virtual void SetUp()
{
@@ -106,4 +128,89 @@ TEST_F(MemoryCacheTest, DeadResourceEviction)
ASSERT_EQ(0u, memoryCache()->liveSize());
}
+// Verifies that CachedResources are eviced from the decode cache
Stephen White 2013/07/25 18:01:07 Nit: eviced.
+// according to their DecodeCachePriority.
+TEST_F(MemoryCacheTest, DecodeCacheOrder)
+{
+ memoryCache()->setDelayBeforeLiveDecodedPrune(0);
+ CachedResourceHandle<MockCachedImage> cachedImageLowPriority =
+ new MockCachedImage(ResourceRequest(""), CachedResource::RawResource);
+ CachedResourceHandle<MockCachedImage> cachedImageMediumPriority =
+ new MockCachedImage(ResourceRequest(""), CachedResource::RawResource);
+ CachedResourceHandle<MockCachedImage> cachedImageHighPriority =
+ new MockCachedImage(ResourceRequest(""), CachedResource::RawResource);
+
+ MockCachedImageClient clientLowPriority;
+ MockCachedImageClient clientMediumPriority;
+ MockCachedImageClient clientHighPriority;
+ cachedImageLowPriority->addClient(&clientLowPriority);
+ cachedImageMediumPriority->addClient(&clientMediumPriority);
+ cachedImageHighPriority->addClient(&clientHighPriority);
+
+ const char data[5] = "abcd";
+ cachedImageLowPriority->appendData(data, 1);
+ cachedImageMediumPriority->appendData(data, 2);
+ cachedImageHighPriority->appendData(data, 4);
+ const unsigned lowPrioritySize = cachedImageLowPriority->size();
+ const unsigned mediumPrioritySize = cachedImageMediumPriority->size();
+ const unsigned highPrioritySize = cachedImageHighPriority->size();
+ const unsigned lowPriorityMockDecodeSize = cachedImageLowPriority->decodedSize();
+ const unsigned mediumPriorityMockDecodeSize = cachedImageMediumPriority->decodedSize();
+ const unsigned highPriorityMockDecodeSize = cachedImageHighPriority->decodedSize();
+ const unsigned totalSize = lowPrioritySize + mediumPrioritySize + highPrioritySize;
+
+ // Verify all the sizes to be different in order to properly test eviction order.
+ ASSERT_GT(lowPrioritySize, 0u);
+ ASSERT_NE(lowPrioritySize, mediumPrioritySize);
+ ASSERT_NE(mediumPrioritySize, highPrioritySize);
+ ASSERT_GT(lowPriorityMockDecodeSize, 0u);
+ ASSERT_NE(lowPriorityMockDecodeSize, mediumPriorityMockDecodeSize);
+ ASSERT_NE(mediumPriorityMockDecodeSize, highPriorityMockDecodeSize);
+
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), 0u);
+
+ // Add the three items in a random order.
+ memoryCache()->add(cachedImageHighPriority.get());
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), highPrioritySize);
+
+ memoryCache()->add(cachedImageLowPriority.get());
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), highPrioritySize + lowPrioritySize);
+
+ memoryCache()->add(cachedImageMediumPriority.get());
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), highPrioritySize + mediumPrioritySize + lowPrioritySize);
+
+ // Insert all items in the decoded items list with the same priority
+ memoryCache()->insertInLiveDecodedResourcesList(cachedImageHighPriority.get());
+ memoryCache()->insertInLiveDecodedResourcesList(cachedImageLowPriority.get());
+ memoryCache()->insertInLiveDecodedResourcesList(cachedImageMediumPriority.get());
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), totalSize);
+
+ // Now we will assign their priority and make sure they are moved to the correct buckets.
+ cachedImageLowPriority->setCachePriority(CachedResource::CachePriorityLow);
+ cachedImageMediumPriority->setCachePriority(CachedResource::CachePriorityMedium);
+ cachedImageHighPriority->setCachePriority(CachedResource::CachePriorityHigh);
+
+ // Should prune the LowPriority item.
+ memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()->maxDeadCapacity(), memoryCache()->liveSize() - 10);
+ memoryCache()->prune();
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize);
+
+ // Should prune the MediumPriority item.
+ memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()->maxDeadCapacity(), memoryCache()->liveSize() - 10);
+ memoryCache()->prune();
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - mediumPriorityMockDecodeSize);
+
+ // Should prune the HighPriority item.
+ memoryCache()->setCapacities(memoryCache()->minDeadCapacity(), memoryCache()->maxDeadCapacity(), memoryCache()->liveSize() - 10);
+ memoryCache()->prune();
+ ASSERT_EQ(memoryCache()->deadSize(), 0u);
+ ASSERT_EQ(memoryCache()->liveSize(), totalSize - lowPriorityMockDecodeSize - mediumPriorityMockDecodeSize - highPriorityMockDecodeSize);
+}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698