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