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

Unified Diff: base/observer_list_unittest.cc

Issue 7024037: Fix bug in ObserverListThreadsafe::RemoveObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 | « 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 d313367b3068752c3b7b36033ff584f0b4adf984..8315a2b48a2fc4103b1449819929b5ac831620d5 100644
--- a/base/observer_list_unittest.cc
+++ b/base/observer_list_unittest.cc
@@ -175,7 +175,7 @@ class AddRemoveThread : public PlatformThread::Delegate,
TEST(ObserverListTest, BasicTest) {
ObserverList<Foo> observer_list;
- Adder a(1), b(-1), c(1), d(-1);
+ Adder a(1), b(-1), c(1), d(-1), e(-1);
Disrupter evil(&observer_list, &c);
observer_list.AddObserver(&a);
@@ -187,12 +187,16 @@ TEST(ObserverListTest, BasicTest) {
observer_list.AddObserver(&c);
observer_list.AddObserver(&d);
+ // Removing an observer not in the list should do nothing.
+ observer_list.RemoveObserver(&e);
+
FOR_EACH_OBSERVER(Foo, observer_list, Observe(10));
EXPECT_EQ(a.total, 20);
EXPECT_EQ(b.total, -20);
EXPECT_EQ(c.total, 0);
EXPECT_EQ(d.total, -10);
+ EXPECT_EQ(e.total, 0);
}
TEST(ObserverListThreadSafeTest, BasicTest) {
@@ -225,6 +229,35 @@ TEST(ObserverListThreadSafeTest, BasicTest) {
EXPECT_EQ(d.total, -10);
}
+TEST(ObserverListThreadSafeTest, RemoveObserver) {
+ MessageLoop loop;
+
+ scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
+ new ObserverListThreadSafe<Foo>);
+ Adder a(1), b(1);
+
+ // Should do nothing.
+ observer_list->RemoveObserver(&a);
+ observer_list->RemoveObserver(&b);
+
+ observer_list->Notify(&Foo::Observe, 10);
+ loop.RunAllPending();
+
+ EXPECT_EQ(a.total, 0);
+ EXPECT_EQ(b.total, 0);
+
+ observer_list->AddObserver(&a);
+
+ // Should also do nothing.
+ observer_list->RemoveObserver(&b);
+
+ observer_list->Notify(&Foo::Observe, 10);
+ loop.RunAllPending();
+
+ EXPECT_EQ(a.total, 10);
+ EXPECT_EQ(b.total, 0);
+}
+
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