diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 03:09:41 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 03:09:41 +0000 |
commit | 84aebedeaa91c3fadf523260c12afa136420c7d3 (patch) | |
tree | c5ca8ca0e7bd3f5dba957556cbb062851b4d7853 /base/observer_list_unittest.cc | |
parent | efeaf7e7f80c74b91aa87edbbb0ace868f3574a7 (diff) | |
download | chromium_src-84aebedeaa91c3fadf523260c12afa136420c7d3.zip chromium_src-84aebedeaa91c3fadf523260c12afa136420c7d3.tar.gz chromium_src-84aebedeaa91c3fadf523260c12afa136420c7d3.tar.bz2 |
Reland 39942 - Switch NetworkChangeNotifier implementations to use ObserverList.
Fixed build problem with database_tracker.(cc|h).
BUG=36590
Review URL: http://codereview.chromium.org/660039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39983 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, 47 insertions, 2 deletions
diff --git a/base/observer_list_unittest.cc b/base/observer_list_unittest.cc index 79af96a..6982d3d 100644 --- a/base/observer_list_unittest.cc +++ b/base/observer_list_unittest.cc @@ -172,8 +172,6 @@ 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); @@ -304,3 +302,50 @@ 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 |