Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698