Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/test/test_simple_task_runner.h" | 6 #include "base/test/test_simple_task_runner.h" |
| 7 #include "device/bluetooth/bluetooth_adapter.h" | 7 #include "device/bluetooth/bluetooth_adapter.h" |
| 8 #include "device/bluetooth/bluetooth_adapter_mac.h" | 8 #include "device/bluetooth/bluetooth_adapter_mac.h" |
| 9 #include "device/bluetooth/bluetooth_discovery_session.h" | 9 #include "device/bluetooth/bluetooth_discovery_session.h" |
| 10 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" | 10 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace device { | 13 namespace device { |
| 14 | 14 |
| 15 class BluetoothAdapterMacTest : public testing::Test { | 15 class BluetoothAdapterMacTest : public testing::Test { |
| 16 public: | 16 public: |
| 17 BluetoothAdapterMacTest() | 17 BluetoothAdapterMacTest() |
| 18 : ui_task_runner_(new base::TestSimpleTaskRunner()), | 18 : ui_task_runner_(new base::TestSimpleTaskRunner()), |
| 19 adapter_(new BluetoothAdapterMac()), | 19 adapter_(new BluetoothAdapterMac()), |
| 20 adapter_mac_(static_cast<BluetoothAdapterMac*>(adapter_.get())), | 20 adapter_mac_(static_cast<BluetoothAdapterMac*>(adapter_.get())), |
| 21 callback_count_(0), | 21 callback_count_(0), |
| 22 error_callback_count_(0) { | 22 error_callback_count_(0) { |
| 23 adapter_mac_->InitForTest(ui_task_runner_); | 23 adapter_mac_->InitForTest(ui_task_runner_); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Helper methods for setup and access to BluetoothAdapterMacTest's members. | 26 // Helper methods for setup and access to BluetoothAdapterMacTest's members. |
| 27 bool SetMockCentralManager() { | 27 bool SetMockCentralManager() { |
| 28 Class aClass = NSClassFromString(@"CBCentralManager"); | 28 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { |
| 29 if (aClass == nil) { | 29 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 30 LOG(WARNING) << "CoreBluetooth not available, skipping unit test."; | |
| 31 return false; | 30 return false; |
| 32 } | 31 } |
| 33 mock_central_manager_ = [[MockCentralManager alloc] init]; | 32 mock_central_manager_ = [[MockCentralManager alloc] init]; |
|
armansito
2015/07/15 18:04:59
This is unrelated to this CL but you can replace a
krstnmnlsn
2015/07/15 19:36:09
Yeah, I've heard of that, thought there was a slig
| |
| 34 adapter_mac_->low_energy_discovery_manager_->SetManagerForTesting( | 33 adapter_mac_->low_energy_discovery_manager_->SetManagerForTesting( |
| 35 mock_central_manager_); | 34 mock_central_manager_); |
| 36 return true; | 35 return true; |
| 37 } | 36 } |
| 38 | 37 |
| 39 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { | 38 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { |
| 40 adapter_mac_->AddDiscoverySession( | 39 adapter_mac_->AddDiscoverySession( |
| 41 discovery_filter, | 40 discovery_filter, |
| 42 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), | 41 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), |
| 43 base::Bind(&BluetoothAdapterMacTest::ErrorCallback, | 42 base::Bind(&BluetoothAdapterMacTest::ErrorCallback, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 RemoveDiscoverySession(discovery_filter.get()); | 153 RemoveDiscoverySession(discovery_filter.get()); |
| 155 EXPECT_EQ(0, callback_count_); | 154 EXPECT_EQ(0, callback_count_); |
| 156 EXPECT_EQ(1, error_callback_count_); | 155 EXPECT_EQ(1, error_callback_count_); |
| 157 EXPECT_EQ(0, NumDiscoverySessions()); | 156 EXPECT_EQ(0, NumDiscoverySessions()); |
| 158 | 157 |
| 159 // Check that stopScan was not called. | 158 // Check that stopScan was not called. |
| 160 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); | 159 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); |
| 161 } | 160 } |
| 162 | 161 |
| 163 } // namespace device | 162 } // namespace device |
| OLD | NEW |