| 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/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" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 12 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
| 19 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 19 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
| 20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 20 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 21 #include "device/bluetooth/test/mock_bluetooth_device.h" | 21 #include "device/bluetooth/test/mock_bluetooth_device.h" |
| 22 #include "device/bluetooth/test/mock_bluetooth_socket.h" | 22 #include "device/bluetooth/test/mock_bluetooth_socket.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 | 24 |
| 25 using device::BluetoothAdapter; | 25 using device::BluetoothAdapter; |
| 26 using device::BluetoothDevice; | 26 using device::BluetoothDevice; |
| 27 using device::BluetoothOutOfBandPairingData; | 27 using device::BluetoothOutOfBandPairingData; |
| 28 using device::MockBluetoothAdapter; | 28 using device::MockBluetoothAdapter; |
| 29 using device::MockBluetoothDevice; | 29 using device::MockBluetoothDevice; |
| 30 using extensions::Extension; | |
| 31 | 30 |
| 32 namespace utils = extension_function_test_utils; | 31 namespace utils = extension_function_test_utils; |
| 33 namespace api = extensions::api; | 32 |
| 33 namespace extensions { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6"; | 37 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6"; |
| 38 static const char* kName = "whatsinaname"; | 38 static const char* kName = "whatsinaname"; |
| 39 | 39 |
| 40 class BluetoothApiTest : public ExtensionApiTest { | 40 class BluetoothApiTest : public ExtensionApiTest { |
| 41 public: | 41 public: |
| 42 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} | 42 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} |
| 43 | 43 |
| 44 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 44 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 45 ExtensionApiTest::SetUpCommandLine(command_line); | 45 ExtensionApiTest::SetUpCommandLine(command_line); |
| 46 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 46 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual void SetUpOnMainThread() OVERRIDE { | 49 virtual void SetUpOnMainThread() OVERRIDE { |
| 50 ExtensionApiTest::SetUpOnMainThread(); |
| 50 SetUpMockAdapter(); | 51 SetUpMockAdapter(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 virtual void CleanUpOnMainThread() OVERRIDE { | 54 virtual void CleanUpOnMainThread() OVERRIDE { |
| 54 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); | 55 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); |
| 56 ExtensionApiTest::CleanUpOnMainThread(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void SetUpMockAdapter() { | 59 void SetUpMockAdapter() { |
| 58 // The browser will clean this up when it is torn down | 60 // The browser will clean this up when it is torn down |
| 59 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>( | 61 mock_adapter_ = new testing::StrictMock<MockBluetoothAdapter>( |
| 60 kAdapterAddress, kName); | 62 kAdapterAddress, kName); |
| 61 event_router()->SetAdapterForTest(mock_adapter_); | 63 event_router()->SetAdapterForTest(mock_adapter_); |
| 62 | 64 |
| 63 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( | 65 device1_.reset(new testing::NiceMock<MockBluetoothDevice>( |
| 64 mock_adapter_, "d1", "11:12:13:14:15:16", | 66 mock_adapter_, "d1", "11:12:13:14:15:16", |
| 65 true /* paired */, false /* bonded */, true /* connected */)); | 67 true /* paired */, false /* bonded */, true /* connected */)); |
| 66 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( | 68 device2_.reset(new testing::NiceMock<MockBluetoothDevice>( |
| 67 mock_adapter_, "d2", "21:22:23:24:25:26", | 69 mock_adapter_, "d2", "21:22:23:24:25:26", |
| 68 false /* paired */, true /* bonded */, false /* connected */)); | 70 false /* paired */, true /* bonded */, false /* connected */)); |
| 69 } | 71 } |
| 70 | 72 |
| 71 template <class T> | 73 template <class T> |
| 72 T* setupFunction(T* function) { | 74 T* setupFunction(T* function) { |
| 73 function->set_extension(empty_extension_.get()); | 75 function->set_extension(empty_extension_.get()); |
| 74 function->set_has_callback(true); | 76 function->set_has_callback(true); |
| 75 return function; | 77 return function; |
| 76 } | 78 } |
| 77 | 79 |
| 78 protected: | 80 protected: |
| 79 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; | 81 testing::StrictMock<MockBluetoothAdapter>* mock_adapter_; |
| 80 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; | 82 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device1_; |
| 81 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; | 83 scoped_ptr<testing::NiceMock<MockBluetoothDevice> > device2_; |
| 82 | 84 |
| 83 extensions::ExtensionBluetoothEventRouter* event_router() { | 85 ExtensionBluetoothEventRouter* event_router() { |
| 84 return extensions::BluetoothAPI::Get(browser()->profile()) | 86 return BluetoothAPI::Get(browser()->profile())->bluetooth_event_router(); |
| 85 ->bluetooth_event_router(); | |
| 86 } | 87 } |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 scoped_refptr<Extension> empty_extension_; | 90 scoped_refptr<Extension> empty_extension_; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 // This is the canonical UUID for the short UUID 0010. | 93 // This is the canonical UUID for the short UUID 0010. |
| 93 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; | 94 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; |
| 94 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; | 95 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; |
| 95 | 96 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 473 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 473 | 474 |
| 474 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address())) | 475 EXPECT_CALL(*mock_adapter_, GetDevice(device1_->address())) |
| 475 .WillOnce(testing::Return(device1_.get())); | 476 .WillOnce(testing::Return(device1_.get())); |
| 476 EXPECT_CALL(*device1_, | 477 EXPECT_CALL(*device1_, |
| 477 ConnectToService(testing::_, testing::_)) | 478 ConnectToService(testing::_, testing::_)) |
| 478 .WillOnce(testing::Invoke(CallConnectToServiceCallback)); | 479 .WillOnce(testing::Invoke(CallConnectToServiceCallback)); |
| 479 | 480 |
| 480 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_; | 481 EXPECT_TRUE(RunExtensionTest("bluetooth/permissions")) << message_; |
| 481 } | 482 } |
| 483 |
| 484 } // namespace extensions |
| OLD | NEW |