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

Unified Diff: base/observer_list_unittest.cc

Issue 2419673003: Remove base::ObserverList<T>::Iter::GetNext(). (Closed)
Patch Set: ios fix too Created 4 years, 2 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') | ios/web/web_state/web_state_impl.mm » ('j') | 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 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);
}
« no previous file with comments | « base/observer_list_threadsafe.h ('k') | ios/web/web_state/web_state_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698