OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
17 #include "device/bluetooth/bluetooth_adapter.h" | 17 #include "device/bluetooth/bluetooth_adapter.h" |
18 #include "device/bluetooth/bluetooth_adapter_bluez.h" | |
19 #include "device/bluetooth/bluetooth_adapter_factory.h" | 18 #include "device/bluetooth/bluetooth_adapter_factory.h" |
20 #include "device/bluetooth/bluetooth_device.h" | 19 #include "device/bluetooth/bluetooth_device.h" |
21 #include "device/bluetooth/bluetooth_device_bluez.h" | |
22 #include "device/bluetooth/bluetooth_discovery_session.h" | 20 #include "device/bluetooth/bluetooth_discovery_session.h" |
23 #include "device/bluetooth/bluetooth_pairing_bluez.h" | 21 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" |
| 22 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" |
| 23 #include "device/bluetooth/bluez/bluetooth_pairing_bluez.h" |
24 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 24 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
25 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" | 25 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
26 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" | 26 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
27 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 27 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
28 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" | 28 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
29 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" | 29 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
30 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 30 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "third_party/cros_system_api/dbus/service_constants.h" | 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
33 | 33 |
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2216 | 2216 |
2217 // Install an observer; expect the DeviceChanged method to be called when | 2217 // Install an observer; expect the DeviceChanged method to be called when |
2218 // we change the appearance of the device. | 2218 // we change the appearance of the device. |
2219 TestBluetoothAdapterObserver observer(adapter_); | 2219 TestBluetoothAdapterObserver observer(adapter_); |
2220 | 2220 |
2221 bluez::FakeBluetoothDeviceClient::Properties* properties = | 2221 bluez::FakeBluetoothDeviceClient::Properties* properties = |
2222 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( | 2222 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
2223 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2223 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
2224 | 2224 |
2225 // Let the device come without bluetooth_class. | 2225 // Let the device come without bluetooth_class. |
2226 properties->appearance.ReplaceValue(0); // DeviceChanged method called | 2226 properties->appearance.ReplaceValue(0); // DeviceChanged method called |
2227 EXPECT_EQ(1, observer.device_changed_count()); | 2227 EXPECT_EQ(1, observer.device_changed_count()); |
2228 EXPECT_EQ(devices[idx], observer.last_device()); | 2228 EXPECT_EQ(devices[idx], observer.last_device()); |
2229 | 2229 |
2230 // Set the device appearance as keyboard (961). | 2230 // Set the device appearance as keyboard (961). |
2231 properties->appearance.ReplaceValue(961); // DeviceChanged method called | 2231 properties->appearance.ReplaceValue(961); // DeviceChanged method called |
2232 properties->appearance.set_valid(true); | 2232 properties->appearance.set_valid(true); |
2233 EXPECT_EQ(2, observer.device_changed_count()); | 2233 EXPECT_EQ(2, observer.device_changed_count()); |
2234 EXPECT_EQ(devices[idx], observer.last_device()); | 2234 EXPECT_EQ(devices[idx], observer.last_device()); |
2235 EXPECT_EQ(961, devices[idx]->GetAppearance()); | 2235 EXPECT_EQ(961, devices[idx]->GetAppearance()); |
2236 // When discovery is over, the value should be invalidated. | 2236 // When discovery is over, the value should be invalidated. |
2237 properties->appearance.set_valid(false); | 2237 properties->appearance.set_valid(false); |
2238 // DeviceChanged method called by NotifyPropertyChanged() | 2238 // DeviceChanged method called by NotifyPropertyChanged() |
2239 properties->NotifyPropertyChanged(properties->appearance.name()); | 2239 properties->NotifyPropertyChanged(properties->appearance.name()); |
2240 EXPECT_EQ(3, observer.device_changed_count()); | 2240 EXPECT_EQ(3, observer.device_changed_count()); |
2241 EXPECT_EQ(devices[idx], observer.last_device()); | 2241 EXPECT_EQ(devices[idx], observer.last_device()); |
2242 EXPECT_EQ((int) BluetoothDevice::kAppearanceNotPresent, | 2242 EXPECT_EQ((int)BluetoothDevice::kAppearanceNotPresent, |
2243 devices[idx]->GetAppearance()); | 2243 devices[idx]->GetAppearance()); |
2244 | 2244 |
2245 // Change the device appearance to mouse (962). | 2245 // Change the device appearance to mouse (962). |
2246 properties->appearance.ReplaceValue(962); // DeviceChanged method called | 2246 properties->appearance.ReplaceValue(962); // DeviceChanged method called |
2247 properties->appearance.set_valid(true); | 2247 properties->appearance.set_valid(true); |
2248 EXPECT_EQ(4, observer.device_changed_count()); | 2248 EXPECT_EQ(4, observer.device_changed_count()); |
2249 EXPECT_EQ(devices[idx], observer.last_device()); | 2249 EXPECT_EQ(devices[idx], observer.last_device()); |
2250 EXPECT_EQ(962, devices[idx]->GetAppearance()); | 2250 EXPECT_EQ(962, devices[idx]->GetAppearance()); |
2251 // When discovery is over, the value should be invalidated. | 2251 // When discovery is over, the value should be invalidated. |
2252 properties->appearance.set_valid(false); | 2252 properties->appearance.set_valid(false); |
2253 // DeviceChanged method called by NotifyPropertyChanged() | 2253 // DeviceChanged method called by NotifyPropertyChanged() |
2254 properties->NotifyPropertyChanged(properties->appearance.name()); | 2254 properties->NotifyPropertyChanged(properties->appearance.name()); |
2255 EXPECT_EQ(5, observer.device_changed_count()); | 2255 EXPECT_EQ(5, observer.device_changed_count()); |
2256 EXPECT_EQ(devices[idx], observer.last_device()); | 2256 EXPECT_EQ(devices[idx], observer.last_device()); |
2257 EXPECT_EQ((int) BluetoothDevice::kAppearanceNotPresent, | 2257 EXPECT_EQ((int)BluetoothDevice::kAppearanceNotPresent, |
2258 devices[idx]->GetAppearance()); | 2258 devices[idx]->GetAppearance()); |
2259 } | 2259 } |
2260 | 2260 |
2261 TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) { | 2261 TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) { |
2262 // Test device type of a device with appearance but without bluetooth class. | 2262 // Test device type of a device with appearance but without bluetooth class. |
2263 GetAdapter(); | 2263 GetAdapter(); |
2264 | 2264 |
2265 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 2265 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
2266 ASSERT_EQ(2U, devices.size()); | 2266 ASSERT_EQ(2U, devices.size()); |
2267 | 2267 |
(...skipping 11 matching lines...) Expand all Loading... |
2279 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); | 2279 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
2280 | 2280 |
2281 // Let the device come without bluetooth_class. | 2281 // Let the device come without bluetooth_class. |
2282 properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called | 2282 properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called |
2283 properties->appearance.ReplaceValue(0); // DeviceChanged method called | 2283 properties->appearance.ReplaceValue(0); // DeviceChanged method called |
2284 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); | 2284 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); |
2285 EXPECT_EQ(2, observer.device_changed_count()); | 2285 EXPECT_EQ(2, observer.device_changed_count()); |
2286 EXPECT_EQ(devices[idx], observer.last_device()); | 2286 EXPECT_EQ(devices[idx], observer.last_device()); |
2287 | 2287 |
2288 // Set the device appearance as keyboard. | 2288 // Set the device appearance as keyboard. |
2289 properties->appearance.ReplaceValue(961); // DeviceChanged method called | 2289 properties->appearance.ReplaceValue(961); // DeviceChanged method called |
2290 properties->appearance.set_valid(true); | 2290 properties->appearance.set_valid(true); |
2291 EXPECT_EQ(BluetoothDevice::DEVICE_KEYBOARD, devices[idx]->GetDeviceType()); | 2291 EXPECT_EQ(BluetoothDevice::DEVICE_KEYBOARD, devices[idx]->GetDeviceType()); |
2292 EXPECT_EQ(3, observer.device_changed_count()); | 2292 EXPECT_EQ(3, observer.device_changed_count()); |
2293 EXPECT_EQ(devices[idx], observer.last_device()); | 2293 EXPECT_EQ(devices[idx], observer.last_device()); |
2294 // When discovery is over, the value should be invalidated. | 2294 // When discovery is over, the value should be invalidated. |
2295 properties->appearance.set_valid(false); | 2295 properties->appearance.set_valid(false); |
2296 // DeviceChanged method called by NotifyPropertyChanged() | 2296 // DeviceChanged method called by NotifyPropertyChanged() |
2297 properties->NotifyPropertyChanged(properties->appearance.name()); | 2297 properties->NotifyPropertyChanged(properties->appearance.name()); |
2298 EXPECT_EQ(4, observer.device_changed_count()); | 2298 EXPECT_EQ(4, observer.device_changed_count()); |
2299 EXPECT_EQ(devices[idx], observer.last_device()); | 2299 EXPECT_EQ(devices[idx], observer.last_device()); |
2300 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); | 2300 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); |
2301 | 2301 |
2302 // Change the device appearance to mouse. | 2302 // Change the device appearance to mouse. |
2303 properties->appearance.ReplaceValue(962); // DeviceChanged method called | 2303 properties->appearance.ReplaceValue(962); // DeviceChanged method called |
2304 properties->appearance.set_valid(true); | 2304 properties->appearance.set_valid(true); |
2305 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); | 2305 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); |
2306 EXPECT_EQ(5, observer.device_changed_count()); | 2306 EXPECT_EQ(5, observer.device_changed_count()); |
2307 EXPECT_EQ(devices[idx], observer.last_device()); | 2307 EXPECT_EQ(devices[idx], observer.last_device()); |
2308 // When discovery is over, the value should be invalidated. | 2308 // When discovery is over, the value should be invalidated. |
2309 properties->appearance.set_valid(false); | 2309 properties->appearance.set_valid(false); |
2310 // DeviceChanged method called by NotifyPropertyChanged() | 2310 // DeviceChanged method called by NotifyPropertyChanged() |
2311 properties->NotifyPropertyChanged(properties->appearance.name()); | 2311 properties->NotifyPropertyChanged(properties->appearance.name()); |
2312 EXPECT_EQ(6, observer.device_changed_count()); | 2312 EXPECT_EQ(6, observer.device_changed_count()); |
2313 EXPECT_EQ(devices[idx], observer.last_device()); | 2313 EXPECT_EQ(devices[idx], observer.last_device()); |
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4481 adapter_->Shutdown(); | 4481 adapter_->Shutdown(); |
4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
4483 | 4483 |
4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
4486 EXPECT_EQ(0, callback_count_); | 4486 EXPECT_EQ(0, callback_count_); |
4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
4488 } | 4488 } |
4489 | 4489 |
4490 } // namespace bluez | 4490 } // namespace bluez |
OLD | NEW |