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
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
7 #include "chrome/common/pref_names.h"
8 #include "chrome/test/base/scoped_testing_local_state.h"
9 #include "chrome/test/base/testing_browser_process.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 #if defined(OS_CHROMEOS)
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 #include "chrome/browser/chromeos/settings/device_settings_service.h"
15 #endif // defined(OS_CHROMEOS)
17 class ChromeMetricsServiceAccessorTest
: public testing::Test
{
19 ChromeMetricsServiceAccessorTest()
20 : testing_local_state_(TestingBrowserProcess::GetGlobal()) {
23 PrefService
* GetLocalState() {
24 return testing_local_state_
.Get();
28 ScopedTestingLocalState testing_local_state_
;
29 #if defined(OS_CHROMEOS)
30 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_
;
31 chromeos::ScopedTestCrosSettings test_cros_settings_
;
32 #endif // defined(OS_CHROMEOS)
34 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceAccessorTest
);
37 TEST_F(ChromeMetricsServiceAccessorTest
, MetricsReportingEnabled
) {
38 #if defined(GOOGLE_CHROME_BUILD)
39 #if !defined(OS_CHROMEOS)
40 GetLocalState()->SetBoolean(prefs::kMetricsReportingEnabled
, false);
41 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
42 GetLocalState()->SetBoolean(prefs::kMetricsReportingEnabled
, true);
43 EXPECT_TRUE(ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
44 GetLocalState()->ClearPref(prefs::kMetricsReportingEnabled
);
45 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
47 // ChromeOS does not register prefs::kMetricsReportingEnabled and uses
48 // device settings for metrics reporting.
49 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
52 // Metrics Reporting is never enabled when GOOGLE_CHROME_BUILD is undefined.
53 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
57 TEST_F(ChromeMetricsServiceAccessorTest
, CrashReportingEnabled
) {
58 #if defined(GOOGLE_CHROME_BUILD)
59 // ChromeOS has different device settings for crash reporting.
60 #if !defined(OS_CHROMEOS)
61 #if defined(OS_ANDROID)
62 const char* crash_pref
= prefs::kCrashReportingEnabled
;
64 const char* crash_pref
= prefs::kMetricsReportingEnabled
;
66 GetLocalState()->SetBoolean(crash_pref
, false);
67 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsCrashReportingEnabled());
68 GetLocalState()->SetBoolean(crash_pref
, true);
69 EXPECT_TRUE(ChromeMetricsServiceAccessor::IsCrashReportingEnabled());
70 GetLocalState()->ClearPref(crash_pref
);
71 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsCrashReportingEnabled());
72 #endif // !defined(OS_CHROMEOS)
73 #else // defined(GOOGLE_CHROME_BUILD)
74 // Chromium branded browsers never have crash reporting enabled.
75 EXPECT_FALSE(ChromeMetricsServiceAccessor::IsCrashReportingEnabled());
76 #endif // defined(GOOGLE_CHROME_BUILD)