| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 protected: | 94 protected: |
| 95 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; | 95 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; |
| 96 scoped_ptr<testing::NiceMock<MockBluetoothDiscoverySession> > mock_session_; | 96 scoped_ptr<testing::NiceMock<MockBluetoothDiscoverySession> > mock_session_; |
| 97 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; | 97 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; |
| 98 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; | 98 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; |
| 99 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device3_; | 99 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device3_; |
| 100 scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile1_; | 100 scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile1_; |
| 101 scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile2_; | 101 scoped_ptr<testing::NiceMock<MockBluetoothProfile> > profile2_; |
| 102 | 102 |
| 103 extensions::ExtensionBluetoothEventRouter* event_router() { | 103 extensions::ExtensionBluetoothEventRouter* event_router() { |
| 104 return extensions::BluetoothAPI::Get(browser()->profile()) | 104 return bluetooth_api()->event_router(); |
| 105 ->bluetooth_event_router(); | 105 } |
| 106 |
| 107 extensions::BluetoothAPI* bluetooth_api() { |
| 108 return extensions::BluetoothAPI::Get(browser()->profile()); |
| 106 } | 109 } |
| 107 | 110 |
| 108 private: | 111 private: |
| 109 scoped_refptr<Extension> empty_extension_; | 112 scoped_refptr<Extension> empty_extension_; |
| 110 }; | 113 }; |
| 111 | 114 |
| 112 class TestBluetoothAddProfileFunction | 115 class TestBluetoothAddProfileFunction |
| 113 : public api::BluetoothAddProfileFunction { | 116 : public api::BluetoothAddProfileFunction { |
| 114 public: | 117 public: |
| 115 explicit TestBluetoothAddProfileFunction(BluetoothProfile* profile) | 118 explicit TestBluetoothAddProfileFunction(BluetoothProfile* profile) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 143 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, | 146 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, |
| 144 device::kBluetoothOutOfBandPairingDataSize); | 147 device::kBluetoothOutOfBandPairingDataSize); |
| 145 return data; | 148 return data; |
| 146 } | 149 } |
| 147 | 150 |
| 148 static bool CallClosure(const base::Closure& callback) { | 151 static bool CallClosure(const base::Closure& callback) { |
| 149 callback.Run(); | 152 callback.Run(); |
| 150 return true; | 153 return true; |
| 151 } | 154 } |
| 152 | 155 |
| 156 static bool CallErrorClosure(const BluetoothDevice::ErrorCallback& callback) { |
| 157 callback.Run("<error>"); |
| 158 return true; |
| 159 } |
| 160 |
| 153 static void StopDiscoverySessionCallback(const base::Closure& callback, | 161 static void StopDiscoverySessionCallback(const base::Closure& callback, |
| 154 const base::Closure& error_callback) { | 162 const base::Closure& error_callback) { |
| 155 callback.Run(); | 163 callback.Run(); |
| 156 } | 164 } |
| 157 | 165 |
| 158 static void CallOutOfBandPairingDataCallback( | 166 static void CallOutOfBandPairingDataCallback( |
| 159 const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, | 167 const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, |
| 160 const BluetoothAdapter::ErrorCallback& error_callback) { | 168 const BluetoothAdapter::ErrorCallback& error_callback) { |
| 161 callback.Run(GetOutOfBandPairingData()); | 169 callback.Run(GetOutOfBandPairingData()); |
| 162 } | 170 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 new api::BluetoothSetOutOfBandPairingDataFunction); | 315 new api::BluetoothSetOutOfBandPairingDataFunction); |
| 308 // There isn't actually a result. | 316 // There isn't actually a result. |
| 309 (void) utils::RunFunctionAndReturnSingleResult( | 317 (void) utils::RunFunctionAndReturnSingleResult( |
| 310 set_oob_function.get(), params, browser()); | 318 set_oob_function.get(), params, browser()); |
| 311 | 319 |
| 312 // Try again with an error | 320 // Try again with an error |
| 313 testing::Mock::VerifyAndClearExpectations(mock_adapter_); | 321 testing::Mock::VerifyAndClearExpectations(mock_adapter_); |
| 314 testing::Mock::VerifyAndClearExpectations(device1_.get()); | 322 testing::Mock::VerifyAndClearExpectations(device1_.get()); |
| 315 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) | 323 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->GetAddress())) |
| 316 .WillOnce(testing::Return(device1_.get())); | 324 .WillOnce(testing::Return(device1_.get())); |
| 317 EXPECT_CALL(*device1_, | 325 EXPECT_CALL( |
| 318 ClearOutOfBandPairingData(testing::_, | 326 *device1_, |
| 319 testing::Truly(CallClosure))); | 327 ClearOutOfBandPairingData(testing::_, testing::Truly(CallErrorClosure))); |
| 320 | 328 |
| 321 set_oob_function = setupFunction( | 329 set_oob_function = setupFunction( |
| 322 new api::BluetoothSetOutOfBandPairingDataFunction); | 330 new api::BluetoothSetOutOfBandPairingDataFunction); |
| 323 std::string error(utils::RunFunctionAndReturnError( | 331 std::string error(utils::RunFunctionAndReturnError( |
| 324 set_oob_function.get(), params, browser())); | 332 set_oob_function.get(), params, browser())); |
| 325 EXPECT_FALSE(error.empty()); | 333 EXPECT_FALSE(error.empty()); |
| 326 | 334 |
| 327 // TODO(bryeung): Also test setting the data when there is support for | 335 // TODO(bryeung): Also test setting the data when there is support for |
| 328 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. | 336 // ArrayBuffers in the arguments to the RunFunctionAnd* methods. |
| 329 // crbug.com/132796 | 337 // crbug.com/132796 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 ExtensionTestMessageListener listener("ready", true); | 560 ExtensionTestMessageListener listener("ready", true); |
| 553 scoped_refptr<const Extension> extension( | 561 scoped_refptr<const Extension> extension( |
| 554 LoadExtension(test_data_dir_.AppendASCII("bluetooth/on_connection"))); | 562 LoadExtension(test_data_dir_.AppendASCII("bluetooth/on_connection"))); |
| 555 ASSERT_TRUE(extension.get()); | 563 ASSERT_TRUE(extension.get()); |
| 556 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 564 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 557 | 565 |
| 558 scoped_refptr<device::MockBluetoothSocket> socket = | 566 scoped_refptr<device::MockBluetoothSocket> socket = |
| 559 new device::MockBluetoothSocket(); | 567 new device::MockBluetoothSocket(); |
| 560 | 568 |
| 561 event_router()->AddProfile("1234", extension->id(), profile1_.get()); | 569 event_router()->AddProfile("1234", extension->id(), profile1_.get()); |
| 562 event_router()->DispatchConnectionEvent( | 570 bluetooth_api()->DispatchConnectionEvent( |
| 563 extension->id(), "1234", device1_.get(), socket); | 571 extension->id(), "1234", device1_.get(), socket); |
| 564 | 572 |
| 565 listener.Reply("go"); | 573 listener.Reply("go"); |
| 566 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 574 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 567 event_router()->RemoveProfile("1234"); | 575 event_router()->RemoveProfile("1234"); |
| 568 } | 576 } |
| 569 | 577 |
| 570 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetProfiles) { | 578 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetProfiles) { |
| 571 ResultCatcher catcher; | 579 ResultCatcher catcher; |
| 572 catcher.RestrictToProfile(browser()->profile()); | 580 catcher.RestrictToProfile(browser()->profile()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 // Load and wait for setup | 615 // Load and wait for setup |
| 608 ExtensionTestMessageListener listener("ready", true); | 616 ExtensionTestMessageListener listener("ready", true); |
| 609 ASSERT_TRUE( | 617 ASSERT_TRUE( |
| 610 LoadExtension(test_data_dir_.AppendASCII("bluetooth/get_devices"))); | 618 LoadExtension(test_data_dir_.AppendASCII("bluetooth/get_devices"))); |
| 611 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 619 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 612 | 620 |
| 613 listener.Reply("go"); | 621 listener.Reply("go"); |
| 614 | 622 |
| 615 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 623 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 616 } | 624 } |
| OLD | NEW |