OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/observer_list.h" | 5 #include "base/observer_list.h" |
6 #include "base/observer_list_threadsafe.h" | 6 #include "base/observer_list_threadsafe.h" |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 observer_list.AddObserver(&a); | 888 observer_list.AddObserver(&a); |
889 observer_list.AddObserver(&b); | 889 observer_list.AddObserver(&b); |
890 add_observers = false; | 890 add_observers = false; |
891 } | 891 } |
892 } | 892 } |
893 | 893 |
894 EXPECT_EQ(12, a.total); | 894 EXPECT_EQ(12, a.total); |
895 EXPECT_EQ(-12, b.total); | 895 EXPECT_EQ(-12, b.total); |
896 } | 896 } |
897 | 897 |
898 TEST(ObserverListTest, AddObserverInTheLastObserve) { | |
danakj
2016/10/13 19:38:13
Why kill the test?
loyso (OOO)
2016/10/13 23:33:52
+1. Even without GetNext a user is able to write G
| |
899 using FooList = ObserverList<Foo>; | |
900 FooList observer_list; | |
901 | |
902 AddInObserve<FooList> a(&observer_list); | |
903 Adder b(-1); | |
904 | |
905 a.SetToAdd(&b); | |
906 observer_list.AddObserver(&a); | |
907 | |
908 FooList::Iterator it(&observer_list); | |
909 Foo* foo; | |
910 while ((foo = it.GetNext()) != nullptr) | |
911 foo->Observe(10); | |
912 | |
913 EXPECT_EQ(-10, b.total); | |
914 } | |
915 | |
916 } // namespace base | 898 } // namespace base |
OLD | NEW |