Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 "chrome/browser/metrics/metrics_services_manager.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/prefs/testing_pref_service.h" | |
| 10 #include "chrome/common/pref_names.h" | |
| 11 #include "chrome/test/base/testing_browser_process.h" | |
| 12 #include "chrome/test/base/testing_profile_manager.h" | |
| 13 #include "components/rappor/rappor_pref_names.h" | |
| 14 #include "components/rappor/rappor_prefs.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 class MetricsServicesManagerTest : public testing::Test { | |
| 18 public: | |
| 19 MetricsServicesManagerTest() | |
| 20 : test_profile_manager_(TestingBrowserProcess::GetGlobal()) { | |
| 21 rappor::internal::RegisterPrefs(test_prefs_.registry()); | |
| 22 } | |
| 23 | |
| 24 void SetUp() override { | |
| 25 ASSERT_TRUE(test_profile_manager_.SetUp()); | |
| 26 } | |
| 27 | |
| 28 void CreateProfile(const std::string& name, bool sb_enabled) { | |
| 29 TestingProfile* profile = test_profile_manager_.CreateTestingProfile(name); | |
| 30 profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, sb_enabled); | |
| 31 } | |
| 32 | |
| 33 protected: | |
| 34 TestingProfileManager test_profile_manager_; | |
| 35 TestingPrefServiceSimple test_prefs_; | |
| 36 | |
| 37 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.
| |
| 38 }; | |
| 39 | |
| 40 TEST_F(MetricsServicesManagerTest, CheckRapporDefaultDisable) { | |
| 41 MetricsServicesManager manager(&test_prefs_); | |
| 42 test_prefs_.ClearPref(rappor::prefs::kRapporEnabled); | |
| 43 CreateProfile("profile1", true); | |
| 44 CreateProfile("profile2", false); | |
| 45 bool uma_enabled = false; | |
| 46 EXPECT_FALSE(manager.IsRapporEnabled(uma_enabled)); | |
| 47 EXPECT_TRUE(test_prefs_.HasPrefPath(rappor::prefs::kRapporEnabled)); | |
| 48 } | |
| 49 | |
| 50 TEST_F(MetricsServicesManagerTest, CheckRapporDefaultEnabledBySafeBrowsing) { | |
| 51 MetricsServicesManager manager(&test_prefs_); | |
| 52 test_prefs_.ClearPref(rappor::prefs::kRapporEnabled); | |
| 53 CreateProfile("profile1", true); | |
| 54 CreateProfile("profile2", true); | |
| 55 bool uma_enabled = false; | |
| 56 EXPECT_TRUE(manager.IsRapporEnabled(uma_enabled)); | |
| 57 EXPECT_TRUE(test_prefs_.HasPrefPath(rappor::prefs::kRapporEnabled)); | |
| 58 } | |
| 59 | |
| 60 TEST_F(MetricsServicesManagerTest, CheckRapporDefaultEnabledByUMA) { | |
| 61 MetricsServicesManager manager(&test_prefs_); | |
| 62 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
| |
| 63 CreateProfile("profile1", false); | |
| 64 CreateProfile("profile2", false); | |
| 65 bool uma_enabled = true; | |
| 66 EXPECT_TRUE(manager.IsRapporEnabled(uma_enabled)); | |
| 67 EXPECT_TRUE(test_prefs_.HasPrefPath(rappor::prefs::kRapporEnabled)); | |
| 68 } | |
| 69 | |
| 70 TEST_F(MetricsServicesManagerTest, CheckRapporEnable) { | |
| 71 MetricsServicesManager manager(&test_prefs_); | |
| 72 test_prefs_.SetBoolean(rappor::prefs::kRapporEnabled, true); | |
| 73 CreateProfile("profile1", false); | |
| 74 CreateProfile("profile2", false); | |
| 75 bool uma_enabled = false; | |
| 76 EXPECT_TRUE(manager.IsRapporEnabled(uma_enabled)); | |
| 77 } | |
| 78 | |
| 79 TEST_F(MetricsServicesManagerTest, CheckRapporDisable) { | |
| 80 MetricsServicesManager manager(&test_prefs_); | |
| 81 test_prefs_.SetBoolean(rappor::prefs::kRapporEnabled, false); | |
| 82 CreateProfile("profile1", true); | |
| 83 CreateProfile("profile2", true); | |
| 84 bool uma_enabled = true; | |
| 85 EXPECT_FALSE(manager.IsRapporEnabled(uma_enabled)); | |
| 86 } | |
| OLD | NEW |