Index: base/memory/weak_ptr_unittest.cc |
diff --git a/base/memory/weak_ptr_unittest.cc b/base/memory/weak_ptr_unittest.cc |
index c1a952634fd204615fa782a33b496bf173c13b06..77b629d35bcd52ccf615b9bc4a1c60a5a6dc7788 100644 |
--- a/base/memory/weak_ptr_unittest.cc |
+++ b/base/memory/weak_ptr_unittest.cc |
@@ -38,6 +38,14 @@ struct Derived : Base {}; |
struct Producer : SupportsWeakPtr<Producer> {}; |
struct Consumer { WeakPtr<Producer> producer; }; |
+struct Complex { |
+ Complex() { |
+ consumer.producer = producer.AsWeakPtr(); |
+ } |
+ Producer producer; |
+ Consumer consumer; |
+}; |
+ |
} // namespace |
TEST(WeakPtrTest, Basic) { |
@@ -148,4 +156,14 @@ TEST(WeakPtrTest, SingleThreaded2) { |
EXPECT_EQ(&producer, consumer->producer.get()); |
} |
+TEST(WeakPtrTest, ReattachThread) { |
awong
2011/08/18 23:58:19
I feel like we should have more unittest to ensure
|
+ // Test that we can move a class that supports weak references to another |
+ // thread. This should work and not trip any runtime checks as long as |
+ // there are no references in existence. |
+ scoped_ptr<Complex> complex(OffThreadObjectCreator<Complex>::NewObject()); |
+ complex->consumer.producer.reset(); |
+ complex->consumer.producer = complex->producer.AsWeakPtr(); |
+ EXPECT_EQ(complex->consumer.producer.get(), &complex->producer); |
+} |
+ |
} // namespace base |