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

Side by Side Diff: device/bluetooth/bluez/bluetooth_bluez_unittest.cc

Issue 2381493005: Add bluetooth device type icons on MD system tray. (Closed)
Patch Set: Move BluetoothDeviceType to device/bluetooth/bluetooth_common.h Created 4 years, 2 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 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
(...skipping 18 matching lines...) Expand all
29 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" 29 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h"
30 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" 30 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h"
31 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 31 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/cros_system_api/dbus/service_constants.h" 33 #include "third_party/cros_system_api/dbus/service_constants.h"
34 34
35 using device::BluetoothAdapter; 35 using device::BluetoothAdapter;
36 using device::BluetoothAdapterFactory; 36 using device::BluetoothAdapterFactory;
37 using device::BluetoothAudioSink; 37 using device::BluetoothAudioSink;
38 using device::BluetoothDevice; 38 using device::BluetoothDevice;
39 using device::BluetoothDeviceType;
39 using device::BluetoothDiscoveryFilter; 40 using device::BluetoothDiscoveryFilter;
40 using device::BluetoothDiscoverySession; 41 using device::BluetoothDiscoverySession;
41 using device::BluetoothUUID; 42 using device::BluetoothUUID;
42 using device::TestBluetoothAdapterObserver; 43 using device::TestBluetoothAdapterObserver;
43 44
44 namespace bluez { 45 namespace bluez {
45 46
46 namespace { 47 namespace {
47 48
48 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the 49 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the
(...skipping 2101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 int idx = GetDeviceIndexByAddress( 2151 int idx = GetDeviceIndexByAddress(
2151 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2152 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2152 ASSERT_NE(-1, idx); 2153 ASSERT_NE(-1, idx);
2153 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2154 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2154 devices[idx]->GetAddress()); 2155 devices[idx]->GetAddress());
2155 2156
2156 // Verify the other device properties. 2157 // Verify the other device properties.
2157 EXPECT_EQ( 2158 EXPECT_EQ(
2158 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias), 2159 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias),
2159 devices[idx]->GetNameForDisplay()); 2160 devices[idx]->GetNameForDisplay());
2160 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2161 EXPECT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2161 EXPECT_TRUE(devices[idx]->IsPaired()); 2162 EXPECT_TRUE(devices[idx]->IsPaired());
2162 EXPECT_FALSE(devices[idx]->IsConnected()); 2163 EXPECT_FALSE(devices[idx]->IsConnected());
2163 EXPECT_FALSE(devices[idx]->IsConnecting()); 2164 EXPECT_FALSE(devices[idx]->IsConnecting());
2164 2165
2165 // Non HID devices are always connectable. 2166 // Non HID devices are always connectable.
2166 EXPECT_TRUE(devices[idx]->IsConnectable()); 2167 EXPECT_TRUE(devices[idx]->IsConnectable());
2167 2168
2168 BluetoothDevice::UUIDSet uuids = devices[idx]->GetUUIDs(); 2169 BluetoothDevice::UUIDSet uuids = devices[idx]->GetUUIDs();
2169 EXPECT_EQ(2U, uuids.size()); 2170 EXPECT_EQ(2U, uuids.size());
2170 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800"))); 2171 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800")));
2171 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801"))); 2172 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801")));
2172 2173
2173 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource()); 2174 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource());
2174 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID()); 2175 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID());
2175 EXPECT_EQ(0x030d, devices[idx]->GetProductID()); 2176 EXPECT_EQ(0x030d, devices[idx]->GetProductID());
2176 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID()); 2177 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID());
2177 } 2178 }
2178 2179
2179 TEST_F(BluetoothBlueZTest, DeviceClassChanged) { 2180 TEST_F(BluetoothBlueZTest, DeviceClassChanged) {
2180 // Simulate a change of class of a device, as sometimes occurs 2181 // Simulate a change of class of a device, as sometimes occurs
2181 // during discovery. 2182 // during discovery.
2182 GetAdapter(); 2183 GetAdapter();
2183 2184
2184 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2185 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2185 ASSERT_EQ(2U, devices.size()); 2186 ASSERT_EQ(2U, devices.size());
2186 2187
2187 int idx = GetDeviceIndexByAddress( 2188 int idx = GetDeviceIndexByAddress(
2188 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2189 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2189 ASSERT_NE(-1, idx); 2190 ASSERT_NE(-1, idx);
2190 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2191 ASSERT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2191 2192
2192 // Install an observer; expect the DeviceChanged method to be called when 2193 // Install an observer; expect the DeviceChanged method to be called when
2193 // we change the class of the device. 2194 // we change the class of the device.
2194 TestBluetoothAdapterObserver observer(adapter_); 2195 TestBluetoothAdapterObserver observer(adapter_);
2195 2196
2196 bluez::FakeBluetoothDeviceClient::Properties* properties = 2197 bluez::FakeBluetoothDeviceClient::Properties* properties =
2197 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2198 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2198 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2199 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2199 2200
2200 properties->bluetooth_class.ReplaceValue(0x002580); 2201 properties->bluetooth_class.ReplaceValue(0x002580);
2201 2202
2202 EXPECT_EQ(1, observer.device_changed_count()); 2203 EXPECT_EQ(1, observer.device_changed_count());
2203 EXPECT_EQ(devices[idx], observer.last_device()); 2204 EXPECT_EQ(devices[idx], observer.last_device());
2204 2205
2205 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); 2206 EXPECT_EQ(BluetoothDeviceType::MOUSE, devices[idx]->GetDeviceType());
2206 } 2207 }
2207 2208
2208 TEST_F(BluetoothBlueZTest, DeviceAppearance) { 2209 TEST_F(BluetoothBlueZTest, DeviceAppearance) {
2209 // Simulate a device with appearance. 2210 // Simulate a device with appearance.
2210 GetAdapter(); 2211 GetAdapter();
2211 2212
2212 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2213 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2213 ASSERT_EQ(2U, devices.size()); 2214 ASSERT_EQ(2U, devices.size());
2214 2215
2215 int idx = GetDeviceIndexByAddress( 2216 int idx = GetDeviceIndexByAddress(
2216 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2217 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2217 ASSERT_NE(-1, idx); 2218 ASSERT_NE(-1, idx);
2218 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2219 ASSERT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2219 2220
2220 // Install an observer; expect the DeviceChanged method to be called when 2221 // Install an observer; expect the DeviceChanged method to be called when
2221 // we change the appearance of the device. 2222 // we change the appearance of the device.
2222 TestBluetoothAdapterObserver observer(adapter_); 2223 TestBluetoothAdapterObserver observer(adapter_);
2223 2224
2224 bluez::FakeBluetoothDeviceClient::Properties* properties = 2225 bluez::FakeBluetoothDeviceClient::Properties* properties =
2225 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2226 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2226 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2227 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2227 2228
2228 // Let the device come without bluetooth_class. 2229 // Let the device come without bluetooth_class.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) { 2265 TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) {
2265 // Test device type of a device with appearance but without bluetooth class. 2266 // Test device type of a device with appearance but without bluetooth class.
2266 GetAdapter(); 2267 GetAdapter();
2267 2268
2268 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2269 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2269 ASSERT_EQ(2U, devices.size()); 2270 ASSERT_EQ(2U, devices.size());
2270 2271
2271 int idx = GetDeviceIndexByAddress( 2272 int idx = GetDeviceIndexByAddress(
2272 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2273 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2273 ASSERT_NE(-1, idx); 2274 ASSERT_NE(-1, idx);
2274 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2275 ASSERT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2275 2276
2276 // Install an observer; expect the DeviceChanged method to be called when 2277 // Install an observer; expect the DeviceChanged method to be called when
2277 // we change the appearance of the device. 2278 // we change the appearance of the device.
2278 TestBluetoothAdapterObserver observer(adapter_); 2279 TestBluetoothAdapterObserver observer(adapter_);
2279 2280
2280 bluez::FakeBluetoothDeviceClient::Properties* properties = 2281 bluez::FakeBluetoothDeviceClient::Properties* properties =
2281 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2282 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2282 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2283 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2283 2284
2284 // Let the device come without bluetooth_class. 2285 // Let the device come without bluetooth_class.
2285 properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called 2286 properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called
2286 properties->appearance.ReplaceValue(0); // DeviceChanged method called 2287 properties->appearance.ReplaceValue(0); // DeviceChanged method called
2287 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); 2288 EXPECT_EQ(BluetoothDeviceType::UNKNOWN, devices[idx]->GetDeviceType());
2288 EXPECT_EQ(2, observer.device_changed_count()); 2289 EXPECT_EQ(2, observer.device_changed_count());
2289 EXPECT_EQ(devices[idx], observer.last_device()); 2290 EXPECT_EQ(devices[idx], observer.last_device());
2290 2291
2291 // Set the device appearance as keyboard. 2292 // Set the device appearance as keyboard.
2292 properties->appearance.ReplaceValue(961); // DeviceChanged method called 2293 properties->appearance.ReplaceValue(961); // DeviceChanged method called
2293 properties->appearance.set_valid(true); 2294 properties->appearance.set_valid(true);
2294 EXPECT_EQ(BluetoothDevice::DEVICE_KEYBOARD, devices[idx]->GetDeviceType()); 2295 EXPECT_EQ(BluetoothDeviceType::KEYBOARD, devices[idx]->GetDeviceType());
2295 EXPECT_EQ(3, observer.device_changed_count()); 2296 EXPECT_EQ(3, observer.device_changed_count());
2296 EXPECT_EQ(devices[idx], observer.last_device()); 2297 EXPECT_EQ(devices[idx], observer.last_device());
2297 // When discovery is over, the value should be invalidated. 2298 // When discovery is over, the value should be invalidated.
2298 properties->appearance.set_valid(false); 2299 properties->appearance.set_valid(false);
2299 // DeviceChanged method called by NotifyPropertyChanged() 2300 // DeviceChanged method called by NotifyPropertyChanged()
2300 properties->NotifyPropertyChanged(properties->appearance.name()); 2301 properties->NotifyPropertyChanged(properties->appearance.name());
2301 EXPECT_EQ(4, observer.device_changed_count()); 2302 EXPECT_EQ(4, observer.device_changed_count());
2302 EXPECT_EQ(devices[idx], observer.last_device()); 2303 EXPECT_EQ(devices[idx], observer.last_device());
2303 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); 2304 EXPECT_EQ(BluetoothDeviceType::UNKNOWN, devices[idx]->GetDeviceType());
2304 2305
2305 // Change the device appearance to mouse. 2306 // Change the device appearance to mouse.
2306 properties->appearance.ReplaceValue(962); // DeviceChanged method called 2307 properties->appearance.ReplaceValue(962); // DeviceChanged method called
2307 properties->appearance.set_valid(true); 2308 properties->appearance.set_valid(true);
2308 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); 2309 EXPECT_EQ(BluetoothDeviceType::MOUSE, devices[idx]->GetDeviceType());
2309 EXPECT_EQ(5, observer.device_changed_count()); 2310 EXPECT_EQ(5, observer.device_changed_count());
2310 EXPECT_EQ(devices[idx], observer.last_device()); 2311 EXPECT_EQ(devices[idx], observer.last_device());
2311 // When discovery is over, the value should be invalidated. 2312 // When discovery is over, the value should be invalidated.
2312 properties->appearance.set_valid(false); 2313 properties->appearance.set_valid(false);
2313 // DeviceChanged method called by NotifyPropertyChanged() 2314 // DeviceChanged method called by NotifyPropertyChanged()
2314 properties->NotifyPropertyChanged(properties->appearance.name()); 2315 properties->NotifyPropertyChanged(properties->appearance.name());
2315 EXPECT_EQ(6, observer.device_changed_count()); 2316 EXPECT_EQ(6, observer.device_changed_count());
2316 EXPECT_EQ(devices[idx], observer.last_device()); 2317 EXPECT_EQ(devices[idx], observer.last_device());
2317 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); 2318 EXPECT_EQ(BluetoothDeviceType::UNKNOWN, devices[idx]->GetDeviceType());
2318 } 2319 }
2319 2320
2320 TEST_F(BluetoothBlueZTest, DeviceNameChanged) { 2321 TEST_F(BluetoothBlueZTest, DeviceNameChanged) {
2321 // Simulate a change of name of a device. 2322 // Simulate a change of name of a device.
2322 GetAdapter(); 2323 GetAdapter();
2323 2324
2324 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2325 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2325 ASSERT_EQ(2U, devices.size()); 2326 ASSERT_EQ(2U, devices.size());
2326 2327
2327 int idx = GetDeviceIndexByAddress( 2328 int idx = GetDeviceIndexByAddress(
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after
4510 adapter_->Shutdown(); 4511 adapter_->Shutdown();
4511 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4512 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4512 4513
4513 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4514 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4514 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4515 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4515 EXPECT_EQ(0, callback_count_); 4516 EXPECT_EQ(0, callback_count_);
4516 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4517 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4517 } 4518 }
4518 4519
4519 } // namespace bluez 4520 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698