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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 }; | 175 }; |
176 | 176 |
177 TEST(ObserverListTest, BasicTest) { | 177 TEST(ObserverListTest, BasicTest) { |
178 ObserverList<Foo> observer_list; | 178 ObserverList<Foo> observer_list; |
179 Adder a(1), b(-1), c(1), d(-1), e(-1); | 179 Adder a(1), b(-1), c(1), d(-1), e(-1); |
180 Disrupter evil(&observer_list, &c); | 180 Disrupter evil(&observer_list, &c); |
181 | 181 |
182 observer_list.AddObserver(&a); | 182 observer_list.AddObserver(&a); |
183 observer_list.AddObserver(&b); | 183 observer_list.AddObserver(&b); |
184 | 184 |
| 185 EXPECT_TRUE(observer_list.HasObserver(&a)); |
| 186 EXPECT_FALSE(observer_list.HasObserver(&c)); |
| 187 |
185 FOR_EACH_OBSERVER(Foo, observer_list, Observe(10)); | 188 FOR_EACH_OBSERVER(Foo, observer_list, Observe(10)); |
186 | 189 |
187 observer_list.AddObserver(&evil); | 190 observer_list.AddObserver(&evil); |
188 observer_list.AddObserver(&c); | 191 observer_list.AddObserver(&c); |
189 observer_list.AddObserver(&d); | 192 observer_list.AddObserver(&d); |
190 | 193 |
191 // Removing an observer not in the list should do nothing. | 194 // Removing an observer not in the list should do nothing. |
192 observer_list.RemoveObserver(&e); | 195 observer_list.RemoveObserver(&e); |
193 | 196 |
194 FOR_EACH_OBSERVER(Foo, observer_list, Observe(10)); | 197 FOR_EACH_OBSERVER(Foo, observer_list, Observe(10)); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 ListDestructor a(observer_list); | 534 ListDestructor a(observer_list); |
532 observer_list->AddObserver(&a); | 535 observer_list->AddObserver(&a); |
533 | 536 |
534 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); | 537 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); |
535 // If this test fails, there'll be Valgrind errors when this function goes out | 538 // If this test fails, there'll be Valgrind errors when this function goes out |
536 // of scope. | 539 // of scope. |
537 } | 540 } |
538 | 541 |
539 } // namespace | 542 } // namespace |
540 } // namespace base | 543 } // namespace base |
OLD | NEW |