Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: chrome/browser/sync/weak_handle_unittest.cc

Issue 7572010: [Sync] Avoid leaking in WeakHandle even when the owner thread is gone (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/weak_handle.cc ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/weak_handle_unittest.cc
diff --git a/chrome/browser/sync/weak_handle_unittest.cc b/chrome/browser/sync/weak_handle_unittest.cc
index c545abcb8d00e51deecd09f31ba02c97921599cb..b4bfe41305ecd8daeadf8d39593d16843d15c7f7 100644
--- a/chrome/browser/sync/weak_handle_unittest.cc
+++ b/chrome/browser/sync/weak_handle_unittest.cc
@@ -16,6 +16,8 @@
namespace browser_sync {
namespace {
+using ::testing::_;
+using ::testing::SaveArg;
using ::testing::StrictMock;
class Base {
@@ -36,6 +38,8 @@ class Base {
MOCK_METHOD3(Test3, void(const int&, Base*, float));
MOCK_METHOD4(Test4, void(const int&, Base*, float, const char*));
+ MOCK_METHOD1(TestWithSelf, void(const WeakHandle<Base>&));
+
private:
base::WeakPtrFactory<Base> weak_ptr_factory_;
};
@@ -201,6 +205,34 @@ TEST_F(WeakHandleTest, DeleteOnOtherThread) {
PumpLoop();
}
+void CallTestWithSelf(const WeakHandle<Base>& b1) {
+ StrictMock<Base> b2;
+ b1.Call(FROM_HERE, &Base::TestWithSelf, b2.AsWeakHandle());
+}
+
+TEST_F(WeakHandleTest, WithDestroyedThread) {
+ StrictMock<Base> b1;
+ WeakHandle<Base> b2;
+ EXPECT_CALL(b1, TestWithSelf(_)).WillOnce(SaveArg<0>(&b2));
+
+ {
+ base::Thread t("Test thread");
+ ASSERT_TRUE(t.Start());
+ t.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&CallTestWithSelf,
+ b1.AsWeakHandle()));
+ }
+
+ // Calls b1.TestWithSelf().
+ PumpLoop();
+
+ // Shouldn't do anything, since the thread is gone.
+ b2.Call(FROM_HERE, &Base::Test);
+
+ // |b2| shouldn't leak when it's destroyed, even if the original
+ // thread is gone.
+}
+
TEST_F(WeakHandleTest, InitializedAcrossCopyAssign) {
StrictMock<Base> b;
EXPECT_CALL(b, Test()).Times(3);
« no previous file with comments | « chrome/browser/sync/weak_handle.cc ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698