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/bluetooth_event_router.h" |
| 6 #include "chrome/browser/extensions/event_names.h" |
| 7 #include "chrome/test/base/testing_profile.h" |
| 8 #include "device/bluetooth/test/mock_bluetooth_adapter.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 const char* kNonBluetoothEventName = "Non bluetooth event name"; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 namespace extensions { |
| 21 |
| 22 class ExtensionBluetoothEventRouterTest : public testing::Test { |
| 23 public: |
| 24 ExtensionBluetoothEventRouterTest() |
| 25 : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>( |
| 26 kAdapterAddress, kName)), |
| 27 router_(&profile_, mock_adapter_) { |
| 28 } |
| 29 |
| 30 virtual ~ExtensionBluetoothEventRouterTest() { |
| 31 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); |
| 32 } |
| 33 |
| 34 protected: |
| 35 TestingProfile profile_; |
| 36 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; |
| 37 ExtensionBluetoothEventRouter router_; |
| 38 }; |
| 39 |
| 40 TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListenerAdded) { |
| 41 EXPECT_CALL(*mock_adapter_, AddObserver(testing::_)) |
| 42 .WillOnce(testing::Return()); |
| 43 router_.OnEventListenerAdded( |
| 44 extensions::event_names::kBluetoothOnAvailabilityChanged); |
| 45 } |
| 46 |
| 47 TEST_F(ExtensionBluetoothEventRouterTest, NonBluetoothEventListenerAdded) { |
| 48 router_.OnEventListenerAdded(kNonBluetoothEventName); |
| 49 } |
| 50 |
| 51 TEST_F(ExtensionBluetoothEventRouterTest, |
| 52 BluetoothEventListenerAddedTwiceButAddObserverOnce) { |
| 53 EXPECT_CALL(*mock_adapter_, AddObserver(testing::_)) |
| 54 .WillOnce(testing::Return()); |
| 55 router_.OnEventListenerAdded( |
| 56 extensions::event_names::kBluetoothOnAvailabilityChanged); |
| 57 router_.OnEventListenerAdded( |
| 58 extensions::event_names::kBluetoothOnAvailabilityChanged); |
| 59 } |
| 60 |
| 61 } // namespace extensions |
OLD | NEW |