Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / dom_distiller / core / distilled_page_prefs_unittests.cc
blobfe9df73096afb6455f84eb04f7ed923707b2b16a
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
3 // found in the LICENSE file.
5 #include "components/dom_distiller/core/distilled_page_prefs.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "components/pref_registry/testing_pref_service_syncable.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace dom_distiller {
14 namespace {
16 class TestingObserver : public DistilledPagePrefs::Observer {
17 public:
18 TestingObserver()
19 : font_(DistilledPagePrefs::SANS_SERIF),
20 theme_(DistilledPagePrefs::LIGHT) {}
22 virtual void OnChangeFontFamily(
23 DistilledPagePrefs::FontFamily new_font) OVERRIDE {
24 font_ = new_font;
27 DistilledPagePrefs::FontFamily GetFontFamily() { return font_; }
29 virtual void OnChangeTheme(DistilledPagePrefs::Theme new_theme) OVERRIDE {
30 theme_ = new_theme;
33 DistilledPagePrefs::Theme GetTheme() { return theme_; }
35 private:
36 DistilledPagePrefs::FontFamily font_;
37 DistilledPagePrefs::Theme theme_;
40 } // namespace
42 class DistilledPagePrefsTest : public testing::Test {
43 protected:
44 virtual void SetUp() OVERRIDE {
45 pref_service_.reset(new user_prefs::TestingPrefServiceSyncable());
46 DistilledPagePrefs::RegisterProfilePrefs(pref_service_->registry());
47 distilled_page_prefs_.reset(new DistilledPagePrefs(pref_service_.get()));
50 scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_;
51 scoped_ptr<DistilledPagePrefs> distilled_page_prefs_;
53 private:
54 base::MessageLoop message_loop_;
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);
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);
87 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) {
88 TestingObserver obs;
89 distilled_page_prefs_->AddObserver(&obs);
90 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA);
91 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs.GetTheme());
92 base::RunLoop().RunUntilIdle();
93 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
94 distilled_page_prefs_->SetTheme(DistilledPagePrefs::DARK);
95 base::RunLoop().RunUntilIdle();
96 EXPECT_EQ(DistilledPagePrefs::DARK, obs.GetTheme());
97 distilled_page_prefs_->RemoveObserver(&obs);
100 TEST_F(DistilledPagePrefsTest, TestingMultipleObserversTheme) {
101 TestingObserver obs;
102 distilled_page_prefs_->AddObserver(&obs);
103 TestingObserver obs2;
104 distilled_page_prefs_->AddObserver(&obs2);
105 distilled_page_prefs_->SetTheme(DistilledPagePrefs::SEPIA);
106 base::RunLoop().RunUntilIdle();
107 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
108 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs2.GetTheme());
109 distilled_page_prefs_->RemoveObserver(&obs);
110 distilled_page_prefs_->SetTheme(DistilledPagePrefs::LIGHT);
111 base::RunLoop().RunUntilIdle();
112 EXPECT_EQ(DistilledPagePrefs::SEPIA, obs.GetTheme());
113 EXPECT_EQ(DistilledPagePrefs::LIGHT, obs2.GetTheme());
114 distilled_page_prefs_->RemoveObserver(&obs2);
117 } // namespace dom_distiller