OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 5 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 private: | 28 private: |
29 content::TestBrowserThreadBundle thread_bundle_; | 29 content::TestBrowserThreadBundle thread_bundle_; |
30 ScopedTestingLocalState testing_local_state_; | 30 ScopedTestingLocalState testing_local_state_; |
31 | 31 |
32 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceAccessorTest); | 32 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceAccessorTest); |
33 }; | 33 }; |
34 | 34 |
35 TEST_F(ChromeMetricsServiceAccessorTest, MetricsReportingEnabled) { | 35 TEST_F(ChromeMetricsServiceAccessorTest, MetricsReportingEnabled) { |
36 #if defined(GOOGLE_CHROME_BUILD) | 36 #if defined(GOOGLE_CHROME_BUILD) |
37 #if !defined(OS_CHROMEOS) | |
38 #if defined(OS_ANDROID) | |
39 const char* pref = prefs::kCrashReportingEnabled; | |
40 #else | |
41 const char* pref = metrics::prefs::kMetricsReportingEnabled; | 37 const char* pref = metrics::prefs::kMetricsReportingEnabled; |
42 #endif // defined(OS_ANDROID) | |
43 GetLocalState()->SetDefaultPrefValue(pref, new base::FundamentalValue(false)); | 38 GetLocalState()->SetDefaultPrefValue(pref, new base::FundamentalValue(false)); |
44 | 39 |
45 GetLocalState()->SetBoolean(pref, false); | 40 GetLocalState()->SetBoolean(pref, false); |
46 EXPECT_FALSE( | 41 EXPECT_FALSE( |
47 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 42 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
48 GetLocalState()->SetBoolean(pref, true); | 43 GetLocalState()->SetBoolean(pref, true); |
49 EXPECT_TRUE( | 44 EXPECT_TRUE( |
50 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 45 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
51 GetLocalState()->ClearPref(pref); | 46 GetLocalState()->ClearPref(pref); |
52 EXPECT_FALSE( | 47 EXPECT_FALSE( |
53 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 48 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
54 | 49 |
55 // If field trials are forced, metrics should always be disabled, regardless | 50 // If field trials are forced, metrics should always be disabled, regardless |
56 // of the value of the pref. | 51 // of the value of the pref. |
57 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 52 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
58 switches::kForceFieldTrials); | 53 switches::kForceFieldTrials); |
59 EXPECT_FALSE( | 54 EXPECT_FALSE( |
60 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 55 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
61 GetLocalState()->SetBoolean(pref, true); | 56 GetLocalState()->SetBoolean(pref, true); |
62 EXPECT_FALSE( | 57 EXPECT_FALSE( |
63 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 58 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
64 #endif // !defined(OS_CHROMEOS) | |
65 #else | 59 #else |
66 // Metrics Reporting is never enabled when GOOGLE_CHROME_BUILD is undefined. | 60 // Metrics Reporting is never enabled when GOOGLE_CHROME_BUILD is undefined. |
67 EXPECT_FALSE( | 61 EXPECT_FALSE( |
68 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); | 62 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()); |
69 #endif | 63 #endif |
70 } | 64 } |
OLD | NEW |