| 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 17 matching lines...) Expand all Loading... |
| 28 #include "components/metrics/proto/system_profile.pb.h" | 28 #include "components/metrics/proto/system_profile.pb.h" |
| 29 #include "components/metrics/test_metrics_service_client.h" | 29 #include "components/metrics/test_metrics_service_client.h" |
| 30 #include "components/variations/active_field_trials.h" | 30 #include "components/variations/active_field_trials.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/common/process_type.h" | 32 #include "content/public/common/process_type.h" |
| 33 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
| 34 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 37 | 37 |
| 38 #if defined(OS_CHROMEOS) | |
| 39 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | |
| 40 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 41 #include "chrome/browser/metrics/metrics_log_chromeos.h" | |
| 42 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | |
| 43 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | |
| 44 #include "chromeos/dbus/fake_bluetooth_device_client.h" | |
| 45 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" | |
| 46 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" | |
| 47 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | |
| 48 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
| 49 #include "chromeos/dbus/fake_dbus_thread_manager.h" | |
| 50 | |
| 51 using chromeos::DBusThreadManager; | |
| 52 using chromeos::BluetoothAdapterClient; | |
| 53 using chromeos::BluetoothAgentManagerClient; | |
| 54 using chromeos::BluetoothDeviceClient; | |
| 55 using chromeos::BluetoothGattCharacteristicClient; | |
| 56 using chromeos::BluetoothGattDescriptorClient; | |
| 57 using chromeos::BluetoothGattServiceClient; | |
| 58 using chromeos::BluetoothInputClient; | |
| 59 using chromeos::FakeBluetoothAdapterClient; | |
| 60 using chromeos::FakeBluetoothAgentManagerClient; | |
| 61 using chromeos::FakeBluetoothDeviceClient; | |
| 62 using chromeos::FakeBluetoothGattCharacteristicClient; | |
| 63 using chromeos::FakeBluetoothGattDescriptorClient; | |
| 64 using chromeos::FakeBluetoothGattServiceClient; | |
| 65 using chromeos::FakeBluetoothInputClient; | |
| 66 using chromeos::FakeDBusThreadManager; | |
| 67 #endif // OS_CHROMEOS | |
| 68 | |
| 69 using base::TimeDelta; | 38 using base::TimeDelta; |
| 70 using metrics::ProfilerEventProto; | 39 using metrics::ProfilerEventProto; |
| 71 using tracked_objects::ProcessDataSnapshot; | 40 using tracked_objects::ProcessDataSnapshot; |
| 72 using tracked_objects::TaskSnapshot; | 41 using tracked_objects::TaskSnapshot; |
| 73 | 42 |
| 74 namespace { | 43 namespace { |
| 75 | 44 |
| 76 const char kClientId[] = "bogus client ID"; | 45 const char kClientId[] = "bogus client ID"; |
| 77 const int64 kInstallDate = 1373051956; | 46 const int64 kInstallDate = 1373051956; |
| 78 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate. | 47 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate. |
| 79 const int64 kEnabledDate = 1373001211; | 48 const int64 kEnabledDate = 1373001211; |
| 80 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. | 49 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. |
| 81 const int kSessionId = 127; | 50 const int kSessionId = 127; |
| 82 const variations::ActiveGroupId kFieldTrialIds[] = { | 51 const variations::ActiveGroupId kFieldTrialIds[] = { |
| 83 {37, 43}, | 52 {37, 43}, |
| 84 {13, 47}, | 53 {13, 47}, |
| 85 {23, 17} | 54 {23, 17} |
| 86 }; | 55 }; |
| 87 const variations::ActiveGroupId kSyntheticTrials[] = { | 56 const variations::ActiveGroupId kSyntheticTrials[] = { |
| 88 {55, 15}, | 57 {55, 15}, |
| 89 {66, 16} | 58 {66, 16} |
| 90 }; | 59 }; |
| 91 | 60 |
| 92 #if defined(OS_CHROMEOS) | |
| 93 class TestMetricsLogChromeOS : public MetricsLogChromeOS { | |
| 94 public: | |
| 95 explicit TestMetricsLogChromeOS( | |
| 96 metrics::ChromeUserMetricsExtension* uma_proto) | |
| 97 : MetricsLogChromeOS(uma_proto) { | |
| 98 } | |
| 99 }; | |
| 100 #endif // OS_CHROMEOS | |
| 101 | |
| 102 class TestMetricsLog : public MetricsLog { | 61 class TestMetricsLog : public MetricsLog { |
| 103 public: | 62 public: |
| 104 TestMetricsLog(const std::string& client_id, | 63 TestMetricsLog(const std::string& client_id, |
| 105 int session_id, | 64 int session_id, |
| 106 LogType log_type, | 65 LogType log_type, |
| 107 metrics::MetricsServiceClient* client) | 66 metrics::MetricsServiceClient* client) |
| 108 : MetricsLog(client_id, session_id, log_type, client), | 67 : MetricsLog(client_id, session_id, log_type, client), |
| 109 prefs_(&scoped_prefs_) { | 68 prefs_(&scoped_prefs_) { |
| 110 #if defined(OS_CHROMEOS) | |
| 111 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( | |
| 112 MetricsLog::uma_proto())); | |
| 113 #endif // OS_CHROMEOS | |
| 114 chrome::RegisterLocalState(scoped_prefs_.registry()); | 69 chrome::RegisterLocalState(scoped_prefs_.registry()); |
| 115 InitPrefs(); | 70 InitPrefs(); |
| 116 } | 71 } |
| 117 | 72 |
| 118 // Creates a TestMetricsLog that will use |prefs| as the fake local state. | 73 // Creates a TestMetricsLog that will use |prefs| as the fake local state. |
| 119 // Useful for tests that need to re-use the local state prefs between logs. | 74 // Useful for tests that need to re-use the local state prefs between logs. |
| 120 TestMetricsLog(const std::string& client_id, | 75 TestMetricsLog(const std::string& client_id, |
| 121 int session_id, | 76 int session_id, |
| 122 LogType log_type, | 77 LogType log_type, |
| 123 metrics::MetricsServiceClient* client, | 78 metrics::MetricsServiceClient* client, |
| 124 TestingPrefServiceSimple* prefs) | 79 TestingPrefServiceSimple* prefs) |
| 125 : MetricsLog(client_id, session_id, log_type, client), prefs_(prefs) { | 80 : MetricsLog(client_id, session_id, log_type, client), prefs_(prefs) { |
| 126 #if defined(OS_CHROMEOS) | |
| 127 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( | |
| 128 MetricsLog::uma_proto())); | |
| 129 #endif // OS_CHROMEOS | |
| 130 InitPrefs(); | 81 InitPrefs(); |
| 131 } | 82 } |
| 132 | 83 |
| 133 virtual ~TestMetricsLog() {} | 84 virtual ~TestMetricsLog() {} |
| 134 | 85 |
| 135 virtual PrefService* GetPrefService() OVERRIDE { | 86 virtual PrefService* GetPrefService() OVERRIDE { |
| 136 return prefs_; | 87 return prefs_; |
| 137 } | 88 } |
| 138 | 89 |
| 139 const metrics::ChromeUserMetricsExtension& uma_proto() const { | 90 const metrics::ChromeUserMetricsExtension& uma_proto() const { |
| 140 return *MetricsLog::uma_proto(); | 91 return *MetricsLog::uma_proto(); |
| 141 } | 92 } |
| 142 | 93 |
| 143 const metrics::SystemProfileProto& system_profile() const { | 94 const metrics::SystemProfileProto& system_profile() const { |
| 144 return uma_proto().system_profile(); | 95 return uma_proto().system_profile(); |
| 145 } | 96 } |
| 146 | 97 |
| 147 private: | 98 private: |
| 148 void InitPrefs() { | 99 void InitPrefs() { |
| 149 prefs_->SetInt64(prefs::kInstallDate, kInstallDate); | 100 prefs_->SetInt64(prefs::kInstallDate, kInstallDate); |
| 150 prefs_->SetString(prefs::kMetricsReportingEnabledTimestamp, | 101 prefs_->SetString(prefs::kMetricsReportingEnabledTimestamp, |
| 151 base::Int64ToString(kEnabledDate)); | 102 base::Int64ToString(kEnabledDate)); |
| 152 #if defined(OS_CHROMEOS) | |
| 153 prefs_->SetInteger(prefs::kStabilityChildProcessCrashCount, 10); | |
| 154 prefs_->SetInteger(prefs::kStabilityOtherUserCrashCount, 11); | |
| 155 prefs_->SetInteger(prefs::kStabilityKernelCrashCount, 12); | |
| 156 prefs_->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13); | |
| 157 #endif // OS_CHROMEOS | |
| 158 } | 103 } |
| 159 | 104 |
| 160 virtual void GetFieldTrialIds( | 105 virtual void GetFieldTrialIds( |
| 161 std::vector<variations::ActiveGroupId>* field_trial_ids) const | 106 std::vector<variations::ActiveGroupId>* field_trial_ids) const |
| 162 OVERRIDE { | 107 OVERRIDE { |
| 163 ASSERT_TRUE(field_trial_ids->empty()); | 108 ASSERT_TRUE(field_trial_ids->empty()); |
| 164 | 109 |
| 165 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { | 110 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { |
| 166 field_trial_ids->push_back(kFieldTrialIds[i]); | 111 field_trial_ids->push_back(kFieldTrialIds[i]); |
| 167 } | 112 } |
| 168 } | 113 } |
| 169 | 114 |
| 170 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|. | 115 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|. |
| 171 TestingPrefServiceSimple scoped_prefs_; | 116 TestingPrefServiceSimple scoped_prefs_; |
| 172 // Weak pointer to the PrefsService used by this log. | 117 // Weak pointer to the PrefsService used by this log. |
| 173 TestingPrefServiceSimple* prefs_; | 118 TestingPrefServiceSimple* prefs_; |
| 174 | 119 |
| 175 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); | 120 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); |
| 176 }; | 121 }; |
| 177 | 122 |
| 178 } // namespace | 123 } // namespace |
| 179 | 124 |
| 180 class MetricsLogTest : public testing::Test { | 125 class MetricsLogTest : public testing::Test { |
| 181 public: | 126 public: |
| 182 MetricsLogTest() {} | 127 MetricsLogTest() {} |
| 183 | 128 |
| 184 protected: | 129 protected: |
| 185 virtual void SetUp() OVERRIDE { | |
| 186 #if defined(OS_CHROMEOS) | |
| 187 // Set up the fake Bluetooth environment, | |
| 188 scoped_ptr<FakeDBusThreadManager> fake_dbus_thread_manager( | |
| 189 new FakeDBusThreadManager); | |
| 190 fake_dbus_thread_manager->SetBluetoothAdapterClient( | |
| 191 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); | |
| 192 fake_dbus_thread_manager->SetBluetoothDeviceClient( | |
| 193 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient)); | |
| 194 fake_dbus_thread_manager->SetBluetoothGattCharacteristicClient( | |
| 195 scoped_ptr<BluetoothGattCharacteristicClient>( | |
| 196 new FakeBluetoothGattCharacteristicClient)); | |
| 197 fake_dbus_thread_manager->SetBluetoothGattDescriptorClient( | |
| 198 scoped_ptr<BluetoothGattDescriptorClient>( | |
| 199 new FakeBluetoothGattDescriptorClient)); | |
| 200 fake_dbus_thread_manager->SetBluetoothGattServiceClient( | |
| 201 scoped_ptr<BluetoothGattServiceClient>( | |
| 202 new FakeBluetoothGattServiceClient)); | |
| 203 fake_dbus_thread_manager->SetBluetoothInputClient( | |
| 204 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); | |
| 205 fake_dbus_thread_manager->SetBluetoothAgentManagerClient( | |
| 206 scoped_ptr<BluetoothAgentManagerClient>( | |
| 207 new FakeBluetoothAgentManagerClient)); | |
| 208 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager.release()); | |
| 209 | |
| 210 // Grab pointers to members of the thread manager for easier testing. | |
| 211 fake_bluetooth_adapter_client_ = static_cast<FakeBluetoothAdapterClient*>( | |
| 212 DBusThreadManager::Get()->GetBluetoothAdapterClient()); | |
| 213 fake_bluetooth_device_client_ = static_cast<FakeBluetoothDeviceClient*>( | |
| 214 DBusThreadManager::Get()->GetBluetoothDeviceClient()); | |
| 215 #endif // OS_CHROMEOS | |
| 216 } | |
| 217 | |
| 218 virtual void TearDown() OVERRIDE { | |
| 219 #if defined(OS_CHROMEOS) | |
| 220 DBusThreadManager::Shutdown(); | |
| 221 #endif // OS_CHROMEOS | |
| 222 } | |
| 223 | |
| 224 // Check that the values in |system_values| correspond to the test data | 130 // Check that the values in |system_values| correspond to the test data |
| 225 // defined at the top of this file. | 131 // defined at the top of this file. |
| 226 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) { | 132 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) { |
| 227 EXPECT_EQ(kInstallDateExpected, system_profile.install_date()); | 133 EXPECT_EQ(kInstallDateExpected, system_profile.install_date()); |
| 228 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date()); | 134 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date()); |
| 229 | 135 |
| 230 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials), | 136 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials), |
| 231 static_cast<size_t>(system_profile.field_trial_size())); | 137 static_cast<size_t>(system_profile.field_trial_size())); |
| 232 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { | 138 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { |
| 233 const metrics::SystemProfileProto::FieldTrial& field_trial = | 139 const metrics::SystemProfileProto::FieldTrial& field_trial = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 250 system_profile.hardware(); | 156 system_profile.hardware(); |
| 251 | 157 |
| 252 EXPECT_TRUE(hardware.has_cpu()); | 158 EXPECT_TRUE(hardware.has_cpu()); |
| 253 EXPECT_TRUE(hardware.cpu().has_vendor_name()); | 159 EXPECT_TRUE(hardware.cpu().has_vendor_name()); |
| 254 EXPECT_TRUE(hardware.cpu().has_signature()); | 160 EXPECT_TRUE(hardware.cpu().has_signature()); |
| 255 | 161 |
| 256 // TODO(isherman): Verify other data written into the protobuf as a result | 162 // TODO(isherman): Verify other data written into the protobuf as a result |
| 257 // of this call. | 163 // of this call. |
| 258 } | 164 } |
| 259 | 165 |
| 260 protected: | |
| 261 #if defined(OS_CHROMEOS) | |
| 262 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_; | |
| 263 FakeBluetoothDeviceClient* fake_bluetooth_device_client_; | |
| 264 #endif // OS_CHROMEOS | |
| 265 | |
| 266 private: | 166 private: |
| 267 content::TestBrowserThreadBundle thread_bundle_; | 167 content::TestBrowserThreadBundle thread_bundle_; |
| 268 | 168 |
| 269 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); | 169 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest); |
| 270 }; | 170 }; |
| 271 | 171 |
| 272 TEST_F(MetricsLogTest, RecordEnvironment) { | 172 TEST_F(MetricsLogTest, RecordEnvironment) { |
| 273 metrics::TestMetricsServiceClient client; | 173 metrics::TestMetricsServiceClient client; |
| 274 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); | 174 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); |
| 275 | 175 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 tracked_object->process_type()); | 465 tracked_object->process_type()); |
| 566 } | 466 } |
| 567 } | 467 } |
| 568 | 468 |
| 569 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { | 469 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { |
| 570 metrics::TestMetricsServiceClient client; | 470 metrics::TestMetricsServiceClient client; |
| 571 TestMetricsLog log( | 471 TestMetricsLog log( |
| 572 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client); | 472 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client); |
| 573 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); | 473 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); |
| 574 } | 474 } |
| 575 | |
| 576 #if defined(OS_CHROMEOS) | |
| 577 TEST_F(MetricsLogTest, MultiProfileUserCount) { | |
| 578 std::string user1("user1@example.com"); | |
| 579 std::string user2("user2@example.com"); | |
| 580 std::string user3("user3@example.com"); | |
| 581 | |
| 582 // |scoped_enabler| takes over the lifetime of |user_manager|. | |
| 583 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); | |
| 584 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); | |
| 585 user_manager->AddKioskAppUser(user1); | |
| 586 user_manager->AddKioskAppUser(user2); | |
| 587 user_manager->AddKioskAppUser(user3); | |
| 588 | |
| 589 user_manager->LoginUser(user1); | |
| 590 user_manager->LoginUser(user3); | |
| 591 | |
| 592 metrics::TestMetricsServiceClient client; | |
| 593 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); | |
| 594 std::vector<metrics::MetricsProvider*> metrics_providers; | |
| 595 std::vector<variations::ActiveGroupId> synthetic_trials; | |
| 596 log.RecordEnvironment(metrics_providers, synthetic_trials); | |
| 597 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count()); | |
| 598 } | |
| 599 | |
| 600 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) { | |
| 601 std::string user1("user1@example.com"); | |
| 602 std::string user2("user2@example.com"); | |
| 603 std::string user3("user3@example.com"); | |
| 604 | |
| 605 // |scoped_enabler| takes over the lifetime of |user_manager|. | |
| 606 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); | |
| 607 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager); | |
| 608 user_manager->AddKioskAppUser(user1); | |
| 609 user_manager->AddKioskAppUser(user2); | |
| 610 user_manager->AddKioskAppUser(user3); | |
| 611 | |
| 612 user_manager->LoginUser(user1); | |
| 613 | |
| 614 metrics::TestMetricsServiceClient client; | |
| 615 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); | |
| 616 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count()); | |
| 617 | |
| 618 user_manager->LoginUser(user2); | |
| 619 std::vector<metrics::MetricsProvider*> metrics_providers; | |
| 620 std::vector<variations::ActiveGroupId> synthetic_trials; | |
| 621 log.RecordEnvironment(metrics_providers, synthetic_trials); | |
| 622 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count()); | |
| 623 } | |
| 624 | |
| 625 TEST_F(MetricsLogTest, BluetoothHardwareDisabled) { | |
| 626 metrics::TestMetricsServiceClient client; | |
| 627 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); | |
| 628 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), | |
| 629 std::vector<variations::ActiveGroupId>()); | |
| 630 | |
| 631 EXPECT_TRUE(log.system_profile().has_hardware()); | |
| 632 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); | |
| 633 | |
| 634 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); | |
| 635 EXPECT_FALSE(log.system_profile().hardware().bluetooth().is_enabled()); | |
| 636 } | |
| 637 | |
| 638 TEST_F(MetricsLogTest, BluetoothHardwareEnabled) { | |
| 639 FakeBluetoothAdapterClient::Properties* properties = | |
| 640 fake_bluetooth_adapter_client_->GetProperties( | |
| 641 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); | |
| 642 properties->powered.ReplaceValue(true); | |
| 643 | |
| 644 metrics::TestMetricsServiceClient client; | |
| 645 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); | |
| 646 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), | |
| 647 std::vector<variations::ActiveGroupId>()); | |
| 648 | |
| 649 EXPECT_TRUE(log.system_profile().has_hardware()); | |
| 650 EXPECT_TRUE(log.system_profile().hardware().has_bluetooth()); | |
| 651 | |
| 652 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_present()); | |
| 653 EXPECT_TRUE(log.system_profile().hardware().bluetooth().is_enabled()); | |
| 654 } | |
| 655 | |
| 656 TEST_F(MetricsLogTest, BluetoothPairedDevices) { | |
| 657 // The fake bluetooth adapter class already claims to be paired with one | |
| 658 // device when initialized. Add a second and third fake device to it so we | |
| 659 // can test the cases where a device is not paired (LE device, generally) | |
| 660 // and a device that does not have Device ID information. | |
| 661 fake_bluetooth_device_client_->CreateDevice( | |
| 662 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | |
| 663 dbus::ObjectPath(FakeBluetoothDeviceClient::kRequestPinCodePath)); | |
| 664 | |
| 665 fake_bluetooth_device_client_->CreateDevice( | |
| 666 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), | |
| 667 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | |
| 668 | |
| 669 FakeBluetoothDeviceClient::Properties* properties = | |
| 670 fake_bluetooth_device_client_->GetProperties( | |
| 671 dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath)); | |
| 672 properties->paired.ReplaceValue(true); | |
| 673 | |
| 674 metrics::TestMetricsServiceClient client; | |
| 675 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client); | |
| 676 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), | |
| 677 std::vector<variations::ActiveGroupId>()); | |
| 678 | |
| 679 ASSERT_TRUE(log.system_profile().has_hardware()); | |
| 680 ASSERT_TRUE(log.system_profile().hardware().has_bluetooth()); | |
| 681 | |
| 682 // Only two of the devices should appear. | |
| 683 EXPECT_EQ(2, | |
| 684 log.system_profile().hardware().bluetooth().paired_device_size()); | |
| 685 | |
| 686 typedef metrics::SystemProfileProto::Hardware::Bluetooth::PairedDevice | |
| 687 PairedDevice; | |
| 688 | |
| 689 // First device should match the Paired Device object, complete with | |
| 690 // parsed Device ID information. | |
| 691 PairedDevice device1 = | |
| 692 log.system_profile().hardware().bluetooth().paired_device(0); | |
| 693 | |
| 694 EXPECT_EQ(FakeBluetoothDeviceClient::kPairedDeviceClass, | |
| 695 device1.bluetooth_class()); | |
| 696 EXPECT_EQ(PairedDevice::DEVICE_COMPUTER, device1.type()); | |
| 697 EXPECT_EQ(0x001122U, device1.vendor_prefix()); | |
| 698 EXPECT_EQ(PairedDevice::VENDOR_ID_USB, device1.vendor_id_source()); | |
| 699 EXPECT_EQ(0x05ACU, device1.vendor_id()); | |
| 700 EXPECT_EQ(0x030DU, device1.product_id()); | |
| 701 EXPECT_EQ(0x0306U, device1.device_id()); | |
| 702 | |
| 703 // Second device should match the Confirm Passkey object, this has | |
| 704 // no Device ID information. | |
| 705 PairedDevice device2 = | |
| 706 log.system_profile().hardware().bluetooth().paired_device(1); | |
| 707 | |
| 708 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, | |
| 709 device2.bluetooth_class()); | |
| 710 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); | |
| 711 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); | |
| 712 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); | |
| 713 } | |
| 714 #endif // OS_CHROMEOS | |
| OLD | NEW |