Index: base/observer_list_unittest.cc |
diff --git a/base/observer_list_unittest.cc b/base/observer_list_unittest.cc |
index 299a33f2e896053bf452887191559944c3c53334..9615653127cd02e3fcb5c42bb5fc9f49c29dd691 100644 |
--- a/base/observer_list_unittest.cc |
+++ b/base/observer_list_unittest.cc |
@@ -905,10 +905,18 @@ TEST(ObserverListTest, AddObserverInTheLastObserve) { |
a.SetToAdd(&b); |
observer_list.AddObserver(&a); |
- FooList::Iterator it(&observer_list); |
- Foo* foo; |
- while ((foo = it.GetNext()) != nullptr) |
- foo->Observe(10); |
+ auto it = observer_list.begin(); |
+ while (it != observer_list.end()) { |
loyso (OOO)
2016/10/16 23:20:17
nit: you recreate the end iterator many times here
|
+ auto& observer = *it; |
+ // Intentionally increment the iterator before calling Observe(). The |
+ // ObserverList starts with only one observer, and it == observer_list.end() |
+ // should be true after the next line. |
+ ++it; |
+ // However, the first Observe() call will add a second observer: at this |
+ // point, it != observer_list.end() should be true, and Observe() should be |
+ // called on the newly added observer on the next iteration of the loop. |
+ observer.Observe(10); |
+ } |
EXPECT_EQ(-10, b.total); |
} |