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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: Created 4 years, 3 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() : SettingsObserver() {}
24 ~MockSettingsObserver() override = default;
25
26 MOCK_METHOD1(OnShowNetworkStatsChanged, void(bool));
David Trainor- moved to gerrit 2016/09/27 04:10:06 What about enable?
Menglin 2016/09/30 23:48:57 Done.
27 MOCK_METHOD1(OnRecordWholeDocumentChanged, void(bool));
28 MOCK_METHOD0(OnRestartRequired, void());
29 };
30
31 class SettingsTest : public testing::Test {
32 public:
33 SettingsTest() : settings_(&prefs_) {
34 Settings::RegisterPrefs(prefs_.registry());
35 std::unique_ptr<MockSettingsObserver> observer_uniqueptr =
36 base::MakeUnique<MockSettingsObserver>();
37 observer_ = observer_uniqueptr.get();
38
39 settings_.AddObserver(std::move(observer_uniqueptr));
40 }
41
42 ~SettingsTest() override {}
David Trainor- moved to gerrit 2016/09/27 04:10:06 = default?
Menglin 2016/09/30 23:48:57 Done.
43
44 MockSettingsObserver* observer_;
David Trainor- moved to gerrit 2016/09/27 04:10:07 make this the unique_ptr once you move AddObserver
Menglin 2016/09/30 23:48:57 Since I moved InitializeFromCommandLineAndPref to
David Trainor- moved to gerrit 2016/10/01 03:26:34 sg!
45 Settings settings_;
46 TestingPrefServiceSimple prefs_;
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
50 };
51
52 TEST_F(SettingsTest, TestSetShowNetworkStats) {
53 EXPECT_CALL(*observer_, OnShowNetworkStatsChanged(false)). Times(1);
David Trainor- moved to gerrit 2016/09/27 04:10:07 If we don't expect calls on sets to the same value
Menglin 2016/09/30 23:48:57 Done.
54 settings_.SetShowNetworkStats(false);
55 EXPECT_CALL(*observer_, OnShowNetworkStatsChanged(true)). Times(1);
56 settings_.SetShowNetworkStats(true);
57 }
58
59 TEST_F(SettingsTest, TestSetEnableBlimpMode) {
60 EXPECT_FALSE(prefs_.GetBoolean(prefs::kBlimpEnabled));
61 EXPECT_CALL(*observer_, OnRestartRequired()).Times(3);
62
63 settings_.SetEnableBlimpMode(false);
64 settings_.SetEnableBlimpMode(true);
65 EXPECT_TRUE(prefs_.GetBoolean(prefs::kBlimpEnabled));
66 settings_.SetEnableBlimpMode(false);
67 EXPECT_FALSE(prefs_.GetBoolean(prefs::kBlimpEnabled));
68 }
69
70 TEST_F(SettingsTest, TestSetRecordWholeDocument) {
71 EXPECT_FALSE(prefs_.GetBoolean(prefs::kRecordWholeDocument));
72
73 EXPECT_CALL(*observer_, OnRecordWholeDocumentChanged(_)).Times(0);
74 settings_.SetRecordWholeDocument(false);
75
76 EXPECT_CALL(*observer_, OnRecordWholeDocumentChanged(true)).Times(1);
77 settings_.SetRecordWholeDocument(true);
78 EXPECT_TRUE(prefs_.GetBoolean(prefs::kRecordWholeDocument));
79
80 EXPECT_CALL(*observer_, OnRecordWholeDocumentChanged(false)).Times(1);
81 settings_.SetRecordWholeDocument(false);
82 EXPECT_FALSE(prefs_.GetBoolean(prefs::kRecordWholeDocument));
83 }
84
85 TEST_F(SettingsTest, TestInitializeFromCommandLineAndPref) {
86 auto* cmd_line = base::CommandLine::ForCurrentProcess();
87
88 EXPECT_CALL(*observer_, OnRecordWholeDocumentChanged(_)).Times(0);
89 cmd_line->AppendSwitch(switches::kEnableBlimp);
90 settings_.InitializeFromCommandLineAndPref();
91 EXPECT_TRUE(settings_.blimp_enabled());
92
93 EXPECT_CALL(*observer_, OnRecordWholeDocumentChanged(true)).Times(1);
94 cmd_line->AppendSwitch(switches::kDownloadWholeDocument);
95 settings_.InitializeFromCommandLineAndPref();
96 EXPECT_TRUE(prefs_.GetBoolean(prefs::kRecordWholeDocument));
97 }
98
99 } // namespace
100 } // namespace client
101 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698