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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac_unittest.mm

Issue 2063353002: device/bluetooth: split out transport enum (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing new use in components/arc/bluetooth Created 4 years, 6 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 "device/bluetooth/bluetooth_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/test/test_simple_task_runner.h" 11 #include "base/test/test_simple_task_runner.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "device/bluetooth/bluetooth_adapter.h" 13 #include "device/bluetooth/bluetooth_adapter.h"
14 #include "device/bluetooth/bluetooth_common.h"
14 #include "device/bluetooth/bluetooth_discovery_session.h" 15 #include "device/bluetooth/bluetooth_discovery_session.h"
15 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" 16 #include "device/bluetooth/bluetooth_discovery_session_outcome.h"
16 #include "device/bluetooth/bluetooth_low_energy_device_mac.h" 17 #include "device/bluetooth/bluetooth_low_energy_device_mac.h"
17 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h" 18 #include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
18 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" 19 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/ocmock/OCMock/OCMock.h" 21 #include "third_party/ocmock/OCMock/OCMock.h"
21 22
22 #if defined(OS_IOS) 23 #if defined(OS_IOS)
23 #import <CoreBluetooth/CoreBluetooth.h> 24 #import <CoreBluetooth/CoreBluetooth.h>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty()); 159 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty());
159 } 160 }
160 161
161 TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) { 162 TEST_F(BluetoothAdapterMacTest, AddDiscoverySessionWithLowEnergyFilter) {
162 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) 163 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
163 return; 164 return;
164 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); 165 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
165 EXPECT_EQ(0, NumDiscoverySessions()); 166 EXPECT_EQ(0, NumDiscoverySessions());
166 167
167 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( 168 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(
168 new BluetoothDiscoveryFilter( 169 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE));
169 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE));
170 AddDiscoverySession(discovery_filter.get()); 170 AddDiscoverySession(discovery_filter.get());
171 EXPECT_EQ(1, callback_count_); 171 EXPECT_EQ(1, callback_count_);
172 EXPECT_EQ(0, error_callback_count_); 172 EXPECT_EQ(0, error_callback_count_);
173 EXPECT_EQ(1, NumDiscoverySessions()); 173 EXPECT_EQ(1, NumDiscoverySessions());
174 174
175 // Check that adding a discovery session resulted in 175 // Check that adding a discovery session resulted in
176 // scanForPeripheralsWithServices being called on the Central Manager. 176 // scanForPeripheralsWithServices being called on the Central Manager.
177 EXPECT_EQ(1, [mock_central_manager_ scanForPeripheralsCallCount]); 177 EXPECT_EQ(1, [mock_central_manager_ scanForPeripheralsCallCount]);
178 } 178 }
179 179
180 // TODO(krstnmnlsn): Test changing the filter when adding the second discovery 180 // TODO(krstnmnlsn): Test changing the filter when adding the second discovery
181 // session (once we have that ability). 181 // session (once we have that ability).
182 TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) { 182 TEST_F(BluetoothAdapterMacTest, AddSecondDiscoverySessionWithLowEnergyFilter) {
183 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) 183 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
184 return; 184 return;
185 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( 185 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(
186 new BluetoothDiscoveryFilter( 186 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE));
187 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE));
188 AddDiscoverySession(discovery_filter.get()); 187 AddDiscoverySession(discovery_filter.get());
189 EXPECT_EQ(1, callback_count_); 188 EXPECT_EQ(1, callback_count_);
190 EXPECT_EQ(0, error_callback_count_); 189 EXPECT_EQ(0, error_callback_count_);
191 EXPECT_EQ(1, NumDiscoverySessions()); 190 EXPECT_EQ(1, NumDiscoverySessions());
192 191
193 // We replaced the success callback handed to AddDiscoverySession, so 192 // We replaced the success callback handed to AddDiscoverySession, so
194 // |adapter_mac_| should remain in a discovering state indefinitely. 193 // |adapter_mac_| should remain in a discovering state indefinitely.
195 EXPECT_TRUE(adapter_mac_->IsDiscovering()); 194 EXPECT_TRUE(adapter_mac_->IsDiscovering());
196 195
197 AddDiscoverySession(discovery_filter.get()); 196 AddDiscoverySession(discovery_filter.get());
198 EXPECT_EQ(2, [mock_central_manager_ scanForPeripheralsCallCount]); 197 EXPECT_EQ(2, [mock_central_manager_ scanForPeripheralsCallCount]);
199 EXPECT_EQ(2, callback_count_); 198 EXPECT_EQ(2, callback_count_);
200 EXPECT_EQ(0, error_callback_count_); 199 EXPECT_EQ(0, error_callback_count_);
201 EXPECT_EQ(2, NumDiscoverySessions()); 200 EXPECT_EQ(2, NumDiscoverySessions());
202 } 201 }
203 202
204 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) { 203 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilter) {
205 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) 204 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
206 return; 205 return;
207 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); 206 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
208 207
209 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( 208 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(
210 new BluetoothDiscoveryFilter( 209 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE));
211 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE));
212 AddDiscoverySession(discovery_filter.get()); 210 AddDiscoverySession(discovery_filter.get());
213 EXPECT_EQ(1, callback_count_); 211 EXPECT_EQ(1, callback_count_);
214 EXPECT_EQ(0, error_callback_count_); 212 EXPECT_EQ(0, error_callback_count_);
215 EXPECT_EQ(1, NumDiscoverySessions()); 213 EXPECT_EQ(1, NumDiscoverySessions());
216 214
217 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); 215 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
218 RemoveDiscoverySession(discovery_filter.get()); 216 RemoveDiscoverySession(discovery_filter.get());
219 EXPECT_EQ(2, callback_count_); 217 EXPECT_EQ(2, callback_count_);
220 EXPECT_EQ(0, error_callback_count_); 218 EXPECT_EQ(0, error_callback_count_);
221 EXPECT_EQ(0, NumDiscoverySessions()); 219 EXPECT_EQ(0, NumDiscoverySessions());
222 220
223 // Check that removing the discovery session resulted in stopScan being called 221 // Check that removing the discovery session resulted in stopScan being called
224 // on the Central Manager. 222 // on the Central Manager.
225 EXPECT_EQ(1, [mock_central_manager_ stopScanCallCount]); 223 EXPECT_EQ(1, [mock_central_manager_ stopScanCallCount]);
226 } 224 }
227 225
228 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) { 226 TEST_F(BluetoothAdapterMacTest, RemoveDiscoverySessionWithLowEnergyFilterFail) {
229 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn)) 227 if (!SetMockCentralManager(CBCentralManagerStatePoweredOn))
230 return; 228 return;
231 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]); 229 EXPECT_EQ(0, [mock_central_manager_ scanForPeripheralsCallCount]);
232 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); 230 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
233 EXPECT_EQ(0, NumDiscoverySessions()); 231 EXPECT_EQ(0, NumDiscoverySessions());
234 232
235 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter( 233 std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter(
236 new BluetoothDiscoveryFilter( 234 new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE));
237 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE));
238 RemoveDiscoverySession(discovery_filter.get()); 235 RemoveDiscoverySession(discovery_filter.get());
239 EXPECT_EQ(0, callback_count_); 236 EXPECT_EQ(0, callback_count_);
240 EXPECT_EQ(1, error_callback_count_); 237 EXPECT_EQ(1, error_callback_count_);
241 EXPECT_EQ(0, NumDiscoverySessions()); 238 EXPECT_EQ(0, NumDiscoverySessions());
242 239
243 // Check that stopScan was not called. 240 // Check that stopScan was not called.
244 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); 241 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
245 } 242 }
246 243
247 TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) { 244 TEST_F(BluetoothAdapterMacTest, CheckGetPeripheralHashAddress) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 EXPECT_EQ(1, NumDevices()); 317 EXPECT_EQ(1, NumDevices());
321 EXPECT_TRUE(DevicePresent(mock_peripheral)); 318 EXPECT_TRUE(DevicePresent(mock_peripheral));
322 319
323 // Check that object pointed to by |device| is deleted by the adapter. 320 // Check that object pointed to by |device| is deleted by the adapter.
324 RemoveTimedOutDevices(); 321 RemoveTimedOutDevices();
325 EXPECT_EQ(0, NumDevices()); 322 EXPECT_EQ(0, NumDevices());
326 EXPECT_FALSE(DevicePresent(mock_peripheral)); 323 EXPECT_FALSE(DevicePresent(mock_peripheral));
327 } 324 }
328 325
329 } // namespace device 326 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_mac.mm ('k') | device/bluetooth/bluetooth_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698