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 class ChromeMetricsServiceAccessorTest
: public testing::Test
{
14 ChromeMetricsServiceAccessorTest()
15 : testing_local_state_(TestingBrowserProcess::GetGlobal()) {
18 PrefService
* GetLocalState() {
19 return testing_local_state_
.Get();
23 ScopedTestingLocalState testing_local_state_
;
25 DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceAccessorTest
);
28 TEST_F(ChromeMetricsServiceAccessorTest
, MetricsReportingEnabled
) {
29 #if defined(GOOGLE_CHROME_BUILD)
30 #if !defined(OS_CHROMEOS)
31 #if defined(OS_ANDROID)
32 const char* pref
= prefs::kCrashReportingEnabled
;
34 const char* pref
= prefs::kMetricsReportingEnabled
;
35 #endif // defined(OS_ANDROID)
36 GetLocalState()->SetDefaultPrefValue(pref
, new base::FundamentalValue(false));
38 GetLocalState()->SetBoolean(pref
, false);
40 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
41 GetLocalState()->SetBoolean(pref
, true);
43 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
44 GetLocalState()->ClearPref(pref
);
46 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
47 #endif // !defined(OS_CHROMEOS)
49 // Metrics Reporting is never enabled when GOOGLE_CHROME_BUILD is undefined.
51 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());