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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc

Issue 10694106: Added support for multiple parameters to Extension API callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review fixes. Created 8 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 (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 20 matching lines...) Expand all
31 virtual void SetUpOnMainThread() OVERRIDE { 31 virtual void SetUpOnMainThread() OVERRIDE {
32 // The browser will clean this up when it is torn down 32 // The browser will clean this up when it is torn down
33 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>; 33 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>;
34 event_router()->SetAdapterForTest(mock_adapter_); 34 event_router()->SetAdapterForTest(mock_adapter_);
35 } 35 }
36 36
37 void expectBooleanResult(bool expected, 37 void expectBooleanResult(bool expected,
38 UIThreadExtensionFunction* function, 38 UIThreadExtensionFunction* function,
39 const std::string& args) { 39 const std::string& args) {
40 scoped_ptr<base::Value> result( 40 scoped_ptr<base::Value> result(
41 utils::RunFunctionAndReturnResult(function, args, browser())); 41 utils::RunFunctionAndReturnSingleResult(function, args, browser()));
42 ASSERT_TRUE(result.get() != NULL); 42 ASSERT_TRUE(result.get() != NULL);
43 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 43 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
44 bool boolean_value; 44 bool boolean_value;
45 result->GetAsBoolean(&boolean_value); 45 result->GetAsBoolean(&boolean_value);
46 EXPECT_EQ(expected, boolean_value); 46 EXPECT_EQ(expected, boolean_value);
47 } 47 }
48 48
49 template <class T> 49 template <class T>
50 T* setupFunction(T* function) { 50 T* setupFunction(T* function) {
51 function->set_extension(empty_extension_.get()); 51 function->set_extension(empty_extension_.get());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 .WillOnce(testing::Return(false)); 140 .WillOnce(testing::Return(false));
141 EXPECT_CALL(device2, ProvidesServiceWithUUID("foo")) 141 EXPECT_CALL(device2, ProvidesServiceWithUUID("foo"))
142 .WillOnce(testing::Return(true)); 142 .WillOnce(testing::Return(true));
143 143
144 EXPECT_CALL(*mock_adapter_, GetDevices()) 144 EXPECT_CALL(*mock_adapter_, GetDevices())
145 .WillOnce(testing::Return(devices)); 145 .WillOnce(testing::Return(devices));
146 146
147 scoped_refptr<api::BluetoothGetDevicesFunction> get_devices; 147 scoped_refptr<api::BluetoothGetDevicesFunction> get_devices;
148 148
149 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); 149 get_devices = setupFunction(new api::BluetoothGetDevicesFunction);
150 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnResult( 150 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
151 get_devices, 151 get_devices,
152 "[{\"uuid\":\"foo\"}]", 152 "[{\"uuid\":\"foo\"}]",
153 browser())); 153 browser()));
154 154
155 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); 155 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType());
156 base::ListValue* list; 156 base::ListValue* list;
157 ASSERT_TRUE(result->GetAsList(&list)); 157 ASSERT_TRUE(result->GetAsList(&list));
158 158
159 EXPECT_EQ(1u, list->GetSize()); 159 EXPECT_EQ(1u, list->GetSize());
160 base::Value* device_value; 160 base::Value* device_value;
(...skipping 18 matching lines...) Expand all
179 ASSERT_TRUE(device->GetBoolean("connected", &connected)); 179 ASSERT_TRUE(device->GetBoolean("connected", &connected));
180 EXPECT_FALSE(connected); 180 EXPECT_FALSE(connected);
181 181
182 // Try again with no options 182 // Try again with no options
183 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 183 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
184 EXPECT_CALL(*mock_adapter_, GetDevices()) 184 EXPECT_CALL(*mock_adapter_, GetDevices())
185 .WillOnce(testing::Return(devices)); 185 .WillOnce(testing::Return(devices));
186 186
187 get_devices = setupFunction(new api::BluetoothGetDevicesFunction); 187 get_devices = setupFunction(new api::BluetoothGetDevicesFunction);
188 result.reset( 188 result.reset(
189 utils::RunFunctionAndReturnResult(get_devices, "[{}]", browser())); 189 utils::RunFunctionAndReturnSingleResult(get_devices, "[{}]", browser()));
190 190
191 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType()); 191 ASSERT_EQ(base::Value::TYPE_LIST, result->GetType());
192 ASSERT_TRUE(result->GetAsList(&list)); 192 ASSERT_TRUE(result->GetAsList(&list));
193 193
194 EXPECT_EQ(2u, list->GetSize()); 194 EXPECT_EQ(2u, list->GetSize());
195 } 195 }
196 196
197 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) { 197 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) {
198 EXPECT_CALL(*mock_adapter_, 198 EXPECT_CALL(*mock_adapter_,
199 ReadLocalOutOfBandPairingData( 199 ReadLocalOutOfBandPairingData(
200 testing::Truly(CallOutOfBandPairingDataCallback), 200 testing::Truly(CallOutOfBandPairingDataCallback),
201 testing::_)); 201 testing::_));
202 202
203 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction> 203 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction>
204 get_oob_function(setupFunction( 204 get_oob_function(setupFunction(
205 new api::BluetoothGetLocalOutOfBandPairingDataFunction)); 205 new api::BluetoothGetLocalOutOfBandPairingDataFunction));
206 206
207 scoped_ptr<base::Value> result( 207 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
208 utils::RunFunctionAndReturnResult(get_oob_function, "[]", browser())); 208 get_oob_function, "[]", browser()));
209 209
210 base::DictionaryValue* dict; 210 base::DictionaryValue* dict;
211 EXPECT_TRUE(result->GetAsDictionary(&dict)); 211 EXPECT_TRUE(result->GetAsDictionary(&dict));
212 212
213 base::BinaryValue* binary_value; 213 base::BinaryValue* binary_value;
214 EXPECT_TRUE(dict->GetBinary("hash", &binary_value)); 214 EXPECT_TRUE(dict->GetBinary("hash", &binary_value));
215 EXPECT_STREQ(kOutOfBandPairingDataHash, 215 EXPECT_STREQ(kOutOfBandPairingDataHash,
216 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str()); 216 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str());
217 EXPECT_TRUE(dict->GetBinary("randomizer", &binary_value)); 217 EXPECT_TRUE(dict->GetBinary("randomizer", &binary_value));
218 EXPECT_STREQ(kOutOfBandPairingDataRandomizer, 218 EXPECT_STREQ(kOutOfBandPairingDataRandomizer,
(...skipping 27 matching lines...) Expand all
246 246
247 char buf[64]; 247 char buf[64];
248 snprintf(buf, sizeof(buf), 248 snprintf(buf, sizeof(buf),
249 "[{\"deviceAddress\":\"%s\"}]", device_address.c_str()); 249 "[{\"deviceAddress\":\"%s\"}]", device_address.c_str());
250 std::string params(buf); 250 std::string params(buf);
251 251
252 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function; 252 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function;
253 set_oob_function = setupFunction( 253 set_oob_function = setupFunction(
254 new api::BluetoothSetOutOfBandPairingDataFunction); 254 new api::BluetoothSetOutOfBandPairingDataFunction);
255 // There isn't actually a result. 255 // There isn't actually a result.
256 (void)utils::RunFunctionAndReturnResult(set_oob_function, params, browser()); 256 (void)utils::RunFunctionAndReturnSingleResult(
257 set_oob_function, params, browser());
257 258
258 // Try again with an error 259 // Try again with an error
259 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 260 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
260 testing::Mock::VerifyAndClearExpectations(&device); 261 testing::Mock::VerifyAndClearExpectations(&device);
261 EXPECT_CALL(*mock_adapter_, GetDevice(device_address)) 262 EXPECT_CALL(*mock_adapter_, GetDevice(device_address))
262 .WillOnce(testing::Return(&device)); 263 .WillOnce(testing::Return(&device));
263 EXPECT_CALL(device, 264 EXPECT_CALL(device,
264 ClearOutOfBandPairingData(testing::_, 265 ClearOutOfBandPairingData(testing::_,
265 testing::Truly(CallClosure))); 266 testing::Truly(CallClosure)));
266 267
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // TODO(bryeung): test that events are sent now (crbug.com/132616) 303 // TODO(bryeung): test that events are sent now (crbug.com/132616)
303 304
304 // Reset to try stopping 305 // Reset to try stopping
305 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 306 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
306 EXPECT_CALL(*mock_adapter_, 307 EXPECT_CALL(*mock_adapter_,
307 SetDiscovering(false, 308 SetDiscovering(false,
308 testing::Truly(CallClosure), 309 testing::Truly(CallClosure),
309 testing::_)); 310 testing::_));
310 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function; 311 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function;
311 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); 312 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
312 (void)utils::RunFunctionAndReturnResult(stop_function, "[]", browser()); 313 (void)utils::RunFunctionAndReturnSingleResult(stop_function, "[]", browser());
313 314
314 // TODO(bryeung): test that no events are sent now (crbug.com/132616) 315 // TODO(bryeung): test that no events are sent now (crbug.com/132616)
315 316
316 // Reset to try stopping with an error 317 // Reset to try stopping with an error
317 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 318 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
318 EXPECT_CALL(*mock_adapter_, 319 EXPECT_CALL(*mock_adapter_,
319 SetDiscovering(false, 320 SetDiscovering(false,
320 testing::_, 321 testing::_,
321 testing::Truly(CallClosure))); 322 testing::Truly(CallClosure)));
322 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); 323 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
323 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); 324 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser());
324 ASSERT_TRUE(!error.empty()); 325 ASSERT_TRUE(!error.empty());
325 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698