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

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

Issue 13416005: Bluetooth: clean up BluetoothDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More win visible fixes Created 7 years, 8 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 virtual void CleanUpOnMainThread() OVERRIDE { 53 virtual void CleanUpOnMainThread() OVERRIDE {
54 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); 54 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
55 } 55 }
56 56
57 void SetUpMockAdapter() { 57 void SetUpMockAdapter() {
58 // The browser will clean this up when it is torn down 58 // The browser will clean this up when it is torn down
59 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>(); 59 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>();
60 event_router()->SetAdapterForTest(mock_adapter_); 60 event_router()->SetAdapterForTest(mock_adapter_);
61 61
62 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( 62 device1_.reset(new testing::NiceMock<MockBluetoothDevice>(
63 mock_adapter_, "d1", "11:12:13:14:15:16", 63 mock_adapter_, 0, "d1", "11:12:13:14:15:16",
64 true /* paired */, false /* bonded */, true /* connected */)); 64 true /* paired */, true /* connected */));
65 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( 65 device2_.reset(new testing::NiceMock<MockBluetoothDevice>(
66 mock_adapter_, "d2", "21:22:23:24:25:26", 66 mock_adapter_, 0, "d2", "21:22:23:24:25:26",
67 false /* paired */, true /* bonded */, false /* connected */)); 67 false /* paired */, false /* connected */));
68 } 68 }
69 69
70 template <class T> 70 template <class T>
71 T* setupFunction(T* function) { 71 T* setupFunction(T* function) {
72 function->set_extension(empty_extension_.get()); 72 function->set_extension(empty_extension_.get());
73 function->set_has_callback(true); 73 function->set_has_callback(true);
74 return function; 74 return function;
75 } 75 }
76 76
77 protected: 77 protected:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const std::string& name, 135 const std::string& name,
136 const BluetoothDevice::SocketCallback& callback) { 136 const BluetoothDevice::SocketCallback& callback) {
137 scoped_refptr<device::MockBluetoothSocket> socket = 137 scoped_refptr<device::MockBluetoothSocket> socket =
138 new device::MockBluetoothSocket(); 138 new device::MockBluetoothSocket();
139 callback.Run(socket); 139 callback.Run(socket);
140 } 140 }
141 141
142 } // namespace 142 } // namespace
143 143
144 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) { 144 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, OnAdapterStateChanged) {
145 EXPECT_CALL(*mock_adapter_, address()) 145 EXPECT_CALL(*mock_adapter_, GetAddress())
146 .WillOnce(testing::Return(kAdapterAddress)); 146 .WillOnce(testing::Return(kAdapterAddress));
147 EXPECT_CALL(*mock_adapter_, name()) 147 EXPECT_CALL(*mock_adapter_, GetName())
148 .WillOnce(testing::Return(kName)); 148 .WillOnce(testing::Return(kName));
149 EXPECT_CALL(*mock_adapter_, IsPresent()) 149 EXPECT_CALL(*mock_adapter_, IsPresent())
150 .WillOnce(testing::Return(false)); 150 .WillOnce(testing::Return(false));
151 EXPECT_CALL(*mock_adapter_, IsPowered()) 151 EXPECT_CALL(*mock_adapter_, IsPowered())
152 .WillOnce(testing::Return(true)); 152 .WillOnce(testing::Return(true));
153 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 153 EXPECT_CALL(*mock_adapter_, IsDiscovering())
154 .WillOnce(testing::Return(false)); 154 .WillOnce(testing::Return(false));
155 155
156 scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state; 156 scoped_refptr<api::BluetoothGetAdapterStateFunction> get_adapter_state;
157 get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction); 157 get_adapter_state = setupFunction(new api::BluetoothGetAdapterStateFunction);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 get_oob_function = 202 get_oob_function =
203 setupFunction(new api::BluetoothGetLocalOutOfBandPairingDataFunction); 203 setupFunction(new api::BluetoothGetLocalOutOfBandPairingDataFunction);
204 204
205 std::string error( 205 std::string error(
206 utils::RunFunctionAndReturnError(get_oob_function, "[]", browser())); 206 utils::RunFunctionAndReturnError(get_oob_function, "[]", browser()));
207 EXPECT_FALSE(error.empty()); 207 EXPECT_FALSE(error.empty());
208 } 208 }
209 209
210 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, SetOutOfBandPairingData) { 210 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, SetOutOfBandPairingData) {
211 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address())) 211 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
212 .WillOnce(testing::Return(device1_.get())); 212 .WillOnce(testing::Return(device1_.get()));
213 EXPECT_CALL(*device1_, 213 EXPECT_CALL(*device1_,
214 ClearOutOfBandPairingData(testing::Truly(CallClosure), 214 ClearOutOfBandPairingData(testing::Truly(CallClosure),
215 testing::_)); 215 testing::_));
216 216
217 std::string params = base::StringPrintf( 217 std::string params = base::StringPrintf(
218 "[{\"deviceAddress\":\"%s\"}]", device1_->address().c_str()); 218 "[{\"deviceAddress\":\"%s\"}]", device1_->GetAddress().c_str());
219 219
220 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function; 220 scoped_refptr<api::BluetoothSetOutOfBandPairingDataFunction> set_oob_function;
221 set_oob_function = setupFunction( 221 set_oob_function = setupFunction(
222 new api::BluetoothSetOutOfBandPairingDataFunction); 222 new api::BluetoothSetOutOfBandPairingDataFunction);
223 // There isn't actually a result. 223 // There isn't actually a result.
224 (void)utils::RunFunctionAndReturnSingleResult( 224 (void)utils::RunFunctionAndReturnSingleResult(
225 set_oob_function, params, browser()); 225 set_oob_function, params, browser());
226 226
227 // Try again with an error 227 // Try again with an error
228 testing::Mock::VerifyAndClearExpectations(mock_adapter_); 228 testing::Mock::VerifyAndClearExpectations(mock_adapter_);
229 testing::Mock::VerifyAndClearExpectations(device1_.get()); 229 testing::Mock::VerifyAndClearExpectations(device1_.get());
230 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address())) 230 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
231 .WillOnce(testing::Return(device1_.get())); 231 .WillOnce(testing::Return(device1_.get()));
232 EXPECT_CALL(*device1_, 232 EXPECT_CALL(*device1_,
233 ClearOutOfBandPairingData(testing::_, 233 ClearOutOfBandPairingData(testing::_,
234 testing::Truly(CallClosure))); 234 testing::Truly(CallClosure)));
235 235
236 set_oob_function = setupFunction( 236 set_oob_function = setupFunction(
237 new api::BluetoothSetOutOfBandPairingDataFunction); 237 new api::BluetoothSetOutOfBandPairingDataFunction);
238 std::string error( 238 std::string error(
239 utils::RunFunctionAndReturnError(set_oob_function, params, browser())); 239 utils::RunFunctionAndReturnError(set_oob_function, params, browser()));
240 EXPECT_FALSE(error.empty()); 240 EXPECT_FALSE(error.empty());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); 307 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied());
308 308
309 SetUpMockAdapter(); 309 SetUpMockAdapter();
310 event_router()->DeviceAdded(mock_adapter_, device2_.get()); 310 event_router()->DeviceAdded(mock_adapter_, device2_.get());
311 discovery_stopped.Reply("go"); 311 discovery_stopped.Reply("go");
312 312
313 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 313 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
314 } 314 }
315 315
316 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { 316 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) {
317 EXPECT_CALL(*mock_adapter_, address()) 317 EXPECT_CALL(*mock_adapter_, GetAddress())
318 .WillOnce(testing::Return(kAdapterAddress)); 318 .WillOnce(testing::Return(kAdapterAddress));
319 EXPECT_CALL(*mock_adapter_, name()) 319 EXPECT_CALL(*mock_adapter_, GetName())
320 .WillOnce(testing::Return(kName)); 320 .WillOnce(testing::Return(kName));
321 EXPECT_CALL(*mock_adapter_, IsPresent()) 321 EXPECT_CALL(*mock_adapter_, IsPresent())
322 .WillOnce(testing::Return(true)); 322 .WillOnce(testing::Return(true));
323 EXPECT_CALL(*mock_adapter_, IsPowered()) 323 EXPECT_CALL(*mock_adapter_, IsPowered())
324 .WillOnce(testing::Return(true)); 324 .WillOnce(testing::Return(true));
325 325
326 // Fake that the adapter is discovering 326 // Fake that the adapter is discovering
327 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 327 EXPECT_CALL(*mock_adapter_, IsDiscovering())
328 .WillOnce(testing::Return(true)); 328 .WillOnce(testing::Return(true));
329 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 329 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { 363 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) {
364 ResultCatcher catcher; 364 ResultCatcher catcher;
365 catcher.RestrictToProfile(browser()->profile()); 365 catcher.RestrictToProfile(browser()->profile());
366 366
367 // Load and wait for setup 367 // Load and wait for setup
368 ExtensionTestMessageListener listener("ready", true); 368 ExtensionTestMessageListener listener("ready", true);
369 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bluetooth/events"))); 369 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bluetooth/events")));
370 EXPECT_TRUE(listener.WaitUntilSatisfied()); 370 EXPECT_TRUE(listener.WaitUntilSatisfied());
371 371
372 EXPECT_CALL(*mock_adapter_, address()) 372 EXPECT_CALL(*mock_adapter_, GetAddress())
373 .WillOnce(testing::Return(kAdapterAddress)); 373 .WillOnce(testing::Return(kAdapterAddress));
374 EXPECT_CALL(*mock_adapter_, name()) 374 EXPECT_CALL(*mock_adapter_, GetName())
375 .WillOnce(testing::Return(kName)); 375 .WillOnce(testing::Return(kName));
376 EXPECT_CALL(*mock_adapter_, IsPresent()) 376 EXPECT_CALL(*mock_adapter_, IsPresent())
377 .WillOnce(testing::Return(false)); 377 .WillOnce(testing::Return(false));
378 EXPECT_CALL(*mock_adapter_, IsPowered()) 378 EXPECT_CALL(*mock_adapter_, IsPowered())
379 .WillOnce(testing::Return(false)); 379 .WillOnce(testing::Return(false));
380 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 380 EXPECT_CALL(*mock_adapter_, IsDiscovering())
381 .WillOnce(testing::Return(false)); 381 .WillOnce(testing::Return(false));
382 event_router()->AdapterPoweredChanged(mock_adapter_, false); 382 event_router()->AdapterPoweredChanged(mock_adapter_, false);
383 383
384 EXPECT_CALL(*mock_adapter_, address()) 384 EXPECT_CALL(*mock_adapter_, GetAddress())
385 .WillOnce(testing::Return(kAdapterAddress)); 385 .WillOnce(testing::Return(kAdapterAddress));
386 EXPECT_CALL(*mock_adapter_, name()) 386 EXPECT_CALL(*mock_adapter_, GetName())
387 .WillOnce(testing::Return(kName)); 387 .WillOnce(testing::Return(kName));
388 EXPECT_CALL(*mock_adapter_, IsPresent()) 388 EXPECT_CALL(*mock_adapter_, IsPresent())
389 .WillOnce(testing::Return(true)); 389 .WillOnce(testing::Return(true));
390 EXPECT_CALL(*mock_adapter_, IsPowered()) 390 EXPECT_CALL(*mock_adapter_, IsPowered())
391 .WillOnce(testing::Return(true)); 391 .WillOnce(testing::Return(true));
392 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 392 EXPECT_CALL(*mock_adapter_, IsDiscovering())
393 .WillOnce(testing::Return(true)); 393 .WillOnce(testing::Return(true));
394 event_router()->AdapterPresentChanged(mock_adapter_, true); 394 event_router()->AdapterPresentChanged(mock_adapter_, true);
395 395
396 EXPECT_CALL(*mock_adapter_, address()) 396 EXPECT_CALL(*mock_adapter_, GetAddress())
397 .WillOnce(testing::Return(kAdapterAddress)); 397 .WillOnce(testing::Return(kAdapterAddress));
398 EXPECT_CALL(*mock_adapter_, name()) 398 EXPECT_CALL(*mock_adapter_, GetName())
399 .WillOnce(testing::Return(kName)); 399 .WillOnce(testing::Return(kName));
400 EXPECT_CALL(*mock_adapter_, IsPresent()) 400 EXPECT_CALL(*mock_adapter_, IsPresent())
401 .WillOnce(testing::Return(true)); 401 .WillOnce(testing::Return(true));
402 EXPECT_CALL(*mock_adapter_, IsPowered()) 402 EXPECT_CALL(*mock_adapter_, IsPowered())
403 .WillOnce(testing::Return(true)); 403 .WillOnce(testing::Return(true));
404 EXPECT_CALL(*mock_adapter_, IsDiscovering()) 404 EXPECT_CALL(*mock_adapter_, IsDiscovering())
405 .WillOnce(testing::Return(true)); 405 .WillOnce(testing::Return(true));
406 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 406 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
407 407
408 listener.Reply("go"); 408 listener.Reply("go");
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 listener.Reply("go"); 484 listener.Reply("go");
485 485
486 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 486 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
487 } 487 }
488 488
489 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Permissions) { 489 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Permissions) {
490 PermissionsRequestFunction::SetAutoConfirmForTests(true); 490 PermissionsRequestFunction::SetAutoConfirmForTests(true);
491 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 491 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
492 492
493 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address())) 493 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress()))
494 .WillOnce(testing::Return(device1_.get())); 494 .WillOnce(testing::Return(device1_.get()));
495 EXPECT_CALL(*device1_, 495 EXPECT_CALL(*device1_,
496 ConnectToService(testing::_, testing::_)) 496 ConnectToService(testing::_, testing::_))
497 .WillOnce(testing::Invoke(CallConnectToServiceCallback)); 497 .WillOnce(testing::Invoke(CallConnectToServiceCallback));
498 498
499 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_; 499 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_;
500 } 500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698