Popular sites on the NTP: re-download popular suggestions once per Chrome run
[chromium-blink-merge.git] / chrome / browser / metrics / chrome_metrics_service_accessor_unittest.cc
blobdc70144850271f2d6cab58b506839de7b5054f21
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 {
13 public:
14 ChromeMetricsServiceAccessorTest()
15 : testing_local_state_(TestingBrowserProcess::GetGlobal()) {
18 PrefService* GetLocalState() {
19 return testing_local_state_.Get();
22 private:
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;
33 #else
34 const char* pref = prefs::kMetricsReportingEnabled;
35 #endif // defined(OS_ANDROID)
36 GetLocalState()->SetDefaultPrefValue(pref, new base::FundamentalValue(false));
38 GetLocalState()->SetBoolean(pref, false);
39 EXPECT_FALSE(
40 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
41 GetLocalState()->SetBoolean(pref, true);
42 EXPECT_TRUE(
43 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
44 GetLocalState()->ClearPref(pref);
45 EXPECT_FALSE(
46 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
47 #endif // !defined(OS_CHROMEOS)
48 #else
49 // Metrics Reporting is never enabled when GOOGLE_CHROME_BUILD is undefined.
50 EXPECT_FALSE(
51 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
52 #endif