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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 private: | 599 private: |
600 ObserverList<Foo>* list_; | 600 ObserverList<Foo>* list_; |
601 }; | 601 }; |
602 | 602 |
603 | 603 |
604 TEST(ObserverListTest, IteratorOutlivesList) { | 604 TEST(ObserverListTest, IteratorOutlivesList) { |
605 ObserverList<Foo>* observer_list = new ObserverList<Foo>; | 605 ObserverList<Foo>* observer_list = new ObserverList<Foo>; |
606 ListDestructor a(observer_list); | 606 ListDestructor a(observer_list); |
607 observer_list->AddObserver(&a); | 607 observer_list->AddObserver(&a); |
608 | 608 |
609 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); | 609 for (auto& observer : *observer_list) |
| 610 observer.Observe(0); |
610 // If this test fails, there'll be Valgrind errors when this function goes out | 611 // If this test fails, there'll be Valgrind errors when this function goes out |
611 // of scope. | 612 // of scope. |
612 } | 613 } |
613 | 614 |
614 TEST(ObserverListTest, BasicStdIterator) { | 615 TEST(ObserverListTest, BasicStdIterator) { |
615 using FooList = ObserverList<Foo>; | 616 using FooList = ObserverList<Foo>; |
616 FooList observer_list; | 617 FooList observer_list; |
617 | 618 |
618 // An optimization: begin() and end() do not involve weak pointers on | 619 // An optimization: begin() and end() do not involve weak pointers on |
619 // empty list. | 620 // empty list. |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 // However, the first Observe() call will add a second observer: at this | 926 // However, the first Observe() call will add a second observer: at this |
926 // point, it != observer_list.end() should be true, and Observe() should be | 927 // point, it != observer_list.end() should be true, and Observe() should be |
927 // called on the newly added observer on the next iteration of the loop. | 928 // called on the newly added observer on the next iteration of the loop. |
928 observer.Observe(10); | 929 observer.Observe(10); |
929 } | 930 } |
930 | 931 |
931 EXPECT_EQ(-10, b.total); | 932 EXPECT_EQ(-10, b.total); |
932 } | 933 } |
933 | 934 |
934 } // namespace base | 935 } // namespace base |
OLD | NEW |