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

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

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
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
33 using chromeos::DBusThreadManager; 34 using chromeos::DBusThreadManager;
34 using chromeos::DBusThreadManagerSetter; 35 using chromeos::DBusThreadManagerSetter;
Ilya Sherman 2015/09/23 23:18:46 nit: Please re-alphabetize
rkc 2015/09/27 07:51:56 Done.
35 using chromeos::BluetoothAdapterClient; 36 using bluez::BluetoothAdapterClient;
36 using chromeos::BluetoothAgentManagerClient; 37 using bluez::BluetoothAgentManagerClient;
37 using chromeos::BluetoothDeviceClient; 38 using bluez::BluetoothDeviceClient;
38 using chromeos::BluetoothGattCharacteristicClient; 39 using bluez::BluetoothGattCharacteristicClient;
39 using chromeos::BluetoothGattDescriptorClient; 40 using bluez::BluetoothGattDescriptorClient;
40 using chromeos::BluetoothGattServiceClient; 41 using bluez::BluetoothGattServiceClient;
41 using chromeos::BluetoothInputClient; 42 using bluez::BluetoothInputClient;
42 using chromeos::FakeBluetoothAdapterClient; 43 using bluez::BluezDBusManager;
43 using chromeos::FakeBluetoothAgentManagerClient; 44 using bluez::BluezDBusManagerSetter;
44 using chromeos::FakeBluetoothDeviceClient; 45 using bluez::FakeBluetoothAdapterClient;
45 using chromeos::FakeBluetoothGattCharacteristicClient; 46 using bluez::FakeBluetoothAgentManagerClient;
46 using chromeos::FakeBluetoothGattDescriptorClient; 47 using bluez::FakeBluetoothDeviceClient;
47 using chromeos::FakeBluetoothGattServiceClient; 48 using bluez::FakeBluetoothGattCharacteristicClient;
48 using chromeos::FakeBluetoothInputClient; 49 using bluez::FakeBluetoothGattDescriptorClient;
50 using bluez::FakeBluetoothGattServiceClient;
51 using bluez::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,
66 scoped_ptr<BluezDBusManagerSetter> bluez_dbus_setter =
67 BluezDBusManager::GetSetterForTesting();
68 bluez_dbus_setter->SetBluetoothAdapterClient(
69 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient));
70 bluez_dbus_setter->SetBluetoothDeviceClient(
71 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient));
72 bluez_dbus_setter->SetBluetoothGattCharacteristicClient(
73 scoped_ptr<BluetoothGattCharacteristicClient>(
74 new FakeBluetoothGattCharacteristicClient));
75 bluez_dbus_setter->SetBluetoothGattDescriptorClient(
76 scoped_ptr<BluetoothGattDescriptorClient>(
77 new FakeBluetoothGattDescriptorClient));
78 bluez_dbus_setter->SetBluetoothGattServiceClient(
79 scoped_ptr<BluetoothGattServiceClient>(
80 new FakeBluetoothGattServiceClient));
81 bluez_dbus_setter->SetBluetoothInputClient(
82 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient));
83 bluez_dbus_setter->SetBluetoothAgentManagerClient(
84 scoped_ptr<BluetoothAgentManagerClient>(
85 new FakeBluetoothAgentManagerClient));
86
87 // Set up the fake Bluetooth environment,
Ilya Sherman 2015/09/23 23:18:46 nit: Remove this comment.
rkc 2015/09/27 07:51:56 Done.
63 scoped_ptr<DBusThreadManagerSetter> dbus_setter = 88 scoped_ptr<DBusThreadManagerSetter> dbus_setter =
64 DBusThreadManager::GetSetterForTesting(); 89 DBusThreadManager::GetSetterForTesting();
Ilya Sherman 2015/09/23 23:18:46 nit: Move this line below the follow comment.
rkc 2015/09/27 07:51:56 Done.
65 dbus_setter->SetBluetoothAdapterClient(
66 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient));
67 dbus_setter->SetBluetoothDeviceClient(
68 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient));
69 dbus_setter->SetBluetoothGattCharacteristicClient(
70 scoped_ptr<BluetoothGattCharacteristicClient>(
71 new FakeBluetoothGattCharacteristicClient));
72 dbus_setter->SetBluetoothGattDescriptorClient(
73 scoped_ptr<BluetoothGattDescriptorClient>(
74 new FakeBluetoothGattDescriptorClient));
75 dbus_setter->SetBluetoothGattServiceClient(
76 scoped_ptr<BluetoothGattServiceClient>(
77 new FakeBluetoothGattServiceClient));
78 dbus_setter->SetBluetoothInputClient(
79 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient));
80 dbus_setter->SetBluetoothAgentManagerClient(
81 scoped_ptr<BluetoothAgentManagerClient>(
82 new FakeBluetoothAgentManagerClient));
83 90
84 // Set up a PowerManagerClient instance for PerfProvider. 91 // Set up a PowerManagerClient instance for PerfProvider.
85 dbus_setter->SetPowerManagerClient( 92 dbus_setter->SetPowerManagerClient(
86 scoped_ptr<PowerManagerClient>( 93 scoped_ptr<PowerManagerClient>(
87 PowerManagerClient::Create(STUB_DBUS_CLIENT_IMPLEMENTATION))); 94 PowerManagerClient::Create(STUB_DBUS_CLIENT_IMPLEMENTATION)));
88 95
89 // Grab pointers to members of the thread manager for easier testing. 96 // Grab pointers to members of the thread manager for easier testing.
90 fake_bluetooth_adapter_client_ = static_cast<FakeBluetoothAdapterClient*>( 97 fake_bluetooth_adapter_client_ = static_cast<FakeBluetoothAdapterClient*>(
91 DBusThreadManager::Get()->GetBluetoothAdapterClient()); 98 BluezDBusManager::Get()->GetBluetoothAdapterClient());
92 fake_bluetooth_device_client_ = static_cast<FakeBluetoothDeviceClient*>( 99 fake_bluetooth_device_client_ = static_cast<FakeBluetoothDeviceClient*>(
93 DBusThreadManager::Get()->GetBluetoothDeviceClient()); 100 BluezDBusManager::Get()->GetBluetoothDeviceClient());
94 101
95 // Initialize the login state trackers. 102 // Initialize the login state trackers.
96 if (!chromeos::LoginState::IsInitialized()) 103 if (!chromeos::LoginState::IsInitialized())
97 chromeos::LoginState::Initialize(); 104 chromeos::LoginState::Initialize();
98 } 105 }
99 106
100 void TearDown() override { 107 void TearDown() override {
101 // Destroy the login state tracker if it was initialized. 108 // Destroy the login state tracker if it was initialized.
102 chromeos::LoginState::Shutdown(); 109 chromeos::LoginState::Shutdown();
103 110
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Third device should match the Confirm Passkey object, this has 249 // Third device should match the Confirm Passkey object, this has
243 // no Device ID information. 250 // no Device ID information.
244 PairedDevice device2 = system_profile.hardware().bluetooth().paired_device(1); 251 PairedDevice device2 = system_profile.hardware().bluetooth().paired_device(1);
245 252
246 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass, 253 EXPECT_EQ(FakeBluetoothDeviceClient::kConfirmPasskeyClass,
247 device2.bluetooth_class()); 254 device2.bluetooth_class());
248 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type()); 255 EXPECT_EQ(PairedDevice::DEVICE_PHONE, device2.type());
249 EXPECT_EQ(0x207D74U, device2.vendor_prefix()); 256 EXPECT_EQ(0x207D74U, device2.vendor_prefix());
250 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source()); 257 EXPECT_EQ(PairedDevice::VENDOR_ID_UNKNOWN, device2.vendor_id_source());
251 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698