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

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

Issue 1228863002: Runtime checks so that CoreBluetooth only used on >= 10.10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timeinfo
Patch Set: not compiling Created 5 years, 5 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 "base/mac/mac_util.h"
5 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
6 #include "base/test/test_simple_task_runner.h" 7 #include "base/test/test_simple_task_runner.h"
7 #include "device/bluetooth/bluetooth_adapter.h" 8 #include "device/bluetooth/bluetooth_adapter.h"
8 #include "device/bluetooth/bluetooth_adapter_mac.h" 9 #include "device/bluetooth/bluetooth_adapter_mac.h"
9 #include "device/bluetooth/bluetooth_discovery_session.h" 10 #include "device/bluetooth/bluetooth_discovery_session.h"
10 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h" 11 #include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace device { 14 namespace device {
14 15
15 class BluetoothAdapterMacTest : public testing::Test { 16 class BluetoothAdapterMacTest : public testing::Test {
16 public: 17 public:
17 BluetoothAdapterMacTest() 18 BluetoothAdapterMacTest()
18 : ui_task_runner_(new base::TestSimpleTaskRunner()), 19 : ui_task_runner_(new base::TestSimpleTaskRunner()),
19 adapter_(new BluetoothAdapterMac()), 20 adapter_(new BluetoothAdapterMac()),
20 adapter_mac_(static_cast<BluetoothAdapterMac*>(adapter_.get())), 21 adapter_mac_(static_cast<BluetoothAdapterMac*>(adapter_.get())),
21 callback_count_(0), 22 callback_count_(0),
22 error_callback_count_(0) { 23 error_callback_count_(0) {
23 adapter_mac_->InitForTest(ui_task_runner_); 24 adapter_mac_->InitForTest(ui_task_runner_);
24 } 25 }
25 26
26 // Helper methods for setup and access to BluetoothAdapterMacTest's members. 27 // Helper methods for setup and access to BluetoothAdapterMacTest's members.
27 bool SetMockCentralManager() { 28 bool SetMockCentralManager() {
28 Class aClass = NSClassFromString(@"CBCentralManager"); 29 if (!base::mac::IsOSYosemiteOrLater()) {
29 if (aClass == nil) { 30 // For stability we only use CoreBluetooth on OS X >= 10.10. Thus on
30 LOG(WARNING) << "CoreBluetooth not available, skipping unit test."; 31 // previous OS X versions the code cannot be tested.
32 LOG(WARNING) << "OS X version < 10.10, skipping unit test.";
31 return false; 33 return false;
32 } 34 }
33 mock_central_manager_ = [[MockCentralManager alloc] init]; 35 mock_central_manager_ = [[MockCentralManager alloc] init];
34 adapter_mac_->low_energy_discovery_manager_->SetManagerForTesting( 36 adapter_mac_->low_energy_discovery_manager_->SetManagerForTesting(
35 mock_central_manager_); 37 mock_central_manager_);
36 return true; 38 return true;
37 } 39 }
38 40
39 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { 41 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) {
40 adapter_mac_->AddDiscoverySession( 42 adapter_mac_->AddDiscoverySession(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 RemoveDiscoverySession(discovery_filter.get()); 156 RemoveDiscoverySession(discovery_filter.get());
155 EXPECT_EQ(0, callback_count_); 157 EXPECT_EQ(0, callback_count_);
156 EXPECT_EQ(1, error_callback_count_); 158 EXPECT_EQ(1, error_callback_count_);
157 EXPECT_EQ(0, NumDiscoverySessions()); 159 EXPECT_EQ(0, NumDiscoverySessions());
158 160
159 // Check that stopScan was not called. 161 // Check that stopScan was not called.
160 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]); 162 EXPECT_EQ(0, [mock_central_manager_ stopScanCallCount]);
161 } 163 }
162 164
163 } // namespace device 165 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698