| 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_log.h" | 5 #include "chrome/browser/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" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 public: | 122 public: |
| 123 explicit TestMetricsLogChromeOS( | 123 explicit TestMetricsLogChromeOS( |
| 124 metrics::ChromeUserMetricsExtension* uma_proto) | 124 metrics::ChromeUserMetricsExtension* uma_proto) |
| 125 : MetricsLogChromeOS(uma_proto) { | 125 : MetricsLogChromeOS(uma_proto) { |
| 126 } | 126 } |
| 127 }; | 127 }; |
| 128 #endif // OS_CHROMEOS | 128 #endif // OS_CHROMEOS |
| 129 | 129 |
| 130 class TestMetricsLog : public MetricsLog { | 130 class TestMetricsLog : public MetricsLog { |
| 131 public: | 131 public: |
| 132 TestMetricsLog(const std::string& client_id, int session_id, LogType log_type) | |
| 133 : MetricsLog(client_id, session_id, log_type), | |
| 134 prefs_(&scoped_prefs_), | |
| 135 brand_for_testing_(kBrandForTesting) { | |
| 136 #if defined(OS_CHROMEOS) | |
| 137 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( | |
| 138 MetricsLog::uma_proto())); | |
| 139 #endif // OS_CHROMEOS | |
| 140 chrome::RegisterLocalState(scoped_prefs_.registry()); | |
| 141 InitPrefs(); | |
| 142 } | |
| 143 // Creates a TestMetricsLog that will use |prefs| as the fake local state. | |
| 144 // Useful for tests that need to re-use the local state prefs between logs. | |
| 145 TestMetricsLog(const std::string& client_id, | 132 TestMetricsLog(const std::string& client_id, |
| 146 int session_id, | 133 int session_id, |
| 147 LogType log_type, | 134 LogType log_type, |
| 148 TestingPrefServiceSimple* prefs) | 135 TestingPrefServiceSimple* prefs) |
| 149 : MetricsLog(client_id, session_id, log_type), | 136 : MetricsLog(client_id, session_id, log_type, prefs), |
| 150 prefs_(prefs), | 137 prefs_(prefs), |
| 151 brand_for_testing_(kBrandForTesting) { | 138 brand_for_testing_(kBrandForTesting) { |
| 152 #if defined(OS_CHROMEOS) | 139 #if defined(OS_CHROMEOS) |
| 153 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( | 140 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( |
| 154 MetricsLog::uma_proto())); | 141 MetricsLog::uma_proto())); |
| 155 #endif // OS_CHROMEOS | 142 #endif // OS_CHROMEOS |
| 156 InitPrefs(); | 143 InitPrefs(); |
| 157 } | 144 } |
| 158 virtual ~TestMetricsLog() {} | 145 virtual ~TestMetricsLog() {} |
| 159 | 146 |
| 160 virtual PrefService* GetPrefService() OVERRIDE { | |
| 161 return prefs_; | |
| 162 } | |
| 163 | |
| 164 const metrics::ChromeUserMetricsExtension& uma_proto() const { | 147 const metrics::ChromeUserMetricsExtension& uma_proto() const { |
| 165 return *MetricsLog::uma_proto(); | 148 return *MetricsLog::uma_proto(); |
| 166 } | 149 } |
| 167 | 150 |
| 168 const metrics::SystemProfileProto& system_profile() const { | 151 const metrics::SystemProfileProto& system_profile() const { |
| 169 return uma_proto().system_profile(); | 152 return uma_proto().system_profile(); |
| 170 } | 153 } |
| 171 | 154 |
| 172 private: | 155 private: |
| 173 void InitPrefs() { | 156 void InitPrefs() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 }; | 198 }; |
| 216 | 199 |
| 217 } // namespace | 200 } // namespace |
| 218 | 201 |
| 219 class MetricsLogTest : public testing::Test { | 202 class MetricsLogTest : public testing::Test { |
| 220 public: | 203 public: |
| 221 MetricsLogTest() {} | 204 MetricsLogTest() {} |
| 222 | 205 |
| 223 protected: | 206 protected: |
| 224 virtual void SetUp() OVERRIDE { | 207 virtual void SetUp() OVERRIDE { |
| 208 chrome::RegisterLocalState(prefs_.registry()); |
| 209 |
| 225 #if defined(OS_CHROMEOS) | 210 #if defined(OS_CHROMEOS) |
| 226 // Enable multi-profiles. | 211 // Enable multi-profiles. |
| 227 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); | 212 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); |
| 228 | 213 |
| 229 // Set up the fake Bluetooth environment, | 214 // Set up the fake Bluetooth environment, |
| 230 scoped_ptr<FakeDBusThreadManager> fake_dbus_thread_manager( | 215 scoped_ptr<FakeDBusThreadManager> fake_dbus_thread_manager( |
| 231 new FakeDBusThreadManager); | 216 new FakeDBusThreadManager); |
| 232 fake_dbus_thread_manager->SetBluetoothAdapterClient( | 217 fake_dbus_thread_manager->SetBluetoothAdapterClient( |
| 233 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); | 218 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); |
| 234 fake_dbus_thread_manager->SetBluetoothDeviceClient( | 219 fake_dbus_thread_manager->SetBluetoothDeviceClient( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 281 |
| 297 EXPECT_TRUE(hardware.has_cpu()); | 282 EXPECT_TRUE(hardware.has_cpu()); |
| 298 EXPECT_TRUE(hardware.cpu().has_vendor_name()); | 283 EXPECT_TRUE(hardware.cpu().has_vendor_name()); |
| 299 EXPECT_TRUE(hardware.cpu().has_signature()); | 284 EXPECT_TRUE(hardware.cpu().has_signature()); |
| 300 | 285 |
| 301 // TODO(isherman): Verify other data written into the protobuf as a result | 286 // TODO(isherman): Verify other data written into the protobuf as a result |
| 302 // of this call. | 287 // of this call. |
| 303 } | 288 } |
| 304 | 289 |
| 305 protected: | 290 protected: |
| 291 TestingPrefServiceSimple prefs_; |
| 306 #if defined(OS_CHROMEOS) | 292 #if defined(OS_CHROMEOS) |
| 307 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; | 293 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; |
| 308 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | 294 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; |
| 309 #endif // OS_CHROMEOS | 295 #endif // OS_CHROMEOS |
| 310 | 296 |
| 311 private: | 297 private: |
| 312 content::TestBrowserThreadBundle thread_bundle_; | 298 content::TestBrowserThreadBundle thread_bundle_; |
| 313 | 299 |
| 314 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); | 300 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); |
| 315 }; | 301 }; |
| 316 | 302 |
| 317 TEST_F(MetricsLogTest, RecordEnvironment) { | 303 TEST_F(MetricsLogTest, RecordEnvironment) { |
| 318 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 304 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 319 | 305 |
| 320 std::vector<content::WebPluginInfo> plugins; | 306 std::vector<content::WebPluginInfo> plugins; |
| 321 GoogleUpdateMetrics google_update_metrics; | 307 GoogleUpdateMetrics google_update_metrics; |
| 322 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 308 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; |
| 323 // Add two synthetic trials. | 309 // Add two synthetic trials. |
| 324 synthetic_trials.push_back(kSyntheticTrials[0]); | 310 synthetic_trials.push_back(kSyntheticTrials[0]); |
| 325 synthetic_trials.push_back(kSyntheticTrials[1]); | 311 synthetic_trials.push_back(kSyntheticTrials[1]); |
| 326 | 312 |
| 327 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials); | 313 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials); |
| 328 // Check that the system profile on the log has the correct values set. | 314 // Check that the system profile on the log has the correct values set. |
| 329 CheckSystemProfile(log.system_profile()); | 315 CheckSystemProfile(log.system_profile()); |
| 330 | 316 |
| 331 // Check that the system profile has also been written to prefs. | 317 // Check that the system profile has also been written to prefs. |
| 332 PrefService* local_state = log.GetPrefService(); | |
| 333 const std::string base64_system_profile = | 318 const std::string base64_system_profile = |
| 334 local_state->GetString(prefs::kStabilitySavedSystemProfile); | 319 prefs_.GetString(prefs::kStabilitySavedSystemProfile); |
| 335 EXPECT_FALSE(base64_system_profile.empty()); | 320 EXPECT_FALSE(base64_system_profile.empty()); |
| 336 std::string serialied_system_profile; | 321 std::string serialied_system_profile; |
| 337 EXPECT_TRUE(base::Base64Decode(base64_system_profile, | 322 EXPECT_TRUE(base::Base64Decode(base64_system_profile, |
| 338 &serialied_system_profile)); | 323 &serialied_system_profile)); |
| 339 SystemProfileProto decoded_system_profile; | 324 SystemProfileProto decoded_system_profile; |
| 340 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile)); | 325 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile)); |
| 341 CheckSystemProfile(decoded_system_profile); | 326 CheckSystemProfile(decoded_system_profile); |
| 342 } | 327 } |
| 343 | 328 |
| 344 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) { | 329 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) { |
| 345 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile; | 330 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile; |
| 346 const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash; | 331 const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash; |
| 347 | 332 |
| 348 TestingPrefServiceSimple prefs; | |
| 349 chrome::RegisterLocalState(prefs.registry()); | |
| 350 | |
| 351 // The pref value is empty, so loading it from prefs should fail. | 333 // The pref value is empty, so loading it from prefs should fail. |
| 352 { | 334 { |
| 353 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); | 335 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 354 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); | 336 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); |
| 355 } | 337 } |
| 356 | 338 |
| 357 // Do a RecordEnvironment() call and check whether the pref is recorded. | 339 // Do a RecordEnvironment() call and check whether the pref is recorded. |
| 358 { | 340 { |
| 359 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); | 341 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 360 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 342 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 361 GoogleUpdateMetrics(), | 343 GoogleUpdateMetrics(), |
| 362 std::vector<chrome_variations::ActiveGroupId>()); | 344 std::vector<chrome_variations::ActiveGroupId>()); |
| 363 EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty()); | 345 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); |
| 364 EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty()); | 346 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 365 } | 347 } |
| 366 | 348 |
| 367 { | 349 { |
| 368 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); | 350 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 369 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); | 351 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); |
| 370 // Check some values in the system profile. | 352 // Check some values in the system profile. |
| 371 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); | 353 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); |
| 372 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); | 354 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); |
| 373 // Ensure that the call cleared the prefs. | 355 // Ensure that the call cleared the prefs. |
| 374 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty()); | 356 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); |
| 375 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty()); | 357 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 376 } | 358 } |
| 377 | 359 |
| 378 // Ensure that a non-matching hash results in the pref being invalid. | 360 // Ensure that a non-matching hash results in the pref being invalid. |
| 379 { | 361 { |
| 380 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); | 362 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 381 // Call RecordEnvironment() to record the pref again. | 363 // Call RecordEnvironment() to record the pref again. |
| 382 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 364 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 383 GoogleUpdateMetrics(), | 365 GoogleUpdateMetrics(), |
| 384 std::vector<chrome_variations::ActiveGroupId>()); | 366 std::vector<chrome_variations::ActiveGroupId>()); |
| 385 } | 367 } |
| 386 | 368 |
| 387 { | 369 { |
| 388 // Set the hash to a bad value. | 370 // Set the hash to a bad value. |
| 389 prefs.SetString(kSystemProfileHashPref, "deadbeef"); | 371 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); |
| 390 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); | 372 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 391 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); | 373 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); |
| 392 // Ensure that the prefs are cleared, even if the call failed. | 374 // Ensure that the prefs are cleared, even if the call failed. |
| 393 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty()); | 375 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); |
| 394 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty()); | 376 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 395 } | 377 } |
| 396 } | 378 } |
| 397 | 379 |
| 398 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) { | 380 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) { |
| 399 TestMetricsLog log(kClientId, kSessionId, MetricsLog::INITIAL_STABILITY_LOG); | 381 TestMetricsLog log( |
| 382 kClientId, kSessionId, MetricsLog::INITIAL_STABILITY_LOG, &prefs_); |
| 400 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 383 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 401 GoogleUpdateMetrics(), | 384 GoogleUpdateMetrics(), |
| 402 std::vector<chrome_variations::ActiveGroupId>()); | 385 std::vector<chrome_variations::ActiveGroupId>()); |
| 403 log.RecordStabilityMetrics(base::TimeDelta(), base::TimeDelta()); | 386 log.RecordStabilityMetrics(base::TimeDelta(), base::TimeDelta()); |
| 404 const metrics::SystemProfileProto_Stability& stability = | 387 const metrics::SystemProfileProto_Stability& stability = |
| 405 log.system_profile().stability(); | 388 log.system_profile().stability(); |
| 406 // Required metrics: | 389 // Required metrics: |
| 407 EXPECT_TRUE(stability.has_launch_count()); | 390 EXPECT_TRUE(stability.has_launch_count()); |
| 408 EXPECT_TRUE(stability.has_crash_count()); | 391 EXPECT_TRUE(stability.has_crash_count()); |
| 409 // Initial log metrics: | 392 // Initial log metrics: |
| 410 EXPECT_TRUE(stability.has_incomplete_shutdown_count()); | 393 EXPECT_TRUE(stability.has_incomplete_shutdown_count()); |
| 411 EXPECT_TRUE(stability.has_breakpad_registration_success_count()); | 394 EXPECT_TRUE(stability.has_breakpad_registration_success_count()); |
| 412 EXPECT_TRUE(stability.has_breakpad_registration_failure_count()); | 395 EXPECT_TRUE(stability.has_breakpad_registration_failure_count()); |
| 413 EXPECT_TRUE(stability.has_debugger_present_count()); | 396 EXPECT_TRUE(stability.has_debugger_present_count()); |
| 414 EXPECT_TRUE(stability.has_debugger_not_present_count()); | 397 EXPECT_TRUE(stability.has_debugger_not_present_count()); |
| 415 } | 398 } |
| 416 | 399 |
| 417 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) { | 400 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) { |
| 418 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 401 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 419 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 402 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 420 GoogleUpdateMetrics(), | 403 GoogleUpdateMetrics(), |
| 421 std::vector<chrome_variations::ActiveGroupId>()); | 404 std::vector<chrome_variations::ActiveGroupId>()); |
| 422 log.RecordStabilityMetrics(base::TimeDelta(), base::TimeDelta()); | 405 log.RecordStabilityMetrics(base::TimeDelta(), base::TimeDelta()); |
| 423 const metrics::SystemProfileProto_Stability& stability = | 406 const metrics::SystemProfileProto_Stability& stability = |
| 424 log.system_profile().stability(); | 407 log.system_profile().stability(); |
| 425 // Required metrics: | 408 // Required metrics: |
| 426 EXPECT_TRUE(stability.has_launch_count()); | 409 EXPECT_TRUE(stability.has_launch_count()); |
| 427 EXPECT_TRUE(stability.has_crash_count()); | 410 EXPECT_TRUE(stability.has_crash_count()); |
| 428 // Initial log metrics: | 411 // Initial log metrics: |
| 429 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); | 412 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); |
| 430 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); | 413 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); |
| 431 EXPECT_FALSE(stability.has_breakpad_registration_failure_count()); | 414 EXPECT_FALSE(stability.has_breakpad_registration_failure_count()); |
| 432 EXPECT_FALSE(stability.has_debugger_present_count()); | 415 EXPECT_FALSE(stability.has_debugger_present_count()); |
| 433 EXPECT_FALSE(stability.has_debugger_not_present_count()); | 416 EXPECT_FALSE(stability.has_debugger_not_present_count()); |
| 434 } | 417 } |
| 435 | 418 |
| 436 #if defined(ENABLE_PLUGINS) | 419 #if defined(ENABLE_PLUGINS) |
| 437 TEST_F(MetricsLogTest, Plugins) { | 420 TEST_F(MetricsLogTest, Plugins) { |
| 438 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 421 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 439 | 422 |
| 440 std::vector<content::WebPluginInfo> plugins; | 423 std::vector<content::WebPluginInfo> plugins; |
| 441 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"), | 424 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"), |
| 442 "1.5", true)); | 425 "1.5", true)); |
| 443 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"), | 426 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"), |
| 444 "2.0", false)); | 427 "2.0", false)); |
| 445 log.RecordEnvironment(plugins, GoogleUpdateMetrics(), | 428 log.RecordEnvironment(plugins, GoogleUpdateMetrics(), |
| 446 std::vector<chrome_variations::ActiveGroupId>()); | 429 std::vector<chrome_variations::ActiveGroupId>()); |
| 447 | 430 |
| 448 const metrics::SystemProfileProto& system_profile = log.system_profile(); | 431 const metrics::SystemProfileProto& system_profile = log.system_profile(); |
| 449 ASSERT_EQ(2, system_profile.plugin_size()); | 432 ASSERT_EQ(2, system_profile.plugin_size()); |
| 450 EXPECT_EQ("p1", system_profile.plugin(0).name()); | 433 EXPECT_EQ("p1", system_profile.plugin(0).name()); |
| 451 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename()); | 434 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename()); |
| 452 EXPECT_EQ("1.5", system_profile.plugin(0).version()); | 435 EXPECT_EQ("1.5", system_profile.plugin(0).version()); |
| 453 EXPECT_TRUE(system_profile.plugin(0).is_pepper()); | 436 EXPECT_TRUE(system_profile.plugin(0).is_pepper()); |
| 454 EXPECT_EQ("p2", system_profile.plugin(1).name()); | 437 EXPECT_EQ("p2", system_profile.plugin(1).name()); |
| 455 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename()); | 438 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename()); |
| 456 EXPECT_EQ("2.0", system_profile.plugin(1).version()); | 439 EXPECT_EQ("2.0", system_profile.plugin(1).version()); |
| 457 EXPECT_FALSE(system_profile.plugin(1).is_pepper()); | 440 EXPECT_FALSE(system_profile.plugin(1).is_pepper()); |
| 458 | 441 |
| 459 // Now set some plugin stability stats for p2 and verify they're recorded. | 442 // Now set some plugin stability stats for p2 and verify they're recorded. |
| 460 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue); | 443 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue); |
| 461 plugin_dict->SetString(prefs::kStabilityPluginName, "p2"); | 444 plugin_dict->SetString(prefs::kStabilityPluginName, "p2"); |
| 462 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1); | 445 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1); |
| 463 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2); | 446 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2); |
| 464 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3); | 447 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3); |
| 465 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4); | 448 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4); |
| 466 { | 449 { |
| 467 ListPrefUpdate update(log.GetPrefService(), prefs::kStabilityPluginStats); | 450 ListPrefUpdate update(&prefs_, prefs::kStabilityPluginStats); |
| 468 update.Get()->Append(plugin_dict.release()); | 451 update.Get()->Append(plugin_dict.release()); |
| 469 } | 452 } |
| 470 | 453 |
| 471 log.RecordStabilityMetrics(base::TimeDelta(), base::TimeDelta()); | 454 log.RecordStabilityMetrics(base::TimeDelta(), base::TimeDelta()); |
| 472 const metrics::SystemProfileProto_Stability& stability = | 455 const metrics::SystemProfileProto_Stability& stability = |
| 473 log.system_profile().stability(); | 456 log.system_profile().stability(); |
| 474 ASSERT_EQ(1, stability.plugin_stability_size()); | 457 ASSERT_EQ(1, stability.plugin_stability_size()); |
| 475 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name()); | 458 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name()); |
| 476 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename()); | 459 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename()); |
| 477 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version()); | 460 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version()); |
| 478 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper()); | 461 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper()); |
| 479 EXPECT_EQ(1, stability.plugin_stability(0).launch_count()); | 462 EXPECT_EQ(1, stability.plugin_stability(0).launch_count()); |
| 480 EXPECT_EQ(2, stability.plugin_stability(0).crash_count()); | 463 EXPECT_EQ(2, stability.plugin_stability(0).crash_count()); |
| 481 EXPECT_EQ(3, stability.plugin_stability(0).instance_count()); | 464 EXPECT_EQ(3, stability.plugin_stability(0).instance_count()); |
| 482 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count()); | 465 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count()); |
| 483 } | 466 } |
| 484 #endif // defined(ENABLE_PLUGINS) | 467 #endif // defined(ENABLE_PLUGINS) |
| 485 | 468 |
| 486 // Test that we properly write profiler data to the log. | 469 // Test that we properly write profiler data to the log. |
| 487 TEST_F(MetricsLogTest, RecordProfilerData) { | 470 TEST_F(MetricsLogTest, RecordProfilerData) { |
| 488 // WARNING: If you broke the below check, you've modified how | 471 // WARNING: If you broke the below check, you've modified how |
| 489 // metrics::HashMetricName works. Please also modify all server-side code that | 472 // metrics::HashMetricName works. Please also modify all server-side code that |
| 490 // relies on the existing way of hashing. | 473 // relies on the existing way of hashing. |
| 491 EXPECT_EQ(GG_UINT64_C(1518842999910132863), | 474 EXPECT_EQ(GG_UINT64_C(1518842999910132863), |
| 492 metrics::HashMetricName("birth_thread*")); | 475 metrics::HashMetricName("birth_thread*")); |
| 493 | 476 |
| 494 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 477 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 495 EXPECT_EQ(0, log.uma_proto().profiler_event_size()); | 478 EXPECT_EQ(0, log.uma_proto().profiler_event_size()); |
| 496 | 479 |
| 497 { | 480 { |
| 498 ProcessDataSnapshot process_data; | 481 ProcessDataSnapshot process_data; |
| 499 process_data.process_id = 177; | 482 process_data.process_id = 177; |
| 500 process_data.tasks.push_back(TaskSnapshot()); | 483 process_data.tasks.push_back(TaskSnapshot()); |
| 501 process_data.tasks.back().birth.location.file_name = "a/b/file.h"; | 484 process_data.tasks.back().birth.location.file_name = "a/b/file.h"; |
| 502 process_data.tasks.back().birth.location.function_name = "function"; | 485 process_data.tasks.back().birth.location.function_name = "function"; |
| 503 process_data.tasks.back().birth.location.line_number = 1337; | 486 process_data.tasks.back().birth.location.line_number = 1337; |
| 504 process_data.tasks.back().birth.thread_name = "birth_thread"; | 487 process_data.tasks.back().birth.thread_name = "birth_thread"; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 EXPECT_EQ(109, tracked_object->queue_time_total()); | 628 EXPECT_EQ(109, tracked_object->queue_time_total()); |
| 646 EXPECT_EQ(104, tracked_object->queue_time_sampled()); | 629 EXPECT_EQ(104, tracked_object->queue_time_sampled()); |
| 647 EXPECT_EQ(metrics::HashMetricName(""), | 630 EXPECT_EQ(metrics::HashMetricName(""), |
| 648 tracked_object->exec_thread_name_hash()); | 631 tracked_object->exec_thread_name_hash()); |
| 649 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, | 632 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, |
| 650 tracked_object->process_type()); | 633 tracked_object->process_type()); |
| 651 } | 634 } |
| 652 } | 635 } |
| 653 | 636 |
| 654 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { | 637 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { |
| 655 TestMetricsLog log("user@test.com", kSessionId, MetricsLog::ONGOING_LOG); | 638 TestMetricsLog log( |
| 639 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 656 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); | 640 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); |
| 657 } | 641 } |
| 658 | 642 |
| 659 #if defined(OS_CHROMEOS) | 643 #if defined(OS_CHROMEOS) |
| 660 TEST_F(MetricsLogTest, MultiProfileUserCount) { | 644 TEST_F(MetricsLogTest, MultiProfileUserCount) { |
| 661 std::string user1("user1@example.com"); | 645 std::string user1("user1@example.com"); |
| 662 std::string user2("user2@example.com"); | 646 std::string user2("user2@example.com"); |
| 663 std::string user3("user3@example.com"); | 647 std::string user3("user3@example.com"); |
| 664 | 648 |
| 665 // |scoped_enabler| takes over the lifetime of |user_manager|. | 649 // |scoped_enabler| takes over the lifetime of |user_manager|. |
| 666 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); | 650 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); |
| 667 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); | 651 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); |
| 668 user_manager->AddKioskAppUser(user1); | 652 user_manager->AddKioskAppUser(user1); |
| 669 user_manager->AddKioskAppUser(user2); | 653 user_manager->AddKioskAppUser(user2); |
| 670 user_manager->AddKioskAppUser(user3); | 654 user_manager->AddKioskAppUser(user3); |
| 671 | 655 |
| 672 user_manager->LoginUser(user1); | 656 user_manager->LoginUser(user1); |
| 673 user_manager->LoginUser(user3); | 657 user_manager->LoginUser(user3); |
| 674 | 658 |
| 675 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 659 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 676 std::vector<content::WebPluginInfo> plugins; | 660 std::vector<content::WebPluginInfo> plugins; |
| 677 GoogleUpdateMetrics google_update_metrics; | 661 GoogleUpdateMetrics google_update_metrics; |
| 678 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 662 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; |
| 679 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials); | 663 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials); |
| 680 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count()); | 664 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count()); |
| 681 } | 665 } |
| 682 | 666 |
| 683 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) { | 667 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) { |
| 684 std::string user1("user1@example.com"); | 668 std::string user1("user1@example.com"); |
| 685 std::string user2("user2@example.com"); | 669 std::string user2("user2@example.com"); |
| 686 std::string user3("user3@example.com"); | 670 std::string user3("user3@example.com"); |
| 687 | 671 |
| 688 // |scoped_enabler| takes over the lifetime of |user_manager|. | 672 // |scoped_enabler| takes over the lifetime of |user_manager|. |
| 689 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); | 673 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); |
| 690 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); | 674 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); |
| 691 user_manager->AddKioskAppUser(user1); | 675 user_manager->AddKioskAppUser(user1); |
| 692 user_manager->AddKioskAppUser(user2); | 676 user_manager->AddKioskAppUser(user2); |
| 693 user_manager->AddKioskAppUser(user3); | 677 user_manager->AddKioskAppUser(user3); |
| 694 | 678 |
| 695 user_manager->LoginUser(user1); | 679 user_manager->LoginUser(user1); |
| 696 | 680 |
| 697 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 681 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 698 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count()); | 682 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count()); |
| 699 | 683 |
| 700 user_manager->LoginUser(user2); | 684 user_manager->LoginUser(user2); |
| 701 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 685 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; |
| 702 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 686 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 703 GoogleUpdateMetrics(), synthetic_trials); | 687 GoogleUpdateMetrics(), synthetic_trials); |
| 704 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count()); | 688 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count()); |
| 705 } | 689 } |
| 706 | 690 |
| 707 TEST_F(MetricsLogTest, BluetoothHardwareDisabled) { | 691 TEST_F(MetricsLogTest, BluetoothHardwareDisabled) { |
| 708 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 692 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 709 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 693 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 710 GoogleUpdateMetrics(), | 694 GoogleUpdateMetrics(), |
| 711 std::vector<chrome_variations::ActiveGroupId>()); | 695 std::vector<chrome_variations::ActiveGroupId>()); |
| 712 | 696 |
| 713 EXPECT_TRUE(log.system_profile().has_hardware()); | 697 EXPECT_TRUE(log.system_profile().has_hardware()); |
| 714 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); | 698 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); |
| 715 | 699 |
| 716 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); | 700 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); |
| 717 EXPECT_FALSE(log.system_profile().hardware().bluetooth().is_enabled()); | 701 EXPECT_FALSE(log.system_profile().hardware().bluetooth().is_enabled()); |
| 718 } | 702 } |
| 719 | 703 |
| 720 TEST_F(MetricsLogTest, BluetoothHardwareEnabled) { | 704 TEST_F(MetricsLogTest, BluetoothHardwareEnabled) { |
| 721 FakeBluetoothAdapterClient::Properties* properties = | 705 FakeBluetoothAdapterClient::Properties* properties = |
| 722 fake_bluetooth_adapter_client_->GetProperties( | 706 fake_bluetooth_adapter_client_->GetProperties( |
| 723 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | 707 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); |
| 724 properties->powered.ReplaceValue(true); | 708 properties->powered.ReplaceValue(true); |
| 725 | 709 |
| 726 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 710 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 727 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 711 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 728 GoogleUpdateMetrics(), | 712 GoogleUpdateMetrics(), |
| 729 std::vector<chrome_variations::ActiveGroupId>()); | 713 std::vector<chrome_variations::ActiveGroupId>()); |
| 730 | 714 |
| 731 EXPECT_TRUE(log.system_profile().has_hardware()); | 715 EXPECT_TRUE(log.system_profile().has_hardware()); |
| 732 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); | 716 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); |
| 733 | 717 |
| 734 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); | 718 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); |
| 735 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_enabled()); | 719 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_enabled()); |
| 736 } | 720 } |
| 737 | 721 |
| 738 TEST_F(MetricsLogTest, BluetoothPairedDevices) { | 722 TEST_F(MetricsLogTest, BluetoothPairedDevices) { |
| 739 // The fake bluetooth adapter class already claims to be paired with one | 723 // The fake bluetooth adapter class already claims to be paired with one |
| 740 // device when initialized. Add a second and third fake device to it so we | 724 // device when initialized. Add a second and third fake device to it so we |
| 741 // can test the cases where a device is not paired (LE device, generally) | 725 // can test the cases where a device is not paired (LE device, generally) |
| 742 // and a device that does not have Device ID information. | 726 // and a device that does not have Device ID information. |
| 743 fake_bluetooth_device_client_->CreateDevice( | 727 fake_bluetooth_device_client_->CreateDevice( |
| 744 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 728 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 745 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | 729 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); |
| 746 | 730 |
| 747 fake_bluetooth_device_client_->CreateDevice( | 731 fake_bluetooth_device_client_->CreateDevice( |
| 748 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | 732 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), |
| 749 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 733 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 750 | 734 |
| 751 FakeBluetoothDeviceClient::Properties* properties = | 735 FakeBluetoothDeviceClient::Properties* properties = |
| 752 fake_bluetooth_device_client_->GetProperties( | 736 fake_bluetooth_device_client_->GetProperties( |
| 753 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | 737 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); |
| 754 properties->paired.ReplaceValue(true); | 738 properties->paired.ReplaceValue(true); |
| 755 | 739 |
| 756 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); | 740 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_); |
| 757 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | 741 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
| 758 GoogleUpdateMetrics(), | 742 GoogleUpdateMetrics(), |
| 759 std::vector<chrome_variations::ActiveGroupId>()); | 743 std::vector<chrome_variations::ActiveGroupId>()); |
| 760 | 744 |
| 761 ASSERT_TRUE(log.system_profile().has_hardware()); | 745 ASSERT_TRUE(log.system_profile().has_hardware()); |
| 762 ASSERT_TRUE(log.system_profile().hardware().has_bluetooth()); | 746 ASSERT_TRUE(log.system_profile().hardware().has_bluetooth()); |
| 763 | 747 |
| 764 // Only two of the devices should appear. | 748 // Only two of the devices should appear. |
| 765 EXPECT_EQ(2, | 749 EXPECT_EQ(2, |
| 766 log.system_profile().hardware().bluetooth().paired_device_size()); | 750 log.system_profile().hardware().bluetooth().paired_device_size()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 787 PairedDevice device2 = | 771 PairedDevice device2 = |
| 788 log.system_profile().hardware().bluetooth().paired_device(1); | 772 log.system_profile().hardware().bluetooth().paired_device(1); |
| 789 | 773 |
| 790 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, | 774 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, |
| 791 device2.bluetooth_class()); | 775 device2.bluetooth_class()); |
| 792 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); | 776 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); |
| 793 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); | 777 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); |
| 794 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); | 778 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); |
| 795 } | 779 } |
| 796 #endif // OS_CHROMEOS | 780 #endif // OS_CHROMEOS |
| OLD | NEW |