OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/mock_resource_context.h" | 10 #include "content/browser/mock_resource_context.h" |
10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 11 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
11 #include "content/browser/renderer_host/media/media_stream_manager.h" | 12 #include "content/browser/renderer_host/media/media_stream_manager.h" |
12 #include "content/browser/renderer_host/media/video_capture_manager.h" | 13 #include "content/browser/renderer_host/media/video_capture_manager.h" |
13 #include "content/browser/resource_context.h" | 14 #include "content/browser/resource_context.h" |
14 #include "content/common/media/media_stream_messages.h" | 15 #include "content/common/media/media_stream_messages.h" |
15 #include "content/common/media/media_stream_options.h" | 16 #include "content/common/media/media_stream_options.h" |
16 #include "content/test/test_browser_thread.h" | |
17 #include "ipc/ipc_message_macros.h" | 17 #include "ipc/ipc_message_macros.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 using ::testing::_; | 21 using ::testing::_; |
22 using ::testing::DeleteArg; | 22 using ::testing::DeleteArg; |
23 using ::testing::DoAll; | 23 using ::testing::DoAll; |
24 using ::testing::Return; | 24 using ::testing::Return; |
25 | 25 |
| 26 using content::BrowserThreadImpl; |
| 27 |
26 const int kProcessId = 5; | 28 const int kProcessId = 5; |
27 const int kRenderId = 6; | 29 const int kRenderId = 6; |
28 const int kPageRequestId = 7; | 30 const int kPageRequestId = 7; |
29 | 31 |
30 namespace media_stream { | 32 namespace media_stream { |
31 | 33 |
32 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost { | 34 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost { |
33 public: | 35 public: |
34 MockMediaStreamDispatcherHost(content::ResourceContext* resource_context, | 36 MockMediaStreamDispatcherHost(content::ResourceContext* resource_context, |
35 MessageLoop* message_loop) | 37 MessageLoop* message_loop) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 class MediaStreamDispatcherHostTest : public testing::Test { | 137 class MediaStreamDispatcherHostTest : public testing::Test { |
136 public: | 138 public: |
137 void WaitForResult() { | 139 void WaitForResult() { |
138 message_loop_->Run(); | 140 message_loop_->Run(); |
139 } | 141 } |
140 | 142 |
141 protected: | 143 protected: |
142 virtual void SetUp() { | 144 virtual void SetUp() { |
143 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); | 145 message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); |
144 // ResourceContext must be created on UI thread. | 146 // ResourceContext must be created on UI thread. |
145 ui_thread_.reset(new content::TestBrowserThread(BrowserThread::UI, | 147 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, |
146 message_loop_.get())); | 148 message_loop_.get())); |
147 // MediaStreamManager must be created and called on IO thread. | 149 // MediaStreamManager must be created and called on IO thread. |
148 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO, | 150 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
149 message_loop_.get())); | 151 message_loop_.get())); |
150 | 152 |
151 // Create a MediaStreamManager instance and hand over pointer to | 153 // Create a MediaStreamManager instance and hand over pointer to |
152 // ResourceContext. | 154 // ResourceContext. |
153 media_stream_manager_.reset(new MediaStreamManager()); | 155 media_stream_manager_.reset(new MediaStreamManager()); |
154 // Make sure we use fake devices to avoid long delays. | 156 // Make sure we use fake devices to avoid long delays. |
155 media_stream_manager_->UseFakeDevice(); | 157 media_stream_manager_->UseFakeDevice(); |
156 content::MockResourceContext::GetInstance()->set_media_stream_manager( | 158 content::MockResourceContext::GetInstance()->set_media_stream_manager( |
157 media_stream_manager_.get()); | 159 media_stream_manager_.get()); |
158 | 160 |
159 host_ = new MockMediaStreamDispatcherHost( | 161 host_ = new MockMediaStreamDispatcherHost( |
(...skipping 29 matching lines...) Expand all Loading... |
189 void SyncWithVideoCaptureManagerThread() { | 191 void SyncWithVideoCaptureManagerThread() { |
190 message_loop_->PostTask( | 192 message_loop_->PostTask( |
191 FROM_HERE, | 193 FROM_HERE, |
192 base::Bind(&PostQuitOnVideoCaptureManagerThread, | 194 base::Bind(&PostQuitOnVideoCaptureManagerThread, |
193 message_loop_.get(), media_stream_manager_.get())); | 195 message_loop_.get(), media_stream_manager_.get())); |
194 message_loop_->Run(); | 196 message_loop_->Run(); |
195 } | 197 } |
196 | 198 |
197 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 199 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
198 scoped_ptr<MessageLoop> message_loop_; | 200 scoped_ptr<MessageLoop> message_loop_; |
199 scoped_ptr<content::TestBrowserThread> ui_thread_; | 201 scoped_ptr<BrowserThreadImpl> ui_thread_; |
200 scoped_ptr<content::TestBrowserThread> io_thread_; | 202 scoped_ptr<BrowserThreadImpl> io_thread_; |
201 scoped_ptr<MediaStreamManager> media_stream_manager_; | 203 scoped_ptr<MediaStreamManager> media_stream_manager_; |
202 }; | 204 }; |
203 | 205 |
204 TEST_F(MediaStreamDispatcherHostTest, GenerateStream) { | 206 TEST_F(MediaStreamDispatcherHostTest, GenerateStream) { |
205 StreamOptions options(false, StreamOptions::kFacingUser); | 207 StreamOptions options(false, StreamOptions::kFacingUser); |
206 | 208 |
207 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 209 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
208 host_->OnGenerateStream(kPageRequestId, options); | 210 host_->OnGenerateStream(kPageRequestId, options); |
209 | 211 |
210 WaitForResult(); | 212 WaitForResult(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 EXPECT_EQ(host_->video_devices_.size(), 0u); | 275 EXPECT_EQ(host_->video_devices_.size(), 0u); |
274 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 276 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
275 | 277 |
276 // TODO(perkj): test audio device failure? | 278 // TODO(perkj): test audio device failure? |
277 | 279 |
278 host_->OnStopGeneratedStream(label); | 280 host_->OnStopGeneratedStream(label); |
279 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 281 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
280 } | 282 } |
281 | 283 |
282 }; // namespace media_stream | 284 }; // namespace media_stream |
OLD | NEW |