OLD | NEW |
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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 bluetooth_task_runner_->ClearPendingTasks(); | 242 bluetooth_task_runner_->ClearPendingTasks(); |
243 for (int i = 0; i < 5; i++) { | 243 for (int i = 0; i < 5; i++) { |
244 int num_start_discovery_callbacks = num_start_discovery_callbacks_; | 244 int num_start_discovery_callbacks = num_start_discovery_callbacks_; |
245 CallAddDiscoverySession( | 245 CallAddDiscoverySession( |
246 base::Bind( | 246 base::Bind( |
247 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, | 247 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, |
248 base::Unretained(this)), | 248 base::Unretained(this)), |
249 DiscoverySessionErrorCallback()); | 249 DiscoverySessionErrorCallback()); |
250 EXPECT_TRUE(adapter_->IsDiscovering()); | 250 EXPECT_TRUE(adapter_->IsDiscovering()); |
251 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); | 251 EXPECT_FALSE(bluetooth_task_runner_->HasPendingTask()); |
252 EXPECT_FALSE(ui_task_runner_->HasPendingTask()); | 252 EXPECT_FALSE(ui_task_runner_->HasPendingTask()); |
253 EXPECT_EQ(num_start_discovery_callbacks + 1, | 253 EXPECT_EQ(num_start_discovery_callbacks + 1, |
254 num_start_discovery_callbacks_); | 254 num_start_discovery_callbacks_); |
255 } | 255 } |
256 EXPECT_EQ(1, observer_.discovering_changed_count()); | 256 EXPECT_EQ(1, observer_.discovering_changed_count()); |
257 } | 257 } |
258 | 258 |
259 TEST_F(BluetoothAdapterWinTest, StartDiscoveryAfterDiscoveringFailure) { | 259 TEST_F(BluetoothAdapterWinTest, StartDiscoveryAfterDiscoveringFailure) { |
260 CallAddDiscoverySession( | 260 CallAddDiscoverySession( |
261 base::Closure(), | 261 base::Closure(), |
(...skipping 23 matching lines...) Expand all Loading... |
285 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, | 285 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, |
286 base::Unretained(this)), | 286 base::Unretained(this)), |
287 DiscoverySessionErrorCallback()); | 287 DiscoverySessionErrorCallback()); |
288 EXPECT_TRUE(adapter_->IsDiscovering()); | 288 EXPECT_TRUE(adapter_->IsDiscovering()); |
289 EXPECT_EQ(0, num_stop_discovery_callbacks_); | 289 EXPECT_EQ(0, num_stop_discovery_callbacks_); |
290 bluetooth_task_runner_->ClearPendingTasks(); | 290 bluetooth_task_runner_->ClearPendingTasks(); |
291 adapter_win_->DiscoveryStopped(); | 291 adapter_win_->DiscoveryStopped(); |
292 ui_task_runner_->RunPendingTasks(); | 292 ui_task_runner_->RunPendingTasks(); |
293 EXPECT_FALSE(adapter_->IsDiscovering()); | 293 EXPECT_FALSE(adapter_->IsDiscovering()); |
294 EXPECT_EQ(1, num_stop_discovery_callbacks_); | 294 EXPECT_EQ(1, num_stop_discovery_callbacks_); |
295 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); | 295 EXPECT_FALSE(bluetooth_task_runner_->HasPendingTask()); |
296 EXPECT_EQ(2, observer_.discovering_changed_count()); | 296 EXPECT_EQ(2, observer_.discovering_changed_count()); |
297 } | 297 } |
298 | 298 |
299 TEST_F(BluetoothAdapterWinTest, MultipleStopDiscoveries) { | 299 TEST_F(BluetoothAdapterWinTest, MultipleStopDiscoveries) { |
300 int num_discoveries = 5; | 300 int num_discoveries = 5; |
301 for (int i = 0; i < num_discoveries; i++) { | 301 for (int i = 0; i < num_discoveries; i++) { |
302 CallAddDiscoverySession(base::Closure(), DiscoverySessionErrorCallback()); | 302 CallAddDiscoverySession(base::Closure(), DiscoverySessionErrorCallback()); |
303 } | 303 } |
304 adapter_win_->DiscoveryStarted(true); | 304 adapter_win_->DiscoveryStarted(true); |
305 ui_task_runner_->ClearPendingTasks(); | 305 ui_task_runner_->ClearPendingTasks(); |
306 bluetooth_task_runner_->ClearPendingTasks(); | 306 bluetooth_task_runner_->ClearPendingTasks(); |
307 for (int i = 0; i < num_discoveries - 1; i++) { | 307 for (int i = 0; i < num_discoveries - 1; i++) { |
308 CallRemoveDiscoverySession( | 308 CallRemoveDiscoverySession( |
309 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, | 309 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, |
310 base::Unretained(this)), | 310 base::Unretained(this)), |
311 DiscoverySessionErrorCallback()); | 311 DiscoverySessionErrorCallback()); |
312 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); | 312 EXPECT_FALSE(bluetooth_task_runner_->HasPendingTask()); |
313 ui_task_runner_->RunPendingTasks(); | 313 ui_task_runner_->RunPendingTasks(); |
314 EXPECT_EQ(i + 1, num_stop_discovery_callbacks_); | 314 EXPECT_EQ(i + 1, num_stop_discovery_callbacks_); |
315 } | 315 } |
316 CallRemoveDiscoverySession( | 316 CallRemoveDiscoverySession( |
317 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, | 317 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, |
318 base::Unretained(this)), | 318 base::Unretained(this)), |
319 DiscoverySessionErrorCallback()); | 319 DiscoverySessionErrorCallback()); |
320 EXPECT_EQ(1u, bluetooth_task_runner_->NumPendingTasks()); | 320 EXPECT_EQ(1u, bluetooth_task_runner_->NumPendingTasks()); |
321 EXPECT_TRUE(adapter_->IsDiscovering()); | 321 EXPECT_TRUE(adapter_->IsDiscovering()); |
322 adapter_win_->DiscoveryStopped(); | 322 adapter_win_->DiscoveryStopped(); |
(...skipping 13 matching lines...) Expand all Loading... |
336 CallAddDiscoverySession( | 336 CallAddDiscoverySession( |
337 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, | 337 base::Bind(&BluetoothAdapterWinTest::IncrementNumStartDiscoveryCallbacks, |
338 base::Unretained(this)), | 338 base::Unretained(this)), |
339 DiscoverySessionErrorCallback()); | 339 DiscoverySessionErrorCallback()); |
340 ui_task_runner_->ClearPendingTasks(); | 340 ui_task_runner_->ClearPendingTasks(); |
341 bluetooth_task_runner_->ClearPendingTasks(); | 341 bluetooth_task_runner_->ClearPendingTasks(); |
342 CallRemoveDiscoverySession( | 342 CallRemoveDiscoverySession( |
343 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, | 343 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, |
344 base::Unretained(this)), | 344 base::Unretained(this)), |
345 DiscoverySessionErrorCallback()); | 345 DiscoverySessionErrorCallback()); |
346 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); | 346 EXPECT_FALSE(bluetooth_task_runner_->HasPendingTask()); |
347 CallRemoveDiscoverySession( | 347 CallRemoveDiscoverySession( |
348 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, | 348 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, |
349 base::Unretained(this)), | 349 base::Unretained(this)), |
350 DiscoverySessionErrorCallback()); | 350 DiscoverySessionErrorCallback()); |
351 EXPECT_EQ(1u, bluetooth_task_runner_->NumPendingTasks()); | 351 EXPECT_EQ(1u, bluetooth_task_runner_->NumPendingTasks()); |
352 } | 352 } |
353 | 353 |
354 TEST_F(BluetoothAdapterWinTest, | 354 TEST_F(BluetoothAdapterWinTest, |
355 StartDiscoveryAndStopDiscoveryAndStartDiscovery) { | 355 StartDiscoveryAndStopDiscoveryAndStartDiscovery) { |
356 CallAddDiscoverySession(base::Closure(), DiscoverySessionErrorCallback()); | 356 CallAddDiscoverySession(base::Closure(), DiscoverySessionErrorCallback()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 DiscoverySessionErrorCallback()); | 402 DiscoverySessionErrorCallback()); |
403 } | 403 } |
404 for (int i = 0; i < num_expected_stop_discoveries; i++) { | 404 for (int i = 0; i < num_expected_stop_discoveries; i++) { |
405 CallRemoveDiscoverySession( | 405 CallRemoveDiscoverySession( |
406 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, | 406 base::Bind(&BluetoothAdapterWinTest::IncrementNumStopDiscoveryCallbacks, |
407 base::Unretained(this)), | 407 base::Unretained(this)), |
408 DiscoverySessionErrorCallback()); | 408 DiscoverySessionErrorCallback()); |
409 } | 409 } |
410 bluetooth_task_runner_->ClearPendingTasks(); | 410 bluetooth_task_runner_->ClearPendingTasks(); |
411 adapter_win_->DiscoveryStarted(true); | 411 adapter_win_->DiscoveryStarted(true); |
412 EXPECT_TRUE(bluetooth_task_runner_->GetPendingTasks().empty()); | 412 EXPECT_FALSE(bluetooth_task_runner_->HasPendingTask()); |
413 ui_task_runner_->RunPendingTasks(); | 413 ui_task_runner_->RunPendingTasks(); |
414 EXPECT_EQ(num_expected_start_discoveries, num_start_discovery_callbacks_); | 414 EXPECT_EQ(num_expected_start_discoveries, num_start_discovery_callbacks_); |
415 EXPECT_EQ(num_expected_stop_discoveries, num_stop_discovery_callbacks_); | 415 EXPECT_EQ(num_expected_stop_discoveries, num_stop_discovery_callbacks_); |
416 } | 416 } |
417 | 417 |
418 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStartedAndFailed) { | 418 TEST_F(BluetoothAdapterWinTest, StopDiscoveryBeforeDiscoveryStartedAndFailed) { |
419 CallAddDiscoverySession( | 419 CallAddDiscoverySession( |
420 base::Closure(), | 420 base::Closure(), |
421 base::Bind( | 421 base::Bind( |
422 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks, | 422 &BluetoothAdapterWinTest::IncrementNumStartDiscoveryErrorCallbacks, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 // Remove a service | 502 // Remove a service |
503 laptop_state->service_record_states.clear(); | 503 laptop_state->service_record_states.clear(); |
504 observer_.Reset(); | 504 observer_.Reset(); |
505 adapter_win_->DevicesPolled(devices); | 505 adapter_win_->DevicesPolled(devices); |
506 EXPECT_EQ(0, observer_.device_added_count()); | 506 EXPECT_EQ(0, observer_.device_added_count()); |
507 EXPECT_EQ(0, observer_.device_removed_count()); | 507 EXPECT_EQ(0, observer_.device_removed_count()); |
508 EXPECT_EQ(1, observer_.device_changed_count()); | 508 EXPECT_EQ(1, observer_.device_changed_count()); |
509 } | 509 } |
510 | 510 |
511 } // namespace device | 511 } // namespace device |
OLD | NEW |