diff options
Diffstat (limited to 'Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp')
-rw-r--r-- | Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp | 98 |
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 |