| OLD | NEW |
| 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 Loading... |
| 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<user_prefs::TestingPrefServiceSyncable> pref_service_; |
| 41 scoped_ptr<DistilledPagePrefs> distilled_page_prefs_; |
| 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; |
| 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 distilled_page_prefs_->RemoveObserver(&obs); |
| 57 } | 58 } |
| 58 | 59 |
| 59 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { | 60 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { |
| 60 TestingObserver* obs = new TestingObserver(); | 61 TestingObserver obs; |
| 61 distilled_page_prefs_->AddObserver(obs); | 62 distilled_page_prefs_->AddObserver(&obs); |
| 62 TestingObserver* obs2 = new TestingObserver(); | 63 TestingObserver obs2; |
| 63 distilled_page_prefs_->AddObserver(obs2); | 64 distilled_page_prefs_->AddObserver(&obs2); |
| 64 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); | 65 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); |
| 65 base::RunLoop().RunUntilIdle(); | 66 base::RunLoop().RunUntilIdle(); |
| 66 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); | 67 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); |
| 67 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2->GetTheme()); | 68 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme()); |
| 68 distilled_page_prefs_->RemoveObserver(obs); | 69 distilled_page_prefs_->RemoveObserver(&obs); |
| 69 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); | 70 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); |
| 70 base::RunLoop().RunUntilIdle(); | 71 base::RunLoop().RunUntilIdle(); |
| 71 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs->GetTheme()); | 72 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); |
| 72 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2->GetTheme()); | 73 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme()); |
| 74 distilled_page_prefs_->RemoveObserver(&obs2); |
| 73 } | 75 } |
| 74 | 76 |
| 75 } // namespace dom_distiller | 77 } // namespace dom_distiller |
| OLD | NEW |