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 { | |
nyquist
2014/07/07 19:12:49
I think you can end this namespace after the obser
smaslo
2014/07/08 19:58:11
Done.
| |
15 | |
16 void RunLoop() { | |
nyquist
2014/07/07 19:12:49
Could you inline this to base::RunLoop().RunUntilI
smaslo
2014/07/08 19:58:11
Done.
| |
17 base::RunLoop run_loop; | |
18 run_loop.RunUntilIdle(); | |
19 } | |
20 | |
21 class TestingObserver | |
22 : public DistilledPagePrefs::Observer { | |
nyquist
2014/07/07 19:12:49
Nit: Does this really need to be on its own line?
smaslo
2014/07/08 19:58:11
Done.
| |
23 public: | |
24 virtual void OnChangeTheme(DistilledPagePrefs::Theme) OVERRIDE; | |
nyquist
2014/07/07 19:12:48
I think this method and GetTheme can probably just
smaslo
2014/07/08 19:58:11
Done.
| |
25 DistilledPagePrefs::Theme GetTheme(); | |
nyquist
2014/07/07 19:12:49
How about adding using DistilledPagePrefs::Observe
smaslo
2014/07/08 19:58:11
Could not add "using DistilledPagePrefs::Theme;" b
| |
26 | |
27 private: | |
28 DistilledPagePrefs::Theme theme; | |
nyquist
2014/07/07 19:12:48
theme_
smaslo
2014/07/08 19:58:11
Done.
| |
29 }; | |
30 | |
31 void TestingObserver::OnChangeTheme( | |
nyquist
2014/07/07 19:12:48
same line after adding 'using'?
smaslo
2014/07/08 19:58:11
Done.
| |
32 DistilledPagePrefs::Theme new_theme) { | |
33 theme = new_theme; | |
34 } | |
35 | |
36 DistilledPagePrefs::Theme TestingObserver::GetTheme() { | |
37 return theme; | |
38 } | |
39 | |
40 class DistilledPagePrefsTest : public testing::Test { | |
41 protected: | |
42 virtual void SetUp() OVERRIDE { | |
43 user_prefs::TestingPrefServiceSyncable* pref_service = | |
44 new user_prefs::TestingPrefServiceSyncable(); | |
45 DistilledPagePrefs::RegisterProfilePrefs(pref_service->registry()); | |
46 distilled_page_prefs_ = new DistilledPagePrefs(pref_service); | |
47 } | |
48 | |
49 DistilledPagePrefs* distilled_page_prefs_; | |
50 | |
51 private: | |
52 base::MessageLoop message_loop_; | |
53 }; | |
54 | |
55 TEST_F(DistilledPagePrefsTest, TestingOnChangeThemeIsBeingCalled) { | |
56 TestingObserver* obs = new TestingObserver(); | |
57 distilled_page_prefs_->AddObserver(obs); | |
58 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kLight); | |
59 RunLoop(); | |
nyquist
2014/07/07 19:12:49
Add an EXPECT_EQ("", ...) before the call to RunLo
smaslo
2014/07/08 19:58:11
Done. Constructor for TestingObserver now initiali
| |
60 EXPECT_EQ(DistilledPagePrefs::Theme::kLight, obs->GetTheme()); | |
61 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kDark); | |
62 RunLoop(); | |
63 EXPECT_EQ(DistilledPagePrefs::Theme::kDark, obs->GetTheme()); | |
64 } | |
65 | |
66 TEST_F(DistilledPagePrefsTest, TestingMultipleObservers) { | |
nyquist
2014/07/07 19:12:48
This is not currently testing multiple observers,
smaslo
2014/07/08 19:58:11
Done.
| |
67 TestingObserver* obs = new TestingObserver(); | |
68 distilled_page_prefs_->AddObserver(obs); | |
69 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kSepia); | |
nyquist
2014/07/07 19:12:49
This has already been tested in the method above.
smaslo
2014/07/08 19:58:11
Done.
| |
70 RunLoop(); | |
71 EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme()); | |
72 distilled_page_prefs_->RemoveObserver(obs); | |
73 distilled_page_prefs_->SetTheme(DistilledPagePrefs::Theme::kLight); | |
74 RunLoop(); | |
75 EXPECT_EQ(DistilledPagePrefs::Theme::kSepia, obs->GetTheme()); | |
76 } | |
77 | |
78 } // namespace | |
79 | |
80 } // namespace dom_distiller | |
OLD | NEW |