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

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

Issue 188473002: device/bluetooth: Remove BluetoothAdapter::Start|StopDiscovering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed BluetoothAdapterWinTest compile errors. Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 void IncrementNumStopDiscoveryCallbacks() { 126 void IncrementNumStopDiscoveryCallbacks() {
127 num_stop_discovery_callbacks_++; 127 num_stop_discovery_callbacks_++;
128 } 128 }
129 129
130 void IncrementNumStopDiscoveryErrorCallbacks() { 130 void IncrementNumStopDiscoveryErrorCallbacks() {
131 num_stop_discovery_error_callbacks_++; 131 num_stop_discovery_error_callbacks_++;
132 } 132 }
133 133
134 void CallAddDiscoverySession(
135 const base::Closure& callback,
136 const BluetoothAdapter::ErrorCallback& error_callback) {
137 adapter_win_->AddDiscoverySession(callback, error_callback);
138 }
139
140 void CallRemoveDiscoverySession(
141 const base::Closure& callback,
142 const BluetoothAdapter::ErrorCallback& error_callback) {
143 adapter_win_->RemoveDiscoverySession(callback, error_callback);
144 }
145
134 protected: 146 protected:
135 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; 147 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_;
136 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_; 148 scoped_refptr<base::TestSimpleTaskRunner> bluetooth_task_runner_;
137 scoped_refptr<BluetoothAdapter> adapter_; 149 scoped_refptr<BluetoothAdapter> adapter_;
138 BluetoothAdapterWin* adapter_win_; 150 BluetoothAdapterWin* adapter_win_;
139 AdapterObserver adapter_observer_; 151 AdapterObserver adapter_observer_;
140 bool init_callback_called_; 152 bool init_callback_called_;
141 int num_start_discovery_callbacks_; 153 int num_start_discovery_callbacks_;
142 int num_start_discovery_error_callbacks_; 154 int num_start_discovery_error_callbacks_;
143 int num_stop_discovery_callbacks_; 155 int num_stop_discovery_callbacks_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_FALSE(adapter_win_->IsInitialized()); 199 EXPECT_FALSE(adapter_win_->IsInitialized());
188 EXPECT_FALSE(init_callback_called_); 200 EXPECT_FALSE(init_callback_called_);
189 BluetoothTaskManagerWin::AdapterState state; 201 BluetoothTaskManagerWin::AdapterState state;
190 adapter_win_->AdapterStateChanged(state); 202 adapter_win_->AdapterStateChanged(state);
191 EXPECT_TRUE(adapter_win_->IsInitialized()); 203 EXPECT_TRUE(adapter_win_->IsInitialized());
192 EXPECT_TRUE(init_callback_called_); 204 EXPECT_TRUE(init_callback_called_);
193 } 205 }
194 206
195 TEST_F(BluetoothAdapterWinTest, SingleStartDiscovery) { 207 TEST_F(BluetoothAdapterWinTest, SingleStartDiscovery) {
196 bluetooth_task_runner_->ClearPendingTasks(); 208 bluetooth_task_runner_->ClearPendingTasks();
197 adapter_win_->StartDiscovering( 209 CallAddDiscoverySession(
198 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 210 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
199 base::Unretained(this)), 211 base::Unretained(this)),
200 BluetoothAdapter::ErrorCallback()); 212 BluetoothAdapter::ErrorCallback());
201 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty()); 213 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty());
202 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size()); 214 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
203 EXPECT_FALSE(adapter_->IsDiscovering()); 215 EXPECT_FALSE(adapter_->IsDiscovering());
204 EXPECT_EQ(0, num_start_discovery_callbacks_); 216 EXPECT_EQ(0, num_start_discovery_callbacks_);
205 adapter_win_->DiscoveryStarted(true); 217 adapter_win_->DiscoveryStarted(true);
206 ui_task_runner_->RunPendingTasks(); 218 ui_task_runner_->RunPendingTasks();
207 EXPECT_TRUE(adapter_->IsDiscovering()); 219 EXPECT_TRUE(adapter_->IsDiscovering());
208 EXPECT_EQ(1, num_start_discovery_callbacks_); 220 EXPECT_EQ(1, num_start_discovery_callbacks_);
209 EXPECT_EQ(1, adapter_observer_.num_discovering_changed()); 221 EXPECT_EQ(1, adapter_observer_.num_discovering_changed());
210 } 222 }
211 223
212 TEST_F(BluetoothAdapterWinTest, SingleStartDiscoveryFailure) { 224 TEST_F(BluetoothAdapterWinTest, SingleStartDiscoveryFailure) {
213 adapter_win_->StartDiscovering( 225 CallAddDiscoverySession(
214 base::Closure(), 226 base::Closure(),
215 base::Bind( 227 base::Bind(
216 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks, 228 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
217 base::Unretained(this))); 229 base::Unretained(this)));
218 adapter_win_->DiscoveryStarted(false); 230 adapter_win_->DiscoveryStarted(false);
219 ui_task_runner_->RunPendingTasks(); 231 ui_task_runner_->RunPendingTasks();
220 EXPECT_FALSE(adapter_->IsDiscovering()); 232 EXPECT_FALSE(adapter_->IsDiscovering());
221 EXPECT_EQ(1, num_start_discovery_error_callbacks_); 233 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
222 EXPECT_EQ(0, adapter_observer_.num_discovering_changed()); 234 EXPECT_EQ(0, adapter_observer_.num_discovering_changed());
223 } 235 }
224 236
225 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveries) { 237 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveries) {
226 bluetooth_task_runner_->ClearPendingTasks(); 238 bluetooth_task_runner_->ClearPendingTasks();
227 int num_discoveries = 5; 239 int num_discoveries = 5;
228 for (int i = 0; i < num_discoveries; i++) { 240 for (int i = 0; i < num_discoveries; i++) {
229 adapter_win_->StartDiscovering( 241 CallAddDiscoverySession(
230 base::Bind( 242 base::Bind(
231 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 243 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
232 base::Unretained(this)), 244 base::Unretained(this)),
233 BluetoothAdapter::ErrorCallback()); 245 BluetoothAdapter::ErrorCallback());
234 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size()); 246 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
235 } 247 }
236 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty()); 248 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty());
237 EXPECT_FALSE(adapter_->IsDiscovering()); 249 EXPECT_FALSE(adapter_->IsDiscovering());
238 EXPECT_EQ(0, num_start_discovery_callbacks_); 250 EXPECT_EQ(0, num_start_discovery_callbacks_);
239 adapter_win_->DiscoveryStarted(true); 251 adapter_win_->DiscoveryStarted(true);
240 ui_task_runner_->RunPendingTasks(); 252 ui_task_runner_->RunPendingTasks();
241 EXPECT_TRUE(adapter_->IsDiscovering()); 253 EXPECT_TRUE(adapter_->IsDiscovering());
242 EXPECT_EQ(num_discoveries, num_start_discovery_callbacks_); 254 EXPECT_EQ(num_discoveries, num_start_discovery_callbacks_);
243 EXPECT_EQ(1, adapter_observer_.num_discovering_changed()); 255 EXPECT_EQ(1, adapter_observer_.num_discovering_changed());
244 } 256 }
245 257
246 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveriesFailure) { 258 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveriesFailure) {
247 int num_discoveries = 5; 259 int num_discoveries = 5;
248 for (int i = 0; i < num_discoveries; i++) { 260 for (int i = 0; i < num_discoveries; i++) {
249 adapter_win_->StartDiscovering( 261 CallAddDiscoverySession(
250 base::Closure(), 262 base::Closure(),
251 base::Bind( 263 base::Bind(
252 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks, 264 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
253 base::Unretained(this))); 265 base::Unretained(this)));
254 } 266 }
255 adapter_win_->DiscoveryStarted(false); 267 adapter_win_->DiscoveryStarted(false);
256 ui_task_runner_->RunPendingTasks(); 268 ui_task_runner_->RunPendingTasks();
257 EXPECT_FALSE(adapter_->IsDiscovering()); 269 EXPECT_FALSE(adapter_->IsDiscovering());
258 EXPECT_EQ(num_discoveries, num_start_discovery_error_callbacks_); 270 EXPECT_EQ(num_discoveries, num_start_discovery_error_callbacks_);
259 EXPECT_EQ(0, adapter_observer_.num_discovering_changed()); 271 EXPECT_EQ(0, adapter_observer_.num_discovering_changed());
260 } 272 }
261 273
262 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveriesAfterDiscovering) { 274 TEST_F(BluetoothAdapterWinTest, MultipleStartDiscoveriesAfterDiscovering) {
263 adapter_win_->StartDiscovering( 275 CallAddDiscoverySession(
264 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 276 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
265 base::Unretained(this)), 277 base::Unretained(this)),
266 BluetoothAdapter::ErrorCallback()); 278 BluetoothAdapter::ErrorCallback());
267 adapter_win_->DiscoveryStarted(true); 279 adapter_win_->DiscoveryStarted(true);
268 ui_task_runner_->RunPendingTasks(); 280 ui_task_runner_->RunPendingTasks();
269 EXPECT_TRUE(adapter_->IsDiscovering()); 281 EXPECT_TRUE(adapter_->IsDiscovering());
270 EXPECT_EQ(1, num_start_discovery_callbacks_); 282 EXPECT_EQ(1, num_start_discovery_callbacks_);
271 283
272 bluetooth_task_runner_->ClearPendingTasks(); 284 bluetooth_task_runner_->ClearPendingTasks();
273 for (int i = 0; i < 5; i++) { 285 for (int i = 0; i < 5; i++) {
274 int num_start_discovery_callbacks = num_start_discovery_callbacks_; 286 int num_start_discovery_callbacks = num_start_discovery_callbacks_;
275 adapter_win_->StartDiscovering( 287 CallAddDiscoverySession(
276 base::Bind( 288 base::Bind(
277 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 289 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
278 base::Unretained(this)), 290 base::Unretained(this)),
279 BluetoothAdapter::ErrorCallback()); 291 BluetoothAdapter::ErrorCallback());
280 EXPECT_TRUE(adapter_->IsDiscovering()); 292 EXPECT_TRUE(adapter_->IsDiscovering());
281 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); 293 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
282 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty()); 294 EXPECT_TRUE(ui_task_runner_->GetPendingTasks().empty());
283 EXPECT_EQ(num_start_discovery_callbacks + 1, 295 EXPECT_EQ(num_start_discovery_callbacks + 1,
284 num_start_discovery_callbacks_); 296 num_start_discovery_callbacks_);
285 } 297 }
286 EXPECT_EQ(1, adapter_observer_.num_discovering_changed()); 298 EXPECT_EQ(1, adapter_observer_.num_discovering_changed());
287 } 299 }
288 300
289 TEST_F(BluetoothAdapterWinTest, StartDiscoveryAfterDiscoveringFailure) { 301 TEST_F(BluetoothAdapterWinTest, StartDiscoveryAfterDiscoveringFailure) {
290 adapter_win_->StartDiscovering( 302 CallAddDiscoverySession(
291 base::Closure(), 303 base::Closure(),
292 base::Bind( 304 base::Bind(
293 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks, 305 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
294 base::Unretained(this))); 306 base::Unretained(this)));
295 adapter_win_->DiscoveryStarted(false); 307 adapter_win_->DiscoveryStarted(false);
296 ui_task_runner_->RunPendingTasks(); 308 ui_task_runner_->RunPendingTasks();
297 EXPECT_FALSE(adapter_->IsDiscovering()); 309 EXPECT_FALSE(adapter_->IsDiscovering());
298 EXPECT_EQ(1, num_start_discovery_error_callbacks_); 310 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
299 311
300 adapter_win_->StartDiscovering( 312 CallAddDiscoverySession(
301 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 313 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
302 base::Unretained(this)), 314 base::Unretained(this)),
303 BluetoothAdapter::ErrorCallback()); 315 BluetoothAdapter::ErrorCallback());
304 adapter_win_->DiscoveryStarted(true); 316 adapter_win_->DiscoveryStarted(true);
305 ui_task_runner_->RunPendingTasks(); 317 ui_task_runner_->RunPendingTasks();
306 EXPECT_TRUE(adapter_->IsDiscovering()); 318 EXPECT_TRUE(adapter_->IsDiscovering());
307 EXPECT_EQ(1, num_start_discovery_callbacks_); 319 EXPECT_EQ(1, num_start_discovery_callbacks_);
308 } 320 }
309 321
310 TEST_F(BluetoothAdapterWinTest, SingleStopDiscovery) { 322 TEST_F(BluetoothAdapterWinTest, SingleStopDiscovery) {
311 adapter_win_->StartDiscovering( 323 CallAddDiscoverySession(
312 base::Closure(), BluetoothAdapter::ErrorCallback()); 324 base::Closure(), BluetoothAdapter::ErrorCallback());
313 adapter_win_->DiscoveryStarted(true); 325 adapter_win_->DiscoveryStarted(true);
314 ui_task_runner_->ClearPendingTasks(); 326 ui_task_runner_->ClearPendingTasks();
315 adapter_win_->StopDiscovering( 327 CallRemoveDiscoverySession(
316 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 328 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
317 base::Unretained(this)), 329 base::Unretained(this)),
318 BluetoothAdapter::ErrorCallback()); 330 BluetoothAdapter::ErrorCallback());
319 EXPECT_TRUE(adapter_->IsDiscovering()); 331 EXPECT_TRUE(adapter_->IsDiscovering());
320 EXPECT_EQ(0, num_stop_discovery_callbacks_); 332 EXPECT_EQ(0, num_stop_discovery_callbacks_);
321 bluetooth_task_runner_->ClearPendingTasks(); 333 bluetooth_task_runner_->ClearPendingTasks();
322 adapter_win_->DiscoveryStopped(); 334 adapter_win_->DiscoveryStopped();
323 ui_task_runner_->RunPendingTasks(); 335 ui_task_runner_->RunPendingTasks();
324 EXPECT_FALSE(adapter_->IsDiscovering()); 336 EXPECT_FALSE(adapter_->IsDiscovering());
325 EXPECT_EQ(1, num_stop_discovery_callbacks_); 337 EXPECT_EQ(1, num_stop_discovery_callbacks_);
326 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); 338 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
327 EXPECT_EQ(2, adapter_observer_.num_discovering_changed()); 339 EXPECT_EQ(2, adapter_observer_.num_discovering_changed());
328 } 340 }
329 341
330 TEST_F(BluetoothAdapterWinTest, MultipleStopDiscoveries) { 342 TEST_F(BluetoothAdapterWinTest, MultipleStopDiscoveries) {
331 int num_discoveries = 5; 343 int num_discoveries = 5;
332 for (int i = 0; i < num_discoveries; i++) { 344 for (int i = 0; i < num_discoveries; i++) {
333 adapter_win_->StartDiscovering( 345 CallAddDiscoverySession(
334 base::Closure(), BluetoothAdapter::ErrorCallback()); 346 base::Closure(), BluetoothAdapter::ErrorCallback());
335 } 347 }
336 adapter_win_->DiscoveryStarted(true); 348 adapter_win_->DiscoveryStarted(true);
337 ui_task_runner_->ClearPendingTasks(); 349 ui_task_runner_->ClearPendingTasks();
338 bluetooth_task_runner_->ClearPendingTasks(); 350 bluetooth_task_runner_->ClearPendingTasks();
339 for (int i = 0; i < num_discoveries - 1; i++) { 351 for (int i = 0; i < num_discoveries - 1; i++) {
340 adapter_win_->StopDiscovering( 352 CallRemoveDiscoverySession(
341 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 353 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
342 base::Unretained(this)), 354 base::Unretained(this)),
343 BluetoothAdapter::ErrorCallback()); 355 BluetoothAdapter::ErrorCallback());
344 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); 356 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
345 ui_task_runner_->RunPendingTasks(); 357 ui_task_runner_->RunPendingTasks();
346 EXPECT_EQ(i + 1, num_stop_discovery_callbacks_); 358 EXPECT_EQ(i + 1, num_stop_discovery_callbacks_);
347 } 359 }
348 adapter_win_->StopDiscovering( 360 CallRemoveDiscoverySession(
349 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 361 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
350 base::Unretained(this)), 362 base::Unretained(this)),
351 BluetoothAdapter::ErrorCallback()); 363 BluetoothAdapter::ErrorCallback());
352 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size()); 364 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
353 EXPECT_TRUE(adapter_->IsDiscovering()); 365 EXPECT_TRUE(adapter_->IsDiscovering());
354 adapter_win_->DiscoveryStopped(); 366 adapter_win_->DiscoveryStopped();
355 ui_task_runner_->RunPendingTasks(); 367 ui_task_runner_->RunPendingTasks();
356 EXPECT_FALSE(adapter_->IsDiscovering()); 368 EXPECT_FALSE(adapter_->IsDiscovering());
357 EXPECT_EQ(num_discoveries, num_stop_discovery_callbacks_); 369 EXPECT_EQ(num_discoveries, num_stop_discovery_callbacks_);
358 EXPECT_EQ(2, adapter_observer_.num_discovering_changed()); 370 EXPECT_EQ(2, adapter_observer_.num_discovering_changed());
359 } 371 }
360 372
361 TEST_F(BluetoothAdapterWinTest, 373 TEST_F(BluetoothAdapterWinTest,
362 StartDiscoveryAndStartDiscoveryAndStopDiscoveries) { 374 StartDiscoveryAndStartDiscoveryAndStopDiscoveries) {
363 adapter_win_->StartDiscovering( 375 CallAddDiscoverySession(
364 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 376 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
365 base::Unretained(this)), 377 base::Unretained(this)),
366 BluetoothAdapter::ErrorCallback()); 378 BluetoothAdapter::ErrorCallback());
367 adapter_win_->DiscoveryStarted(true); 379 adapter_win_->DiscoveryStarted(true);
368 adapter_win_->StartDiscovering( 380 CallAddDiscoverySession(
369 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 381 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
370 base::Unretained(this)), 382 base::Unretained(this)),
371 BluetoothAdapter::ErrorCallback()); 383 BluetoothAdapter::ErrorCallback());
372 ui_task_runner_->ClearPendingTasks(); 384 ui_task_runner_->ClearPendingTasks();
373 bluetooth_task_runner_->ClearPendingTasks(); 385 bluetooth_task_runner_->ClearPendingTasks();
374 adapter_win_->StopDiscovering( 386 CallRemoveDiscoverySession(
375 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 387 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
376 base::Unretained(this)), 388 base::Unretained(this)),
377 BluetoothAdapter::ErrorCallback()); 389 BluetoothAdapter::ErrorCallback());
378 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); 390 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
379 adapter_win_->StopDiscovering( 391 CallRemoveDiscoverySession(
380 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 392 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
381 base::Unretained(this)), 393 base::Unretained(this)),
382 BluetoothAdapter::ErrorCallback()); 394 BluetoothAdapter::ErrorCallback());
383 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size()); 395 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
384 } 396 }
385 397
386 TEST_F(BluetoothAdapterWinTest, 398 TEST_F(BluetoothAdapterWinTest,
387 StartDiscoveryAndStopDiscoveryAndStartDiscovery) { 399 StartDiscoveryAndStopDiscoveryAndStartDiscovery) {
388 adapter_win_->StartDiscovering( 400 CallAddDiscoverySession(
389 base::Closure(), BluetoothAdapter::ErrorCallback()); 401 base::Closure(), BluetoothAdapter::ErrorCallback());
390 adapter_win_->DiscoveryStarted(true); 402 adapter_win_->DiscoveryStarted(true);
391 EXPECT_TRUE(adapter_->IsDiscovering()); 403 EXPECT_TRUE(adapter_->IsDiscovering());
392 adapter_win_->StopDiscovering( 404 CallRemoveDiscoverySession(
393 base::Closure(), BluetoothAdapter::ErrorCallback()); 405 base::Closure(), BluetoothAdapter::ErrorCallback());
394 adapter_win_->DiscoveryStopped(); 406 adapter_win_->DiscoveryStopped();
395 EXPECT_FALSE(adapter_->IsDiscovering()); 407 EXPECT_FALSE(adapter_->IsDiscovering());
396 adapter_win_->StartDiscovering( 408 CallAddDiscoverySession(
397 base::Closure(), BluetoothAdapter::ErrorCallback()); 409 base::Closure(), BluetoothAdapter::ErrorCallback());
398 adapter_win_->DiscoveryStarted(true); 410 adapter_win_->DiscoveryStarted(true);
399 EXPECT_TRUE(adapter_->IsDiscovering()); 411 EXPECT_TRUE(adapter_->IsDiscovering());
400 } 412 }
401 413
402 TEST_F(BluetoothAdapterWinTest, StartDiscoveryBeforeDiscoveryStopped) { 414 TEST_F(BluetoothAdapterWinTest, StartDiscoveryBeforeDiscoveryStopped) {
403 adapter_win_->StartDiscovering( 415 CallAddDiscoverySession(
404 base::Closure(), BluetoothAdapter::ErrorCallback()); 416 base::Closure(), BluetoothAdapter::ErrorCallback());
405 adapter_win_->DiscoveryStarted(true); 417 adapter_win_->DiscoveryStarted(true);
406 adapter_win_->StopDiscovering( 418 CallRemoveDiscoverySession(
407 base::Closure(), BluetoothAdapter::ErrorCallback()); 419 base::Closure(), BluetoothAdapter::ErrorCallback());
408 adapter_win_->StartDiscovering( 420 CallAddDiscoverySession(
409 base::Closure(), BluetoothAdapter::ErrorCallback()); 421 base::Closure(), BluetoothAdapter::ErrorCallback());
410 bluetooth_task_runner_->ClearPendingTasks(); 422 bluetooth_task_runner_->ClearPendingTasks();
411 adapter_win_->DiscoveryStopped(); 423 adapter_win_->DiscoveryStopped();
412 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size()); 424 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
413 } 425 }
414 426
415 TEST_F(BluetoothAdapterWinTest, StopDiscoveryWithoutStartDiscovery) { 427 TEST_F(BluetoothAdapterWinTest, StopDiscoveryWithoutStartDiscovery) {
416 adapter_win_->StopDiscovering( 428 CallRemoveDiscoverySession(
417 base::Closure(), 429 base::Closure(),
418 base::Bind( 430 base::Bind(
419 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryErrorCallbacks, 431 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryErrorCallbacks,
420 base::Unretained(this))); 432 base::Unretained(this)));
421 EXPECT_EQ(1, num_stop_discovery_error_callbacks_); 433 EXPECT_EQ(1, num_stop_discovery_error_callbacks_);
422 } 434 }
423 435
424 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStarted) { 436 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStarted) {
425 adapter_win_->StartDiscovering( 437 CallAddDiscoverySession(
426 base::Closure(), BluetoothAdapter::ErrorCallback()); 438 base::Closure(), BluetoothAdapter::ErrorCallback());
427 adapter_win_->StopDiscovering( 439 CallRemoveDiscoverySession(
428 base::Closure(), BluetoothAdapter::ErrorCallback()); 440 base::Closure(), BluetoothAdapter::ErrorCallback());
429 bluetooth_task_runner_->ClearPendingTasks(); 441 bluetooth_task_runner_->ClearPendingTasks();
430 adapter_win_->DiscoveryStarted(true); 442 adapter_win_->DiscoveryStarted(true);
431 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size()); 443 EXPECT_EQ(1, bluetooth_task_runner_->GetPendingTasks().size());
432 } 444 }
433 445
434 TEST_F(BluetoothAdapterWinTest, StartAndStopBeforeDiscoveryStarted) { 446 TEST_F(BluetoothAdapterWinTest, StartAndStopBeforeDiscoveryStarted) {
435 int num_expected_start_discoveries = 3; 447 int num_expected_start_discoveries = 3;
436 int num_expected_stop_discoveries = 2; 448 int num_expected_stop_discoveries = 2;
437 for (int i = 0; i < num_expected_start_discoveries; i++) { 449 for (int i = 0; i < num_expected_start_discoveries; i++) {
438 adapter_win_->StartDiscovering( 450 CallAddDiscoverySession(
439 base::Bind( 451 base::Bind(
440 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, 452 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks,
441 base::Unretained(this)), 453 base::Unretained(this)),
442 BluetoothAdapter::ErrorCallback()); 454 BluetoothAdapter::ErrorCallback());
443 } 455 }
444 for (int i = 0; i < num_expected_stop_discoveries; i++) { 456 for (int i = 0; i < num_expected_stop_discoveries; i++) {
445 adapter_win_->StopDiscovering( 457 CallRemoveDiscoverySession(
446 base::Bind( 458 base::Bind(
447 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 459 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
448 base::Unretained(this)), 460 base::Unretained(this)),
449 BluetoothAdapter::ErrorCallback()); 461 BluetoothAdapter::ErrorCallback());
450 } 462 }
451 bluetooth_task_runner_->ClearPendingTasks(); 463 bluetooth_task_runner_->ClearPendingTasks();
452 adapter_win_->DiscoveryStarted(true); 464 adapter_win_->DiscoveryStarted(true);
453 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); 465 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty());
454 ui_task_runner_->RunPendingTasks(); 466 ui_task_runner_->RunPendingTasks();
455 EXPECT_EQ(num_expected_start_discoveries, num_start_discovery_callbacks_); 467 EXPECT_EQ(num_expected_start_discoveries, num_start_discovery_callbacks_);
456 EXPECT_EQ(num_expected_stop_discoveries, num_stop_discovery_callbacks_); 468 EXPECT_EQ(num_expected_stop_discoveries, num_stop_discovery_callbacks_);
457 } 469 }
458 470
459 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStartedAndFailed) { 471 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStartedAndFailed) {
460 adapter_win_->StartDiscovering( 472 CallAddDiscoverySession(
461 base::Closure(), 473 base::Closure(),
462 base::Bind( 474 base::Bind(
463 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks, 475 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks,
464 base::Unretained(this))); 476 base::Unretained(this)));
465 adapter_win_->StopDiscovering( 477 CallRemoveDiscoverySession(
466 base::Bind( 478 base::Bind(
467 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, 479 &BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks,
468 base::Unretained(this)), 480 base::Unretained(this)),
469 BluetoothAdapter::ErrorCallback()); 481 BluetoothAdapter::ErrorCallback());
470 ui_task_runner_->ClearPendingTasks(); 482 ui_task_runner_->ClearPendingTasks();
471 adapter_win_->DiscoveryStarted(false); 483 adapter_win_->DiscoveryStarted(false);
472 ui_task_runner_->RunPendingTasks(); 484 ui_task_runner_->RunPendingTasks();
473 EXPECT_EQ(1, num_start_discovery_error_callbacks_); 485 EXPECT_EQ(1, num_start_discovery_error_callbacks_);
474 EXPECT_EQ(1, num_stop_discovery_callbacks_); 486 EXPECT_EQ(1, num_stop_discovery_callbacks_);
475 EXPECT_EQ(0, adapter_observer_.num_discovering_changed()); 487 EXPECT_EQ(0, adapter_observer_.num_discovering_changed());
(...skipping 12 matching lines...) Expand all
488 ScopedVector<BluetoothTaskManagerWin::DeviceState> devices; 500 ScopedVector<BluetoothTaskManagerWin::DeviceState> devices;
489 devices.push_back(android_phone_state); 501 devices.push_back(android_phone_state);
490 devices.push_back(laptop_state); 502 devices.push_back(laptop_state);
491 devices.push_back(iphone_state); 503 devices.push_back(iphone_state);
492 504
493 adapter_win_->DevicesDiscovered(devices); 505 adapter_win_->DevicesDiscovered(devices);
494 EXPECT_EQ(3, adapter_observer_.num_device_added()); 506 EXPECT_EQ(3, adapter_observer_.num_device_added());
495 } 507 }
496 508
497 } // namespace device 509 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_unittest.cc ('k') | device/bluetooth/bluetooth_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698