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

Side by Side Diff: components/dom_distiller/core/distilled_page_prefs_unittests.cc

Issue 394973004: Fixing memory leak in DistilledPagePrefs unittests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/dom_distiller/core/distilled_page_prefs.h" 5 #include "components/dom_distiller/core/distilled_page_prefs.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "components/pref_registry/testing_pref_service_syncable.h" 9 #include "components/pref_registry/testing_pref_service_syncable.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 14 matching lines...) Expand all
25 25
26 private: 26 private:
27 DistilledPagePrefs::Theme theme_; 27 DistilledPagePrefs::Theme theme_;
28 }; 28 };
29 29
30 } // namespace 30 } // namespace
31 31
32 class DistilledPagePrefsTest : public testing::Test { 32 class DistilledPagePrefsTest : public testing::Test {
33 protected: 33 protected:
34 virtual void SetUp() OVERRIDE { 34 virtual void SetUp() OVERRIDE {
35 user_prefs::TestingPrefServiceSyncable* pref_service = 35 pref_service_.reset(new user_prefs::TestingPrefServiceSyncable());
36 new user_prefs::TestingPrefServiceSyncable(); 36 DistilledPagePrefs::RegisterProfilePrefs(pref_service_->registry());
37 DistilledPagePrefs::RegisterProfilePrefs(pref_service->registry()); 37 distilled_page_prefs_.reset(new DistilledPagePrefs(pref_service_.get()));
38 distilled_page_prefs_ = new DistilledPagePrefs(pref_service);
39 } 38 }
40 39
41 DistilledPagePrefs* distilled_page_prefs_; 40 scoped_ptr<DistilledPagePrefs> distilled_page_prefs_;
nyquist 2014/07/16 16:10:53 I think the ordering of these two needs to be swap
smaslo 2014/07/16 16:12:51 Done.
41 scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_;
42 42
43 private: 43 private:
44 base::MessageLoop message_loop_; 44 base::MessageLoop message_loop_;
45 }; 45 };
46 46
47 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { 47 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) {
48 TestingObserver* obs = new TestingObserver(); 48 TestingObserver obs;
nyquist 2014/07/16 16:02:57 Remove this as an observer here and in the test be
smaslo 2014/07/16 16:06:50 Done.
49 distilled_page_prefs_->AddObserver(obs); 49 distilled_page_prefs_->AddObserver(&obs);
50 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); 50 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA);
51 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs->GetTheme()); 51 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs.GetTheme());
52 base::RunLoop().RunUntilIdle(); 52 base::RunLoop().RunUntilIdle();
53 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); 53 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
54 distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK); 54 distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK);
55 base::RunLoop().RunUntilIdle(); 55 base::RunLoop().RunUntilIdle();
56 EXPECT_EQ(DistilledPagePrefs::DARK, obs->GetTheme()); 56 EXPECT_EQ(DistilledPagePrefs::DARK, obs.GetTheme());
57 } 57 }
58 58
59 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { 59 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) {
60 TestingObserver* obs = new TestingObserver(); 60 TestingObserver obs;
61 distilled_page_prefs_->AddObserver(obs); 61 distilled_page_prefs_->AddObserver(&obs);
62 TestingObserver* obs2 = new TestingObserver(); 62 TestingObserver obs2;
63 distilled_page_prefs_->AddObserver(obs2); 63 distilled_page_prefs_->AddObserver(&obs2);
64 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); 64 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA);
65 base::RunLoop().RunUntilIdle(); 65 base::RunLoop().RunUntilIdle();
66 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); 66 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
67 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2->GetTheme()); 67 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme());
68 distilled_page_prefs_->RemoveObserver(obs); 68 distilled_page_prefs_->RemoveObserver(&obs);
69 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); 69 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT);
70 base::RunLoop().RunUntilIdle(); 70 base::RunLoop().RunUntilIdle();
71 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); 71 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
72 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2->GetTheme()); 72 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme());
73 } 73 }
74 74
75 } // namespace dom_distiller 75 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698