| 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 "components/metrics/metrics_log.h" | 5 #include "components/metrics/metrics_log.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/port.h" | 12 #include "base/port.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "chrome/browser/google/google_util.h" | |
| 21 #include "chrome/browser/metrics/metrics_service.h" | |
| 22 #include "chrome/browser/prefs/browser_prefs.h" | |
| 23 #include "chrome/common/chrome_version_info.h" | |
| 24 #include "chrome/common/pref_names.h" | |
| 25 #include "components/metrics/metrics_hashes.h" | 20 #include "components/metrics/metrics_hashes.h" |
| 21 #include "components/metrics/metrics_pref_names.h" |
| 26 #include "components/metrics/metrics_provider.h" | 22 #include "components/metrics/metrics_provider.h" |
| 23 #include "components/metrics/metrics_state_manager.h" |
| 27 #include "components/metrics/proto/profiler_event.pb.h" | 24 #include "components/metrics/proto/profiler_event.pb.h" |
| 28 #include "components/metrics/proto/system_profile.pb.h" | 25 #include "components/metrics/proto/system_profile.pb.h" |
| 29 #include "components/metrics/test_metrics_service_client.h" | 26 #include "components/metrics/test_metrics_service_client.h" |
| 30 #include "components/variations/active_field_trials.h" | 27 #include "components/variations/active_field_trials.h" |
| 31 #include "content/public/browser/browser_thread.h" | |
| 32 #include "content/public/test/test_browser_thread_bundle.h" | |
| 33 #include "content/public/test/test_utils.h" | |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 36 | 30 |
| 37 #if defined(OS_CHROMEOS) | |
| 38 #include "chromeos/login/login_state.h" | |
| 39 #endif // defined(OS_CHROMEOS) | |
| 40 | |
| 41 using base::TimeDelta; | 31 using base::TimeDelta; |
| 42 | 32 |
| 43 namespace { | 33 namespace { |
| 44 | 34 |
| 45 const char kClientId[] = "bogus client ID"; | 35 const char kClientId[] = "bogus client ID"; |
| 46 const int64 kInstallDate = 1373051956; | 36 const int64 kInstallDate = 1373051956; |
| 47 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate. | 37 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate. |
| 48 const int64 kEnabledDate = 1373001211; | 38 const int64 kEnabledDate = 1373001211; |
| 49 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. | 39 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. |
| 50 const int kSessionId = 127; | 40 const int kSessionId = 127; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 TestingPrefServiceSimple* prefs_; | 90 TestingPrefServiceSimple* prefs_; |
| 101 | 91 |
| 102 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); | 92 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); |
| 103 }; | 93 }; |
| 104 | 94 |
| 105 } // namespace | 95 } // namespace |
| 106 | 96 |
| 107 class MetricsLogTest : public testing::Test { | 97 class MetricsLogTest : public testing::Test { |
| 108 public: | 98 public: |
| 109 MetricsLogTest() { | 99 MetricsLogTest() { |
| 110 MetricsService::RegisterPrefs(prefs_.registry()); | 100 MetricsLog::RegisterPrefs(prefs_.registry()); |
| 111 #if defined(OS_CHROMEOS) | 101 metrics::MetricsStateManager::RegisterPrefs(prefs_.registry()); |
| 112 // TODO(blundell): Remove this code once MetricsService no longer creates | |
| 113 // ChromeOSMetricsProvider. Also remove the #include of login_state.h | |
| 114 // (http://crbug.com/375776) | |
| 115 if (!chromeos::LoginState::IsInitialized()) | |
| 116 chromeos::LoginState::Initialize(); | |
| 117 #endif // defined(OS_CHROMEOS) | |
| 118 } | 102 } |
| 119 | 103 |
| 120 virtual ~MetricsLogTest() { | 104 virtual ~MetricsLogTest() { |
| 121 #if defined(OS_CHROMEOS) | |
| 122 // TODO(blundell): Remove this code once MetricsService no longer creates | |
| 123 // ChromeOSMetricsProvider. | |
| 124 chromeos::LoginState::Shutdown(); | |
| 125 #endif // defined(OS_CHROMEOS) | |
| 126 } | 105 } |
| 127 | 106 |
| 128 protected: | 107 protected: |
| 129 // Check that the values in |system_values| correspond to the test data | 108 // Check that the values in |system_values| correspond to the test data |
| 130 // defined at the top of this file. | 109 // defined at the top of this file. |
| 131 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) { | 110 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) { |
| 132 EXPECT_EQ(kInstallDateExpected, system_profile.install_date()); | 111 EXPECT_EQ(kInstallDateExpected, system_profile.install_date()); |
| 133 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date()); | 112 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date()); |
| 134 | 113 |
| 135 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials), | 114 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 159 EXPECT_TRUE(hardware.cpu().has_signature()); | 138 EXPECT_TRUE(hardware.cpu().has_signature()); |
| 160 | 139 |
| 161 // TODO(isherman): Verify other data written into the protobuf as a result | 140 // TODO(isherman): Verify other data written into the protobuf as a result |
| 162 // of this call. | 141 // of this call. |
| 163 } | 142 } |
| 164 | 143 |
| 165 protected: | 144 protected: |
| 166 TestingPrefServiceSimple prefs_; | 145 TestingPrefServiceSimple prefs_; |
| 167 | 146 |
| 168 private: | 147 private: |
| 169 content::TestBrowserThreadBundle thread_bundle_; | |
| 170 | |
| 171 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); | 148 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); |
| 172 }; | 149 }; |
| 173 | 150 |
| 174 TEST_F(MetricsLogTest, RecordEnvironment) { | 151 TEST_F(MetricsLogTest, RecordEnvironment) { |
| 175 metrics::TestMetricsServiceClient client; | 152 metrics::TestMetricsServiceClient client; |
| 176 client.set_install_date(kInstallDate); | 153 client.set_install_date(kInstallDate); |
| 177 TestMetricsLog log( | 154 TestMetricsLog log( |
| 178 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 155 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 179 | 156 |
| 180 std::vector<variations::ActiveGroupId> synthetic_trials; | 157 std::vector<variations::ActiveGroupId> synthetic_trials; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 EXPECT_FALSE(stability.has_debugger_present_count()); | 280 EXPECT_FALSE(stability.has_debugger_present_count()); |
| 304 EXPECT_FALSE(stability.has_debugger_not_present_count()); | 281 EXPECT_FALSE(stability.has_debugger_not_present_count()); |
| 305 } | 282 } |
| 306 | 283 |
| 307 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { | 284 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { |
| 308 metrics::TestMetricsServiceClient client; | 285 metrics::TestMetricsServiceClient client; |
| 309 TestMetricsLog log( | 286 TestMetricsLog log( |
| 310 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 287 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 311 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); | 288 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); |
| 312 } | 289 } |
| OLD | NEW |