OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "components/dom_distiller/core/distilled_page_prefs.h" |
| 6 |
| 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" |
| 11 |
| 12 namespace dom_distiller { |
| 13 |
| 14 namespace { |
| 15 |
| 16 class TestingObserver : public DistilledPagePrefs::Observer { |
| 17 public: |
| 18 TestingObserver() : theme_(DistilledPagePrefs::Theme::LIGHT) {} |
| 19 |
| 20 virtual void OnChangeTheme(DistilledPagePrefs::Theme new_theme) OVERRIDE { |
| 21 theme_ = new_theme; |
| 22 } |
| 23 |
| 24 DistilledPagePrefs::Theme GetTheme() { return theme_; } |
| 25 |
| 26 private: |
| 27 DistilledPagePrefs::Theme theme_; |
| 28 }; |
| 29 |
| 30 } // namespace |
| 31 |
| 32 class DistilledPagePrefsTest : public testing::Test { |
| 33 protected: |
| 34 virtual void SetUp() OVERRIDE { |
| 35 user_prefs::TestingPrefServiceSyncable* pref_service = |
| 36 new user_prefs::TestingPrefServiceSyncable(); |
| 37 DistilledPagePrefs::RegisterProfilePrefs(pref_service->registry()); |
| 38 distilled_page_prefs_ = new DistilledPagePrefs(pref_service); |
| 39 } |
| 40 |
| 41 DistilledPagePrefs* distilled_page_prefs_; |
| 42 |
| 43 private: |
| 44 base::MessageLoop message_loop_; |
| 45 }; |
| 46 |
| 47 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { |
| 48 TestingObserver* obs = new TestingObserver(); |
| 49 distilled_page_prefs_->AddObserver(obs); |
| 50 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::SEPIA); |
| 51 EXPECT_EQ(DistilledPagePrefs::Theme::LIGHT, obs->GetTheme()); |
| 52 base::RunLoop().RunUntilIdle(); |
| 53 EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs->GetTheme()); |
| 54 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::DARK); |
| 55 base::RunLoop().RunUntilIdle(); |
| 56 EXPECT_EQ(DistilledPagePrefs::Theme::DARK, obs->GetTheme()); |
| 57 } |
| 58 |
| 59 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { |
| 60 TestingObserver* obs = new TestingObserver(); |
| 61 distilled_page_prefs_->AddObserver(obs); |
| 62 TestingObserver* obs2 = new TestingObserver(); |
| 63 distilled_page_prefs_->AddObserver(obs2); |
| 64 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::SEPIA); |
| 65 base::RunLoop().RunUntilIdle(); |
| 66 EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs->GetTheme()); |
| 67 EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs2->GetTheme()); |
| 68 distilled_page_prefs_->RemoveObserver(obs); |
| 69 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::LIGHT); |
| 70 base::RunLoop().RunUntilIdle(); |
| 71 EXPECT_EQ(DistilledPagePrefs::Theme::SEPIA, obs->GetTheme()); |
| 72 EXPECT_EQ(DistilledPagePrefs::Theme::LIGHT, obs2->GetTheme()); |
| 73 } |
| 74 |
| 75 } // namespace dom_distiller |
OLD | NEW |