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

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

Issue 2394473005: Move enum BluetoothDevice::DeviceType out of BluetoothDevice class. (Closed)
Patch Set: 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
« no previous file with comments | « device/bluetooth/bluetooth_device.cc ('k') | device/bluetooth/test/mock_bluetooth_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
28 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 28 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
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::BluetoothDevice; 37 using device::BluetoothDevice;
38 using device::BluetoothDeviceType;
38 using device::BluetoothDiscoveryFilter; 39 using device::BluetoothDiscoveryFilter;
39 using device::BluetoothDiscoverySession; 40 using device::BluetoothDiscoverySession;
40 using device::BluetoothUUID; 41 using device::BluetoothUUID;
41 using device::TestBluetoothAdapterObserver; 42 using device::TestBluetoothAdapterObserver;
42 43
43 namespace bluez { 44 namespace bluez {
44 45
45 namespace { 46 namespace {
46 47
47 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the 48 // Callback for BluetoothDevice::GetConnectionInfo() that simply saves the
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 int idx = GetDeviceIndexByAddress( 2140 int idx = GetDeviceIndexByAddress(
2140 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2141 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2141 ASSERT_NE(-1, idx); 2142 ASSERT_NE(-1, idx);
2142 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2143 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2143 devices[idx]->GetAddress()); 2144 devices[idx]->GetAddress());
2144 2145
2145 // Verify the other device properties. 2146 // Verify the other device properties.
2146 EXPECT_EQ( 2147 EXPECT_EQ(
2147 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias), 2148 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias),
2148 devices[idx]->GetNameForDisplay()); 2149 devices[idx]->GetNameForDisplay());
2149 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2150 EXPECT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2150 EXPECT_TRUE(devices[idx]->IsPaired()); 2151 EXPECT_TRUE(devices[idx]->IsPaired());
2151 EXPECT_FALSE(devices[idx]->IsConnected()); 2152 EXPECT_FALSE(devices[idx]->IsConnected());
2152 EXPECT_FALSE(devices[idx]->IsConnecting()); 2153 EXPECT_FALSE(devices[idx]->IsConnecting());
2153 2154
2154 // Non HID devices are always connectable. 2155 // Non HID devices are always connectable.
2155 EXPECT_TRUE(devices[idx]->IsConnectable()); 2156 EXPECT_TRUE(devices[idx]->IsConnectable());
2156 2157
2157 BluetoothDevice::UUIDSet uuids = devices[idx]->GetUUIDs(); 2158 BluetoothDevice::UUIDSet uuids = devices[idx]->GetUUIDs();
2158 EXPECT_EQ(2U, uuids.size()); 2159 EXPECT_EQ(2U, uuids.size());
2159 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800"))); 2160 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800")));
2160 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801"))); 2161 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801")));
2161 2162
2162 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource()); 2163 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource());
2163 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID()); 2164 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID());
2164 EXPECT_EQ(0x030d, devices[idx]->GetProductID()); 2165 EXPECT_EQ(0x030d, devices[idx]->GetProductID());
2165 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID()); 2166 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID());
2166 } 2167 }
2167 2168
2168 TEST_F(BluetoothBlueZTest, DeviceClassChanged) { 2169 TEST_F(BluetoothBlueZTest, DeviceClassChanged) {
2169 // Simulate a change of class of a device, as sometimes occurs 2170 // Simulate a change of class of a device, as sometimes occurs
2170 // during discovery. 2171 // during discovery.
2171 GetAdapter(); 2172 GetAdapter();
2172 2173
2173 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2174 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2174 ASSERT_EQ(2U, devices.size()); 2175 ASSERT_EQ(2U, devices.size());
2175 2176
2176 int idx = GetDeviceIndexByAddress( 2177 int idx = GetDeviceIndexByAddress(
2177 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2178 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2178 ASSERT_NE(-1, idx); 2179 ASSERT_NE(-1, idx);
2179 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2180 ASSERT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2180 2181
2181 // Install an observer; expect the DeviceChanged method to be called when 2182 // Install an observer; expect the DeviceChanged method to be called when
2182 // we change the class of the device. 2183 // we change the class of the device.
2183 TestBluetoothAdapterObserver observer(adapter_); 2184 TestBluetoothAdapterObserver observer(adapter_);
2184 2185
2185 bluez::FakeBluetoothDeviceClient::Properties* properties = 2186 bluez::FakeBluetoothDeviceClient::Properties* properties =
2186 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2187 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2187 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2188 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2188 2189
2189 properties->bluetooth_class.ReplaceValue(0x002580); 2190 properties->bluetooth_class.ReplaceValue(0x002580);
2190 2191
2191 EXPECT_EQ(1, observer.device_changed_count()); 2192 EXPECT_EQ(1, observer.device_changed_count());
2192 EXPECT_EQ(devices[idx], observer.last_device()); 2193 EXPECT_EQ(devices[idx], observer.last_device());
2193 2194
2194 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); 2195 EXPECT_EQ(BluetoothDeviceType::MOUSE, devices[idx]->GetDeviceType());
2195 } 2196 }
2196 2197
2197 TEST_F(BluetoothBlueZTest, DeviceAppearance) { 2198 TEST_F(BluetoothBlueZTest, DeviceAppearance) {
2198 // Simulate a device with appearance. 2199 // Simulate a device with appearance.
2199 GetAdapter(); 2200 GetAdapter();
2200 2201
2201 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2202 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2202 ASSERT_EQ(2U, devices.size()); 2203 ASSERT_EQ(2U, devices.size());
2203 2204
2204 int idx = GetDeviceIndexByAddress( 2205 int idx = GetDeviceIndexByAddress(
2205 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2206 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2206 ASSERT_NE(-1, idx); 2207 ASSERT_NE(-1, idx);
2207 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2208 ASSERT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2208 2209
2209 // Install an observer; expect the DeviceChanged method to be called when 2210 // Install an observer; expect the DeviceChanged method to be called when
2210 // we change the appearance of the device. 2211 // we change the appearance of the device.
2211 TestBluetoothAdapterObserver observer(adapter_); 2212 TestBluetoothAdapterObserver observer(adapter_);
2212 2213
2213 bluez::FakeBluetoothDeviceClient::Properties* properties = 2214 bluez::FakeBluetoothDeviceClient::Properties* properties =
2214 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2215 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2215 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2216 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2216 2217
2217 // Let the device come without bluetooth_class. 2218 // Let the device come without bluetooth_class.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) { 2254 TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) {
2254 // Test device type of a device with appearance but without bluetooth class. 2255 // Test device type of a device with appearance but without bluetooth class.
2255 GetAdapter(); 2256 GetAdapter();
2256 2257
2257 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2258 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2258 ASSERT_EQ(2U, devices.size()); 2259 ASSERT_EQ(2U, devices.size());
2259 2260
2260 int idx = GetDeviceIndexByAddress( 2261 int idx = GetDeviceIndexByAddress(
2261 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2262 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2262 ASSERT_NE(-1, idx); 2263 ASSERT_NE(-1, idx);
2263 ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2264 ASSERT_EQ(BluetoothDeviceType::COMPUTER, devices[idx]->GetDeviceType());
2264 2265
2265 // Install an observer; expect the DeviceChanged method to be called when 2266 // Install an observer; expect the DeviceChanged method to be called when
2266 // we change the appearance of the device. 2267 // we change the appearance of the device.
2267 TestBluetoothAdapterObserver observer(adapter_); 2268 TestBluetoothAdapterObserver observer(adapter_);
2268 2269
2269 bluez::FakeBluetoothDeviceClient::Properties* properties = 2270 bluez::FakeBluetoothDeviceClient::Properties* properties =
2270 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2271 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2271 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2272 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2272 2273
2273 // Let the device come without bluetooth_class. 2274 // Let the device come without bluetooth_class.
2274 properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called 2275 properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called
2275 properties->appearance.ReplaceValue(0); // DeviceChanged method called 2276 properties->appearance.ReplaceValue(0); // DeviceChanged method called
2276 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); 2277 EXPECT_EQ(BluetoothDeviceType::UNKNOWN, devices[idx]->GetDeviceType());
2277 EXPECT_EQ(2, observer.device_changed_count()); 2278 EXPECT_EQ(2, observer.device_changed_count());
2278 EXPECT_EQ(devices[idx], observer.last_device()); 2279 EXPECT_EQ(devices[idx], observer.last_device());
2279 2280
2280 // Set the device appearance as keyboard. 2281 // Set the device appearance as keyboard.
2281 properties->appearance.ReplaceValue(961); // DeviceChanged method called 2282 properties->appearance.ReplaceValue(961); // DeviceChanged method called
2282 properties->appearance.set_valid(true); 2283 properties->appearance.set_valid(true);
2283 EXPECT_EQ(BluetoothDevice::DEVICE_KEYBOARD, devices[idx]->GetDeviceType()); 2284 EXPECT_EQ(BluetoothDeviceType::KEYBOARD, devices[idx]->GetDeviceType());
2284 EXPECT_EQ(3, observer.device_changed_count()); 2285 EXPECT_EQ(3, observer.device_changed_count());
2285 EXPECT_EQ(devices[idx], observer.last_device()); 2286 EXPECT_EQ(devices[idx], observer.last_device());
2286 // When discovery is over, the value should be invalidated. 2287 // When discovery is over, the value should be invalidated.
2287 properties->appearance.set_valid(false); 2288 properties->appearance.set_valid(false);
2288 // DeviceChanged method called by NotifyPropertyChanged() 2289 // DeviceChanged method called by NotifyPropertyChanged()
2289 properties->NotifyPropertyChanged(properties->appearance.name()); 2290 properties->NotifyPropertyChanged(properties->appearance.name());
2290 EXPECT_EQ(4, observer.device_changed_count()); 2291 EXPECT_EQ(4, observer.device_changed_count());
2291 EXPECT_EQ(devices[idx], observer.last_device()); 2292 EXPECT_EQ(devices[idx], observer.last_device());
2292 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); 2293 EXPECT_EQ(BluetoothDeviceType::UNKNOWN, devices[idx]->GetDeviceType());
2293 2294
2294 // Change the device appearance to mouse. 2295 // Change the device appearance to mouse.
2295 properties->appearance.ReplaceValue(962); // DeviceChanged method called 2296 properties->appearance.ReplaceValue(962); // DeviceChanged method called
2296 properties->appearance.set_valid(true); 2297 properties->appearance.set_valid(true);
2297 EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType()); 2298 EXPECT_EQ(BluetoothDeviceType::MOUSE, devices[idx]->GetDeviceType());
2298 EXPECT_EQ(5, observer.device_changed_count()); 2299 EXPECT_EQ(5, observer.device_changed_count());
2299 EXPECT_EQ(devices[idx], observer.last_device()); 2300 EXPECT_EQ(devices[idx], observer.last_device());
2300 // When discovery is over, the value should be invalidated. 2301 // When discovery is over, the value should be invalidated.
2301 properties->appearance.set_valid(false); 2302 properties->appearance.set_valid(false);
2302 // DeviceChanged method called by NotifyPropertyChanged() 2303 // DeviceChanged method called by NotifyPropertyChanged()
2303 properties->NotifyPropertyChanged(properties->appearance.name()); 2304 properties->NotifyPropertyChanged(properties->appearance.name());
2304 EXPECT_EQ(6, observer.device_changed_count()); 2305 EXPECT_EQ(6, observer.device_changed_count());
2305 EXPECT_EQ(devices[idx], observer.last_device()); 2306 EXPECT_EQ(devices[idx], observer.last_device());
2306 EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType()); 2307 EXPECT_EQ(BluetoothDeviceType::UNKNOWN, devices[idx]->GetDeviceType());
2307 } 2308 }
2308 2309
2309 TEST_F(BluetoothBlueZTest, DeviceNameChanged) { 2310 TEST_F(BluetoothBlueZTest, DeviceNameChanged) {
2310 // Simulate a change of name of a device. 2311 // Simulate a change of name of a device.
2311 GetAdapter(); 2312 GetAdapter();
2312 2313
2313 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2314 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2314 ASSERT_EQ(2U, devices.size()); 2315 ASSERT_EQ(2U, devices.size());
2315 2316
2316 int idx = GetDeviceIndexByAddress( 2317 int idx = GetDeviceIndexByAddress(
(...skipping 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after
4480 adapter_->Shutdown(); 4481 adapter_->Shutdown();
4481 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4482 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4482 4483
4483 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4484 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4484 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4485 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4485 EXPECT_EQ(0, callback_count_); 4486 EXPECT_EQ(0, callback_count_);
4486 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4487 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4487 } 4488 }
4488 4489
4489 } // namespace bluez 4490 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device.cc ('k') | device/bluetooth/test/mock_bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698