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

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

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: fix trybot error 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
35 private:
36 Settings* settings_;
37 };
38
39 class SettingsTest : public testing::Test {
40 public:
41 SettingsTest() {
42 Settings::RegisterPrefs(prefs.registry());
43 }
44
45 ~SettingsTest() override = default;
46
47 TestingPrefServiceSimple prefs;
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(SettingsTest);
51 };
52
53 TEST_F(SettingsTest, TestSetShowNetworkStats) {
54 Settings settings(&prefs);
55 MockSettingsObserver observer(&settings);
56
57 EXPECT_FALSE(settings.show_network_stats());
58
59 EXPECT_CALL(observer, OnShowNetworkStatsChanged(_)). Times(0);
60 settings.SetShowNetworkStats(false);
61 EXPECT_CALL(observer, OnShowNetworkStatsChanged(true)). Times(1);
62 settings.SetShowNetworkStats(true);
63 EXPECT_TRUE(settings.show_network_stats());
64 }
65
66 TEST_F(SettingsTest, TestSetEnableBlimpMode) {
67 Settings settings(&prefs);
68 MockSettingsObserver observer(&settings);
69
70 EXPECT_FALSE(settings.blimp_enabled());
71
72 settings.SetEnableBlimpMode(false);
73 EXPECT_FALSE(settings.blimp_enabled());
74
75 settings.SetEnableBlimpMode(true);
76 EXPECT_TRUE(settings.blimp_enabled());
77 }
78
79 TEST_F(SettingsTest, TestSetRecordWholeDocument) {
80 Settings settings(&prefs);
81 MockSettingsObserver observer(&settings);
82
83 EXPECT_FALSE(settings.record_whole_document());
84
85 settings.SetRecordWholeDocument(false);
86 EXPECT_FALSE(settings.record_whole_document());
87
88 settings.SetRecordWholeDocument(true);
89 EXPECT_TRUE(settings.record_whole_document());
90 }
91
92 } // namespace
93 } // namespace client
94 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698