| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 // the main thread. | 350 // the main thread. |
| 351 ThreadSafeObserverHarness(7, false); | 351 ThreadSafeObserverHarness(7, false); |
| 352 } | 352 } |
| 353 | 353 |
| 354 TEST(ObserverListThreadSafeTest, CrossThreadNotifications) { | 354 TEST(ObserverListThreadSafeTest, CrossThreadNotifications) { |
| 355 // Use 3 observer threads. Notifications will fire from | 355 // Use 3 observer threads. Notifications will fire from |
| 356 // the main thread and all 3 observer threads. | 356 // the main thread and all 3 observer threads. |
| 357 ThreadSafeObserverHarness(3, true); | 357 ThreadSafeObserverHarness(3, true); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST(ObserverListThreadSafeTest, OutlivesMessageLoop) { |
| 361 MessageLoop* loop = new MessageLoop; |
| 362 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list( |
| 363 new ObserverListThreadSafe<Foo>); |
| 364 |
| 365 Adder a(1); |
| 366 observer_list->AddObserver(&a); |
| 367 delete loop; |
| 368 // Test passes if we don't crash here. |
| 369 observer_list->Notify(&Foo::Observe, 1); |
| 370 } |
| 371 |
| 360 TEST(ObserverListTest, Existing) { | 372 TEST(ObserverListTest, Existing) { |
| 361 ObserverList<Foo> observer_list(ObserverList<Foo>::NOTIFY_EXISTING_ONLY); | 373 ObserverList<Foo> observer_list(ObserverList<Foo>::NOTIFY_EXISTING_ONLY); |
| 362 Adder a(1); | 374 Adder a(1); |
| 363 AddInObserve b(&observer_list); | 375 AddInObserve b(&observer_list); |
| 364 | 376 |
| 365 observer_list.AddObserver(&a); | 377 observer_list.AddObserver(&a); |
| 366 observer_list.AddObserver(&b); | 378 observer_list.AddObserver(&b); |
| 367 | 379 |
| 368 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); | 380 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); |
| 369 | 381 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 ObserverList<Foo>* observer_list = new ObserverList<Foo>; | 451 ObserverList<Foo>* observer_list = new ObserverList<Foo>; |
| 440 ListDestructor a(observer_list); | 452 ListDestructor a(observer_list); |
| 441 observer_list->AddObserver(&a); | 453 observer_list->AddObserver(&a); |
| 442 | 454 |
| 443 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); | 455 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); |
| 444 // If this test fails, there'll be Valgrind errors when this function goes out | 456 // If this test fails, there'll be Valgrind errors when this function goes out |
| 445 // of scope. | 457 // of scope. |
| 446 } | 458 } |
| 447 | 459 |
| 448 } // namespace | 460 } // namespace |
| OLD | NEW |