From 715be629d51174233403237bfc563cf150087dc8 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 25 Sep 2012 13:02:02 +0200 Subject: Imported WebKit commit ce614b0924ba46f78d4435e28ff93c8525fbb7cc (http://svn.webkit.org/repository/webkit/trunk@129485) New snapshot that includes MingW build fixes --- .../WebKit/chromium/tests/FilterOperationsTest.cpp | 103 +++++++++++++++++++++ .../chromium/tests/MemoryInstrumentationTest.cpp | 72 ++++++++++++++ 2 files changed, 175 insertions(+) (limited to 'Source/WebKit/chromium/tests') diff --git a/Source/WebKit/chromium/tests/FilterOperationsTest.cpp b/Source/WebKit/chromium/tests/FilterOperationsTest.cpp index 8a3c5d8a1..873d216cd 100644 --- a/Source/WebKit/chromium/tests/FilterOperationsTest.cpp +++ b/Source/WebKit/chromium/tests/FilterOperationsTest.cpp @@ -89,5 +89,108 @@ TEST(WebFilterOperationsTest, getOutsetsDropShadow) EXPECT_EQ(54, left); } +#define SAVE_RESTORE_AMOUNT(Type, a) \ + { \ + WebFilterOperation op = WebFilterOperation::create##Type##Filter(a); \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \ + EXPECT_EQ(a, op.amount()); \ + \ + WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \ + op2.setType(WebFilterOperation::FilterType##Type); \ + \ + EXPECT_NE(a, op2.amount()); \ + \ + op2.setAmount(a); \ + \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \ + EXPECT_EQ(a, op2.amount()); \ + } + +#define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(Type, a, b, c) \ + { \ + WebFilterOperation op = WebFilterOperation::create##Type##Filter(a, b, c); \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \ + EXPECT_EQ(a, op.dropShadowOffset()); \ + EXPECT_EQ(b, op.amount()); \ + EXPECT_EQ(c, op.dropShadowColor()); \ + \ + WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \ + op2.setType(WebFilterOperation::FilterType##Type); \ + \ + EXPECT_NE(a, op2.dropShadowOffset()); \ + EXPECT_NE(b, op2.amount()); \ + EXPECT_NE(c, op2.dropShadowColor()); \ + \ + op2.setDropShadowOffset(a); \ + op2.setAmount(b); \ + op2.setDropShadowColor(c); \ + \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \ + EXPECT_EQ(a, op2.dropShadowOffset()); \ + EXPECT_EQ(b, op2.amount()); \ + EXPECT_EQ(c, op2.dropShadowColor()); \ + } + +#define SAVE_RESTORE_MATRIX(Type, a) \ + { \ + WebFilterOperation op = WebFilterOperation::create##Type##Filter(a); \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \ + for (unsigned i = 0; i < 20; ++i) \ + EXPECT_EQ(a[i], op.matrix()[i]); \ + \ + WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \ + op2.setType(WebFilterOperation::FilterType##Type); \ + \ + for (unsigned i = 0; i < 20; ++i) \ + EXPECT_NE(a[i], op2.matrix()[i]); \ + \ + op2.setMatrix(a); \ + \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \ + for (unsigned i = 0; i < 20; ++i) \ + EXPECT_EQ(a[i], op.matrix()[i]); \ + } + +#define SAVE_RESTORE_ZOOMRECT_AMOUNT(Type, a, b) \ + { \ + WebFilterOperation op = WebFilterOperation::create##Type##Filter(a, b); \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op.type()); \ + EXPECT_EQ(a, op.zoomRect()); \ + EXPECT_EQ(b, op.amount()); \ + \ + WebFilterOperation op2 = WebFilterOperation::createEmptyFilter(); \ + op2.setType(WebFilterOperation::FilterType##Type); \ + \ + EXPECT_NE(a, op2.zoomRect()); \ + EXPECT_NE(b, op2.amount()); \ + \ + op2.setZoomRect(a); \ + op2.setAmount(b); \ + \ + EXPECT_EQ(WebFilterOperation::FilterType##Type, op2.type()); \ + EXPECT_EQ(a, op2.zoomRect()); \ + EXPECT_EQ(b, op2.amount()); \ + } + + +TEST(WebFilterOperationsTest, saveAndRestore) +{ + SAVE_RESTORE_AMOUNT(Grayscale, 0.6f); + SAVE_RESTORE_AMOUNT(Sepia, 0.6f); + SAVE_RESTORE_AMOUNT(Saturate, 0.6f); + SAVE_RESTORE_AMOUNT(HueRotate, 0.6f); + SAVE_RESTORE_AMOUNT(Invert, 0.6f); + SAVE_RESTORE_AMOUNT(Brightness, 0.6f); + SAVE_RESTORE_AMOUNT(Contrast, 0.6f); + SAVE_RESTORE_AMOUNT(Opacity, 0.6f); + SAVE_RESTORE_AMOUNT(Blur, 0.6f); + SAVE_RESTORE_OFFSET_AMOUNT_COLOR(DropShadow, WebPoint(3, 4), 0.4f, 0xffffff00); + + SkScalar matrix[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; + SAVE_RESTORE_MATRIX(ColorMatrix, matrix); + + SAVE_RESTORE_ZOOMRECT_AMOUNT(Zoom, WebRect(20, 19, 18, 17), 32); +} + } diff --git a/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp b/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp index 4acf496ad..21ce96316 100644 --- a/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp +++ b/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -235,6 +236,7 @@ class InstrumentedOwner { public: template InstrumentedOwner(const V& value) : m_value(value) { } + InstrumentedOwner() { } void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const { MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); @@ -367,5 +369,75 @@ TEST(MemoryInstrumentationTest, detectReportMemoryUsageMethod) } } +TEST(MemoryInstrumentationTest, vectorZeroInlineCapacity) +{ + VisitedObjects visitedObjects; + MemoryInstrumentationImpl impl(visitedObjects); + InstrumentedOwner > vectorOwner(16); + impl.addRootObject(vectorOwner); + EXPECT_EQ(16 * sizeof(int), impl.reportedSizeForAllTypes()); + EXPECT_EQ(1, visitedObjects.size()); +} + +TEST(MemoryInstrumentationTest, vectorFieldWithInlineCapacity) +{ + VisitedObjects visitedObjects; + MemoryInstrumentationImpl impl(visitedObjects); + InstrumentedOwner > vectorOwner; + impl.addRootObject(vectorOwner); + EXPECT_EQ(static_cast(0), impl.reportedSizeForAllTypes()); + EXPECT_EQ(0, visitedObjects.size()); +} + +TEST(MemoryInstrumentationTest, vectorFieldWithInlineCapacityResized) +{ + VisitedObjects visitedObjects; + MemoryInstrumentationImpl impl(visitedObjects); + InstrumentedOwner > vectorOwner; + vectorOwner.m_value.reserveCapacity(8); + impl.addRootObject(vectorOwner); + EXPECT_EQ(8 * sizeof(int), impl.reportedSizeForAllTypes()); + EXPECT_EQ(1, visitedObjects.size()); +} + +TEST(MemoryInstrumentationTest, heapAllocatedVectorWithInlineCapacity) +{ + VisitedObjects visitedObjects; + MemoryInstrumentationImpl impl(visitedObjects); + InstrumentedOwner > > vectorOwner; + vectorOwner.m_value = adoptPtr(new Vector()); + impl.addRootObject(vectorOwner); + EXPECT_EQ(sizeof(Vector), impl.reportedSizeForAllTypes()); + EXPECT_EQ(1, visitedObjects.size()); +} + +TEST(MemoryInstrumentationTest, heapAllocatedVectorWithInlineCapacityResized) +{ + VisitedObjects visitedObjects; + MemoryInstrumentationImpl impl(visitedObjects); + InstrumentedOwner > > vectorOwner; + vectorOwner.m_value = adoptPtr(new Vector()); + vectorOwner.m_value->reserveCapacity(8); + impl.addRootObject(vectorOwner); + EXPECT_EQ(8 * sizeof(int) + sizeof(Vector), impl.reportedSizeForAllTypes()); + EXPECT_EQ(2, visitedObjects.size()); +} + +TEST(MemoryInstrumentationTest, vectorWithInstrumentedType) +{ + VisitedObjects visitedObjects; + MemoryInstrumentationImpl impl(visitedObjects); + + typedef Vector StringVector; + OwnPtr value = adoptPtr(new StringVector()); + size_t count = 10; + for (size_t i = 0; i < count; ++i) + value->append("string"); + InstrumentedOwner root(value.get()); + impl.addRootObject(root); + EXPECT_EQ(sizeof(StringVector) + sizeof(String) * value->capacity() + sizeof(StringImpl) * value->size(), impl.reportedSizeForAllTypes()); + EXPECT_EQ(count + 2, (size_t)visitedObjects.size()); +} + } // namespace -- cgit v1.2.1