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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/run_loop.h" |
9 #include "content/browser/browser_thread_impl.h" | 11 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 12 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
11 #include "content/browser/renderer_host/media/media_stream_manager.h" | 13 #include "content/browser/renderer_host/media/media_stream_manager.h" |
12 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 14 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
13 #include "content/browser/renderer_host/media/video_capture_manager.h" | 15 #include "content/browser/renderer_host/media/video_capture_manager.h" |
14 #include "content/common/media/media_stream_messages.h" | 16 #include "content/common/media/media_stream_messages.h" |
15 #include "content/common/media/media_stream_options.h" | 17 #include "content/common/media/media_stream_options.h" |
16 #include "content/public/test/mock_resource_context.h" | 18 #include "content/public/test/mock_resource_context.h" |
17 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "content/test/test_content_browser_client.h" | 20 #include "content/test/test_content_browser_client.h" |
19 #include "content/test/test_content_client.h" | 21 #include "content/test/test_content_client.h" |
20 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
21 #include "media/audio/audio_manager.h" | 23 #include "media/audio/audio_manager.h" |
22 #include "media/video/capture/fake_video_capture_device.h" | 24 #include "media/video/capture/fake_video_capture_device.h" |
23 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 using ::testing::_; | 29 using ::testing::_; |
28 using ::testing::DeleteArg; | 30 using ::testing::DeleteArg; |
29 using ::testing::DoAll; | 31 using ::testing::DoAll; |
30 using ::testing::Return; | 32 using ::testing::Return; |
31 using ::testing::SaveArg; | 33 using ::testing::SaveArg; |
32 | 34 |
33 const int kProcessId = 5; | 35 const int kProcessId = 5; |
34 const int kRenderId = 6; | 36 const int kRenderId = 6; |
35 const int kPageRequestId = 7; | 37 const int kPageRequestId = 7; |
36 | 38 |
37 namespace content { | 39 namespace content { |
38 | 40 |
39 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 41 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
40 public TestContentBrowserClient { | 42 public TestContentBrowserClient { |
41 public: | 43 public: |
42 MockMediaStreamDispatcherHost(base::MessageLoop* message_loop, | 44 MockMediaStreamDispatcherHost( |
43 MediaStreamManager* manager) | 45 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 46 MediaStreamManager* manager) |
44 : MediaStreamDispatcherHost(kProcessId, manager), | 47 : MediaStreamDispatcherHost(kProcessId, manager), |
45 message_loop_(message_loop) {} | 48 message_loop_(message_loop) {} |
46 | 49 |
47 // A list of mock methods. | 50 // A list of mock methods. |
48 MOCK_METHOD4(OnStreamGenerated, | 51 MOCK_METHOD4(OnStreamGenerated, |
49 void(int routing_id, int request_id, int audio_array_size, | 52 void(int routing_id, int request_id, int audio_array_size, |
50 int video_array_size)); | 53 int video_array_size)); |
51 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); | 54 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); |
52 | 55 |
53 // Accessor to private functions. | 56 // Accessor to private functions. |
54 void OnGenerateStream(int page_request_id, const StreamOptions& components) { | 57 void OnGenerateStream(int page_request_id, |
55 MediaStreamDispatcherHost::OnGenerateStream(kRenderId, | 58 const StreamOptions& components, |
56 page_request_id, | 59 const base::Closure& quit_closure) { |
57 components, | 60 quit_closure_ = quit_closure; |
58 GURL()); | 61 MediaStreamDispatcherHost::OnGenerateStream( |
| 62 kRenderId, page_request_id, components, GURL()); |
59 } | 63 } |
| 64 |
60 void OnStopGeneratedStream(const std::string& label) { | 65 void OnStopGeneratedStream(const std::string& label) { |
61 MediaStreamDispatcherHost::OnStopGeneratedStream(kRenderId, label); | 66 MediaStreamDispatcherHost::OnStopGeneratedStream(kRenderId, label); |
62 } | 67 } |
63 | 68 |
64 // Return the number of streams that have been opened or is being open. | 69 // Return the number of streams that have been opened or is being open. |
65 size_t NumberOfStreams() { | 70 size_t NumberOfStreams() { |
66 return streams_.size(); | 71 return streams_.size(); |
67 } | 72 } |
68 | 73 |
69 std::string label_; | 74 std::string label_; |
(...skipping 27 matching lines...) Expand all Loading... |
97 // These handler methods do minimal things and delegate to the mock methods. | 102 // These handler methods do minimal things and delegate to the mock methods. |
98 void OnStreamGenerated( | 103 void OnStreamGenerated( |
99 const IPC::Message& msg, | 104 const IPC::Message& msg, |
100 int request_id, | 105 int request_id, |
101 std::string label, | 106 std::string label, |
102 StreamDeviceInfoArray audio_device_list, | 107 StreamDeviceInfoArray audio_device_list, |
103 StreamDeviceInfoArray video_device_list) { | 108 StreamDeviceInfoArray video_device_list) { |
104 OnStreamGenerated(msg.routing_id(), request_id, audio_device_list.size(), | 109 OnStreamGenerated(msg.routing_id(), request_id, audio_device_list.size(), |
105 video_device_list.size()); | 110 video_device_list.size()); |
106 // Notify that the event have occured. | 111 // Notify that the event have occured. |
107 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 112 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure_)); |
108 label_ = label; | 113 label_ = label; |
109 audio_devices_ = audio_device_list; | 114 audio_devices_ = audio_device_list; |
110 video_devices_ = video_device_list; | 115 video_devices_ = video_device_list; |
111 } | 116 } |
112 | 117 |
113 void OnStreamGenerationFailed(const IPC::Message& msg, int request_id) { | 118 void OnStreamGenerationFailed(const IPC::Message& msg, int request_id) { |
114 OnStreamGenerationFailed(msg.routing_id(), request_id); | 119 OnStreamGenerationFailed(msg.routing_id(), request_id); |
115 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 120 if (!quit_closure_.is_null()) |
| 121 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure_)); |
116 label_= ""; | 122 label_= ""; |
117 } | 123 } |
118 | 124 |
119 base::MessageLoop* message_loop_; | 125 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 126 base::Closure quit_closure_; |
120 }; | 127 }; |
121 | 128 |
122 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { | 129 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { |
123 public: | 130 public: |
124 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); | 131 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); |
125 }; | 132 }; |
126 | 133 |
127 class MediaStreamDispatcherHostTest : public testing::Test { | 134 class MediaStreamDispatcherHostTest : public testing::Test { |
128 public: | 135 public: |
129 MediaStreamDispatcherHostTest() : old_browser_client_(NULL) {} | 136 MediaStreamDispatcherHostTest() |
130 virtual ~MediaStreamDispatcherHostTest() {} | 137 : old_browser_client_(NULL), |
131 | 138 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
132 void WaitForResult() { | |
133 message_loop_->Run(); | |
134 } | |
135 | |
136 protected: | |
137 virtual void SetUp() OVERRIDE { | |
138 // MediaStreamManager must be created and called on IO thread. | |
139 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO)); | |
140 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, | |
141 message_loop_.get())); | |
142 io_thread_.reset(new TestBrowserThread(BrowserThread::IO, | |
143 message_loop_.get())); | |
144 | |
145 // Create our own MediaStreamManager. | 139 // Create our own MediaStreamManager. |
146 audio_manager_.reset(media::AudioManager::Create()); | 140 audio_manager_.reset(media::AudioManager::Create()); |
147 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 141 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
148 // Make sure we use fake devices to avoid long delays. | 142 // Make sure we use fake devices to avoid long delays. |
149 media_stream_manager_->UseFakeDevice(); | 143 media_stream_manager_->UseFakeDevice(); |
150 | 144 |
151 host_ = new MockMediaStreamDispatcherHost(message_loop_.get(), | 145 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), |
152 media_stream_manager_.get()); | 146 media_stream_manager_.get()); |
153 | 147 |
154 // Use the fake content client and browser. | 148 // Use the fake content client and browser. |
155 content_client_.reset(new TestContentClient); | 149 content_client_.reset(new TestContentClient()); |
156 SetContentClient(content_client_.get()); | 150 SetContentClient(content_client_.get()); |
157 old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 151 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
158 } | 152 } |
159 | 153 |
| 154 virtual ~MediaStreamDispatcherHostTest() { |
| 155 // Recover the old browser client and content client. |
| 156 SetBrowserClientForTesting(old_browser_client_); |
| 157 content_client_.reset(); |
| 158 } |
| 159 |
| 160 protected: |
160 virtual void SetupFakeUI(bool expect_started) { | 161 virtual void SetupFakeUI(bool expect_started) { |
161 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); | 162 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
162 if (expect_started) { | 163 if (expect_started) { |
163 EXPECT_CALL(*stream_ui, OnStarted(_)); | 164 EXPECT_CALL(*stream_ui, OnStarted(_)); |
164 } | 165 } |
165 media_stream_manager_->UseFakeUI( | 166 media_stream_manager_->UseFakeUI( |
166 stream_ui.PassAs<FakeMediaStreamUIProxy>()); | 167 stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
167 } | 168 } |
168 | 169 |
169 virtual void TearDown() OVERRIDE { | 170 void GenerateStreamAndWaitForResult(int page_request_id, |
170 message_loop_->RunUntilIdle(); | 171 const StreamOptions& options) { |
171 | 172 base::RunLoop run_loop; |
172 // Recover the old browser client and content client. | 173 host_->OnGenerateStream(page_request_id, options, run_loop.QuitClosure()); |
173 SetBrowserClientForTesting(old_browser_client_); | 174 run_loop.Run(); |
174 content_client_.reset(); | |
175 | |
176 // Delete the IO message loop to delete the device thread, | |
177 // AudioInputDeviceManager and VideoCaptureManager. | |
178 message_loop_.reset(); | |
179 } | 175 } |
180 | 176 |
181 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 177 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
182 scoped_ptr<base::MessageLoop> message_loop_; | |
183 scoped_ptr<TestBrowserThread> ui_thread_; | |
184 scoped_ptr<TestBrowserThread> io_thread_; | |
185 scoped_ptr<media::AudioManager> audio_manager_; | 178 scoped_ptr<media::AudioManager> audio_manager_; |
186 scoped_ptr<MediaStreamManager> media_stream_manager_; | 179 scoped_ptr<MediaStreamManager> media_stream_manager_; |
187 ContentBrowserClient* old_browser_client_; | 180 ContentBrowserClient* old_browser_client_; |
188 scoped_ptr<ContentClient> content_client_; | 181 scoped_ptr<ContentClient> content_client_; |
| 182 content::TestBrowserThreadBundle thread_bundle_; |
189 }; | 183 }; |
190 | 184 |
191 TEST_F(MediaStreamDispatcherHostTest, GenerateStream) { | 185 TEST_F(MediaStreamDispatcherHostTest, GenerateStream) { |
192 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 186 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
193 | 187 |
194 SetupFakeUI(true); | 188 SetupFakeUI(true); |
195 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 189 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
196 host_->OnGenerateStream(kPageRequestId, options); | 190 GenerateStreamAndWaitForResult(kPageRequestId, options); |
197 | |
198 WaitForResult(); | |
199 | 191 |
200 std::string label = host_->label_; | 192 std::string label = host_->label_; |
201 | 193 |
202 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 194 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
203 EXPECT_EQ(host_->video_devices_.size(), 1u); | 195 EXPECT_EQ(host_->video_devices_.size(), 1u); |
204 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 196 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
205 | 197 |
206 host_->OnStopGeneratedStream(label); | 198 host_->OnStopGeneratedStream(label); |
207 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 199 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
208 } | 200 } |
209 | 201 |
210 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) { | 202 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) { |
211 // This test opens three video capture devices. Two fake devices exists and it | 203 // This test opens three video capture devices. Two fake devices exists and it |
212 // is expected the last call to |Open()| will open the first device again, but | 204 // is expected the last call to |Open()| will open the first device again, but |
213 // with a different label. | 205 // with a different label. |
214 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 206 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
215 | 207 |
216 // Generate first stream. | 208 // Generate first stream. |
217 SetupFakeUI(true); | 209 SetupFakeUI(true); |
218 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 210 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
219 host_->OnGenerateStream(kPageRequestId, options); | 211 GenerateStreamAndWaitForResult(kPageRequestId, options); |
220 | |
221 WaitForResult(); | |
222 | 212 |
223 // Check the latest generated stream. | 213 // Check the latest generated stream. |
224 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 214 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
225 EXPECT_EQ(host_->video_devices_.size(), 1u); | 215 EXPECT_EQ(host_->video_devices_.size(), 1u); |
226 std::string label1 = host_->label_; | 216 std::string label1 = host_->label_; |
227 std::string device_id1 = host_->video_devices_.front().device.id; | 217 std::string device_id1 = host_->video_devices_.front().device.id; |
228 | 218 |
229 // Check that we now have one opened streams. | 219 // Check that we now have one opened streams. |
230 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 220 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
231 | 221 |
232 // Generate second stream. | 222 // Generate second stream. |
233 SetupFakeUI(true); | 223 SetupFakeUI(true); |
234 EXPECT_CALL(*host_.get(), | 224 EXPECT_CALL(*host_.get(), |
235 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); | 225 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); |
236 host_->OnGenerateStream(kPageRequestId + 1, options); | 226 GenerateStreamAndWaitForResult(kPageRequestId + 1, options); |
237 | |
238 WaitForResult(); | |
239 | 227 |
240 // Check the latest generated stream. | 228 // Check the latest generated stream. |
241 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 229 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
242 EXPECT_EQ(host_->video_devices_.size(), 1u); | 230 EXPECT_EQ(host_->video_devices_.size(), 1u); |
243 std::string label2 = host_->label_; | 231 std::string label2 = host_->label_; |
244 std::string device_id2 = host_->video_devices_.front().device.id; | 232 std::string device_id2 = host_->video_devices_.front().device.id; |
245 EXPECT_EQ(device_id1, device_id2); | 233 EXPECT_EQ(device_id1, device_id2); |
246 EXPECT_NE(label1, label2); | 234 EXPECT_NE(label1, label2); |
247 | 235 |
248 // Check that we now have two opened streams. | 236 // Check that we now have two opened streams. |
249 EXPECT_EQ(2u, host_->NumberOfStreams()); | 237 EXPECT_EQ(2u, host_->NumberOfStreams()); |
250 | 238 |
251 // Generate third stream. | 239 // Generate third stream. |
252 SetupFakeUI(true); | 240 SetupFakeUI(true); |
253 EXPECT_CALL(*host_.get(), | 241 EXPECT_CALL(*host_.get(), |
254 OnStreamGenerated(kRenderId, kPageRequestId + 2, 0, 1)); | 242 OnStreamGenerated(kRenderId, kPageRequestId + 2, 0, 1)); |
255 host_->OnGenerateStream(kPageRequestId + 2, options); | 243 GenerateStreamAndWaitForResult(kPageRequestId + 2, options); |
256 | |
257 WaitForResult(); | |
258 | 244 |
259 // Check the latest generated stream. | 245 // Check the latest generated stream. |
260 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 246 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
261 EXPECT_EQ(host_->video_devices_.size(), 1u); | 247 EXPECT_EQ(host_->video_devices_.size(), 1u); |
262 std::string label3 = host_->label_; | 248 std::string label3 = host_->label_; |
263 std::string device_id3 = host_->video_devices_.front().device.id; | 249 std::string device_id3 = host_->video_devices_.front().device.id; |
264 EXPECT_EQ(device_id1, device_id3); | 250 EXPECT_EQ(device_id1, device_id3); |
265 EXPECT_NE(label1, label3); | 251 EXPECT_NE(label1, label3); |
266 EXPECT_NE(label2, label3); | 252 EXPECT_NE(label2, label3); |
267 | 253 |
268 // Check that we now have three opened streams. | 254 // Check that we now have three opened streams. |
269 EXPECT_EQ(host_->NumberOfStreams(), 3u); | 255 EXPECT_EQ(host_->NumberOfStreams(), 3u); |
270 | 256 |
271 host_->OnStopGeneratedStream(label1); | 257 host_->OnStopGeneratedStream(label1); |
272 host_->OnStopGeneratedStream(label2); | 258 host_->OnStopGeneratedStream(label2); |
273 host_->OnStopGeneratedStream(label3); | 259 host_->OnStopGeneratedStream(label3); |
274 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 260 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
275 } | 261 } |
276 | 262 |
277 TEST_F(MediaStreamDispatcherHostTest, FailOpenVideoDevice) { | 263 TEST_F(MediaStreamDispatcherHostTest, FailOpenVideoDevice) { |
278 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 264 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
279 | 265 |
280 media::FakeVideoCaptureDevice::SetFailNextCreate(); | 266 media::FakeVideoCaptureDevice::SetFailNextCreate(); |
281 SetupFakeUI(false); | 267 SetupFakeUI(false); |
282 host_->OnGenerateStream(kPageRequestId, options); | |
283 EXPECT_CALL(*host_.get(), | 268 EXPECT_CALL(*host_.get(), |
284 OnStreamGenerationFailed(kRenderId, kPageRequestId)); | 269 OnStreamGenerationFailed(kRenderId, kPageRequestId)); |
285 WaitForResult(); | 270 GenerateStreamAndWaitForResult(kPageRequestId, options); |
286 } | 271 } |
287 | 272 |
288 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { | 273 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { |
289 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 274 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
290 | 275 |
| 276 base::RunLoop run_loop; |
| 277 |
291 // Create multiple GenerateStream requests. | 278 // Create multiple GenerateStream requests. |
292 size_t streams = 5; | 279 size_t streams = 5; |
293 for (size_t i = 1; i <= streams; ++i) { | 280 for (size_t i = 1; i <= streams; ++i) { |
294 host_->OnGenerateStream(kPageRequestId + i, options); | 281 host_->OnGenerateStream( |
| 282 kPageRequestId + i, options, run_loop.QuitClosure()); |
295 EXPECT_EQ(host_->NumberOfStreams(), i); | 283 EXPECT_EQ(host_->NumberOfStreams(), i); |
296 } | 284 } |
297 | 285 |
298 // Calling OnChannelClosing() to cancel all the pending requests. | 286 // Calling OnChannelClosing() to cancel all the pending requests. |
299 host_->OnChannelClosing(); | 287 host_->OnChannelClosing(); |
| 288 run_loop.RunUntilIdle(); |
300 | 289 |
301 // Streams should have been cleaned up. | 290 // Streams should have been cleaned up. |
302 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 291 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
303 } | 292 } |
304 | 293 |
305 TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) { | 294 TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) { |
306 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 295 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
307 | 296 |
308 // Create first group of streams. | 297 // Create first group of streams. |
309 size_t generated_streams = 3; | 298 size_t generated_streams = 3; |
310 for (size_t i = 0; i < generated_streams; ++i) { | 299 for (size_t i = 0; i < generated_streams; ++i) { |
311 SetupFakeUI(true); | 300 SetupFakeUI(true); |
312 EXPECT_CALL(*host_.get(), | 301 EXPECT_CALL(*host_.get(), |
313 OnStreamGenerated(kRenderId, kPageRequestId + i, 0, 1)); | 302 OnStreamGenerated(kRenderId, kPageRequestId + i, 0, 1)); |
314 host_->OnGenerateStream(kPageRequestId + i, options); | 303 GenerateStreamAndWaitForResult(kPageRequestId + i, options); |
315 | |
316 // Wait until the stream is generated. | |
317 WaitForResult(); | |
318 } | 304 } |
319 EXPECT_EQ(host_->NumberOfStreams(), generated_streams); | 305 EXPECT_EQ(host_->NumberOfStreams(), generated_streams); |
320 | 306 |
321 // Calling OnChannelClosing() to cancel all the pending/generated streams. | 307 // Calling OnChannelClosing() to cancel all the pending/generated streams. |
322 host_->OnChannelClosing(); | 308 host_->OnChannelClosing(); |
323 | 309 base::RunLoop().RunUntilIdle(); |
324 message_loop_->RunUntilIdle(); | |
325 | 310 |
326 // Streams should have been cleaned up. | 311 // Streams should have been cleaned up. |
327 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 312 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
328 } | 313 } |
329 | 314 |
330 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { | 315 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { |
331 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 316 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
332 | 317 |
333 base::Closure close_callback; | 318 base::Closure close_callback; |
334 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); | 319 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); |
335 EXPECT_CALL(*stream_ui, OnStarted(_)) | 320 EXPECT_CALL(*stream_ui, OnStarted(_)) |
336 .WillOnce(SaveArg<0>(&close_callback)); | 321 .WillOnce(SaveArg<0>(&close_callback)); |
337 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); | 322 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); |
338 | 323 |
339 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); | 324 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); |
340 EXPECT_CALL(*host_.get(), | 325 EXPECT_CALL(*host_.get(), |
341 OnStreamGenerationFailed(kRenderId, kPageRequestId)); | 326 OnStreamGenerationFailed(kRenderId, kPageRequestId)); |
342 host_->OnGenerateStream(kPageRequestId, options); | 327 GenerateStreamAndWaitForResult(kPageRequestId, options); |
343 | |
344 WaitForResult(); | |
345 | 328 |
346 EXPECT_EQ(host_->audio_devices_.size(), 0u); | 329 EXPECT_EQ(host_->audio_devices_.size(), 0u); |
347 EXPECT_EQ(host_->video_devices_.size(), 1u); | 330 EXPECT_EQ(host_->video_devices_.size(), 1u); |
348 EXPECT_EQ(host_->NumberOfStreams(), 1u); | 331 EXPECT_EQ(host_->NumberOfStreams(), 1u); |
349 | 332 |
350 ASSERT_FALSE(close_callback.is_null()); | 333 ASSERT_FALSE(close_callback.is_null()); |
351 close_callback.Run(); | 334 close_callback.Run(); |
352 message_loop_->RunUntilIdle(); | 335 base::RunLoop().RunUntilIdle(); |
353 | 336 |
354 EXPECT_EQ(host_->NumberOfStreams(), 0u); | 337 EXPECT_EQ(host_->NumberOfStreams(), 0u); |
355 } | 338 } |
356 | 339 |
357 }; // namespace content | 340 }; // namespace content |
OLD | NEW |