Commit 9ca51ef7 authored by smaslo@chromium.org's avatar smaslo@chromium.org

Fixing memory leak in DistilledPagePrefs unittests

Bug was introduced in r283303.

BUG=383630

Review URL: https://codereview.chromium.org/394973004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283716 0039d316-1c4b-4281-b951-d872f2087c98
parent 7b47431a
...@@ -32,44 +32,46 @@ class TestingObserver : public DistilledPagePrefs::Observer { ...@@ -32,44 +32,46 @@ class TestingObserver : public DistilledPagePrefs::Observer {
class DistilledPagePrefsTest : public testing::Test { class DistilledPagePrefsTest : public testing::Test {
protected: protected:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
user_prefs::TestingPrefServiceSyncable* pref_service = pref_service_.reset(new user_prefs::TestingPrefServiceSyncable());
new user_prefs::TestingPrefServiceSyncable(); DistilledPagePrefs::RegisterProfilePrefs(pref_service_->registry());
DistilledPagePrefs::RegisterProfilePrefs(pref_service->registry()); distilled_page_prefs_.reset(new DistilledPagePrefs(pref_service_.get()));
distilled_page_prefs_ = new DistilledPagePrefs(pref_service);
} }
DistilledPagePrefs* distilled_page_prefs_; scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_;
scoped_ptr<DistilledPagePrefs> distilled_page_prefs_;
private: private:
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
}; };
TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) {
TestingObserver* obs = new TestingObserver(); TestingObserver obs;
distilled_page_prefs_->AddObserver(obs); distilled_page_prefs_->AddObserver(&obs);
distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA);
EXPECT_EQ(DistilledPagePrefs::LIGHT, obs->GetTheme()); EXPECT_EQ(DistilledPagePrefs::LIGHT, obs.GetTheme());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK); distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::DARK, obs->GetTheme()); EXPECT_EQ(DistilledPagePrefs::DARK, obs.GetTheme());
distilled_page_prefs_->RemoveObserver(&obs);
} }
TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) {
TestingObserver* obs = new TestingObserver(); TestingObserver obs;
distilled_page_prefs_->AddObserver(obs); distilled_page_prefs_->AddObserver(&obs);
TestingObserver* obs2 = new TestingObserver(); TestingObserver obs2;
distilled_page_prefs_->AddObserver(obs2); distilled_page_prefs_->AddObserver(&obs2);
distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2->GetTheme()); EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme());
distilled_page_prefs_->RemoveObserver(obs); distilled_page_prefs_->RemoveObserver(&obs);
distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2->GetTheme()); EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme());
distilled_page_prefs_->RemoveObserver(&obs2);
} }
} // namespace dom_distiller } // namespace dom_distiller
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment