| 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 "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 6 #include "chrome/test/base/testing_profile.h" | 6 #include "chrome/test/base/testing_profile.h" |
| 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 7 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace { | |
| 12 | |
| 13 const char* kAdapterAddress = "Mock Adapter address for testing"; | |
| 14 const char* kName = "Mock Adapter name for testing"; | |
| 15 | |
| 16 } // namespace | |
| 17 | |
| 18 namespace extensions { | 11 namespace extensions { |
| 19 | 12 |
| 20 class ExtensionBluetoothEventRouterTest : public testing::Test { | 13 class ExtensionBluetoothEventRouterTest : public testing::Test { |
| 21 public: | 14 public: |
| 22 ExtensionBluetoothEventRouterTest() | 15 ExtensionBluetoothEventRouterTest() |
| 23 : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>( | 16 : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()), |
| 24 kAdapterAddress, kName)), | |
| 25 router_(&test_profile_) { | 17 router_(&test_profile_) { |
| 26 router_.SetAdapterForTest(mock_adapter_); | 18 router_.SetAdapterForTest(mock_adapter_); |
| 27 } | 19 } |
| 28 | 20 |
| 29 protected: | 21 protected: |
| 30 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; | 22 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; |
| 31 TestingProfile test_profile_; | 23 TestingProfile test_profile_; |
| 32 ExtensionBluetoothEventRouter router_; | 24 ExtensionBluetoothEventRouter router_; |
| 33 }; | 25 }; |
| 34 | 26 |
| 35 TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) { | 27 TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) { |
| 36 router_.OnListenerAdded(); | 28 router_.OnListenerAdded(); |
| 37 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 29 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 38 router_.OnListenerRemoved(); | 30 router_.OnListenerRemoved(); |
| 39 } | 31 } |
| 40 | 32 |
| 41 TEST_F(ExtensionBluetoothEventRouterTest, MultipleBluetoothEventListeners) { | 33 TEST_F(ExtensionBluetoothEventRouterTest, MultipleBluetoothEventListeners) { |
| 42 router_.OnListenerAdded(); | 34 router_.OnListenerAdded(); |
| 43 router_.OnListenerAdded(); | 35 router_.OnListenerAdded(); |
| 44 router_.OnListenerAdded(); | 36 router_.OnListenerAdded(); |
| 45 router_.OnListenerRemoved(); | 37 router_.OnListenerRemoved(); |
| 46 router_.OnListenerRemoved(); | 38 router_.OnListenerRemoved(); |
| 47 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 39 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 48 router_.OnListenerRemoved(); | 40 router_.OnListenerRemoved(); |
| 49 } | 41 } |
| 50 | 42 |
| 51 } // namespace extensions | 43 } // namespace extensions |
| OLD | NEW |