Chromium Code Reviews| 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" | |
| 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | |
| 9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" | |
| 10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" | |
| 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 7 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 8 #include "chrome/browser/extensions/bluetooth_event_router.h" | |
| 12 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 16 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 17 #include "chromeos/dbus/bluetooth_out_of_band_client.h" | |
| 18 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h" | |
| 19 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "device/bluetooth/bluetooth_adapter.h" | |
| 16 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | |
| 17 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | |
| 18 #include "device/bluetooth/test/mock_bluetooth_device.h" | |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 21 | 20 |
| 21 using bluetooth::BluetoothAdapter; | |
| 22 using bluetooth::BluetoothDevice; | |
| 23 using bluetooth::BluetoothOutOfBandPairingData; | |
| 24 using bluetooth::MockBluetoothAdapter; | |
| 25 using bluetooth::MockBluetoothDevice; | |
| 22 using extensions::Extension; | 26 using extensions::Extension; |
| 23 | 27 |
| 24 namespace utils = extension_function_test_utils; | 28 namespace utils = extension_function_test_utils; |
| 25 namespace api = extensions::api; | 29 namespace api = extensions::api; |
| 26 | 30 |
| 27 namespace { | 31 namespace { |
| 28 | 32 |
| 29 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6"; | 33 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6"; |
| 30 static const char* kName = "whatsinaname"; | 34 static const char* kName = "whatsinaname"; |
| 31 | 35 |
| 32 class BluetoothApiTest : public PlatformAppApiTest { | 36 class BluetoothApiTest : public PlatformAppApiTest { |
| 33 public: | 37 public: |
| 34 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} | 38 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} |
| 35 | 39 |
| 36 virtual void SetUpOnMainThread() OVERRIDE { | 40 virtual void SetUpOnMainThread() OVERRIDE { |
| 37 // The browser will clean this up when it is torn down | 41 // The browser will clean this up when it is torn down |
| 38 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>( | 42 mock_adapter_ = |
| 39 kAdapterAddress, kName); | 43 new testing::StrictMock<MockBluetoothAdapter>(kAdapterAddress, kName); |
|
bryeung
2012/10/11 15:15:39
why the wrapping change?
youngki
2012/10/11 16:21:18
Done.
| |
| 40 event_router()->SetAdapterForTest(mock_adapter_); | 44 event_router()->SetAdapterForTest(mock_adapter_); |
| 41 | 45 |
| 42 device1_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( | 46 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( |
| 43 mock_adapter_, "d1", "11:12:13:14:15:16", | 47 mock_adapter_, "d1", "11:12:13:14:15:16", |
| 44 true /* paired */, false /* bonded */, true /* connected */)); | 48 true /* paired */, false /* bonded */, true /* connected */)); |
| 45 device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( | 49 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( |
| 46 mock_adapter_, "d2", "21:22:23:24:25:26", | 50 mock_adapter_, "d2", "21:22:23:24:25:26", |
| 47 false /* paired */, true /* bonded */, false /* connected */)); | 51 false /* paired */, true /* bonded */, false /* connected */)); |
| 48 } | 52 } |
| 49 | 53 |
| 50 virtual void CleanUpOnMainThread() OVERRIDE { | 54 virtual void CleanUpOnMainThread() OVERRIDE { |
| 51 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); | 55 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); |
| 52 } | 56 } |
| 53 | 57 |
| 54 void expectBooleanResult(bool expected, | 58 void expectBooleanResult(bool expected, |
| 55 UIThreadExtensionFunction* function) { | 59 UIThreadExtensionFunction* function) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 74 } | 78 } |
| 75 | 79 |
| 76 template <class T> | 80 template <class T> |
| 77 T* setupFunction(T* function) { | 81 T* setupFunction(T* function) { |
| 78 function->set_extension(empty_extension_.get()); | 82 function->set_extension(empty_extension_.get()); |
| 79 function->set_has_callback(true); | 83 function->set_has_callback(true); |
| 80 return function; | 84 return function; |
| 81 } | 85 } |
| 82 | 86 |
| 83 protected: | 87 protected: |
| 84 testing::StrictMock<chromeos::MockBluetoothAdapter>* mock_adapter_; | 88 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; |
| 85 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device1_; | 89 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; |
| 86 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device2_; | 90 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; |
| 87 | 91 |
| 88 chromeos::ExtensionBluetoothEventRouter* event_router() { | 92 extensions::ExtensionBluetoothEventRouter* event_router() { |
| 89 return browser()->profile()->GetExtensionService()-> | 93 return browser()->profile()->GetExtensionService()-> |
| 90 bluetooth_event_router(); | 94 bluetooth_event_router(); |
| 91 } | 95 } |
| 92 | 96 |
| 93 private: | 97 private: |
| 94 scoped_refptr<Extension> empty_extension_; | 98 scoped_refptr<Extension> empty_extension_; |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 // This is the canonical UUID for the short UUID 0010. | 101 // This is the canonical UUID for the short UUID 0010. |
| 98 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; | 102 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; |
| 99 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; | 103 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; |
| 100 | 104 |
| 101 static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { | 105 static BluetoothOutOfBandPairingData GetOutOfBandPairingData() { |
| 102 chromeos::BluetoothOutOfBandPairingData data; | 106 BluetoothOutOfBandPairingData data; |
| 103 memcpy(&(data.hash), kOutOfBandPairingDataHash, | 107 memcpy(&(data.hash), kOutOfBandPairingDataHash, |
| 104 chromeos::kBluetoothOutOfBandPairingDataSize); | 108 bluetooth::kBluetoothOutOfBandPairingDataSize); |
| 105 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, | 109 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, |
| 106 chromeos::kBluetoothOutOfBandPairingDataSize); | 110 bluetooth::kBluetoothOutOfBandPairingDataSize); |
| 107 return data; | 111 return data; |
| 108 } | 112 } |
| 109 | 113 |
| 110 static bool CallClosure(const base::Closure& callback) { | 114 static bool CallClosure(const base::Closure& callback) { |
| 111 callback.Run(); | 115 callback.Run(); |
| 112 return true; | 116 return true; |
| 113 } | 117 } |
| 114 | 118 |
| 115 static void CallOutOfBandPairingDataCallback( | 119 static void CallOutOfBandPairingDataCallback( |
| 116 const chromeos::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& | 120 const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, |
| 117 callback, | 121 const BluetoothAdapter::ErrorCallback& error_callback) { |
| 118 const chromeos::BluetoothAdapter::ErrorCallback& error_callback) { | |
| 119 callback.Run(GetOutOfBandPairingData()); | 122 callback.Run(GetOutOfBandPairingData()); |
| 120 } | 123 } |
| 121 | 124 |
| 122 template <bool Value> | 125 template <bool Value> |
| 123 static void CallProvidesServiceCallback( | 126 static void CallProvidesServiceCallback( |
| 124 const std::string& name, | 127 const std::string& name, |
| 125 const chromeos::BluetoothDevice::ProvidesServiceCallback& callback) { | 128 const BluetoothDevice::ProvidesServiceCallback& callback) { |
| 126 callback.Run(Value); | 129 callback.Run(Value); |
| 127 } | 130 } |
| 128 | 131 |
| 129 } // namespace | 132 } // namespace |
| 130 | 133 |
| 131 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsAvailable) { | 134 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsAvailable) { |
| 132 EXPECT_CALL(*mock_adapter_, IsPresent()) | 135 EXPECT_CALL(*mock_adapter_, IsPresent()) |
| 133 .WillOnce(testing::Return(false)); | 136 .WillOnce(testing::Return(false)); |
| 134 | 137 |
| 135 scoped_refptr<api::BluetoothIsAvailableFunction> is_available; | 138 scoped_refptr<api::BluetoothIsAvailableFunction> is_available; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); | 304 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(false)); |
| 302 EXPECT_CALL(*mock_adapter_, | 305 EXPECT_CALL(*mock_adapter_, |
| 303 SetDiscovering(true, testing::Truly(CallClosure), testing::_)); | 306 SetDiscovering(true, testing::Truly(CallClosure), testing::_)); |
| 304 EXPECT_CALL(*mock_adapter_, | 307 EXPECT_CALL(*mock_adapter_, |
| 305 SetDiscovering(false, testing::Truly(CallClosure), testing::_)); | 308 SetDiscovering(false, testing::Truly(CallClosure), testing::_)); |
| 306 | 309 |
| 307 ResultCatcher catcher; | 310 ResultCatcher catcher; |
| 308 catcher.RestrictToProfile(browser()->profile()); | 311 catcher.RestrictToProfile(browser()->profile()); |
| 309 | 312 |
| 310 ExtensionTestMessageListener discovery_started("ready", true); | 313 ExtensionTestMessageListener discovery_started("ready", true); |
| 311 const extensions::Extension* extension = | 314 const Extension* extension = |
| 312 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 315 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 313 GURL page_url = extension->GetResourceURL("test_discovery.html"); | 316 GURL page_url = extension->GetResourceURL("test_discovery.html"); |
| 314 ui_test_utils::NavigateToURL(browser(), page_url); | 317 ui_test_utils::NavigateToURL(browser(), page_url); |
| 315 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); | 318 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); |
| 316 | 319 |
| 317 event_router()->DeviceAdded(mock_adapter_, device1_.get()); | 320 event_router()->DeviceAdded(mock_adapter_, device1_.get()); |
| 318 | 321 |
| 319 discovery_started.Reply("go"); | 322 discovery_started.Reply("go"); |
| 320 ExtensionTestMessageListener discovery_stopped("ready", true); | 323 ExtensionTestMessageListener discovery_stopped("ready", true); |
| 321 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); | 324 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); |
| 322 | 325 |
| 323 event_router()->DeviceAdded(mock_adapter_, device2_.get()); | 326 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 324 discovery_stopped.Reply("go"); | 327 discovery_stopped.Reply("go"); |
| 325 | 328 |
| 326 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 329 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 327 } | 330 } |
| 328 | 331 |
| 329 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { | 332 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { |
| 330 // Fake that the adapter is discovering | 333 // Fake that the adapter is discovering |
| 331 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(true)); | 334 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(true)); |
| 332 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); | 335 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
| 333 | 336 |
| 334 // Cache a device before the extension starts discovering | 337 // Cache a device before the extension starts discovering |
| 335 event_router()->DeviceAdded(mock_adapter_, device1_.get()); | 338 event_router()->DeviceAdded(mock_adapter_, device1_.get()); |
| 336 | 339 |
| 337 ResultCatcher catcher; | 340 ResultCatcher catcher; |
| 338 catcher.RestrictToProfile(browser()->profile()); | 341 catcher.RestrictToProfile(browser()->profile()); |
| 339 | 342 |
| 340 ExtensionTestMessageListener discovery_started("ready", true); | 343 ExtensionTestMessageListener discovery_started("ready", true); |
| 341 const extensions::Extension* extension = | 344 const Extension* extension = |
| 342 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 345 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 343 GURL page_url = extension->GetResourceURL("test_discovery_in_progress.html"); | 346 GURL page_url = extension->GetResourceURL("test_discovery_in_progress.html"); |
| 344 ui_test_utils::NavigateToURL(browser(), page_url); | 347 ui_test_utils::NavigateToURL(browser(), page_url); |
| 345 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); | 348 EXPECT_TRUE(discovery_started.WaitUntilSatisfied()); |
| 346 | 349 |
| 347 // This should be received in addition to the cached device above. | 350 // This should be received in addition to the cached device above. |
| 348 event_router()->DeviceAdded(mock_adapter_, device2_.get()); | 351 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 349 | 352 |
| 350 discovery_started.Reply("go"); | 353 discovery_started.Reply("go"); |
| 351 ExtensionTestMessageListener discovery_stopped("ready", true); | 354 ExtensionTestMessageListener discovery_stopped("ready", true); |
| 352 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); | 355 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); |
| 353 | 356 |
| 354 event_router()->DeviceAdded(mock_adapter_, device2_.get()); | 357 event_router()->DeviceAdded(mock_adapter_, device2_.get()); |
| 355 discovery_stopped.Reply("go"); | 358 discovery_stopped.Reply("go"); |
| 356 | 359 |
| 357 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 360 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 358 } | 361 } |
| 359 | 362 |
| 360 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { | 363 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { |
| 361 ResultCatcher catcher; | 364 ResultCatcher catcher; |
| 362 catcher.RestrictToProfile(browser()->profile()); | 365 catcher.RestrictToProfile(browser()->profile()); |
| 363 | 366 |
| 364 // Load and wait for setup | 367 // Load and wait for setup |
| 365 ExtensionTestMessageListener listener("ready", true); | 368 ExtensionTestMessageListener listener("ready", true); |
| 366 const extensions::Extension* extension = | 369 const Extension* extension = |
| 367 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 370 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 368 GURL page_url = extension->GetResourceURL("test_events.html"); | 371 GURL page_url = extension->GetResourceURL("test_events.html"); |
| 369 ui_test_utils::NavigateToURL(browser(), page_url); | 372 ui_test_utils::NavigateToURL(browser(), page_url); |
| 370 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 373 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 371 | 374 |
| 372 event_router()->AdapterPoweredChanged(mock_adapter_, true); | 375 event_router()->AdapterPoweredChanged(mock_adapter_, true); |
| 373 event_router()->AdapterPoweredChanged(mock_adapter_, false); | 376 event_router()->AdapterPoweredChanged(mock_adapter_, false); |
| 374 event_router()->AdapterPresentChanged(mock_adapter_, true); | 377 event_router()->AdapterPresentChanged(mock_adapter_, true); |
| 375 event_router()->AdapterPresentChanged(mock_adapter_, false); | 378 event_router()->AdapterPresentChanged(mock_adapter_, false); |
| 376 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); | 379 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); |
| 377 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); | 380 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); |
| 378 | 381 |
| 379 listener.Reply("go"); | 382 listener.Reply("go"); |
| 380 | 383 |
| 381 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 384 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 382 } | 385 } |
| 383 | 386 |
| 384 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { | 387 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { |
| 385 ResultCatcher catcher; | 388 ResultCatcher catcher; |
| 386 catcher.RestrictToProfile(browser()->profile()); | 389 catcher.RestrictToProfile(browser()->profile()); |
| 387 | 390 |
| 388 chromeos::BluetoothAdapter::ConstDeviceList devices; | 391 BluetoothAdapter::ConstDeviceList devices; |
| 389 devices.push_back(device1_.get()); | 392 devices.push_back(device1_.get()); |
| 390 devices.push_back(device2_.get()); | 393 devices.push_back(device2_.get()); |
| 391 | 394 |
| 392 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(testing::_)) | 395 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(testing::_)) |
| 393 .WillOnce(testing::Return(false)); | 396 .WillOnce(testing::Return(false)); |
| 394 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) | 397 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) |
| 395 .WillOnce(testing::Invoke(CallProvidesServiceCallback<true>)); | 398 .WillOnce(testing::Invoke(CallProvidesServiceCallback<true>)); |
| 396 | 399 |
| 397 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(testing::_)) | 400 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(testing::_)) |
| 398 .WillOnce(testing::Return(true)); | 401 .WillOnce(testing::Return(true)); |
| 399 EXPECT_CALL(*device2_, ProvidesServiceWithName(testing::_, testing::_)) | 402 EXPECT_CALL(*device2_, ProvidesServiceWithName(testing::_, testing::_)) |
| 400 .WillOnce(testing::Invoke(CallProvidesServiceCallback<false>)); | 403 .WillOnce(testing::Invoke(CallProvidesServiceCallback<false>)); |
| 401 | 404 |
| 402 EXPECT_CALL(*mock_adapter_, GetDevices()) | 405 EXPECT_CALL(*mock_adapter_, GetDevices()) |
| 403 .Times(3) | 406 .Times(3) |
| 404 .WillRepeatedly(testing::Return(devices)); | 407 .WillRepeatedly(testing::Return(devices)); |
| 405 | 408 |
| 406 // Load and wait for setup | 409 // Load and wait for setup |
| 407 ExtensionTestMessageListener listener("ready", true); | 410 ExtensionTestMessageListener listener("ready", true); |
| 408 const extensions::Extension* extension = | 411 const Extension* extension = |
| 409 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 412 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 410 GURL page_url = extension->GetResourceURL("test_getdevices.html"); | 413 GURL page_url = extension->GetResourceURL("test_getdevices.html"); |
| 411 ui_test_utils::NavigateToURL(browser(), page_url); | 414 ui_test_utils::NavigateToURL(browser(), page_url); |
| 412 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 415 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 413 | 416 |
| 414 listener.Reply("go"); | 417 listener.Reply("go"); |
| 415 | 418 |
| 416 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 419 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 417 } | 420 } |
| 418 | 421 |
| 419 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) { | 422 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) { |
| 420 ResultCatcher catcher; | 423 ResultCatcher catcher; |
| 421 catcher.RestrictToProfile(browser()->profile()); | 424 catcher.RestrictToProfile(browser()->profile()); |
| 422 | 425 |
| 423 chromeos::BluetoothAdapter::ConstDeviceList devices; | 426 BluetoothAdapter::ConstDeviceList devices; |
| 424 devices.push_back(device1_.get()); | 427 devices.push_back(device1_.get()); |
| 425 | 428 |
| 426 // Save the callback to delay execution so that we can force the calls to | 429 // Save the callback to delay execution so that we can force the calls to |
| 427 // happen concurrently. This will be called after the listener is satisfied. | 430 // happen concurrently. This will be called after the listener is satisfied. |
| 428 chromeos::BluetoothDevice::ProvidesServiceCallback callback; | 431 BluetoothDevice::ProvidesServiceCallback callback; |
| 429 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) | 432 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) |
| 430 .WillOnce(testing::SaveArg<1>(&callback)); | 433 .WillOnce(testing::SaveArg<1>(&callback)); |
| 431 | 434 |
| 432 EXPECT_CALL(*mock_adapter_, GetDevices()) | 435 EXPECT_CALL(*mock_adapter_, GetDevices()) |
| 433 .WillOnce(testing::Return(devices)); | 436 .WillOnce(testing::Return(devices)); |
| 434 | 437 |
| 435 // Load and wait for setup | 438 // Load and wait for setup |
| 436 ExtensionTestMessageListener listener("ready", true); | 439 ExtensionTestMessageListener listener("ready", true); |
| 437 const extensions::Extension* extension = | 440 const Extension* extension = |
| 438 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); | 441 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); |
| 439 GURL page_url = | 442 GURL page_url = |
| 440 extension->GetResourceURL("test_getdevices_concurrently.html"); | 443 extension->GetResourceURL("test_getdevices_concurrently.html"); |
| 441 ui_test_utils::NavigateToURL(browser(), page_url); | 444 ui_test_utils::NavigateToURL(browser(), page_url); |
| 442 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 445 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 443 | 446 |
| 444 callback.Run(false); | 447 callback.Run(false); |
| 445 listener.Reply("go"); | 448 listener.Reply("go"); |
| 446 | 449 |
| 447 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 450 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 448 } | 451 } |
| OLD | NEW |