OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 6 #include "chrome/test/base/testing_profile.h" |
| 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 8 #include "device/bluetooth/test/mock_bluetooth_socket.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const char* kAdapterAddress = "Mock Adapter address for testing"; |
| 15 const char* kName = "Mock Adapter name for testing"; |
| 16 |
| 17 const int kSocketId = 1; |
| 18 const int kAnotherSocketId = 2; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 namespace extensions { |
| 23 |
| 24 class ExtensionBluetoothEventRouterTest : public testing::Test { |
| 25 public: |
| 26 ExtensionBluetoothEventRouterTest() |
| 27 : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>( |
| 28 kAdapterAddress, kName)), |
| 29 mock_socket_(new testing::NiceMock<device::MockBluetoothSocket>()), |
| 30 mock_another_socket_( |
| 31 new testing::NiceMock<device::MockBluetoothSocket>()), |
| 32 router_(&test_profile_) { |
| 33 router_.SetAdapterForTest(mock_adapter_); |
| 34 } |
| 35 |
| 36 protected: |
| 37 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; |
| 38 testing::NiceMock<device::MockBluetoothSocket>* mock_socket_; |
| 39 testing::NiceMock<device::MockBluetoothSocket>* mock_another_socket_; |
| 40 TestingProfile test_profile_; |
| 41 ExtensionBluetoothEventRouter router_; |
| 42 }; |
| 43 |
| 44 TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) { |
| 45 router_.OnListenerAdded(); |
| 46 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 47 router_.OnListenerRemoved(); |
| 48 } |
| 49 |
| 50 TEST_F(ExtensionBluetoothEventRouterTest, MultipleBluetoothEventListeners) { |
| 51 router_.OnListenerAdded(); |
| 52 router_.OnListenerAdded(); |
| 53 router_.OnListenerAdded(); |
| 54 router_.OnListenerRemoved(); |
| 55 router_.OnListenerRemoved(); |
| 56 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 57 router_.OnListenerRemoved(); |
| 58 } |
| 59 |
| 60 TEST_F(ExtensionBluetoothEventRouterTest, RegisterSocket) { |
| 61 EXPECT_CALL(*mock_socket_, fd()).WillRepeatedly(testing::Return(kSocketId)); |
| 62 int socket_id = router_.RegisterSocket(mock_socket_); |
| 63 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 64 router_.ReleaseSocket(socket_id); |
| 65 } |
| 66 |
| 67 TEST_F(ExtensionBluetoothEventRouterTest, RegisterMultipleSockets) { |
| 68 EXPECT_CALL(*mock_socket_, fd()).WillRepeatedly(testing::Return(kSocketId)); |
| 69 int socket_id = router_.RegisterSocket(mock_socket_); |
| 70 EXPECT_CALL(*mock_another_socket_, fd()) |
| 71 .WillRepeatedly(testing::Return(kAnotherSocketId)); |
| 72 int another_socket_id = router_.RegisterSocket(mock_another_socket_); |
| 73 router_.ReleaseSocket(another_socket_id); |
| 74 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 75 router_.ReleaseSocket(socket_id); |
| 76 } |
| 77 |
| 78 TEST_F(ExtensionBluetoothEventRouterTest, RegisterSameSockets) { |
| 79 EXPECT_CALL(*mock_socket_, fd()).WillRepeatedly(testing::Return(kSocketId)); |
| 80 int socket_id = router_.RegisterSocket(mock_socket_); |
| 81 socket_id = router_.RegisterSocket(mock_socket_); |
| 82 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 83 router_.ReleaseSocket(socket_id); |
| 84 } |
| 85 |
| 86 TEST_F(ExtensionBluetoothEventRouterTest, AddEventListerAndSocket) { |
| 87 EXPECT_CALL(*mock_socket_, fd()).WillRepeatedly(testing::Return(kSocketId)); |
| 88 int socket_id = router_.RegisterSocket(mock_socket_); |
| 89 router_.OnListenerAdded(); |
| 90 router_.ReleaseSocket(socket_id); |
| 91 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 92 router_.OnListenerRemoved(); |
| 93 } |
| 94 |
| 95 TEST_F(ExtensionBluetoothEventRouterTest, AddSocketAndEventListener) { |
| 96 EXPECT_CALL(*mock_socket_, fd()).WillRepeatedly(testing::Return(kSocketId)); |
| 97 router_.OnListenerAdded(); |
| 98 int socket_id = router_.RegisterSocket(mock_socket_); |
| 99 router_.OnListenerRemoved(); |
| 100 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 101 router_.ReleaseSocket(socket_id); |
| 102 } |
| 103 |
| 104 } // namespace extensions |
OLD | NEW |