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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: Remove OnRecordWholeDocumentChanged from SettingsObserver and SettingsFeature Created 4 years, 2 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
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(OnBlimpModeEnabled, void(bool));
34 MOCK_METHOD1(OnShowNetworkStatsChanged, 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() {
44 Settings::RegisterPrefs(prefs.registry());
45 }
46
47 ~SettingsTest() override = default;
48
49 TestingPrefServiceSimple prefs;
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
53 };
54
55 TEST_F(SettingsTest, TestSetShowNetworkStats) {
56 Settings settings(&prefs);
57 MockSettingsObserver observer(&settings);
58
59 EXPECT_FALSE(settings.show_network_stats());
60
61 EXPECT_CALL(observer, OnShowNetworkStatsChanged(_)). Times(0);
62 settings.SetShowNetworkStats(false);
63 EXPECT_CALL(observer, OnShowNetworkStatsChanged(true)). Times(1);
64 settings.SetShowNetworkStats(true);
65 }
66
67 TEST_F(SettingsTest, TestSetEnableBlimpMode) {
68 Settings settings(&prefs);
69 MockSettingsObserver observer(&settings);
70
71 EXPECT_FALSE(settings.blimp_enabled());
72
73 EXPECT_FALSE(prefs.GetBoolean(prefs::kBlimpEnabled));
74
75 EXPECT_CALL(observer, OnRestartRequired()).Times(0);
76 EXPECT_CALL(observer, OnBlimpModeEnabled(_)).Times(0);
77 settings.SetEnableBlimpMode(false);
78
79 EXPECT_CALL(observer, OnRestartRequired()).Times(1);
80 EXPECT_CALL(observer, OnBlimpModeEnabled(true)).Times(1);
81 settings.SetEnableBlimpMode(true);
82 EXPECT_TRUE(prefs.GetBoolean(prefs::kBlimpEnabled));
83 }
84
85 TEST_F(SettingsTest, TestSetRecordWholeDocument) {
86 Settings settings(&prefs);
87 MockSettingsObserver observer(&settings);
88
89 EXPECT_FALSE(settings.record_whole_document());
90
91 EXPECT_FALSE(prefs.GetBoolean(prefs::kRecordWholeDocument));
92
93 EXPECT_CALL(observer, OnRestartRequired()).Times(0);
94 settings.SetRecordWholeDocument(false);
95
96 EXPECT_CALL(observer, OnRestartRequired()).Times(1);
97 settings.SetRecordWholeDocument(true);
98 EXPECT_TRUE(prefs.GetBoolean(prefs::kRecordWholeDocument));
99 }
100
101 TEST_F(SettingsTest, TestSettingsConstructor) {
102 auto* cmd_line = base::CommandLine::ForCurrentProcess();
103 cmd_line->AppendSwitch(switches::kEnableBlimp);
104 cmd_line->AppendSwitch(switches::kDownloadWholeDocument);
105
106 Settings settings(&prefs);
107
108 EXPECT_TRUE(settings.blimp_enabled());
109 EXPECT_TRUE(settings.record_whole_document());
110 }
111
112 } // namespace
113 } // namespace client
114 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698