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

Side by Side Diff: trunk/src/base/observer_list_unittest.cc

Issue 269893004: Revert 268203 "There are many ways to get it wrong." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 Adder a(1); 436 Adder a(1);
437 AddInObserve<ObserverList<Foo> > b(&observer_list); 437 AddInObserve<ObserverList<Foo> > b(&observer_list);
438 438
439 observer_list.AddObserver(&a); 439 observer_list.AddObserver(&a);
440 observer_list.AddObserver(&b); 440 observer_list.AddObserver(&b);
441 441
442 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); 442 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
443 443
444 EXPECT_TRUE(b.added); 444 EXPECT_TRUE(b.added);
445 // B's adder should not have been notified because it was added during 445 // B's adder should not have been notified because it was added during
446 // notification. 446 // notificaiton.
447 EXPECT_EQ(0, b.adder.total); 447 EXPECT_EQ(0, b.adder.total);
448 448
449 // Notify again to make sure b's adder is notified. 449 // Notify again to make sure b's adder is notified.
450 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); 450 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
451 EXPECT_EQ(1, b.adder.total); 451 EXPECT_EQ(1, b.adder.total);
452 } 452 }
453 453
454 // Same as above, but for ObserverListThreadSafe 454 // Same as above, but for ObserverListThreadSafe
455 TEST(ObserverListThreadSafeTest, Existing) { 455 TEST(ObserverListThreadSafeTest, Existing) {
456 MessageLoop loop; 456 MessageLoop loop;
457 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list( 457 scoped_refptr<ObserverListThreadSafe<Foo> > observer_list(
458 new ObserverListThreadSafe<Foo>(ObserverList<Foo>::NOTIFY_EXISTING_ONLY)); 458 new ObserverListThreadSafe<Foo>(ObserverList<Foo>::NOTIFY_EXISTING_ONLY));
459 Adder a(1); 459 Adder a(1);
460 AddInObserve<ObserverListThreadSafe<Foo> > b(observer_list.get()); 460 AddInObserve<ObserverListThreadSafe<Foo> > b(observer_list.get());
461 461
462 observer_list->AddObserver(&a); 462 observer_list->AddObserver(&a);
463 observer_list->AddObserver(&b); 463 observer_list->AddObserver(&b);
464 464
465 observer_list->Notify(&Foo::Observe, 1); 465 observer_list->Notify(&Foo::Observe, 1);
466 RunLoop().RunUntilIdle(); 466 RunLoop().RunUntilIdle();
467 467
468 EXPECT_TRUE(b.added); 468 EXPECT_TRUE(b.added);
469 // B's adder should not have been notified because it was added during 469 // B's adder should not have been notified because it was added during
470 // notification. 470 // notificaiton.
471 EXPECT_EQ(0, b.adder.total); 471 EXPECT_EQ(0, b.adder.total);
472 472
473 // Notify again to make sure b's adder is notified. 473 // Notify again to make sure b's adder is notified.
474 observer_list->Notify(&Foo::Observe, 1); 474 observer_list->Notify(&Foo::Observe, 1);
475 RunLoop().RunUntilIdle(); 475 RunLoop().RunUntilIdle();
476 EXPECT_EQ(1, b.adder.total); 476 EXPECT_EQ(1, b.adder.total);
477 } 477 }
478 478
479 class AddInClearObserve : public Foo { 479 class AddInClearObserve : public Foo {
480 public: 480 public:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 ListDestructor a(observer_list); 540 ListDestructor a(observer_list);
541 observer_list->AddObserver(&a); 541 observer_list->AddObserver(&a);
542 542
543 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0)); 543 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0));
544 // If this test fails, there'll be Valgrind errors when this function goes out 544 // If this test fails, there'll be Valgrind errors when this function goes out
545 // of scope. 545 // of scope.
546 } 546 }
547 547
548 } // namespace 548 } // namespace
549 } // namespace base 549 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698