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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: Settings doesn't own its observer anymore. SettingsFeature subclass SettingsObserver 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/blimp_client_switches.h"
9 #include "blimp/client/core/settings/settings_observer.h"
10 #include "blimp/client/core/settings/settings_prefs.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 MockSettingsObserver(Settings* settings) : SettingsObserver(settings) {}
24 ~MockSettingsObserver() override = default;
25
26 MOCK_METHOD1(OnBlimpModeEnabled, void(bool));
27 MOCK_METHOD1(OnShowNetworkStatsChanged, void(bool));
28 MOCK_METHOD1(OnRecordWholeDocumentChanged, void(bool));
29 MOCK_METHOD0(OnRestartRequired, void());
30 };
31
32 class SettingsTest : public testing::Test {
33 public:
34 SettingsTest() {
35 Settings::RegisterPrefs(prefs.registry());
36 }
37
38 ~SettingsTest() override = default;
39
40 TestingPrefServiceSimple prefs;
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
44 };
45
46 TEST_F(SettingsTest, TestSetShowNetworkStats) {
47 Settings settings(&prefs);
48 MockSettingsObserver observer(&settings);
49
50 EXPECT_FALSE(settings.show_network_stats());
51
52 EXPECT_CALL(observer, OnShowNetworkStatsChanged(_)). Times(0);
53 settings.SetShowNetworkStats(false);
54 EXPECT_CALL(observer, OnShowNetworkStatsChanged(true)). Times(1);
55 settings.SetShowNetworkStats(true);
56 }
57
58 TEST_F(SettingsTest, TestSetEnableBlimpMode) {
59 Settings settings(&prefs);
60 MockSettingsObserver observer(&settings);
61
62 EXPECT_FALSE(settings.blimp_enabled());
63
64 EXPECT_FALSE(prefs.GetBoolean(prefs::kBlimpEnabled));
65
66 EXPECT_CALL(observer, OnRestartRequired()).Times(0);
67 EXPECT_CALL(observer, OnBlimpModeEnabled(_)).Times(0);
68 settings.SetEnableBlimpMode(false);
69
70 EXPECT_CALL(observer, OnRestartRequired()).Times(1);
71 EXPECT_CALL(observer, OnBlimpModeEnabled(true)).Times(1);
72 settings.SetEnableBlimpMode(true);
73 EXPECT_TRUE(prefs.GetBoolean(prefs::kBlimpEnabled));
74 }
75
76 TEST_F(SettingsTest, TestSetRecordWholeDocument) {
77 Settings settings(&prefs);
78 MockSettingsObserver observer(&settings);
79
80 EXPECT_FALSE(settings.record_whole_document());
81
82 EXPECT_FALSE(prefs.GetBoolean(prefs::kRecordWholeDocument));
83
84 EXPECT_CALL(observer, OnRestartRequired()).Times(0);
85 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(_)).Times(0);
86 settings.SetRecordWholeDocument(false);
87
88 EXPECT_CALL(observer, OnRestartRequired()).Times(1);
89 EXPECT_CALL(observer, OnRecordWholeDocumentChanged(true)).Times(1);
90 settings.SetRecordWholeDocument(true);
91 EXPECT_TRUE(prefs.GetBoolean(prefs::kRecordWholeDocument));
92 }
93
94 TEST_F(SettingsTest, TestSettingsConstructor) {
95 auto* cmd_line = base::CommandLine::ForCurrentProcess();
96 cmd_line->AppendSwitch(switches::kEnableBlimp);
97 cmd_line->AppendSwitch(switches::kDownloadWholeDocument);
98
99 Settings settings(&prefs);
100
101 EXPECT_TRUE(settings.blimp_enabled());
102 EXPECT_TRUE(settings.record_whole_document());
103 EXPECT_TRUE(prefs.GetBoolean(prefs::kRecordWholeDocument));
104 }
105
106 } // namespace
107 } // namespace client
108 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698