summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-09-18 15:53:33 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2012-09-18 15:53:33 +0200
commit6bbb7fbbac94d0f511a7bd0cbd50854ab643bfb2 (patch)
treed9c68d1cca0b3e352f1e438561f3e504e641a08f /Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
parentd0424a769059c84ae20beb3c217812792ea6726b (diff)
downloadqtwebkit-6bbb7fbbac94d0f511a7bd0cbd50854ab643bfb2.tar.gz
Imported WebKit commit c7503cef7ecb236730d1309676ab9fc723fd061d (http://svn.webkit.org/repository/webkit/trunk@128886)
New snapshot with various build fixes
Diffstat (limited to 'Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp98
1 files changed, 95 insertions, 3 deletions
diff --git a/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp b/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
index 4a0a3cf81..4acf496ad 100644
--- a/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
+++ b/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp
@@ -50,6 +50,7 @@ namespace {
class NotInstrumented {
public:
+ NotInstrumented(const char* = 0) { }
char m_data[42];
};
@@ -192,7 +193,7 @@ public:
void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
- info.addInstrumentedMember(m_instrumentedUndefined);
+ info.addMember(m_instrumentedUndefined);
}
OwnPtr<InstrumentedUndefined> m_instrumentedUndefined;
};
@@ -213,7 +214,7 @@ public:
void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
- info.addInstrumentedMember(m_instrumented);
+ info.addMember(m_instrumented);
}
Instrumented m_instrumented;
@@ -237,7 +238,7 @@ public:
void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
- info.addInstrumentedMember(m_value);
+ info.addMember(m_value);
}
T m_value;
@@ -275,5 +276,96 @@ TEST(MemoryInstrumentationTest, visitStrings)
}
}
+class TwoPointersToRefPtr {
+public:
+ TwoPointersToRefPtr(const RefPtr<StringImpl>& value) : m_ptr1(&value), m_ptr2(&value) { }
+ void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+ {
+ MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
+ info.addMember(m_ptr1);
+ info.addMember(m_ptr2);
+ }
+
+ const RefPtr<StringImpl>* m_ptr1;
+ const RefPtr<StringImpl>* m_ptr2;
+};
+
+TEST(MemoryInstrumentationTest, refPtrPtr)
+{
+ RefPtr<StringImpl> refPtr;
+ TwoPointersToRefPtr root(refPtr);
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ impl.addRootObject(root);
+ EXPECT_EQ(sizeof(RefPtr<StringImpl>), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(1, visitedObjects.size());
+}
+
+class TwoPointersToOwnPtr {
+public:
+ TwoPointersToOwnPtr(const OwnPtr<NotInstrumented>& value) : m_ptr1(&value), m_ptr2(&value) { }
+ void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+ {
+ MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
+ info.addMember(m_ptr1);
+ info.addMember(m_ptr2);
+ }
+
+ const OwnPtr<NotInstrumented>* m_ptr1;
+ const OwnPtr<NotInstrumented>* m_ptr2;
+};
+
+TEST(MemoryInstrumentationTest, ownPtrPtr)
+{
+ OwnPtr<NotInstrumented> ownPtr;
+ TwoPointersToOwnPtr root(ownPtr);
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+ impl.addRootObject(root);
+ EXPECT_EQ(sizeof(OwnPtr<NotInstrumented>), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(1, visitedObjects.size());
+}
+
+template<typename T>
+class InstrumentedTemplate {
+public:
+ template<typename V>
+ InstrumentedTemplate(const V& value) : m_value(value) { }
+
+ template<typename MemoryObjectInfo>
+ void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+ {
+ typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
+ info.addMember(m_value);
+ }
+
+ T m_value;
+};
+
+TEST(MemoryInstrumentationTest, detectReportMemoryUsageMethod)
+{
+ {
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+
+ OwnPtr<InstrumentedTemplate<String> > value = adoptPtr(new InstrumentedTemplate<String>(""));
+ InstrumentedOwner<InstrumentedTemplate<String>* > root(value.get());
+ impl.addRootObject(root);
+ EXPECT_EQ(sizeof(InstrumentedTemplate<String>) + sizeof(StringImpl), impl.reportedSizeForAllTypes());
+ // FIXME: it is failing on Chromium Canary bots but works fine locally.
+ // EXPECT_EQ(2, visitedObjects.size());
+ }
+ {
+ VisitedObjects visitedObjects;
+ MemoryInstrumentationImpl impl(visitedObjects);
+
+ OwnPtr<InstrumentedTemplate<NotInstrumented> > value = adoptPtr(new InstrumentedTemplate<NotInstrumented>(""));
+ InstrumentedOwner<InstrumentedTemplate<NotInstrumented>* > root(value.get());
+ impl.addRootObject(root);
+ EXPECT_EQ(sizeof(InstrumentedTemplate<NotInstrumented>), impl.reportedSizeForAllTypes());
+ EXPECT_EQ(1, visitedObjects.size());
+ }
+}
+
} // namespace