| 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> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 12 #include "chrome/browser/extensions/event_names.h" | 11 #include "chrome/browser/extensions/event_names.h" |
| 13 #include "chrome/browser/extensions/event_router.h" | 12 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "chrome/browser/extensions/extension_system_factory.h" | 13 #include "chrome/browser/extensions/extension_system_factory.h" |
| 15 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
| 16 #include "chrome/common/extensions/api/bluetooth.h" | 15 #include "chrome/common/extensions/api/bluetooth.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 18 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 20 #include "device/bluetooth/test/mock_bluetooth_device.h" | 19 #include "device/bluetooth/test/mock_bluetooth_device.h" |
| 21 #include "device/bluetooth/test/mock_bluetooth_profile.h" | 20 #include "device/bluetooth/test/mock_bluetooth_profile.h" |
| 22 #include "device/bluetooth/test/mock_bluetooth_socket.h" | 21 #include "device/bluetooth/test/mock_bluetooth_socket.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 const char kAudioProfileUuid[] = "audio profile uuid"; | 27 const char kAudioProfileUuid[] = "audio profile uuid"; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 79 |
| 81 namespace extensions { | 80 namespace extensions { |
| 82 | 81 |
| 83 namespace bluetooth = api::bluetooth; | 82 namespace bluetooth = api::bluetooth; |
| 84 | 83 |
| 85 class ExtensionBluetoothEventRouterTest : public testing::Test { | 84 class ExtensionBluetoothEventRouterTest : public testing::Test { |
| 86 public: | 85 public: |
| 87 ExtensionBluetoothEventRouterTest() | 86 ExtensionBluetoothEventRouterTest() |
| 88 : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()), | 87 : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()), |
| 89 test_profile_(new TestingProfile()), | 88 test_profile_(new TestingProfile()), |
| 90 router_(test_profile_.get()), | 89 router_(test_profile_.get()) { |
| 91 ui_thread_(content::BrowserThread::UI, &message_loop_) { | |
| 92 router_.SetAdapterForTest(mock_adapter_); | 90 router_.SetAdapterForTest(mock_adapter_); |
| 93 } | 91 } |
| 94 | 92 |
| 95 virtual void TearDown() OVERRIDE { | 93 virtual void TearDown() OVERRIDE { |
| 96 // Some profile-dependent services rely on UI thread to clean up. We make | 94 // Some profile-dependent services rely on UI thread to clean up. We make |
| 97 // sure they are properly cleaned up by running the UI message loop until | 95 // sure they are properly cleaned up by running the UI message loop until |
| 98 // idle. | 96 // idle. |
| 99 test_profile_.reset(NULL); | 97 test_profile_.reset(); |
| 100 base::RunLoop run_loop; | 98 base::RunLoop().RunUntilIdle(); |
| 101 run_loop.RunUntilIdle(); | |
| 102 } | 99 } |
| 103 | 100 |
| 104 protected: | 101 protected: |
| 102 content::TestBrowserThreadBundle thread_bundle_; |
| 105 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; | 103 testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; |
| 106 testing::NiceMock<device::MockBluetoothProfile> mock_audio_profile_; | 104 testing::NiceMock<device::MockBluetoothProfile> mock_audio_profile_; |
| 107 testing::NiceMock<device::MockBluetoothProfile> mock_health_profile_; | 105 testing::NiceMock<device::MockBluetoothProfile> mock_health_profile_; |
| 108 scoped_ptr<TestingProfile> test_profile_; | 106 scoped_ptr<TestingProfile> test_profile_; |
| 109 ExtensionBluetoothEventRouter router_; | 107 ExtensionBluetoothEventRouter router_; |
| 110 base::MessageLoopForUI message_loop_; | |
| 111 content::TestBrowserThread ui_thread_; | |
| 112 }; | 108 }; |
| 113 | 109 |
| 114 TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) { | 110 TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) { |
| 115 router_.OnListenerAdded(); | 111 router_.OnListenerAdded(); |
| 116 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 112 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 117 router_.OnListenerRemoved(); | 113 router_.OnListenerRemoved(); |
| 118 } | 114 } |
| 119 | 115 |
| 120 TEST_F(ExtensionBluetoothEventRouterTest, MultipleBluetoothEventListeners) { | 116 TEST_F(ExtensionBluetoothEventRouterTest, MultipleBluetoothEventListeners) { |
| 121 router_.OnListenerAdded(); | 117 router_.OnListenerAdded(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 &mock_device, | 201 &mock_device, |
| 206 mock_socket); | 202 mock_socket); |
| 207 FakeEventRouter* fake_event_router = | 203 FakeEventRouter* fake_event_router = |
| 208 static_cast<FakeEventRouter*>(fake_extension_system->event_router()); | 204 static_cast<FakeEventRouter*>(fake_extension_system->event_router()); |
| 209 EXPECT_TRUE(fake_event_router->event() == NULL); | 205 EXPECT_TRUE(fake_event_router->event() == NULL); |
| 210 | 206 |
| 211 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); | 207 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)).Times(1); |
| 212 } | 208 } |
| 213 | 209 |
| 214 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |