diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:53:51 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:53:51 +0000 |
commit | 6f0479fa6d498b8ba48c8b7cbcd507534fda610e (patch) | |
tree | ccd432f1d28d3535ec23c9d6330afbaede7420b6 /base/observer_list_unittest.cc | |
parent | 9a0d91236e8557d37498f002254a6a5427ebf842 (diff) | |
download | chromium_src-6f0479fa6d498b8ba48c8b7cbcd507534fda610e.zip chromium_src-6f0479fa6d498b8ba48c8b7cbcd507534fda610e.tar.gz chromium_src-6f0479fa6d498b8ba48c8b7cbcd507534fda610e.tar.bz2 |
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
Diffstat (limited to 'base/observer_list_unittest.cc')
-rw-r--r-- | base/observer_list_unittest.cc | 49 |
1 files changed, 2 insertions, 47 deletions
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<AddRemoveThread>* factory_; }; +} // namespace + TEST(ObserverListTest, BasicTest) { ObserverList<Foo> 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<Foo>* 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<Foo>* const list_; - - bool added_; - Adder adder_; -}; - -TEST(ObserverListTest, ClearNotifyAll) { - ObserverList<Foo> 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<Foo> observer_list(ObserverList<Foo>::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 |