| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos_metrics_provider.h" | 5 #include "chrome/browser/metrics/chromeos_metrics_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
| 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 12 #include "chrome/browser/metrics/chromeos_metrics_provider.h" | 12 #include "chrome/browser/metrics/chromeos_metrics_provider.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 14 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 14 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 15 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 15 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 16 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
| 16 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" | 17 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" |
| 17 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" | 18 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" |
| 18 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | 19 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
| 19 #include "chromeos/dbus/fake_bluetooth_input_client.h" | 20 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
| 20 #include "chromeos/dbus/fake_dbus_thread_manager.h" | |
| 21 #include "chromeos/dbus/power_manager_client.h" | 21 #include "chromeos/dbus/power_manager_client.h" |
| 22 #include "chromeos/login/login_state.h" | 22 #include "chromeos/login/login_state.h" |
| 23 #include "components/metrics/proto/system_profile.pb.h" | 23 #include "components/metrics/proto/system_profile.pb.h" |
| 24 #include "components/user_manager/user_manager.h" | 24 #include "components/user_manager/user_manager.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 #if defined(USE_X11) | 29 #if defined(USE_X11) |
| 30 #include "ui/events/x/device_data_manager_x11.h" | 30 #include "ui/events/x/device_data_manager_x11.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 using chromeos::DBusThreadManager; | 33 using chromeos::DBusThreadManager; |
| 34 using chromeos::DBusThreadManagerSetter; |
| 34 using chromeos::BluetoothAdapterClient; | 35 using chromeos::BluetoothAdapterClient; |
| 35 using chromeos::BluetoothAgentManagerClient; | 36 using chromeos::BluetoothAgentManagerClient; |
| 36 using chromeos::BluetoothDeviceClient; | 37 using chromeos::BluetoothDeviceClient; |
| 37 using chromeos::BluetoothGattCharacteristicClient; | 38 using chromeos::BluetoothGattCharacteristicClient; |
| 38 using chromeos::BluetoothGattDescriptorClient; | 39 using chromeos::BluetoothGattDescriptorClient; |
| 39 using chromeos::BluetoothGattServiceClient; | 40 using chromeos::BluetoothGattServiceClient; |
| 40 using chromeos::BluetoothInputClient; | 41 using chromeos::BluetoothInputClient; |
| 41 using chromeos::FakeBluetoothAdapterClient; | 42 using chromeos::FakeBluetoothAdapterClient; |
| 42 using chromeos::FakeBluetoothAgentManagerClient; | 43 using chromeos::FakeBluetoothAgentManagerClient; |
| 43 using chromeos::FakeBluetoothDeviceClient; | 44 using chromeos::FakeBluetoothDeviceClient; |
| 44 using chromeos::FakeBluetoothGattCharacteristicClient; | 45 using chromeos::FakeBluetoothGattCharacteristicClient; |
| 45 using chromeos::FakeBluetoothGattDescriptorClient; | 46 using chromeos::FakeBluetoothGattDescriptorClient; |
| 46 using chromeos::FakeBluetoothGattServiceClient; | 47 using chromeos::FakeBluetoothGattServiceClient; |
| 47 using chromeos::FakeBluetoothInputClient; | 48 using chromeos::FakeBluetoothInputClient; |
| 48 using chromeos::FakeDBusThreadManager; | |
| 49 using chromeos::PowerManagerClient; | 49 using chromeos::PowerManagerClient; |
| 50 using chromeos::STUB_DBUS_CLIENT_IMPLEMENTATION; | 50 using chromeos::STUB_DBUS_CLIENT_IMPLEMENTATION; |
| 51 | 51 |
| 52 class ChromeOSMetricsProviderTest : public testing::Test { | 52 class ChromeOSMetricsProviderTest : public testing::Test { |
| 53 public: | 53 public: |
| 54 ChromeOSMetricsProviderTest() {} | 54 ChromeOSMetricsProviderTest() {} |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
| 58 #if defined(USE_X11) | 58 #if defined(USE_X11) |
| 59 ui::DeviceDataManagerX11::CreateInstance(); | 59 ui::DeviceDataManagerX11::CreateInstance(); |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 // Set up the fake Bluetooth environment, | 62 // Set up the fake Bluetooth environment, |
| 63 scoped_ptr<FakeDBusThreadManager> fake_dbus_thread_manager( | 63 scoped_ptr<DBusThreadManagerSetter> dbus_setter = |
| 64 new FakeDBusThreadManager); | 64 DBusThreadManager::GetSetterForTesting(); |
| 65 fake_dbus_thread_manager->SetBluetoothAdapterClient( | 65 dbus_setter->SetBluetoothAdapterClient( |
| 66 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); | 66 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); |
| 67 fake_dbus_thread_manager->SetBluetoothDeviceClient( | 67 dbus_setter->SetBluetoothDeviceClient( |
| 68 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient)); | 68 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient)); |
| 69 fake_dbus_thread_manager->SetBluetoothGattCharacteristicClient( | 69 dbus_setter->SetBluetoothGattCharacteristicClient( |
| 70 scoped_ptr<BluetoothGattCharacteristicClient>( | 70 scoped_ptr<BluetoothGattCharacteristicClient>( |
| 71 new FakeBluetoothGattCharacteristicClient)); | 71 new FakeBluetoothGattCharacteristicClient)); |
| 72 fake_dbus_thread_manager->SetBluetoothGattDescriptorClient( | 72 dbus_setter->SetBluetoothGattDescriptorClient( |
| 73 scoped_ptr<BluetoothGattDescriptorClient>( | 73 scoped_ptr<BluetoothGattDescriptorClient>( |
| 74 new FakeBluetoothGattDescriptorClient)); | 74 new FakeBluetoothGattDescriptorClient)); |
| 75 fake_dbus_thread_manager->SetBluetoothGattServiceClient( | 75 dbus_setter->SetBluetoothGattServiceClient( |
| 76 scoped_ptr<BluetoothGattServiceClient>( | 76 scoped_ptr<BluetoothGattServiceClient>( |
| 77 new FakeBluetoothGattServiceClient)); | 77 new FakeBluetoothGattServiceClient)); |
| 78 fake_dbus_thread_manager->SetBluetoothInputClient( | 78 dbus_setter->SetBluetoothInputClient( |
| 79 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); | 79 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); |
| 80 fake_dbus_thread_manager->SetBluetoothAgentManagerClient( | 80 dbus_setter->SetBluetoothAgentManagerClient( |
| 81 scoped_ptr<BluetoothAgentManagerClient>( | 81 scoped_ptr<BluetoothAgentManagerClient>( |
| 82 new FakeBluetoothAgentManagerClient)); | 82 new FakeBluetoothAgentManagerClient)); |
| 83 | 83 |
| 84 // Set up a PowerManagerClient instance for PerfProvider. | 84 // Set up a PowerManagerClient instance for PerfProvider. |
| 85 fake_dbus_thread_manager->SetPowerManagerClient( | 85 dbus_setter->SetPowerManagerClient( |
| 86 scoped_ptr<PowerManagerClient>( | 86 scoped_ptr<PowerManagerClient>( |
| 87 PowerManagerClient::Create(STUB_DBUS_CLIENT_IMPLEMENTATION))); | 87 PowerManagerClient::Create(STUB_DBUS_CLIENT_IMPLEMENTATION))); |
| 88 | 88 |
| 89 DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager.release()); | |
| 90 | |
| 91 // Grab pointers to members of the thread manager for easier testing. | 89 // Grab pointers to members of the thread manager for easier testing. |
| 92 fake_bluetooth_adapter_client_ = static_cast<FakeBluetoothAdapterClient*>( | 90 fake_bluetooth_adapter_client_ = static_cast<FakeBluetoothAdapterClient*>( |
| 93 DBusThreadManager::Get()->GetBluetoothAdapterClient()); | 91 DBusThreadManager::Get()->GetBluetoothAdapterClient()); |
| 94 fake_bluetooth_device_client_ = static_cast<FakeBluetoothDeviceClient*>( | 92 fake_bluetooth_device_client_ = static_cast<FakeBluetoothDeviceClient*>( |
| 95 DBusThreadManager::Get()->GetBluetoothDeviceClient()); | 93 DBusThreadManager::Get()->GetBluetoothDeviceClient()); |
| 96 | 94 |
| 97 // Initialize the login state trackers. | 95 // Initialize the login state trackers. |
| 98 if (!chromeos::LoginState::IsInitialized()) | 96 if (!chromeos::LoginState::IsInitialized()) |
| 99 chromeos::LoginState::Initialize(); | 97 chromeos::LoginState::Initialize(); |
| 100 } | 98 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Second device should match the Confirm Passkey object, this has | 240 // Second device should match the Confirm Passkey object, this has |
| 243 // no Device ID information. | 241 // no Device ID information. |
| 244 PairedDevice device2 = system_profile.hardware().bluetooth().paired_device(1); | 242 PairedDevice device2 = system_profile.hardware().bluetooth().paired_device(1); |
| 245 | 243 |
| 246 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, | 244 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, |
| 247 device2.bluetooth_class()); | 245 device2.bluetooth_class()); |
| 248 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); | 246 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); |
| 249 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); | 247 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); |
| 250 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); | 248 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); |
| 251 } | 249 } |
| OLD | NEW |