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

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

Issue 1538173003: Implementing GATT connection/disconnect on OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the patch. Created 4 years, 10 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/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/test/test_simple_task_runner.h" 7 #include "base/test/test_simple_task_runner.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
10 #include "device/bluetooth/bluetooth_adapter_mac.h" 10 #include "device/bluetooth/bluetooth_adapter_mac.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return (device != NULL); 109 return (device != NULL);
110 } 110 }
111 111
112 void RemoveTimedOutDevices() { adapter_mac_->RemoveTimedOutDevices(); } 112 void RemoveTimedOutDevices() { adapter_mac_->RemoveTimedOutDevices(); }
113 113
114 bool SetMockCentralManager(CBCentralManagerState desired_state) { 114 bool SetMockCentralManager(CBCentralManagerState desired_state) {
115 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) { 115 if (!BluetoothAdapterMac::IsLowEnergyAvailable()) {
116 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 116 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
117 return false; 117 return false;
118 } 118 }
119 mock_central_manager_ = [[MockCentralManager alloc] init]; 119 mock_central_manager_.reset([[MockCentralManager alloc] init]);
120 [mock_central_manager_ setState:desired_state]; 120 [mock_central_manager_ setState:desired_state];
121 adapter_mac_->SetCentralManagerForTesting(mock_central_manager_); 121 CBCentralManager* centralManager =
122 static_cast<CBCentralManager*>(mock_central_manager_.get());
msarda 2016/02/22 14:01:06 Do not use static_cast for Objective-C objects. Us
jlebel 2016/02/24 16:54:54 It is not possible, this is a mock.
123 adapter_mac_->SetCentralManagerForTesting(centralManager);
122 return true; 124 return true;
123 } 125 }
124 126
125 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) { 127 void AddDiscoverySession(BluetoothDiscoveryFilter* discovery_filter) {
126 adapter_mac_->AddDiscoverySession( 128 adapter_mac_->AddDiscoverySession(
127 discovery_filter, 129 discovery_filter,
128 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)), 130 base::Bind(&BluetoothAdapterMacTest::Callback, base::Unretained(this)),
129 base::Bind(&BluetoothAdapterMacTest::DiscoveryErrorCallback, 131 base::Bind(&BluetoothAdapterMacTest::DiscoveryErrorCallback,
130 base::Unretained(this))); 132 base::Unretained(this)));
131 } 133 }
(...skipping 14 matching lines...) Expand all
146 void DiscoveryErrorCallback(UMABluetoothDiscoverySessionOutcome) { 148 void DiscoveryErrorCallback(UMABluetoothDiscoverySessionOutcome) {
147 ++error_callback_count_; 149 ++error_callback_count_;
148 } 150 }
149 151
150 protected: 152 protected:
151 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_; 153 scoped_refptr<base::TestSimpleTaskRunner> ui_task_runner_;
152 scoped_refptr<BluetoothAdapter> adapter_; 154 scoped_refptr<BluetoothAdapter> adapter_;
153 BluetoothAdapterMac* adapter_mac_; 155 BluetoothAdapterMac* adapter_mac_;
154 156
155 // Owned by |adapter_mac_|. 157 // Owned by |adapter_mac_|.
156 id mock_central_manager_ = NULL; 158 base::scoped_nsobject<MockCentralManager> mock_central_manager_;
157 159
158 int callback_count_; 160 int callback_count_;
159 int error_callback_count_; 161 int error_callback_count_;
160 }; 162 };
161 163
162 TEST_F(BluetoothAdapterMacTest, Poll) { 164 TEST_F(BluetoothAdapterMacTest, Poll) {
163 PollAdapter(); 165 PollAdapter();
164 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty()); 166 EXPECT_FALSE(ui_task_runner_->GetPendingTasks().empty());
165 } 167 }
166 168
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_EQ(1, NumDevices()); 327 EXPECT_EQ(1, NumDevices());
326 EXPECT_TRUE(DevicePresent(mock_peripheral)); 328 EXPECT_TRUE(DevicePresent(mock_peripheral));
327 329
328 // Check that object pointed to by |device| is deleted by the adapter. 330 // Check that object pointed to by |device| is deleted by the adapter.
329 RemoveTimedOutDevices(); 331 RemoveTimedOutDevices();
330 EXPECT_EQ(0, NumDevices()); 332 EXPECT_EQ(0, NumDevices());
331 EXPECT_FALSE(DevicePresent(mock_peripheral)); 333 EXPECT_FALSE(DevicePresent(mock_peripheral));
332 } 334 }
333 335
334 } // namespace device 336 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698