Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/metrics/metrics_log_unittest.cc

Issue 299783004: Create PluginMetricsProvider class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
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/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/prefs/testing_pref_service.h" 15 #include "base/prefs/testing_pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/time/time.h" 20 #include "base/time/time.h"
22 #include "base/tracked_objects.h" 21 #include "base/tracked_objects.h"
23 #include "chrome/browser/google/google_util.h" 22 #include "chrome/browser/google/google_util.h"
24 #include "chrome/browser/prefs/browser_prefs.h" 23 #include "chrome/browser/prefs/browser_prefs.h"
25 #include "chrome/common/chrome_version_info.h" 24 #include "chrome/common/chrome_version_info.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "chrome/installer/util/google_update_settings.h"
28 #include "components/metrics/metrics_hashes.h" 26 #include "components/metrics/metrics_hashes.h"
29 #include "components/metrics/metrics_provider.h" 27 #include "components/metrics/metrics_provider.h"
30 #include "components/metrics/proto/profiler_event.pb.h" 28 #include "components/metrics/proto/profiler_event.pb.h"
31 #include "components/metrics/proto/system_profile.pb.h" 29 #include "components/metrics/proto/system_profile.pb.h"
32 #include "components/variations/active_field_trials.h" 30 #include "components/variations/active_field_trials.h"
33 #include "components/variations/metrics_util.h"
34 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
35 #include "content/public/common/process_type.h" 32 #include "content/public/common/process_type.h"
36 #include "content/public/common/webplugininfo.h"
37 #include "content/public/test/test_browser_thread_bundle.h" 33 #include "content/public/test/test_browser_thread_bundle.h"
38 #include "content/public/test/test_utils.h" 34 #include "content/public/test/test_utils.h"
39 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/gfx/size.h" 36 #include "ui/gfx/size.h"
41 #include "url/gurl.h" 37 #include "url/gurl.h"
42 38
43 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
44 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" 40 #include "chrome/browser/chromeos/login/users/fake_user_manager.h"
45 #include "chrome/browser/chromeos/login/users/user_manager.h" 41 #include "chrome/browser/chromeos/login/users/user_manager.h"
46 #include "chrome/browser/metrics/metrics_log_chromeos.h" 42 #include "chrome/browser/metrics/metrics_log_chromeos.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const variations::ActiveGroupId kFieldTrialIds[] = { 88 const variations::ActiveGroupId kFieldTrialIds[] = {
93 {37, 43}, 89 {37, 43},
94 {13, 47}, 90 {13, 47},
95 {23, 17} 91 {23, 17}
96 }; 92 };
97 const variations::ActiveGroupId kSyntheticTrials[] = { 93 const variations::ActiveGroupId kSyntheticTrials[] = {
98 {55, 15}, 94 {55, 15},
99 {66, 16} 95 {66, 16}
100 }; 96 };
101 97
102 #if defined(ENABLE_PLUGINS)
103 content::WebPluginInfo CreateFakePluginInfo(
104 const std::string& name,
105 const base::FilePath::CharType* path,
106 const std::string& version,
107 bool is_pepper) {
108 content::WebPluginInfo plugin(base::UTF8ToUTF16(name),
109 base::FilePath(path),
110 base::UTF8ToUTF16(version),
111 base::string16());
112 if (is_pepper)
113 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS;
114 else
115 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI;
116 return plugin;
117 }
118 #endif // defined(ENABLE_PLUGINS)
119
120 #if defined(OS_CHROMEOS) 98 #if defined(OS_CHROMEOS)
121 class TestMetricsLogChromeOS : public MetricsLogChromeOS { 99 class TestMetricsLogChromeOS : public MetricsLogChromeOS {
122 public: 100 public:
123 explicit TestMetricsLogChromeOS( 101 explicit TestMetricsLogChromeOS(
124 metrics::ChromeUserMetricsExtension* uma_proto) 102 metrics::ChromeUserMetricsExtension* uma_proto)
125 : MetricsLogChromeOS(uma_proto) { 103 : MetricsLogChromeOS(uma_proto) {
126 } 104 }
127 }; 105 };
128 #endif // OS_CHROMEOS 106 #endif // OS_CHROMEOS
129 107
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 285
308 private: 286 private:
309 content::TestBrowserThreadBundle thread_bundle_; 287 content::TestBrowserThreadBundle thread_bundle_;
310 288
311 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); 289 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest);
312 }; 290 };
313 291
314 TEST_F(MetricsLogTest, RecordEnvironment) { 292 TEST_F(MetricsLogTest, RecordEnvironment) {
315 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 293 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
316 294
317 std::vector<content::WebPluginInfo> plugins;
318 std::vector<variations::ActiveGroupId> synthetic_trials; 295 std::vector<variations::ActiveGroupId> synthetic_trials;
319 // Add two synthetic trials. 296 // Add two synthetic trials.
320 synthetic_trials.push_back(kSyntheticTrials[0]); 297 synthetic_trials.push_back(kSyntheticTrials[0]);
321 synthetic_trials.push_back(kSyntheticTrials[1]); 298 synthetic_trials.push_back(kSyntheticTrials[1]);
322 299
323 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), 300 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
324 plugins, synthetic_trials); 301 synthetic_trials);
325 // Check that the system profile on the log has the correct values set. 302 // Check that the system profile on the log has the correct values set.
326 CheckSystemProfile(log.system_profile()); 303 CheckSystemProfile(log.system_profile());
327 304
328 // Check that the system profile has also been written to prefs. 305 // Check that the system profile has also been written to prefs.
329 PrefService* local_state = log.GetPrefService(); 306 PrefService* local_state = log.GetPrefService();
330 const std::string base64_system_profile = 307 const std::string base64_system_profile =
331 local_state->GetString(prefs::kStabilitySavedSystemProfile); 308 local_state->GetString(prefs::kStabilitySavedSystemProfile);
332 EXPECT_FALSE(base64_system_profile.empty()); 309 EXPECT_FALSE(base64_system_profile.empty());
333 std::string serialied_system_profile; 310 std::string serialied_system_profile;
334 EXPECT_TRUE(base::Base64Decode(base64_system_profile, 311 EXPECT_TRUE(base::Base64Decode(base64_system_profile,
(...skipping 13 matching lines...) Expand all
348 // The pref value is empty, so loading it from prefs should fail. 325 // The pref value is empty, so loading it from prefs should fail.
349 { 326 {
350 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); 327 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
351 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); 328 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
352 } 329 }
353 330
354 // Do a RecordEnvironment() call and check whether the pref is recorded. 331 // Do a RecordEnvironment() call and check whether the pref is recorded.
355 { 332 {
356 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); 333 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
357 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), 334 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
358 std::vector<content::WebPluginInfo>(),
359 std::vector<variations::ActiveGroupId>()); 335 std::vector<variations::ActiveGroupId>());
360 EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty()); 336 EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty());
361 EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty()); 337 EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty());
362 } 338 }
363 339
364 { 340 {
365 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); 341 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
366 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); 342 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs());
367 // Check some values in the system profile. 343 // Check some values in the system profile.
368 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); 344 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
369 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); 345 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
370 // Ensure that the call cleared the prefs. 346 // Ensure that the call cleared the prefs.
371 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty()); 347 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
372 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty()); 348 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
373 } 349 }
374 350
375 // Ensure that a non-matching hash results in the pref being invalid. 351 // Ensure that a non-matching hash results in the pref being invalid.
376 { 352 {
377 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); 353 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
378 // Call RecordEnvironment() to record the pref again. 354 // Call RecordEnvironment() to record the pref again.
379 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), 355 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
380 std::vector<content::WebPluginInfo>(),
381 std::vector<variations::ActiveGroupId>()); 356 std::vector<variations::ActiveGroupId>());
382 } 357 }
383 358
384 { 359 {
385 // Set the hash to a bad value. 360 // Set the hash to a bad value.
386 prefs.SetString(kSystemProfileHashPref, "deadbeef"); 361 prefs.SetString(kSystemProfileHashPref, "deadbeef");
387 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs); 362 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
388 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); 363 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
389 // Ensure that the prefs are cleared, even if the call failed. 364 // Ensure that the prefs are cleared, even if the call failed.
390 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty()); 365 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
391 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty()); 366 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
392 } 367 }
393 } 368 }
394 369
395 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) { 370 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
396 TestMetricsLog log(kClientId, kSessionId, MetricsLog::INITIAL_STABILITY_LOG); 371 TestMetricsLog log(kClientId, kSessionId, MetricsLog::INITIAL_STABILITY_LOG);
397 std::vector<metrics::MetricsProvider*> metrics_providers; 372 std::vector<metrics::MetricsProvider*> metrics_providers;
398 log.RecordEnvironment(metrics_providers, 373 log.RecordEnvironment(metrics_providers,
399 std::vector<content::WebPluginInfo>(),
400 std::vector<variations::ActiveGroupId>()); 374 std::vector<variations::ActiveGroupId>());
401 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), 375 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
402 base::TimeDelta()); 376 base::TimeDelta());
403 const metrics::SystemProfileProto_Stability& stability = 377 const metrics::SystemProfileProto_Stability& stability =
404 log.system_profile().stability(); 378 log.system_profile().stability();
405 // Required metrics: 379 // Required metrics:
406 EXPECT_TRUE(stability.has_launch_count()); 380 EXPECT_TRUE(stability.has_launch_count());
407 EXPECT_TRUE(stability.has_crash_count()); 381 EXPECT_TRUE(stability.has_crash_count());
408 // Initial log metrics: 382 // Initial log metrics:
409 EXPECT_TRUE(stability.has_incomplete_shutdown_count()); 383 EXPECT_TRUE(stability.has_incomplete_shutdown_count());
410 EXPECT_TRUE(stability.has_breakpad_registration_success_count()); 384 EXPECT_TRUE(stability.has_breakpad_registration_success_count());
411 EXPECT_TRUE(stability.has_breakpad_registration_failure_count()); 385 EXPECT_TRUE(stability.has_breakpad_registration_failure_count());
412 EXPECT_TRUE(stability.has_debugger_present_count()); 386 EXPECT_TRUE(stability.has_debugger_present_count());
413 EXPECT_TRUE(stability.has_debugger_not_present_count()); 387 EXPECT_TRUE(stability.has_debugger_not_present_count());
414 } 388 }
415 389
416 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) { 390 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
417 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 391 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
418 std::vector<metrics::MetricsProvider*> metrics_providers; 392 std::vector<metrics::MetricsProvider*> metrics_providers;
419 log.RecordEnvironment(metrics_providers, 393 log.RecordEnvironment(metrics_providers,
420 std::vector<content::WebPluginInfo>(),
421 std::vector<variations::ActiveGroupId>()); 394 std::vector<variations::ActiveGroupId>());
422 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), 395 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
423 base::TimeDelta()); 396 base::TimeDelta());
424 const metrics::SystemProfileProto_Stability& stability = 397 const metrics::SystemProfileProto_Stability& stability =
425 log.system_profile().stability(); 398 log.system_profile().stability();
426 // Required metrics: 399 // Required metrics:
427 EXPECT_TRUE(stability.has_launch_count()); 400 EXPECT_TRUE(stability.has_launch_count());
428 EXPECT_TRUE(stability.has_crash_count()); 401 EXPECT_TRUE(stability.has_crash_count());
429 // Initial log metrics: 402 // Initial log metrics:
430 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); 403 EXPECT_FALSE(stability.has_incomplete_shutdown_count());
431 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); 404 EXPECT_FALSE(stability.has_breakpad_registration_success_count());
432 EXPECT_FALSE(stability.has_breakpad_registration_failure_count()); 405 EXPECT_FALSE(stability.has_breakpad_registration_failure_count());
433 EXPECT_FALSE(stability.has_debugger_present_count()); 406 EXPECT_FALSE(stability.has_debugger_present_count());
434 EXPECT_FALSE(stability.has_debugger_not_present_count()); 407 EXPECT_FALSE(stability.has_debugger_not_present_count());
435 } 408 }
436 409
437 #if defined(ENABLE_PLUGINS)
438 TEST_F(MetricsLogTest, Plugins) {
439 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
440 std::vector<metrics::MetricsProvider*> metrics_providers;
441
442 std::vector<content::WebPluginInfo> plugins;
443 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"),
444 "1.5", true));
445 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"),
446 "2.0", false));
447 log.RecordEnvironment(metrics_providers, plugins,
448 std::vector<variations::ActiveGroupId>());
449
450 const metrics::SystemProfileProto& system_profile = log.system_profile();
451 ASSERT_EQ(2, system_profile.plugin_size());
452 EXPECT_EQ("p1", system_profile.plugin(0).name());
453 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename());
454 EXPECT_EQ("1.5", system_profile.plugin(0).version());
455 EXPECT_TRUE(system_profile.plugin(0).is_pepper());
456 EXPECT_EQ("p2", system_profile.plugin(1).name());
457 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename());
458 EXPECT_EQ("2.0", system_profile.plugin(1).version());
459 EXPECT_FALSE(system_profile.plugin(1).is_pepper());
460
461 // Now set some plugin stability stats for p2 and verify they're recorded.
462 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue);
463 plugin_dict->SetString(prefs::kStabilityPluginName, "p2");
464 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1);
465 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2);
466 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3);
467 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4);
468 {
469 ListPrefUpdate update(log.GetPrefService(), prefs::kStabilityPluginStats);
470 update.Get()->Append(plugin_dict.release());
471 }
472
473 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
474 base::TimeDelta());
475 const metrics::SystemProfileProto_Stability& stability =
476 log.system_profile().stability();
477 ASSERT_EQ(1, stability.plugin_stability_size());
478 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name());
479 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename());
480 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version());
481 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper());
482 EXPECT_EQ(1, stability.plugin_stability(0).launch_count());
483 EXPECT_EQ(2, stability.plugin_stability(0).crash_count());
484 EXPECT_EQ(3, stability.plugin_stability(0).instance_count());
485 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count());
486 }
487 #endif // defined(ENABLE_PLUGINS)
488
489 // Test that we properly write profiler data to the log. 410 // Test that we properly write profiler data to the log.
490 TEST_F(MetricsLogTest, RecordProfilerData) { 411 TEST_F(MetricsLogTest, RecordProfilerData) {
491 // WARNING: If you broke the below check, you've modified how 412 // WARNING: If you broke the below check, you've modified how
492 // metrics::HashMetricName works. Please also modify all server-side code that 413 // metrics::HashMetricName works. Please also modify all server-side code that
493 // relies on the existing way of hashing. 414 // relies on the existing way of hashing.
494 EXPECT_EQ(GG_UINT64_C(1518842999910132863), 415 EXPECT_EQ(GG_UINT64_C(1518842999910132863),
495 metrics::HashMetricName("birth_thread*")); 416 metrics::HashMetricName("birth_thread*"));
496 417
497 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 418 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
498 EXPECT_EQ(0, log.uma_proto().profiler_event_size()); 419 EXPECT_EQ(0, log.uma_proto().profiler_event_size());
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); 591 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
671 user_manager->AddKioskAppUser(user1); 592 user_manager->AddKioskAppUser(user1);
672 user_manager->AddKioskAppUser(user2); 593 user_manager->AddKioskAppUser(user2);
673 user_manager->AddKioskAppUser(user3); 594 user_manager->AddKioskAppUser(user3);
674 595
675 user_manager->LoginUser(user1); 596 user_manager->LoginUser(user1);
676 user_manager->LoginUser(user3); 597 user_manager->LoginUser(user3);
677 598
678 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 599 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
679 std::vector<metrics::MetricsProvider*> metrics_providers; 600 std::vector<metrics::MetricsProvider*> metrics_providers;
680 std::vector<content::WebPluginInfo> plugins;
681 std::vector<variations::ActiveGroupId> synthetic_trials; 601 std::vector<variations::ActiveGroupId> synthetic_trials;
682 log.RecordEnvironment(metrics_providers, plugins, synthetic_trials); 602 log.RecordEnvironment(metrics_providers, synthetic_trials);
683 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count()); 603 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count());
684 } 604 }
685 605
686 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) { 606 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) {
687 std::string user1("user1@example.com"); 607 std::string user1("user1@example.com");
688 std::string user2("user2@example.com"); 608 std::string user2("user2@example.com");
689 std::string user3("user3@example.com"); 609 std::string user3("user3@example.com");
690 610
691 // |scoped_enabler| takes over the lifetime of |user_manager|. 611 // |scoped_enabler| takes over the lifetime of |user_manager|.
692 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); 612 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
693 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); 613 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
694 user_manager->AddKioskAppUser(user1); 614 user_manager->AddKioskAppUser(user1);
695 user_manager->AddKioskAppUser(user2); 615 user_manager->AddKioskAppUser(user2);
696 user_manager->AddKioskAppUser(user3); 616 user_manager->AddKioskAppUser(user3);
697 617
698 user_manager->LoginUser(user1); 618 user_manager->LoginUser(user1);
699 619
700 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 620 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
701 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count()); 621 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count());
702 622
703 user_manager->LoginUser(user2); 623 user_manager->LoginUser(user2);
704 std::vector<metrics::MetricsProvider*> metrics_providers; 624 std::vector<metrics::MetricsProvider*> metrics_providers;
705 std::vector<variations::ActiveGroupId> synthetic_trials; 625 std::vector<variations::ActiveGroupId> synthetic_trials;
706 log.RecordEnvironment(metrics_providers, 626 log.RecordEnvironment(metrics_providers, synthetic_trials);
707 std::vector<content::WebPluginInfo>(),
708 synthetic_trials);
709 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count()); 627 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count());
710 } 628 }
711 629
712 TEST_F(MetricsLogTest, BluetoothHardwareDisabled) { 630 TEST_F(MetricsLogTest, BluetoothHardwareDisabled) {
713 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 631 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
714 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), 632 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
715 std::vector<content::WebPluginInfo>(),
716 std::vector<variations::ActiveGroupId>()); 633 std::vector<variations::ActiveGroupId>());
717 634
718 EXPECT_TRUE(log.system_profile().has_hardware()); 635 EXPECT_TRUE(log.system_profile().has_hardware());
719 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); 636 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth());
720 637
721 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); 638 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present());
722 EXPECT_FALSE(log.system_profile().hardware().bluetooth().is_enabled()); 639 EXPECT_FALSE(log.system_profile().hardware().bluetooth().is_enabled());
723 } 640 }
724 641
725 TEST_F(MetricsLogTest, BluetoothHardwareEnabled) { 642 TEST_F(MetricsLogTest, BluetoothHardwareEnabled) {
726 FakeBluetoothAdapterClient::Properties* properties = 643 FakeBluetoothAdapterClient::Properties* properties =
727 fake_bluetooth_adapter_client_->GetProperties( 644 fake_bluetooth_adapter_client_->GetProperties(
728 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 645 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
729 properties->powered.ReplaceValue(true); 646 properties->powered.ReplaceValue(true);
730 647
731 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 648 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
732 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), 649 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
733 std::vector<content::WebPluginInfo>(),
734 std::vector<variations::ActiveGroupId>()); 650 std::vector<variations::ActiveGroupId>());
735 651
736 EXPECT_TRUE(log.system_profile().has_hardware()); 652 EXPECT_TRUE(log.system_profile().has_hardware());
737 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); 653 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth());
738 654
739 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); 655 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present());
740 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_enabled()); 656 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_enabled());
741 } 657 }
742 658
743 TEST_F(MetricsLogTest, BluetoothPairedDevices) { 659 TEST_F(MetricsLogTest, BluetoothPairedDevices) {
744 // The fake bluetooth adapter class already claims to be paired with one 660 // The fake bluetooth adapter class already claims to be paired with one
745 // device when initialized. Add a second and third fake device to it so we 661 // device when initialized. Add a second and third fake device to it so we
746 // can test the cases where a device is not paired (LE device, generally) 662 // can test the cases where a device is not paired (LE device, generally)
747 // and a device that does not have Device ID information. 663 // and a device that does not have Device ID information.
748 fake_bluetooth_device_client_->CreateDevice( 664 fake_bluetooth_device_client_->CreateDevice(
749 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 665 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
750 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); 666 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath));
751 667
752 fake_bluetooth_device_client_->CreateDevice( 668 fake_bluetooth_device_client_->CreateDevice(
753 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 669 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
754 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 670 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath));
755 671
756 FakeBluetoothDeviceClient::Properties* properties = 672 FakeBluetoothDeviceClient::Properties* properties =
757 fake_bluetooth_device_client_->GetProperties( 673 fake_bluetooth_device_client_->GetProperties(
758 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); 674 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath));
759 properties->paired.ReplaceValue(true); 675 properties->paired.ReplaceValue(true);
760 676
761 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG); 677 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
762 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), 678 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
763 std::vector<content::WebPluginInfo>(),
764 std::vector<variations::ActiveGroupId>()); 679 std::vector<variations::ActiveGroupId>());
765 680
766 ASSERT_TRUE(log.system_profile().has_hardware()); 681 ASSERT_TRUE(log.system_profile().has_hardware());
767 ASSERT_TRUE(log.system_profile().hardware().has_bluetooth()); 682 ASSERT_TRUE(log.system_profile().hardware().has_bluetooth());
768 683
769 // Only two of the devices should appear. 684 // Only two of the devices should appear.
770 EXPECT_EQ(2, 685 EXPECT_EQ(2,
771 log.system_profile().hardware().bluetooth().paired_device_size()); 686 log.system_profile().hardware().bluetooth().paired_device_size());
772 687
773 typedef metrics::SystemProfileProto::Hardware::Bluetooth::PairedDevice 688 typedef metrics::SystemProfileProto::Hardware::Bluetooth::PairedDevice
(...skipping 18 matching lines...) Expand all
792 PairedDevice device2 = 707 PairedDevice device2 =
793 log.system_profile().hardware().bluetooth().paired_device(1); 708 log.system_profile().hardware().bluetooth().paired_device(1);
794 709
795 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, 710 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass,
796 device2.bluetooth_class()); 711 device2.bluetooth_class());
797 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); 712 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type());
798 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); 713 EXPECT_EQ(0x207D74U, device2.vendor_prefix());
799 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); 714 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source());
800 } 715 }
801 #endif // OS_CHROMEOS 716 #endif // OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698