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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 #include "chrome/browser/metrics/metrics_state_manager.h" | 11 #include "chrome/browser/metrics/metrics_state_manager.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/metrics/metrics_log_base.h" | 15 #include "components/metrics/metrics_log_base.h" |
16 #include "components/metrics/metrics_service_observer.h" | 16 #include "components/metrics/metrics_service_observer.h" |
17 #include "components/metrics/test_metrics_service_client.h" | 17 #include "components/metrics/test_metrics_service_client.h" |
18 #include "components/variations/metrics_util.h" | 18 #include "components/variations/metrics_util.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 #if defined(OS_CHROMEOS) | |
23 #include "chrome/browser/metrics/metrics_log_chromeos.h" | |
24 #endif // OS_CHROMEOS | |
25 | |
26 namespace { | 22 namespace { |
27 | 23 |
28 using metrics::MetricsLogManager; | 24 using metrics::MetricsLogManager; |
29 | 25 |
30 class TestMetricsService : public MetricsService { | 26 class TestMetricsService : public MetricsService { |
31 public: | 27 public: |
32 TestMetricsService(metrics::MetricsStateManager* state_manager, | 28 TestMetricsService(metrics::MetricsStateManager* state_manager, |
33 metrics::MetricsServiceClient* client) | 29 metrics::MetricsServiceClient* client) |
34 : MetricsService(state_manager, client) {} | 30 : MetricsService(state_manager, client) {} |
35 virtual ~TestMetricsService() {} | 31 virtual ~TestMetricsService() {} |
36 | 32 |
37 using MetricsService::log_manager; | 33 using MetricsService::log_manager; |
38 | 34 |
39 private: | 35 private: |
40 DISALLOW_COPY_AND_ASSIGN(TestMetricsService); | 36 DISALLOW_COPY_AND_ASSIGN(TestMetricsService); |
41 }; | 37 }; |
42 | 38 |
43 #if defined(OS_CHROMEOS) | |
44 class TestMetricsLogChromeOS : public MetricsLogChromeOS { | |
45 public: | |
46 explicit TestMetricsLogChromeOS( | |
47 metrics::ChromeUserMetricsExtension* uma_proto) | |
48 : MetricsLogChromeOS(uma_proto) { | |
49 } | |
50 | |
51 protected: | |
52 // Don't touch bluetooth information, as it won't be correctly initialized. | |
53 virtual void WriteBluetoothProto() OVERRIDE { | |
54 } | |
55 }; | |
56 #endif // OS_CHROMEOS | |
57 | |
58 class TestMetricsLog : public MetricsLog { | 39 class TestMetricsLog : public MetricsLog { |
59 public: | 40 public: |
60 TestMetricsLog(const std::string& client_id, | 41 TestMetricsLog(const std::string& client_id, |
61 int session_id, | 42 int session_id, |
62 metrics::MetricsServiceClient* client) | 43 metrics::MetricsServiceClient* client) |
63 : MetricsLog(client_id, session_id, MetricsLog::ONGOING_LOG, client) { | 44 : MetricsLog(client_id, session_id, MetricsLog::ONGOING_LOG, client) { |
64 #if defined(OS_CHROMEOS) | |
65 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( | |
66 MetricsLog::uma_proto())); | |
67 #endif // OS_CHROMEOS | |
68 } | 45 } |
| 46 |
69 virtual ~TestMetricsLog() {} | 47 virtual ~TestMetricsLog() {} |
70 | 48 |
71 private: | 49 private: |
72 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); | 50 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); |
73 }; | 51 }; |
74 | 52 |
75 class MetricsServiceTest : public testing::Test { | 53 class MetricsServiceTest : public testing::Test { |
76 public: | 54 public: |
77 MetricsServiceTest() | 55 MetricsServiceTest() |
78 : testing_local_state_(TestingBrowserProcess::GetGlobal()), | 56 : testing_local_state_(TestingBrowserProcess::GetGlobal()), |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 283 |
306 service.RemoveObserver(&observer1); | 284 service.RemoveObserver(&observer1); |
307 | 285 |
308 service.OpenNewLog(); | 286 service.OpenNewLog(); |
309 EXPECT_EQ(2, observer1.observed()); | 287 EXPECT_EQ(2, observer1.observed()); |
310 EXPECT_EQ(2, observer2.observed()); | 288 EXPECT_EQ(2, observer2.observed()); |
311 service.log_manager_.FinishCurrentLog(); | 289 service.log_manager_.FinishCurrentLog(); |
312 | 290 |
313 service.RemoveObserver(&observer2); | 291 service.RemoveObserver(&observer2); |
314 } | 292 } |
OLD | NEW |