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

Unified Diff: blimp/client/core/settings/settings_unittest.cc

Issue 2349073002: Blimp Settings framework on the c++ side (Closed)
Patch Set: nits and sync to head 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/client/core/settings/settings_prefs.cc ('k') | blimp/client/core/switches/blimp_client_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/client/core/settings/settings_unittest.cc
diff --git a/blimp/client/core/settings/settings_unittest.cc b/blimp/client/core/settings/settings_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..68e6fc0d9f9347eac8ba61389662daffdceb4bc6
--- /dev/null
+++ b/blimp/client/core/settings/settings_unittest.cc
@@ -0,0 +1,98 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/client/core/settings/settings.h"
+
+#include "base/command_line.h"
+#include "blimp/client/core/settings/settings_observer.h"
+#include "blimp/client/core/settings/settings_prefs.h"
+#include "blimp/client/core/switches/blimp_client_switches.h"
+#include "components/prefs/testing_pref_service.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::_;
+
+namespace blimp {
+namespace client {
+namespace {
+
+class MockSettingsObserver : public SettingsObserver {
+ public:
+ explicit MockSettingsObserver(Settings* settings) : settings_(settings) {
+ settings_->AddObserver(this);
+ }
+ ~MockSettingsObserver() {
+ if (settings_) {
+ settings_->RemoveObserver(this);
+ }
+ }
+
+ MOCK_METHOD1(OnShowNetworkStatsChanged, void(bool));
+ MOCK_METHOD1(OnBlimpModeEnabled, void(bool));
+ MOCK_METHOD1(OnRecordWholeDocumentChanged, void(bool));
+ MOCK_METHOD0(OnRestartRequired, void());
+
+ private:
+ Settings* settings_;
+};
+
+class SettingsTest : public testing::Test {
+ public:
+ SettingsTest() { Settings::RegisterPrefs(prefs.registry()); }
+
+ ~SettingsTest() override = default;
+
+ TestingPrefServiceSimple prefs;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SettingsTest);
+};
+
+TEST_F(SettingsTest, TestSetShowNetworkStats) {
+ Settings settings(&prefs);
+ MockSettingsObserver observer(&settings);
+
+ EXPECT_FALSE(settings.show_network_stats());
+
+ EXPECT_CALL(observer, OnShowNetworkStatsChanged(_)).Times(0);
+ settings.SetShowNetworkStats(false);
+ EXPECT_CALL(observer, OnShowNetworkStatsChanged(true)).Times(1);
+ settings.SetShowNetworkStats(true);
+ EXPECT_TRUE(settings.show_network_stats());
+}
+
+TEST_F(SettingsTest, TestSetEnableBlimpMode) {
+ Settings settings(&prefs);
+ MockSettingsObserver observer(&settings);
+
+ EXPECT_FALSE(settings.IsBlimpEnabled());
+
+ EXPECT_CALL(observer, OnBlimpModeEnabled(true)).Times(1);
+ EXPECT_CALL(observer, OnRestartRequired()).Times(1);
+ settings.SetEnableBlimpMode(true);
+ EXPECT_TRUE(settings.IsBlimpEnabled());
+
+ EXPECT_CALL(observer, OnBlimpModeEnabled(_)).Times(0);
+ EXPECT_CALL(observer, OnRestartRequired()).Times(0);
+ settings.SetEnableBlimpMode(true);
+}
+
+TEST_F(SettingsTest, TestSetRecordWholeDocument) {
+ Settings settings(&prefs);
+ MockSettingsObserver observer(&settings);
+
+ EXPECT_FALSE(settings.IsRecordWholeDocument());
+
+ EXPECT_CALL(observer, OnRecordWholeDocumentChanged(true)).Times(1);
+ settings.SetRecordWholeDocument(true);
+ EXPECT_TRUE(settings.IsRecordWholeDocument());
+
+ EXPECT_CALL(observer, OnRecordWholeDocumentChanged(_)).Times(0);
+ settings.SetRecordWholeDocument(true);
+}
+
+} // namespace
+} // namespace client
+} // namespace blimp
« no previous file with comments | « blimp/client/core/settings/settings_prefs.cc ('k') | blimp/client/core/switches/blimp_client_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698