Index: base/memory/ref_counted_unittest.cc |
diff --git a/base/memory/ref_counted_unittest.cc b/base/memory/ref_counted_unittest.cc |
index dcc292f00ddfb024780f2fee88f9daf8dc5793c8..6aa84e17b863942367fc4bf7a6243688b17cfa66 100644 |
--- a/base/memory/ref_counted_unittest.cc |
+++ b/base/memory/ref_counted_unittest.cc |
@@ -22,6 +22,27 @@ class CheckDerivedMemberAccess : public scoped_refptr<SelfAssign> { |
} |
}; |
+class ScopedRefPtrToSelf : public base::RefCounted<ScopedRefPtrToSelf> { |
+ public: |
+ ScopedRefPtrToSelf() |
+ : ALLOW_THIS_IN_INITIALIZER_LIST(self_ptr_(this)) { |
+ } |
+ ~ScopedRefPtrToSelf() { was_destroyed_ = true; } |
+ |
+ static bool was_destroyed() { return was_destroyed_; } |
+ |
+ void SelfDestruct() { self_ptr_ = NULL; } |
+ |
+ private: |
+ friend class base::RefCounted<ScopedRefPtrToSelf>; |
+ |
+ static bool was_destroyed_; |
+ |
+ scoped_refptr<ScopedRefPtrToSelf> self_ptr_; |
+}; |
+ |
+bool ScopedRefPtrToSelf::was_destroyed_ = false; |
+ |
} // end namespace |
TEST(RefCountedUnitTest, TestSelfAssignment) { |
@@ -34,3 +55,10 @@ TEST(RefCountedUnitTest, TestSelfAssignment) { |
TEST(RefCountedUnitTest, ScopedRefPtrMemberAccess) { |
CheckDerivedMemberAccess check; |
} |
+ |
+TEST(RefCountedUnitTest, ScopedRefPtrToSelf) { |
+ ScopedRefPtrToSelf* check = new ScopedRefPtrToSelf(); |
+ EXPECT_FALSE(ScopedRefPtrToSelf::was_destroyed()); |
+ check->SelfDestruct(); |
+ EXPECT_TRUE(ScopedRefPtrToSelf::was_destroyed()); |
+} |