blob: fa5685e16aa6fb8c651a585140f6b81cde08bab3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/metrics/metrics_pref_names.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
class ChromeMetricsServiceAccessorTest : public testing::Test {
public:
ChromeMetricsServiceAccessorTest()
: testing_local_state_(TestingBrowserProcess::GetGlobal()) {
}
PrefService* GetLocalState() {
return testing_local_state_.Get();
}
private:
content::TestBrowserThreadBundle thread_bundle_;
ScopedTestingLocalState testing_local_state_;
DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceAccessorTest);
};
TEST_F(ChromeMetricsServiceAccessorTest, MetricsReportingEnabled) {
#if defined(GOOGLE_CHROME_BUILD)
#if !defined(OS_CHROMEOS)
#if defined(OS_ANDROID)
const char* pref = prefs::kCrashReportingEnabled;
#else
const char* pref = metrics::prefs::kMetricsReportingEnabled;
#endif // defined(OS_ANDROID)
GetLocalState()->SetDefaultPrefValue(pref, new base::FundamentalValue(false));
GetLocalState()->SetBoolean(pref, false);
EXPECT_FALSE(
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
GetLocalState()->SetBoolean(pref, true);
EXPECT_TRUE(
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
GetLocalState()->ClearPref(pref);
EXPECT_FALSE(
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
// If field trials are forced, metrics should always be disabled, regardless
// of the value of the pref.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kForceFieldTrials);
EXPECT_FALSE(
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
GetLocalState()->SetBoolean(pref, true);
EXPECT_FALSE(
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
#endif // !defined(OS_CHROMEOS)
#else
// Metrics Reporting is never enabled when GOOGLE_CHROME_BUILD is undefined.
EXPECT_FALSE(
ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled());
#endif
}
|