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

Side by Side Diff: blimp/client/core/settings/settings_unittest.cc

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: move the PrefService logic from blimp_main.cc Created 4 years, 1 month 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
OLDNEW
(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)
24 :settings_(settings) {
25 settings_->AddObserver(this);
26 }
27 ~MockSettingsObserver() {
28 if (settings_) {
29 settings_->RemoveObserver(this);
30 }
31 }
32
33 MOCK_METHOD1(OnShowNetworkStatsChanged, void(bool));
34 MOCK_METHOD1(OnBlimpModeEnabled, void(bool));
35 MOCK_METHOD1(OnRecordWholeDocumentChanged, void(bool));
36 MOCK_METHOD0(OnRestartRequired, void());
37
38 private:
39 Settings* settings_;
40 };
41
42 class SettingsTest : public testing::Test {
43 public:
44 SettingsTest() {
45 Settings::RegisterPrefs(prefs.registry());
46 }
47
48 ~SettingsTest() override = default;
49
50 TestingPrefServiceSimple prefs;
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
54 };
55
56 TEST_F(SettingsTest, TestSetShowNetworkStats) {
57 Settings settings(&prefs);
58 MockSettingsObserver observer(&settings);
59
60 EXPECT_FALSE(settings.show_network_stats());
61
62 EXPECT_CALL(observer, OnShowNetworkStatsChanged(_)). Times(0);
63 settings.SetShowNetworkStats(false);
64 EXPECT_CALL(observer, OnShowNetworkStatsChanged(true)). Times(1);
65 settings.SetShowNetworkStats(true);
66 EXPECT_TRUE(settings.show_network_stats());
67 }
68
69 TEST_F(SettingsTest, TestSetEnableBlimpMode) {
70 Settings settings(&prefs);
71 MockSettingsObserver observer(&settings);
72
73 EXPECT_FALSE(settings.IsBlimpEnabled());
74
75 EXPECT_CALL(observer, OnBlimpModeEnabled(true)). Times(1);
76 EXPECT_CALL(observer, OnRestartRequired()). Times(1);
77 settings.SetEnableBlimpMode(true);
78 EXPECT_TRUE(settings.IsBlimpEnabled());
79
80 EXPECT_CALL(observer, OnBlimpModeEnabled(_)). Times(0);
81 EXPECT_CALL(observer, OnRestartRequired()). Times(0);
82 settings.SetEnableBlimpMode(true);
83 }
84
85 TEST_F(SettingsTest, TestSetRecordWholeDocument) {
86 Settings settings(&prefs);
87 MockSettingsObserver observer(&settings);
88
89 EXPECT_FALSE(settings.IsRecordWholeDocument());
90
91 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(true)). Times(1);
92 settings.SetRecordWholeDocument(true);
93 EXPECT_TRUE(settings.IsRecordWholeDocument());
94
95 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(_)). Times(0);
96 settings.SetRecordWholeDocument(true);
97 }
98
99 } // namespace
100 } // namespace client
101 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698