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

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

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
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 "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
10 #include "chrome/browser/extensions/api/permissions/permissions_api.h" 10 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 callback.Run(GetOutOfBandPairingData()); 161 callback.Run(GetOutOfBandPairingData());
162 } 162 }
163 163
164 } // namespace 164 } // namespace
165 165
166 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Profiles) { 166 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Profiles) {
167 EXPECT_CALL(*profile1_, SetConnectionCallback(testing::_)); 167 EXPECT_CALL(*profile1_, SetConnectionCallback(testing::_));
168 scoped_refptr<TestBluetoothAddProfileFunction> add_profile_function; 168 scoped_refptr<TestBluetoothAddProfileFunction> add_profile_function;
169 add_profile_function = setupFunction( 169 add_profile_function = setupFunction(
170 new TestBluetoothAddProfileFunction(profile1_.get())); 170 new TestBluetoothAddProfileFunction(profile1_.get()));
171 std::string error( 171 std::string error(utils::RunFunctionAndReturnError(
172 utils::RunFunctionAndReturnError( 172 add_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser()));
173 add_profile_function,
174 "[{\"uuid\": \"1234\"}]",
175 browser()));
176 ASSERT_TRUE(error.empty()); 173 ASSERT_TRUE(error.empty());
177 174
178 // Registering the profile for the same uuid again will throw an error. 175 // Registering the profile for the same uuid again will throw an error.
179 add_profile_function = setupFunction( 176 add_profile_function = setupFunction(
180 new TestBluetoothAddProfileFunction(profile2_.get())); 177 new TestBluetoothAddProfileFunction(profile2_.get()));
181 error = utils::RunFunctionAndReturnError( 178 error = utils::RunFunctionAndReturnError(
182 add_profile_function, 179 add_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser());
183 "[{\"uuid\": \"1234\"}]",
184 browser());
185 ASSERT_FALSE(error.empty()); 180 ASSERT_FALSE(error.empty());
186 181
187 add_profile_function = setupFunction( 182 add_profile_function = setupFunction(
188 new TestBluetoothAddProfileFunction(profile2_.get())); 183 new TestBluetoothAddProfileFunction(profile2_.get()));
189 error = utils::RunFunctionAndReturnError( 184 error = utils::RunFunctionAndReturnError(
190 add_profile_function, 185 add_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
191 "[{\"uuid\": \"5678\"}]",
192 browser());
193 ASSERT_TRUE(error.empty()); 186 ASSERT_TRUE(error.empty());
194 187
195 scoped_refptr<api::BluetoothRemoveProfileFunction> remove_profile_function; 188 scoped_refptr<api::BluetoothRemoveProfileFunction> remove_profile_function;
196 remove_profile_function = setupFunction( 189 remove_profile_function = setupFunction(
197 new api::BluetoothRemoveProfileFunction()); 190 new api::BluetoothRemoveProfileFunction());
198 error = utils::RunFunctionAndReturnError( 191 error = utils::RunFunctionAndReturnError(
199 remove_profile_function, 192 remove_profile_function.get(), "[{\"uuid\": \"1234\"}]", browser());
200 "[{\"uuid\": \"1234\"}]",
201 browser());
202 ASSERT_TRUE(error.empty()); 193 ASSERT_TRUE(error.empty());
203 194
204 remove_profile_function = setupFunction( 195 remove_profile_function = setupFunction(
205 new api::BluetoothRemoveProfileFunction()); 196 new api::BluetoothRemoveProfileFunction());
206 error = utils::RunFunctionAndReturnError( 197 error = utils::RunFunctionAndReturnError(
207 remove_profile_function, 198 remove_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
208 "[{\"uuid\": \"5678\"}]",
209 browser());
210 ASSERT_TRUE(error.empty()); 199 ASSERT_TRUE(error.empty());
211 200
212 // Removing the same profile again will throw an error. 201 // Removing the same profile again will throw an error.
213 remove_profile_function = setupFunction( 202 remove_profile_function = setupFunction(
214 new api::BluetoothRemoveProfileFunction()); 203 new api::BluetoothRemoveProfileFunction());
215 error = utils::RunFunctionAndReturnError( 204 error = utils::RunFunctionAndReturnError(
216 remove_profile_function, 205 remove_profile_function.get(), "[{\"uuid\": \"5678\"}]", browser());
217 "[{\"uuid\": \"5678\"}]",
218 browser());
219 ASSERT_FALSE(error.empty()); 206 ASSERT_FALSE(error.empty());
220 } 207 }
221 208
222 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetAdapterState) { 209 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetAdapterState) {
223 EXPECT_CALL(*mock_adapter_, GetAddress()) 210 EXPECT_CALL(*mock_adapter_, GetAddress())
224 .WillOnce(testing::Return(kAdapterAddress)); 211 .WillOnce(testing::Return(kAdapterAddress));
225 EXPECT_CALL(*mock_adapter_, GetName()) 212 EXPECT_CALL(*mock_adapter_, GetName())
226 .WillOnce(testing::Return(kName)); 213 .WillOnce(testing::Return(kName));
227 EXPECT_CALL(*mock_adapter_, IsPresent()) 214 EXPECT_CALL(*mock_adapter_, IsPresent())
228 .WillOnce(testing::Return(false)); 215 .WillOnce(testing::Return(false));
229 EXPECT_CALL(*mock_adapter_, IsPowered()) 216 EXPECT_CALL(*mock_adapter_, IsPowered())
230 .WillOnce(testing::Return(true)); 217 .WillOnce(testing::Return(true));
231 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 218 EXPECT_CALL(*mock_adapter_, IsDiscovering())
232 .WillOnce(testing::Return(false)); 219 .WillOnce(testing::Return(false));
233 220
234 scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state; 221 scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state;
235 get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction); 222 get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction);
236 223
237 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 224 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
238 get_adapter_state, "[]", browser())); 225 get_adapter_state.get(), "[]", browser()));
239 ASSERT_TRUE(result.get() != NULL); 226 ASSERT_TRUE(result.get() != NULL);
240 api::bluetooth::AdapterState state; 227 api::bluetooth::AdapterState state;
241 ASSERT_TRUE(api::bluetooth::AdapterState::Populate(*result, &state)); 228 ASSERT_TRUE(api::bluetooth::AdapterState::Populate(*result, &state));
242 229
243 EXPECT_FALSE(state.available); 230 EXPECT_FALSE(state.available);
244 EXPECT_TRUE(state.powered); 231 EXPECT_TRUE(state.powered);
245 EXPECT_FALSE(state.discovering); 232 EXPECT_FALSE(state.discovering);
246 EXPECT_EQ(kName, state.name); 233 EXPECT_EQ(kName, state.name);
247 EXPECT_EQ(kAdapterAddress, state.address); 234 EXPECT_EQ(kAdapterAddress, state.address);
248 } 235 }
249 236
250 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) { 237 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetLocalOutOfBandPairingData) {
251 EXPECT_CALL(*mock_adapter_, 238 EXPECT_CALL(*mock_adapter_,
252 ReadLocalOutOfBandPairingData(testing::_, testing::_)) 239 ReadLocalOutOfBandPairingData(testing::_, testing::_))
253 .WillOnce(testing::Invoke(CallOutOfBandPairingDataCallback)); 240 .WillOnce(testing::Invoke(CallOutOfBandPairingDataCallback));
254 241
255 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction> 242 scoped_refptr<api::BluetoothGetLocalOutOfBandPairingDataFunction>
256 get_oob_function(setupFunction( 243 get_oob_function(setupFunction(
257 new api::BluetoothGetLocalOutOfBandPairingDataFunction)); 244 new api::BluetoothGetLocalOutOfBandPairingDataFunction));
258 245
259 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 246 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
260 get_oob_function, "[]", browser())); 247 get_oob_function.get(), "[]", browser()));
261 248
262 base::DictionaryValue* dict; 249 base::DictionaryValue* dict;
263 EXPECT_TRUE(result->GetAsDictionary(&dict)); 250 EXPECT_TRUE(result->GetAsDictionary(&dict));
264 251
265 base::BinaryValue* binary_value; 252 base::BinaryValue* binary_value;
266 EXPECT_TRUE(dict->GetBinary("hash", &binary_value)); 253 EXPECT_TRUE(dict->GetBinary("hash", &binary_value));
267 EXPECT_STREQ(kOutOfBandPairingDataHash, 254 EXPECT_STREQ(kOutOfBandPairingDataHash,
268 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str()); 255 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str());
269 EXPECT_TRUE(dict->GetBinary("randomizer", &binary_value)); 256 EXPECT_TRUE(dict->GetBinary("randomizer", &binary_value));
270 EXPECT_STREQ(kOutOfBandPairingDataRandomizer, 257 EXPECT_STREQ(kOutOfBandPairingDataRandomizer,
271 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str()); 258 std::string(binary_value->GetBuffer(), binary_value->GetSize()).c_str());
272 259
273 // Try again with an error 260 // Try again with an error
274 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 261 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
275 EXPECT_CALL(*mock_adapter_, 262 EXPECT_CALL(*mock_adapter_,
276 ReadLocalOutOfBandPairingData( 263 ReadLocalOutOfBandPairingData(
277 testing::_, 264 testing::_,
278 testing::Truly(CallClosure))); 265 testing::Truly(CallClosure)));
279 266
280 get_oob_function = 267 get_oob_function =
281 setupFunction(new api::BluetoothGetLocalOutOfBandPairingDataFunction); 268 setupFunction(new api::BluetoothGetLocalOutOfBandPairingDataFunction);
282 269
283 std::string error( 270 std::string error(utils::RunFunctionAndReturnError(
284 utils::RunFunctionAndReturnError(get_oob_function, "[]", browser())); 271 get_oob_function.get(), "[]", browser()));
285 EXPECT_FALSE(error.empty()); 272 EXPECT_FALSE(error.empty());
286 } 273 }
287 274
288 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, SetOutOfBandPairingData) { 275 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, SetOutOfBandPairingData) {
289 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) 276 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
290 .WillOnce(testing::Return(device1_.get())); 277 .WillOnce(testing::Return(device1_.get()));
291 EXPECT_CALL(*device1_, 278 EXPECT_CALL(*device1_,
292 ClearOutOfBandPairingData(testing::Truly(CallClosure), 279 ClearOutOfBandPairingData(testing::Truly(CallClosure),
293 testing::_)); 280 testing::_));
294 281
295 std::string params = base::StringPrintf( 282 std::string params = base::StringPrintf(
296 "[{\"deviceAddress\":\"%s\"}]", device1_->GetAddress().c_str()); 283 "[{\"deviceAddress\":\"%s\"}]", device1_->GetAddress().c_str());
297 284
298 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function; 285 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function;
299 set_oob_function = setupFunction( 286 set_oob_function = setupFunction(
300 new api::BluetoothSetOutOfBandPairingDataFunction); 287 new api::BluetoothSetOutOfBandPairingDataFunction);
301 // There isn't actually a result. 288 // There isn't actually a result.
302 (void)utils::RunFunctionAndReturnSingleResult( 289 (void) utils::RunFunctionAndReturnSingleResult(
303 set_oob_function, params, browser()); 290 set_oob_function.get(), params, browser());
304 291
305 // Try again with an error 292 // Try again with an error
306 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 293 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
307 testing::Mock::VerifyAndClearExpectations(device1_.get()); 294 testing::Mock::VerifyAndClearExpectations(device1_.get());
308 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) 295 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
309 .WillOnce(testing::Return(device1_.get())); 296 .WillOnce(testing::Return(device1_.get()));
310 EXPECT_CALL(*device1_, 297 EXPECT_CALL(*device1_,
311 ClearOutOfBandPairingData(testing::_, 298 ClearOutOfBandPairingData(testing::_,
312 testing::Truly(CallClosure))); 299 testing::Truly(CallClosure)));
313 300
314 set_oob_function = setupFunction( 301 set_oob_function = setupFunction(
315 new api::BluetoothSetOutOfBandPairingDataFunction); 302 new api::BluetoothSetOutOfBandPairingDataFunction);
316 std::string error( 303 std::string error(utils::RunFunctionAndReturnError(
317 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); 304 set_oob_function.get(), params, browser()));
318 EXPECT_FALSE(error.empty()); 305 EXPECT_FALSE(error.empty());
319 306
320 // TODO(bryeung): Also test setting the data when there is support for 307 // TODO(bryeung): Also test setting the data when there is support for
321 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. 308 // ArrayBuffers in the arguments to the RunFunctionAnd* methods.
322 // crbug.com/132796 309 // crbug.com/132796
323 } 310 }
324 311
325 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) { 312 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
326 // Try with a failure to start 313 // Try with a failure to start
327 EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_)) 314 EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
328 .WillOnce(testing::Invoke(CallDiscoveryErrorCallback)); 315 .WillOnce(testing::Invoke(CallDiscoveryErrorCallback));
329 // StartDiscovery failure will remove the adapter that is no longer used. 316 // StartDiscovery failure will remove the adapter that is no longer used.
330 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); 317 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
331 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function; 318 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function;
332 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); 319 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
333 std::string error( 320 std::string error(
334 utils::RunFunctionAndReturnError(start_function, "[]", browser())); 321 utils::RunFunctionAndReturnError(start_function.get(), "[]", browser()));
335 ASSERT_FALSE(error.empty()); 322 ASSERT_FALSE(error.empty());
336 323
337 // Reset for a successful start 324 // Reset for a successful start
338 SetUpMockAdapter(); 325 SetUpMockAdapter();
339 EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_)) 326 EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
340 .WillOnce(testing::Invoke(CallDiscoveryCallback)); 327 .WillOnce(testing::Invoke(CallDiscoveryCallback));
341 328
342 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction); 329 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
343 (void)utils::RunFunctionAndReturnError(start_function, "[]", browser()); 330 (void)
331 utils::RunFunctionAndReturnError(start_function.get(), "[]", browser());
344 332
345 // Reset to try stopping 333 // Reset to try stopping
346 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 334 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
347 EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_)) 335 EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
348 .WillOnce(testing::Invoke(CallDiscoveryCallback)); 336 .WillOnce(testing::Invoke(CallDiscoveryCallback));
349 // StopDiscovery success will remove the adapter that is no longer used. 337 // StopDiscovery success will remove the adapter that is no longer used.
350 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); 338 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
351 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function; 339 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function;
352 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); 340 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
353 (void)utils::RunFunctionAndReturnSingleResult(stop_function, "[]", browser()); 341 (void) utils::RunFunctionAndReturnSingleResult(
342 stop_function.get(), "[]", browser());
354 343
355 // Reset to try stopping with an error 344 // Reset to try stopping with an error
356 SetUpMockAdapter(); 345 SetUpMockAdapter();
357 EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_)) 346 EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
358 .WillOnce(testing::Invoke(CallDiscoveryErrorCallback)); 347 .WillOnce(testing::Invoke(CallDiscoveryErrorCallback));
359 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); 348 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
360 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction); 349 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
361 error = utils::RunFunctionAndReturnError(stop_function, "[]", browser()); 350 error =
351 utils::RunFunctionAndReturnError(stop_function.get(), "[]", browser());
362 ASSERT_FALSE(error.empty()); 352 ASSERT_FALSE(error.empty());
363 SetUpMockAdapter(); 353 SetUpMockAdapter();
364 } 354 }
365 355
366 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) { 356 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryCallback) {
367 EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_)) 357 EXPECT_CALL(*mock_adapter_, StartDiscovering(testing::_, testing::_))
368 .WillOnce(testing::Invoke(CallDiscoveryCallback)); 358 .WillOnce(testing::Invoke(CallDiscoveryCallback));
369 EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_)) 359 EXPECT_CALL(*mock_adapter_, StopDiscovering(testing::_, testing::_))
370 .WillOnce(testing::Invoke(CallDiscoveryCallback)); 360 .WillOnce(testing::Invoke(CallDiscoveryCallback));
371 361
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 "00001101-0000-1000-8000-00805f9b34fb", profile1_.get()); 580 "00001101-0000-1000-8000-00805f9b34fb", profile1_.get());
591 581
592 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) 582 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
593 .WillOnce(testing::Return(device1_.get())); 583 .WillOnce(testing::Return(device1_.get()));
594 EXPECT_CALL(*device1_, 584 EXPECT_CALL(*device1_,
595 ConnectToProfile(testing::_, testing::_, testing::_)) 585 ConnectToProfile(testing::_, testing::_, testing::_))
596 .WillOnce(testing::Invoke(CallConnectToProfileCallback)); 586 .WillOnce(testing::Invoke(CallConnectToProfileCallback));
597 587
598 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_; 588 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_;
599 } 589 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698