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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: Merge branch 'refs/heads/master' into settings 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_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 }
67
68 TEST_F(SettingsTest, TestSetEnableBlimpMode) {
69 Settings settings(&prefs);
70 MockSettingsObserver observer(&settings);
71
72 EXPECT_FALSE(settings.blimp_enabled());
73
74 EXPECT_FALSE(prefs.GetBoolean(prefs::kBlimpEnabled));
75
76 EXPECT_CALL(observer, OnRestartRequired()).Times(0);
77 EXPECT_CALL(observer, OnBlimpModeEnabled(_)).Times(0);
78 settings.SetEnableBlimpMode(false);
79
80 EXPECT_CALL(observer, OnRestartRequired()).Times(1);
81 EXPECT_CALL(observer, OnBlimpModeEnabled(true)).Times(1);
82 settings.SetEnableBlimpMode(true);
83 EXPECT_TRUE(prefs.GetBoolean(prefs::kBlimpEnabled));
84 }
85
86 TEST_F(SettingsTest, TestSetRecordWholeDocument) {
87 Settings settings(&prefs);
88 MockSettingsObserver observer(&settings);
89
90 EXPECT_FALSE(settings.record_whole_document());
91
92 EXPECT_FALSE(prefs.GetBoolean(prefs::kRecordWholeDocument));
93
94 EXPECT_CALL(observer, OnRestartRequired()).Times(0);
95 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(_)).Times(0);
96 settings.SetRecordWholeDocument(false);
97
98 EXPECT_CALL(observer, OnRestartRequired()).Times(1);
99 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(true)).Times(1);
100 settings.SetRecordWholeDocument(true);
101 EXPECT_TRUE(prefs.GetBoolean(prefs::kRecordWholeDocument));
102 }
103
104 TEST_F(SettingsTest, TestSettingsConstructor) {
105 auto* cmd_line = base::CommandLine::ForCurrentProcess();
106 cmd_line->AppendSwitch(switches::kEnableBlimp);
107 cmd_line->AppendSwitch(switches::kDownloadWholeDocument);
108
109 Settings settings(&prefs);
110
111 EXPECT_TRUE(settings.blimp_enabled());
112 EXPECT_TRUE(settings.record_whole_document());
113 EXPECT_TRUE(prefs.GetBoolean(prefs::kRecordWholeDocument));
114 }
115
116 } // namespace
117 } // namespace client
118 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698