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