Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: components/dom_distiller/core/distilled_page_prefs_unittests.cc

Issue 341563002: Theme Preferences for Distilled Pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor changes to tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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::kLight) {}
19
20 virtual void OnChangeTheme(DistilledPagePrefs::Theme new_theme) OVERRIDE {
21 theme_ = new_theme;
22 }
23
24 DistilledPagePrefs::Theme GetTheme() {
25 return theme_;
26 }
27
28 private:
29 DistilledPagePrefs::Theme theme_;
30 };
31
32 } // namespace
33
34 class DistilledPagePrefsTest : public testing::Test {
35 protected:
36 virtual void SetUp() OVERRIDE {
37 user_prefs::TestingPrefServiceSyncable* pref_service =
38 new user_prefs::TestingPrefServiceSyncable();
39 DistilledPagePrefs::RegisterProfilePrefs(pref_service->registry());
40 distilled_page_prefs_ = new DistilledPagePrefs(pref_service);
41 }
42
43 DistilledPagePrefs* distilled_page_prefs_;
44
45 private:
46 base::MessageLoop message_loop_;
47 };
48
49 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) {
50 TestingObserver* obs = new TestingObserver();
51 distilled_page_prefs_->AddObserver(obs);
52 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kSepia);
53 EXPECT_EQ(DistilledPagePrefs::Theme::kLight, obs->GetTheme());
54 base::RunLoop().RunUntilIdle();
55 EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme());
56 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kDark);
57 base::RunLoop().RunUntilIdle();
58 EXPECT_EQ(DistilledPagePrefs::Theme::kDark, obs->GetTheme());
59 }
60
61 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) {
62 TestingObserver* obs = new TestingObserver();
63 distilled_page_prefs_->AddObserver(obs);
64 TestingObserver* obs2 = new TestingObserver();
65 distilled_page_prefs_->AddObserver(obs2);
66 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kSepia);
67 base::RunLoop().RunUntilIdle();
68 EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme());
69 EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs2->GetTheme());
70 distilled_page_prefs_->RemoveObserver(obs);
71 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kLight);
72 base::RunLoop().RunUntilIdle();
73 EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme());
74 EXPECT_EQ(DistilledPagePrefs::Theme::kLight, obs2->GetTheme());
75 }
76
77 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698