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

Side by Side Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2205693003: bluetooth: Replace old advertised uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Improve comments Created 4 years, 4 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 "device/bluetooth/bluetooth_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 InitWithFakeAdapter(); 111 InitWithFakeAdapter();
112 StartLowEnergyDiscoverySession(); 112 StartLowEnergyDiscoverySession();
113 BluetoothDevice* device = SimulateLowEnergyDevice(3); 113 BluetoothDevice* device = SimulateLowEnergyDevice(3);
114 ASSERT_TRUE(device); 114 ASSERT_TRUE(device);
115 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 115 BluetoothDevice::UUIDList uuids = device->GetUUIDs();
116 EXPECT_EQ(0u, uuids.size()); 116 EXPECT_EQ(0u, uuids.size());
117 } 117 }
118 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 118 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
119 119
120 #if defined(OS_ANDROID) || defined(OS_MACOSX) 120 #if defined(OS_ANDROID) || defined(OS_MACOSX)
121 // Tests GetUUIDs returns the right UUIDs when device connects and disconnects.
122 TEST_F(BluetoothTest, GetUUIDs) {
123 if (!PlatformSupportsLowEnergy()) {
124 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
125 return;
126 }
127 InitWithFakeAdapter();
128 StartLowEnergyDiscoverySession();
129 BluetoothDevice* device = SimulateLowEnergyDevice(1);
130
131 // Check advertised UUIDs:
132 EXPECT_EQ(2u, device->GetUUIDs().size());
133 EXPECT_TRUE(
134 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
135 EXPECT_TRUE(ContainsValue(device->GetUUIDs(),
136 BluetoothUUID(kTestUUIDGenericAttribute)));
137
138 // Connect.
139 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
140 GetConnectErrorCallback(Call::NOT_EXPECTED));
141 TestBluetoothAdapterObserver observer(adapter_);
142 SimulateGattConnection(device);
143 ASSERT_TRUE(device->IsConnected());
144
145 // No UUIDs until services are completely discovered.
146 EXPECT_EQ(0u, device->GetUUIDs().size());
147
148 // Discover services.
149 std::vector<std::string> services;
150 services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value());
151 SimulateGattServicesDiscovered(device, services);
152
153 // GetUUIDs should return UUIDs of services in device.
154 EXPECT_EQ(1u, device->GetUUIDs().size());
155 EXPECT_TRUE(
156 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
157
158 #if defined(OS_MACOSX)
159 // Android and Windows don't yet support service changed events.
160 // http://crbug.com/548280
161 // http://crbug.com/579202
162 SimulateGattServicesChanged(device);
163
164 // After service changed event we don't know what UUIDs the device has.
165 ASSERT_FALSE(device->IsGattServicesDiscoveryComplete());
166 EXPECT_EQ(0u, device->GetUUIDs().size());
167
168 SimulateGattServicesDiscovered(device, {} /* services */);
169
170 // GetUUIDs should return UUIDs of services in device.
171 EXPECT_EQ(1u, device->GetUUIDs().size());
172 EXPECT_TRUE(
173 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
174 #endif // defined(OS_MACOSX)
175
176 // Disconnect.
177 device->DisconnectGatt();
178 SimulateGattDisconnection(device);
179
180 // After disconnection we don't know what UUIDs the device has.
181 EXPECT_EQ(0u, device->GetUUIDs().size());
182
183 // Discover the device again with different UUIDs.
184 device = SimulateLowEnergyDevice(2);
185
186 // Check advertised UUIDs.
187 EXPECT_EQ(2u, device->GetUUIDs().size());
188 EXPECT_TRUE(ContainsValue(device->GetUUIDs(),
189 BluetoothUUID(kTestUUIDImmediateAlert)));
190 EXPECT_TRUE(
191 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss)));
192 }
193 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
194
195 #if defined(OS_ANDROID) || defined(OS_MACOSX)
121 // GetName for Device with no name. 196 // GetName for Device with no name.
122 TEST_F(BluetoothTest, GetName_NullName) { 197 TEST_F(BluetoothTest, GetName_NullName) {
123 if (!PlatformSupportsLowEnergy()) { 198 if (!PlatformSupportsLowEnergy()) {
124 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 199 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
125 return; 200 return;
126 } 201 }
127 InitWithFakeAdapter(); 202 InitWithFakeAdapter();
128 StartLowEnergyDiscoverySession(); 203 StartLowEnergyDiscoverySession();
129 BluetoothDevice* device = SimulateLowEnergyDevice(5); 204 BluetoothDevice* device = SimulateLowEnergyDevice(5);
130 EXPECT_FALSE(device->GetName()); 205 EXPECT_FALSE(device->GetName());
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 730
656 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); 731 BluetoothDevice* device2 = SimulateLowEnergyDevice(6);
657 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); 732 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType());
658 733
659 BluetoothDevice* device3 = SimulateClassicDevice(); 734 BluetoothDevice* device3 = SimulateClassicDevice();
660 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); 735 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType());
661 } 736 }
662 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 737 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
663 738
664 } // namespace device 739 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_android.cc ('k') | device/bluetooth/bluetooth_low_energy_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698