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