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

Unified Diff: base/observer_list_unittest.cc

Issue 8635002: Make ObserverListThreadSafe key its observers by PlatformThreadId instead of MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment Created 9 years, 1 month 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 | « base/observer_list_threadsafe.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/observer_list_unittest.cc
diff --git a/base/observer_list_unittest.cc b/base/observer_list_unittest.cc
index 34cc4857b83d13d2fec26cdc62f2eda456c76f0e..f7fc1cb34d25ce3cdab2beb67efe13eeb46c09d4 100644
--- a/base/observer_list_unittest.cc
+++ b/base/observer_list_unittest.cc
@@ -258,6 +258,57 @@ TEST(ObserverListThreadSafeTest, RemoveObserver) {
EXPECT_EQ(b.total, 0);
}
+TEST(ObserverListThreadSafeTest, WithoutMessageLoop) {
+ scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
+ new ObserverListThreadSafe<Foo>);
+
+ Adder a(1), b(1), c(1);
+
+ // No MessageLoop, so these should not be added.
+ observer_list->AddObserver(&a);
+ observer_list->AddObserver(&b);
+
+ {
+ // Add c when there's a loop.
+ MessageLoop loop;
+ observer_list->AddObserver(&c);
+
+ observer_list->Notify(&Foo::Observe, 10);
+ loop.RunAllPending();
+
+ EXPECT_EQ(0, a.total);
+ EXPECT_EQ(0, b.total);
+ EXPECT_EQ(10, c.total);
+
+ // Now add a when there's a loop.
+ observer_list->AddObserver(&a);
+
+ // Remove c when there's a loop.
+ observer_list->RemoveObserver(&c);
+
+ // Notify again.
+ observer_list->Notify(&Foo::Observe, 20);
+ loop.RunAllPending();
+
+ EXPECT_EQ(20, a.total);
+ EXPECT_EQ(0, b.total);
+ EXPECT_EQ(10, c.total);
+ }
+
+ // Removing should always succeed with or without a loop.
+ observer_list->RemoveObserver(&a);
+
+ // Notifying should not fail but should also be a no-op.
+ MessageLoop loop;
+ observer_list->AddObserver(&b);
+ observer_list->Notify(&Foo::Observe, 30);
+ loop.RunAllPending();
+
+ EXPECT_EQ(20, a.total);
+ EXPECT_EQ(30, b.total);
+ EXPECT_EQ(10, c.total);
+}
+
class FooRemover : public Foo {
public:
explicit FooRemover(ObserverListThreadSafe<Foo>* list) : list_(list) {}
« no previous file with comments | « base/observer_list_threadsafe.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698