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.h> | 5 #include <string.h> |
6 | 6 |
7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" |
9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" | 9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" |
10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | 10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 true /* paired */, false /* bonded */, true /* connected */)); | 39 true /* paired */, false /* bonded */, true /* connected */)); |
40 device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( | 40 device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( |
41 mock_adapter_, "d2", "21:22:23:24:25:26", | 41 mock_adapter_, "d2", "21:22:23:24:25:26", |
42 false /* paired */, true /* bonded */, false /* connected */)); | 42 false /* paired */, true /* bonded */, false /* connected */)); |
43 } | 43 } |
44 | 44 |
45 void expectBooleanResult(bool expected, | 45 void expectBooleanResult(bool expected, |
46 UIThreadExtensionFunction* function, | 46 UIThreadExtensionFunction* function, |
47 const std::string& args) { | 47 const std::string& args) { |
48 scoped_ptr<base::Value> result( | 48 scoped_ptr<base::Value> result( |
49 utils::RunFunctionAndReturnResult(function, args, browser())); | 49 utils::RunFunctionAndReturnSingleResult(function, args, browser())); |
50 ASSERT_TRUE(result.get() != NULL); | 50 ASSERT_TRUE(result.get() != NULL); |
51 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); | 51 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); |
52 bool boolean_value; | 52 bool boolean_value; |
53 result->GetAsBoolean(&boolean_value); | 53 result->GetAsBoolean(&boolean_value); |
54 EXPECT_EQ(expected, boolean_value); | 54 EXPECT_EQ(expected, boolean_value); |
55 } | 55 } |
56 | 56 |
57 template <class T> | 57 template <class T> |
58 T* setupFunction(T* function) { | 58 T* setupFunction(T* function) { |
59 function->set_extension(empty_extension_.get()); | 59 function->set_extension(empty_extension_.get()); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 .WillOnce(testing::Return(false)); | 144 .WillOnce(testing::Return(false)); |
145 EXPECT_CALL(*device2_, ProvidesServiceWithUUID("foo")) | 145 EXPECT_CALL(*device2_, ProvidesServiceWithUUID("foo")) |
146 .WillOnce(testing::Return(true)); | 146 .WillOnce(testing::Return(true)); |
147 | 147 |
148 EXPECT_CALL(*mock_adapter_, GetDevices()) | 148 EXPECT_CALL(*mock_adapter_, GetDevices()) |
149 .WillOnce(testing::Return(devices)); | 149 .WillOnce(testing::Return(devices)); |
150 | 150 |
151 scoped_refptr<api::BluetoothGetDevicesFunction> get_devices; | 151 scoped_refptr<api::BluetoothGetDevicesFunction> get_devices; |
152 | 152 |
153 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); | 153 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); |
154 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnResult( | 154 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
155 get_devices, | 155 get_devices, |
156 "[{\"uuid\":\"foo\"}]", | 156 "[{\"uuid\":\"foo\"}]", |
157 browser())); | 157 browser())); |
158 | 158 |
159 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); | 159 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); |
160 base::ListValue* list; | 160 base::ListValue* list; |
161 ASSERT_TRUE(result->GetAsList(&list)); | 161 ASSERT_TRUE(result->GetAsList(&list)); |
162 | 162 |
163 EXPECT_EQ(1u, list->GetSize()); | 163 EXPECT_EQ(1u, list->GetSize()); |
164 base::Value* device_value; | 164 base::Value* device_value; |
(...skipping 18 matching lines...) Expand all Loading... |
183 ASSERT_TRUE(device->GetBoolean("connected", &connected)); | 183 ASSERT_TRUE(device->GetBoolean("connected", &connected)); |
184 EXPECT_FALSE(connected); | 184 EXPECT_FALSE(connected); |
185 | 185 |
186 // Try again with no options | 186 // Try again with no options |
187 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 187 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
188 EXPECT_CALL(*mock_adapter_, GetDevices()) | 188 EXPECT_CALL(*mock_adapter_, GetDevices()) |
189 .WillOnce(testing::Return(devices)); | 189 .WillOnce(testing::Return(devices)); |
190 | 190 |
191 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); | 191 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); |
192 result.reset( | 192 result.reset( |
193 utils::RunFunctionAndReturnResult(get_devices, "[{}]", browser())); | 193 utils::RunFunctionAndReturnSingleResult(get_devices, "[{}]", browser())); |
194 | 194 |
195 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); | 195 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); |
196 ASSERT_TRUE(result->GetAsList(&list)); | 196 ASSERT_TRUE(result->GetAsList(&list)); |
197 | 197 |
198 EXPECT_EQ(2u, list->GetSize()); | 198 EXPECT_EQ(2u, list->GetSize()); |
199 } | 199 } |
200 | 200 |
201 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) { | 201 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) { |
202 EXPECT_CALL(*mock_adapter_, | 202 EXPECT_CALL(*mock_adapter_, |
203 ReadLocalOutOfBandPairingData( | 203 ReadLocalOutOfBandPairingData( |
204 testing::Truly(CallOutOfBandPairingDataCallback), | 204 testing::Truly(CallOutOfBandPairingDataCallback), |
205 testing::_)); | 205 testing::_)); |
206 | 206 |
207 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction> | 207 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction> |
208 get_oob_function(setupFunction( | 208 get_oob_function(setupFunction( |
209 new api::BluetoothGetLocalOutOfBandPairingDataFunction)); | 209 new api::BluetoothGetLocalOutOfBandPairingDataFunction)); |
210 | 210 |
211 scoped_ptr<base::Value> result( | 211 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( |
212 utils::RunFunctionAndReturnResult(get_oob_function, "[]", browser())); | 212 get_oob_function, "[]", browser())); |
213 | 213 |
214 base::DictionaryValue* dict; | 214 base::DictionaryValue* dict; |
215 EXPECT_TRUE(result->GetAsDictionary(&dict)); | 215 EXPECT_TRUE(result->GetAsDictionary(&dict)); |
216 | 216 |
217 base::BinaryValue* binary_value; | 217 base::BinaryValue* binary_value; |
218 EXPECT_TRUE(dict->GetBinary("hash", &binary_value)); | 218 EXPECT_TRUE(dict->GetBinary("hash", &binary_value)); |
219 EXPECT_STREQ(kOutOfBandPairingDataHash, | 219 EXPECT_STREQ(kOutOfBandPairingDataHash, |
220 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str()); | 220 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str()); |
221 EXPECT_TRUE(dict->GetBinary("randomizer", &binary_value)); | 221 EXPECT_TRUE(dict->GetBinary("randomizer", &binary_value)); |
222 EXPECT_STREQ(kOutOfBandPairingDataRandomizer, | 222 EXPECT_STREQ(kOutOfBandPairingDataRandomizer, |
(...skipping 24 matching lines...) Expand all Loading... |
247 | 247 |
248 char buf[64]; | 248 char buf[64]; |
249 snprintf(buf, sizeof(buf), | 249 snprintf(buf, sizeof(buf), |
250 "[{\"deviceAddress\":\"%s\"}]", device_address.c_str()); | 250 "[{\"deviceAddress\":\"%s\"}]", device_address.c_str()); |
251 std::string params(buf); | 251 std::string params(buf); |
252 | 252 |
253 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function; | 253 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function; |
254 set_oob_function = setupFunction( | 254 set_oob_function = setupFunction( |
255 new api::BluetoothSetOutOfBandPairingDataFunction); | 255 new api::BluetoothSetOutOfBandPairingDataFunction); |
256 // There isn't actually a result. | 256 // There isn't actually a result. |
257 (void)utils::RunFunctionAndReturnResult(set_oob_function, params, browser()); | 257 (void)utils::RunFunctionAndReturnSingleResult( |
| 258 set_oob_function, params, browser()); |
258 | 259 |
259 // Try again with an error | 260 // Try again with an error |
260 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 261 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
261 testing::Mock::VerifyAndClearExpectations(device1_.get()); | 262 testing::Mock::VerifyAndClearExpectations(device1_.get()); |
262 EXPECT_CALL(*mock_adapter_, GetDevice(device_address)) | 263 EXPECT_CALL(*mock_adapter_, GetDevice(device_address)) |
263 .WillOnce(testing::Return(device1_.get())); | 264 .WillOnce(testing::Return(device1_.get())); |
264 EXPECT_CALL(*device1_, | 265 EXPECT_CALL(*device1_, |
265 ClearOutOfBandPairingData(testing::_, | 266 ClearOutOfBandPairingData(testing::_, |
266 testing::Truly(CallClosure))); | 267 testing::Truly(CallClosure))); |
267 | 268 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); | 300 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); |
300 | 301 |
301 // Reset to try stopping | 302 // Reset to try stopping |
302 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 303 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
303 EXPECT_CALL(*mock_adapter_, | 304 EXPECT_CALL(*mock_adapter_, |
304 SetDiscovering(false, | 305 SetDiscovering(false, |
305 testing::Truly(CallClosure), | 306 testing::Truly(CallClosure), |
306 testing::_)); | 307 testing::_)); |
307 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function; | 308 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function; |
308 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); | 309 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); |
309 (void)utils::RunFunctionAndReturnResult(stop_function, "[]", browser()); | 310 (void)utils::RunFunctionAndReturnSingleResult(stop_function, "[]", browser()); |
310 | 311 |
311 // Reset to try stopping with an error | 312 // Reset to try stopping with an error |
312 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 313 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
313 EXPECT_CALL(*mock_adapter_, | 314 EXPECT_CALL(*mock_adapter_, |
314 SetDiscovering(false, | 315 SetDiscovering(false, |
315 testing::_, | 316 testing::_, |
316 testing::Truly(CallClosure))); | 317 testing::Truly(CallClosure))); |
317 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); | 318 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); |
318 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); | 319 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); |
319 ASSERT_TRUE(!error.empty()); | 320 ASSERT_TRUE(!error.empty()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 362 |
362 event_router()->AdapterPoweredChanged(mock_adapter_, true); | 363 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
363 event_router()->AdapterPoweredChanged(mock_adapter_, false); | 364 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
364 event_router()->AdapterPresentChanged(mock_adapter_, true); | 365 event_router()->AdapterPresentChanged(mock_adapter_, true); |
365 event_router()->AdapterPresentChanged(mock_adapter_, false); | 366 event_router()->AdapterPresentChanged(mock_adapter_, false); |
366 | 367 |
367 listener.Reply("go"); | 368 listener.Reply("go"); |
368 | 369 |
369 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 370 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
370 } | 371 } |
OLD | NEW |