| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/bluetooth_test_win.h" | 5 #include "device/bluetooth/test/bluetooth_test_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/test/test_pending_task.h" | 11 #include "base/test/test_pending_task_info.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "device/bluetooth/bluetooth_adapter_win.h" | 13 #include "device/bluetooth/bluetooth_adapter_win.h" |
| 14 #include "device/bluetooth/bluetooth_low_energy_win.h" | 14 #include "device/bluetooth/bluetooth_low_energy_win.h" |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" | 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h" |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" | 16 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h" |
| 17 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" | 17 #include "device/bluetooth/bluetooth_remote_gatt_service_win.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 BLUETOOTH_ADDRESS CanonicalStringToBLUETOOTH_ADDRESS( | 21 BLUETOOTH_ADDRESS CanonicalStringToBLUETOOTH_ADDRESS( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 win_uuid.Value.LongUuid.Data4[5] = data[8]; | 60 win_uuid.Value.LongUuid.Data4[5] = data[8]; |
| 61 win_uuid.Value.LongUuid.Data4[6] = data[9]; | 61 win_uuid.Value.LongUuid.Data4[6] = data[9]; |
| 62 win_uuid.Value.LongUuid.Data4[7] = data[10]; | 62 win_uuid.Value.LongUuid.Data4[7] = data[10]; |
| 63 } else { | 63 } else { |
| 64 CHECK(false); | 64 CHECK(false); |
| 65 } | 65 } |
| 66 | 66 |
| 67 return win_uuid; | 67 return win_uuid; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // TODO(tzik): Remove this helper once TaskRunner has migrated from Clrosure to |
| 71 // OnceClosure. |
| 72 void RunOnceClosure(base::OnceClosure closure) { |
| 73 std::move(closure).Run(); |
| 74 } |
| 75 |
| 70 } // namespace | 76 } // namespace |
| 71 | 77 |
| 72 namespace device { | 78 namespace device { |
| 73 BluetoothTestWin::BluetoothTestWin() | 79 BluetoothTestWin::BluetoothTestWin() |
| 74 : ui_task_runner_(new base::TestSimpleTaskRunner()), | 80 : ui_task_runner_(new base::TestSimpleTaskRunner()), |
| 75 bluetooth_task_runner_(new base::TestSimpleTaskRunner()), | 81 bluetooth_task_runner_(new base::TestSimpleTaskRunner()), |
| 76 adapter_win_(nullptr), | 82 adapter_win_(nullptr), |
| 77 fake_bt_classic_wrapper_(nullptr), | 83 fake_bt_classic_wrapper_(nullptr), |
| 78 fake_bt_le_wrapper_(nullptr) {} | 84 fake_bt_le_wrapper_(nullptr) {} |
| 79 BluetoothTestWin::~BluetoothTestWin() {} | 85 BluetoothTestWin::~BluetoothTestWin() {} |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return nullptr; | 470 return nullptr; |
| 465 win::GattService* target_service = | 471 win::GattService* target_service = |
| 466 GetSimulatedService(target_device, win_characteristic->GetService()); | 472 GetSimulatedService(target_device, win_characteristic->GetService()); |
| 467 if (target_service == nullptr) | 473 if (target_service == nullptr) |
| 468 return nullptr; | 474 return nullptr; |
| 469 return fake_bt_le_wrapper_->GetSimulatedGattCharacteristic( | 475 return fake_bt_le_wrapper_->GetSimulatedGattCharacteristic( |
| 470 target_service, std::to_string(win_characteristic->GetAttributeHandle())); | 476 target_service, std::to_string(win_characteristic->GetAttributeHandle())); |
| 471 } | 477 } |
| 472 | 478 |
| 473 void BluetoothTestWin::RunPendingTasksUntilCallback() { | 479 void BluetoothTestWin::RunPendingTasksUntilCallback() { |
| 474 std::deque<base::TestPendingTask> tasks = | 480 base::TestPendingTaskQueue tasks = bluetooth_task_runner_->TakePendingTasks(); |
| 475 bluetooth_task_runner_->TakePendingTasks(); | |
| 476 int original_callback_count = callback_count_; | 481 int original_callback_count = callback_count_; |
| 477 int original_error_callback_count = error_callback_count_; | 482 int original_error_callback_count = error_callback_count_; |
| 478 do { | 483 do { |
| 479 base::TestPendingTask task = tasks.front(); | 484 base::OnceClosure task = std::move(tasks.front().second); |
| 480 tasks.pop_front(); | 485 tasks.pop_front(); |
| 481 task.task.Run(); | 486 std::move(task).Run(); |
| 482 base::RunLoop().RunUntilIdle(); | 487 base::RunLoop().RunUntilIdle(); |
| 483 } while (tasks.size() && callback_count_ == original_callback_count && | 488 } while (tasks.size() && callback_count_ == original_callback_count && |
| 484 error_callback_count_ == original_error_callback_count); | 489 error_callback_count_ == original_error_callback_count); |
| 485 | 490 |
| 486 // Put the rest of pending tasks back to Bluetooth task runner. | 491 // Put the rest of pending tasks back to Bluetooth task runner. |
| 487 for (const auto& task : tasks) { | 492 for (auto& pending_task : tasks) { |
| 488 if (task.delay.is_zero()) { | 493 const base::TestPendingTaskInfo& task_info = pending_task.first; |
| 489 bluetooth_task_runner_->PostTask(task.location, task.task); | 494 base::Closure task = |
| 495 base::Bind(&RunOnceClosure, base::Passed(&pending_task.second)); |
| 496 if (task_info.delay.is_zero()) { |
| 497 bluetooth_task_runner_->PostTask(task_info.location, task); |
| 490 } else { | 498 } else { |
| 491 bluetooth_task_runner_->PostDelayedTask(task.location, task.task, | 499 bluetooth_task_runner_->PostDelayedTask(task_info.location, task, |
| 492 task.delay); | 500 task_info.delay); |
| 493 } | 501 } |
| 494 } | 502 } |
| 495 } | 503 } |
| 496 | 504 |
| 497 void BluetoothTestWin::ForceRefreshDevice() { | 505 void BluetoothTestWin::ForceRefreshDevice() { |
| 498 adapter_win_->force_update_device_for_test_ = true; | 506 adapter_win_->force_update_device_for_test_ = true; |
| 499 FinishPendingTasks(); | 507 FinishPendingTasks(); |
| 500 } | 508 } |
| 501 | 509 |
| 502 void BluetoothTestWin::FinishPendingTasks() { | 510 void BluetoothTestWin::FinishPendingTasks() { |
| 503 bluetooth_task_runner_->RunPendingTasks(); | 511 bluetooth_task_runner_->RunPendingTasks(); |
| 504 base::RunLoop().RunUntilIdle(); | 512 base::RunLoop().RunUntilIdle(); |
| 505 } | 513 } |
| 506 } | 514 } |
| OLD | NEW |