OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "blimp/client/core/settings/settings.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "blimp/client/core/settings/settings_observer.h" | |
9 #include "blimp/client/core/settings/settings_prefs.h" | |
10 #include "blimp/client/core/switches/blimp_client_switches.h" | |
11 #include "components/prefs/testing_pref_service.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using testing::_; | |
16 | |
17 namespace blimp { | |
18 namespace client { | |
19 namespace { | |
20 | |
21 class MockSettingsObserver : public SettingsObserver { | |
22 public: | |
23 explicit MockSettingsObserver(Settings* settings) : settings_(settings) { | |
24 settings_->AddObserver(this); | |
25 } | |
26 ~MockSettingsObserver() { | |
27 if (settings_) { | |
28 settings_->RemoveObserver(this); | |
29 } | |
30 } | |
31 | |
32 MOCK_METHOD1(OnShowNetworkStatsChanged, void(bool)); | |
33 MOCK_METHOD1(OnBlimpModeEnabled, void(bool)); | |
34 MOCK_METHOD1(OnRecordWholeDocumentChanged, void(bool)); | |
35 MOCK_METHOD0(OnRestartRequired, void()); | |
36 | |
37 private: | |
38 Settings* settings_; | |
39 }; | |
40 | |
41 class SettingsTest : public testing::Test { | |
42 public: | |
43 SettingsTest() { Settings::RegisterPrefs(prefs.registry()); } | |
44 | |
45 ~SettingsTest() override = default; | |
46 | |
47 TestingPrefServiceSimple prefs; | |
48 | |
49 private: | |
50 DISALLOW_COPY_AND_ASSIGN(SettingsTest); | |
51 }; | |
52 | |
53 TEST_F(SettingsTest, TestSetShowNetworkStats) { | |
54 Settings settings(&prefs); | |
55 MockSettingsObserver observer(&settings); | |
56 | |
57 EXPECT_FALSE(settings.show_network_stats()); | |
58 | |
59 EXPECT_CALL(observer, OnShowNetworkStatsChanged(_)).Times(0); | |
60 settings.SetShowNetworkStats(false); | |
61 EXPECT_CALL(observer, OnShowNetworkStatsChanged(true)).Times(1); | |
62 settings.SetShowNetworkStats(true); | |
63 EXPECT_TRUE(settings.show_network_stats()); | |
64 } | |
65 | |
66 TEST_F(SettingsTest, TestSetEnableBlimpMode) { | |
67 Settings settings(&prefs); | |
68 MockSettingsObserver observer(&settings); | |
69 | |
70 EXPECT_FALSE(settings.IsBlimpEnabled()); | |
71 | |
72 EXPECT_CALL(observer, OnBlimpModeEnabled(true)).Times(1); | |
73 EXPECT_CALL(observer, OnRestartRequired()).Times(1); | |
74 settings.SetEnableBlimpMode(true); | |
75 EXPECT_TRUE(settings.IsBlimpEnabled()); | |
76 | |
77 EXPECT_CALL(observer, OnBlimpModeEnabled(_)).Times(0); | |
78 EXPECT_CALL(observer, OnRestartRequired()).Times(0); | |
79 settings.SetEnableBlimpMode(true); | |
80 } | |
81 | |
82 TEST_F(SettingsTest, TestSetRecordWholeDocument) { | |
83 Settings settings(&prefs); | |
84 MockSettingsObserver observer(&settings); | |
85 | |
86 EXPECT_FALSE(settings.IsRecordWholeDocument()); | |
87 | |
88 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(true)).Times(1); | |
89 settings.SetRecordWholeDocument(true); | |
90 EXPECT_TRUE(settings.IsRecordWholeDocument()); | |
91 | |
92 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(_)).Times(0); | |
93 settings.SetRecordWholeDocument(true); | |
94 } | |
95 | |
96 } // namespace | |
97 } // namespace client | |
98 } // namespace blimp | |
OLD | NEW |