From 6f0479fa6d498b8ba48c8b7cbcd507534fda610e Mon Sep 17 00:00:00 2001 From: "willchan@chromium.org" Date: Wed, 24 Feb 2010 22:53:51 +0000 Subject: Revert 39942 - Switch NetworkChangeNotifier implementations to use ObserverList. Fix up observer list so we can use FOR_EACH_OBSERVER when check_empty is set. Clean up the ObserverList API a bit, replacing GetElementAt() with HasObserver() and Clear(). BUG=36590 Review URL: http://codereview.chromium.org/652205 TBR=willchan@chromium.org Review URL: http://codereview.chromium.org/661029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39945 0039d316-1c4b-4281-b951-d872f2087c98 --- base/observer_list_unittest.cc | 49 ++---------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'base/observer_list_unittest.cc') diff --git a/base/observer_list_unittest.cc b/base/observer_list_unittest.cc index 6982d3d..79af96a 100644 --- a/base/observer_list_unittest.cc +++ b/base/observer_list_unittest.cc @@ -172,6 +172,8 @@ class AddRemoveThread : public PlatformThread::Delegate, ScopedRunnableMethodFactory* factory_; }; +} // namespace + TEST(ObserverListTest, BasicTest) { ObserverList observer_list; Adder a(1), b(-1), c(1), d(-1); @@ -302,50 +304,3 @@ TEST(ObserverListTest, Existing) { FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); EXPECT_EQ(1, b.adder.total); } - -class AddInClearObserve : public Foo { - public: - explicit AddInClearObserve(ObserverList* list) - : list_(list), added_(false), adder_(1) {} - - virtual void Observe(int /* x */) { - list_->Clear(); - list_->AddObserver(&adder_); - added_ = true; - } - - bool added() const { return added_; } - const Adder& adder() const { return adder_; } - - private: - ObserverList* const list_; - - bool added_; - Adder adder_; -}; - -TEST(ObserverListTest, ClearNotifyAll) { - ObserverList observer_list; - AddInClearObserve a(&observer_list); - - observer_list.AddObserver(&a); - - FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); - EXPECT_TRUE(a.added()); - EXPECT_EQ(1, a.adder().total) - << "Adder should observe once and have sum of 1."; -} - -TEST(ObserverListTest, ClearNotifyExistingOnly) { - ObserverList observer_list(ObserverList::NOTIFY_EXISTING_ONLY); - AddInClearObserve a(&observer_list); - - observer_list.AddObserver(&a); - - FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); - EXPECT_TRUE(a.added()); - EXPECT_EQ(0, a.adder().total) - << "Adder should not observe, so sum should still be 0."; -} - -} // namespace -- cgit v1.1