OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/metrics_service.h" | 5 #include "chrome/browser/metrics/metrics_service.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/scoped_testing_local_state.h" | 13 #include "chrome/test/base/scoped_testing_local_state.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
15 #include "components/variations/metrics_util.h" | 15 #include "components/variations/metrics_util.h" |
16 #include "content/public/common/process_type.h" | 16 #include "content/public/common/process_type.h" |
17 #include "content/public/common/webplugininfo.h" | 17 #include "content/public/common/webplugininfo.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
21 | 21 |
| 22 #if defined(OS_CHROMEOS) |
| 23 #include "chrome/browser/metrics/metrics_log_chromeos.h" |
| 24 #endif // OS_CHROMEOS |
| 25 |
22 namespace { | 26 namespace { |
23 | 27 |
24 class TestMetricsService : public MetricsService { | 28 class TestMetricsService : public MetricsService { |
25 public: | 29 public: |
26 TestMetricsService() {} | 30 TestMetricsService() {} |
27 virtual ~TestMetricsService() {} | 31 virtual ~TestMetricsService() {} |
28 | 32 |
29 MetricsLogManager* log_manager() { | 33 MetricsLogManager* log_manager() { |
30 return &log_manager_; | 34 return &log_manager_; |
31 } | 35 } |
32 | 36 |
33 private: | 37 private: |
34 DISALLOW_COPY_AND_ASSIGN(TestMetricsService); | 38 DISALLOW_COPY_AND_ASSIGN(TestMetricsService); |
35 }; | 39 }; |
36 | 40 |
| 41 #if defined(OS_CHROMEOS) |
| 42 class TestMetricsLogChromeOS : public MetricsLogChromeOS { |
| 43 public: |
| 44 explicit TestMetricsLogChromeOS( |
| 45 metrics::ChromeUserMetricsExtension* uma_proto) |
| 46 : MetricsLogChromeOS(uma_proto) { |
| 47 } |
| 48 |
| 49 protected: |
| 50 // Don't touch bluetooth information, as it won't be correctly initialized. |
| 51 virtual void WriteBluetoothProto() OVERRIDE { |
| 52 } |
| 53 }; |
| 54 #endif // OS_CHROMEOS |
| 55 |
37 class TestMetricsLog : public MetricsLog { | 56 class TestMetricsLog : public MetricsLog { |
38 public: | 57 public: |
39 TestMetricsLog(const std::string& client_id, int session_id) | 58 TestMetricsLog(const std::string& client_id, int session_id) |
40 : MetricsLog(client_id, session_id) {} | 59 : MetricsLog(client_id, session_id) { |
| 60 #if defined(OS_CHROMEOS) |
| 61 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( |
| 62 MetricsLog::uma_proto())); |
| 63 #endif // OS_CHROMEOS |
| 64 } |
41 virtual ~TestMetricsLog() {} | 65 virtual ~TestMetricsLog() {} |
42 | 66 |
43 private: | 67 private: |
44 virtual gfx::Size GetScreenSize() const OVERRIDE { | 68 virtual gfx::Size GetScreenSize() const OVERRIDE { |
45 return gfx::Size(1024, 768); | 69 return gfx::Size(1024, 768); |
46 } | 70 } |
47 | 71 |
48 virtual float GetScreenDeviceScaleFactor() const OVERRIDE { | 72 virtual float GetScreenDeviceScaleFactor() const OVERRIDE { |
49 return 1.0f; | 73 return 1.0f; |
50 } | 74 } |
51 | 75 |
52 virtual int GetScreenCount() const OVERRIDE { | 76 virtual int GetScreenCount() const OVERRIDE { |
53 return 1; | 77 return 1; |
54 } | 78 } |
55 | 79 |
56 virtual void WriteBluetoothProto( | |
57 metrics::SystemProfileProto::Hardware* hardware) OVERRIDE { | |
58 } | |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); | 80 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); |
61 }; | 81 }; |
62 | 82 |
63 class MetricsServiceTest : public testing::Test { | 83 class MetricsServiceTest : public testing::Test { |
64 public: | 84 public: |
65 MetricsServiceTest() | 85 MetricsServiceTest() |
66 : testing_local_state_(TestingBrowserProcess::GetGlobal()) { | 86 : testing_local_state_(TestingBrowserProcess::GetGlobal()) { |
67 } | 87 } |
68 | 88 |
69 virtual ~MetricsServiceTest() { | 89 virtual ~MetricsServiceTest() { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 service.log_manager_.FinishCurrentLog(); | 312 service.log_manager_.FinishCurrentLog(); |
293 service.log_manager_.BeginLoggingWithLog(new MetricsLog("clientID", 1), | 313 service.log_manager_.BeginLoggingWithLog(new MetricsLog("clientID", 1), |
294 MetricsLog::ONGOING_LOG); | 314 MetricsLog::ONGOING_LOG); |
295 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); | 315 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); |
296 EXPECT_EQ(3U, synthetic_trials.size()); | 316 EXPECT_EQ(3U, synthetic_trials.size()); |
297 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); | 317 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); |
298 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 318 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
299 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); | 319 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); |
300 service.log_manager_.FinishCurrentLog(); | 320 service.log_manager_.FinishCurrentLog(); |
301 } | 321 } |
OLD | NEW |