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

Unified Diff: chrome/browser/metrics/metrics_services_manager_unittest.cc

Issue 886523003: Add a Rappor option in the settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Created 5 years, 10 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
Index: chrome/browser/metrics/metrics_services_manager_unittest.cc
diff --git a/chrome/browser/metrics/metrics_services_manager_unittest.cc b/chrome/browser/metrics/metrics_services_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2c19d3590e3cb97fafe993cbf47eb07c6824964
--- /dev/null
+++ b/chrome/browser/metrics/metrics_services_manager_unittest.cc
@@ -0,0 +1,86 @@
+// Copyright 2015 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 "chrome/browser/metrics/metrics_services_manager.h"
+
+#include <string>
+
+#include "base/prefs/testing_pref_service.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_profile_manager.h"
+#include "components/rappor/rappor_pref_names.h"
+#include "components/rappor/rappor_prefs.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class MetricsServicesManagerTest : public testing::Test {
+ public:
+ MetricsServicesManagerTest()
+ : test_profile_manager_(TestingBrowserProcess::GetGlobal()) {
+ rappor::internal::RegisterPrefs(test_prefs_.registry());
+ }
+
+ void SetUp() override {
+ ASSERT_TRUE(test_profile_manager_.SetUp());
+ }
+
+ void CreateProfile(const std::string& name, bool sb_enabled) {
+ TestingProfile* profile = test_profile_manager_.CreateTestingProfile(name);
+ profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, sb_enabled);
+ }
+
+ protected:
+ TestingProfileManager test_profile_manager_;
+ TestingPrefServiceSimple test_prefs_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricsServicesManagerTest);
Alexei Svitkine (slow) 2015/02/09 16:10:47 This macro should be in the private section.
Steven Holte 2015/02/09 20:17:38 Done.
+};
+
+TEST_F(MetricsServicesManagerTest, CheckRapporDefaultDisable) {
+ MetricsServicesManager manager(&test_prefs_);
+ test_prefs_.ClearPref(rappor::prefs::kRapporEnabled);
+ CreateProfile("profile1", true);
+ CreateProfile("profile2", false);
+ bool uma_enabled = false;
+ EXPECT_FALSE(manager.IsRapporEnabled(uma_enabled));
+ EXPECT_TRUE(test_prefs_.HasPrefPath(rappor::prefs::kRapporEnabled));
+}
+
+TEST_F(MetricsServicesManagerTest, CheckRapporDefaultEnabledBySafeBrowsing) {
+ MetricsServicesManager manager(&test_prefs_);
+ test_prefs_.ClearPref(rappor::prefs::kRapporEnabled);
+ CreateProfile("profile1", true);
+ CreateProfile("profile2", true);
+ bool uma_enabled = false;
+ EXPECT_TRUE(manager.IsRapporEnabled(uma_enabled));
+ EXPECT_TRUE(test_prefs_.HasPrefPath(rappor::prefs::kRapporEnabled));
+}
+
+TEST_F(MetricsServicesManagerTest, CheckRapporDefaultEnabledByUMA) {
+ MetricsServicesManager manager(&test_prefs_);
+ test_prefs_.ClearPref(rappor::prefs::kRapporEnabled);
Alexei Svitkine (slow) 2015/02/09 16:10:47 If every test starts with these two lines, put the
Steven Holte 2015/02/09 20:17:38 Moved MetricsServicesManager to harness. The Clea
+ CreateProfile("profile1", false);
+ CreateProfile("profile2", false);
+ bool uma_enabled = true;
+ EXPECT_TRUE(manager.IsRapporEnabled(uma_enabled));
+ EXPECT_TRUE(test_prefs_.HasPrefPath(rappor::prefs::kRapporEnabled));
+}
+
+TEST_F(MetricsServicesManagerTest, CheckRapporEnable) {
+ MetricsServicesManager manager(&test_prefs_);
+ test_prefs_.SetBoolean(rappor::prefs::kRapporEnabled, true);
+ CreateProfile("profile1", false);
+ CreateProfile("profile2", false);
+ bool uma_enabled = false;
+ EXPECT_TRUE(manager.IsRapporEnabled(uma_enabled));
+}
+
+TEST_F(MetricsServicesManagerTest, CheckRapporDisable) {
+ MetricsServicesManager manager(&test_prefs_);
+ test_prefs_.SetBoolean(rappor::prefs::kRapporEnabled, false);
+ CreateProfile("profile1", true);
+ CreateProfile("profile2", true);
+ bool uma_enabled = true;
+ EXPECT_FALSE(manager.IsRapporEnabled(uma_enabled));
+}

Powered by Google App Engine
This is Rietveld 408576698