Chromium Code Reviews| 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" |
| 11 | 11 |
| 12 namespace dom_distiller { | 12 namespace dom_distiller { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class TestingObserver : public DistilledPagePrefs::Observer { | 16 class TestingObserver : public DistilledPagePrefs::Observer { |
| 17 public: | 17 public: |
| 18 TestingObserver() : theme_(DistilledPagePrefs::LIGHT) {} | 18 TestingObserver() |
| 19 : font_(DistilledPagePrefs::SANS_SERIF), | |
| 20 theme_(DistilledPagePrefs::LIGHT) {} | |
| 21 | |
| 22 virtual void OnChangeFontFamily( | |
| 23 DistilledPagePrefs::FontFamily new_font) OVERRIDE { | |
| 24 font_ = new_font; | |
| 25 } | |
| 26 DistilledPagePrefs::FontFamily GetFontFamily() { return font_; } | |
|
robliao
2014/08/10 02:43:45
Linebreak above here.
sunangel
2014/08/11 21:51:33
Done.
| |
| 19 | 27 |
| 20 virtual void OnChangeTheme(DistilledPagePrefs::Theme new_theme) OVERRIDE { | 28 virtual void OnChangeTheme(DistilledPagePrefs::Theme new_theme) OVERRIDE { |
| 21 theme_ = new_theme; | 29 theme_ = new_theme; |
| 22 } | 30 } |
| 23 | |
| 24 DistilledPagePrefs::Theme GetTheme() { return theme_; } | 31 DistilledPagePrefs::Theme GetTheme() { return theme_; } |
| 25 | 32 |
| 26 private: | 33 private: |
| 34 DistilledPagePrefs::FontFamily font_; | |
| 27 DistilledPagePrefs::Theme theme_; | 35 DistilledPagePrefs::Theme theme_; |
| 28 }; | 36 }; |
| 29 | 37 |
| 30 } // namespace | 38 } // namespace |
| 31 | 39 |
| 32 class DistilledPagePrefsTest : public testing::Test { | 40 class DistilledPagePrefsTest : public testing::Test { |
| 33 protected: | 41 protected: |
| 34 virtual void SetUp() OVERRIDE { | 42 virtual void SetUp() OVERRIDE { |
| 35 pref_service_.reset(new user_prefs::TestingPrefServiceSyncable()); | 43 pref_service_.reset(new user_prefs::TestingPrefServiceSyncable()); |
| 36 DistilledPagePrefs::RegisterProfilePrefs(pref_service_->registry()); | 44 DistilledPagePrefs::RegisterProfilePrefs(pref_service_->registry()); |
| 37 distilled_page_prefs_.reset(new DistilledPagePrefs(pref_service_.get())); | 45 distilled_page_prefs_.reset(new DistilledPagePrefs(pref_service_.get())); |
| 38 } | 46 } |
| 39 | 47 |
| 40 scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; | 48 scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_; |
| 41 scoped_ptr<DistilledPagePrefs> distilled_page_prefs_; | 49 scoped_ptr<DistilledPagePrefs> distilled_page_prefs_; |
| 42 | 50 |
| 43 private: | 51 private: |
| 44 base::MessageLoop message_loop_; | 52 base::MessageLoop message_loop_; |
| 45 }; | 53 }; |
| 46 | 54 |
| 55 TEST_F(DistilledPagePrefsTest, TestingOnChangeFontIsBeingCalled) { | |
| 56 TestingObserver obs; | |
| 57 distilled_page_prefs_->AddObserver(&obs); | |
| 58 distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::MONOSPACE); | |
| 59 EXPECT_EQ(DistilledPagePrefs::SANS_SERIF, obs.GetFontFamily()); | |
| 60 base::RunLoop().RunUntilIdle(); | |
| 61 EXPECT_EQ(DistilledPagePrefs::MONOSPACE, obs.GetFontFamily()); | |
| 62 distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::SERIF); | |
| 63 base::RunLoop().RunUntilIdle(); | |
| 64 EXPECT_EQ(DistilledPagePrefs::SERIF, obs.GetFontFamily()); | |
| 65 distilled_page_prefs_->RemoveObserver(&obs); | |
| 66 } | |
| 67 | |
| 68 TEST_F(DistilledPagePrefsTest, TestingMultipleObserversFont) { | |
| 69 TestingObserver obs; | |
| 70 distilled_page_prefs_->AddObserver(&obs); | |
| 71 TestingObserver obs2; | |
| 72 distilled_page_prefs_->AddObserver(&obs2); | |
| 73 distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::SERIF); | |
| 74 base::RunLoop().RunUntilIdle(); | |
| 75 EXPECT_EQ(DistilledPagePrefs::SERIF, obs.GetFontFamily()); | |
| 76 EXPECT_EQ(DistilledPagePrefs::SERIF, obs2.GetFontFamily()); | |
| 77 distilled_page_prefs_->RemoveObserver(&obs); | |
| 78 distilled_page_prefs_->SetFontFamily(DistilledPagePrefs::MONOSPACE); | |
| 79 base::RunLoop().RunUntilIdle(); | |
| 80 EXPECT_EQ(DistilledPagePrefs::SERIF, obs.GetFontFamily()); | |
| 81 EXPECT_EQ(DistilledPagePrefs::MONOSPACE, obs2.GetFontFamily()); | |
| 82 distilled_page_prefs_->RemoveObserver(&obs2); | |
| 83 } | |
| 84 | |
| 47 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { | 85 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { |
| 48 TestingObserver obs; | 86 TestingObserver obs; |
| 49 distilled_page_prefs_->AddObserver(&obs); | 87 distilled_page_prefs_->AddObserver(&obs); |
| 50 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); | 88 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); |
| 51 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs.GetTheme()); | 89 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs.GetTheme()); |
| 52 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
| 53 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); | 91 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); |
| 54 distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK); | 92 distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK); |
| 55 base::RunLoop().RunUntilIdle(); | 93 base::RunLoop().RunUntilIdle(); |
| 56 EXPECT_EQ(DistilledPagePrefs::DARK, obs.GetTheme()); | 94 EXPECT_EQ(DistilledPagePrefs::DARK, obs.GetTheme()); |
| 57 distilled_page_prefs_->RemoveObserver(&obs); | 95 distilled_page_prefs_->RemoveObserver(&obs); |
| 58 } | 96 } |
| 59 | 97 |
| 60 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { | 98 TEST_F(DistilledPagePrefsTest, TestingMultipleObserversTheme) { |
| 61 TestingObserver obs; | 99 TestingObserver obs; |
| 62 distilled_page_prefs_->AddObserver(&obs); | 100 distilled_page_prefs_->AddObserver(&obs); |
| 63 TestingObserver obs2; | 101 TestingObserver obs2; |
| 64 distilled_page_prefs_->AddObserver(&obs2); | 102 distilled_page_prefs_->AddObserver(&obs2); |
| 65 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); | 103 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA); |
| 66 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 67 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); | 105 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); |
| 68 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme()); | 106 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme()); |
| 69 distilled_page_prefs_->RemoveObserver(&obs); | 107 distilled_page_prefs_->RemoveObserver(&obs); |
| 70 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); | 108 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT); |
| 71 base::RunLoop().RunUntilIdle(); | 109 base::RunLoop().RunUntilIdle(); |
| 72 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); | 110 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme()); |
| 73 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme()); | 111 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme()); |
| 74 distilled_page_prefs_->RemoveObserver(&obs2); | 112 distilled_page_prefs_->RemoveObserver(&obs2); |
| 75 } | 113 } |
| 76 | 114 |
| 77 } // namespace dom_distiller | 115 } // namespace dom_distiller |
| OLD | NEW |