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

Side by Side Diff: content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc

Issue 10928043: Media Related changes for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename REQUEST_*->MEDIA_REQUEST_* Created 8 years, 2 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/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/browser_thread_impl.h"
10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 10 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 MOCK_METHOD2(OnVideoDeviceFailed, void(int routing_id, int index)); 55 MOCK_METHOD2(OnVideoDeviceFailed, void(int routing_id, int index));
56 MOCK_METHOD0(GetMediaObserver, content::MediaObserver*()); 56 MOCK_METHOD0(GetMediaObserver, content::MediaObserver*());
57 57
58 // Accessor to private functions. 58 // Accessor to private functions.
59 void OnGenerateStream(int page_request_id, const StreamOptions& components) { 59 void OnGenerateStream(int page_request_id, const StreamOptions& components) {
60 MediaStreamDispatcherHost::OnGenerateStream(kRenderId, 60 MediaStreamDispatcherHost::OnGenerateStream(kRenderId,
61 page_request_id, 61 page_request_id,
62 components, 62 components,
63 GURL()); 63 GURL());
64 } 64 }
65 void OnGenerateStreamForDevice(int page_request_id,
66 const StreamOptions& components,
67 const std::string& device_id) {
68 MediaStreamDispatcherHost::OnGenerateStreamForDevice(kRenderId,
69 page_request_id,
70 components,
71 device_id,
72 GURL());
73 }
74 void OnStopGeneratedStream(const std::string& label) { 65 void OnStopGeneratedStream(const std::string& label) {
75 MediaStreamDispatcherHost::OnStopGeneratedStream(kRenderId, label); 66 MediaStreamDispatcherHost::OnStopGeneratedStream(kRenderId, label);
76 } 67 }
77 68
78 // 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.
79 size_t NumberOfStreams() { 70 size_t NumberOfStreams() {
80 return streams_.size(); 71 return streams_.size();
81 } 72 }
82 73
83 std::string label_; 74 std::string label_;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 std::string label = host_->label_; 228 std::string label = host_->label_;
238 229
239 EXPECT_EQ(host_->audio_devices_.size(), 0u); 230 EXPECT_EQ(host_->audio_devices_.size(), 0u);
240 EXPECT_EQ(host_->video_devices_.size(), 1u); 231 EXPECT_EQ(host_->video_devices_.size(), 1u);
241 EXPECT_EQ(host_->NumberOfStreams(), 1u); 232 EXPECT_EQ(host_->NumberOfStreams(), 1u);
242 233
243 host_->OnStopGeneratedStream(label); 234 host_->OnStopGeneratedStream(label);
244 EXPECT_EQ(host_->NumberOfStreams(), 0u); 235 EXPECT_EQ(host_->NumberOfStreams(), 0u);
245 } 236 }
246 237
247 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamForDevice) {
248 static const char kDeviceId[] = "/dev/video0";
249
250 StreamOptions options(content::MEDIA_NO_SERVICE,
251 content::MEDIA_DEVICE_VIDEO_CAPTURE);
252
253 EXPECT_CALL(*host_, GetMediaObserver())
254 .WillRepeatedly(Return(media_observer_.get()));
255 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
256 host_->OnGenerateStreamForDevice(kPageRequestId, options, kDeviceId);
257
258 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesOpened(_, _, _));
259 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _));
260
261 WaitForResult();
262
263 std::string label = host_->label_;
264
265 EXPECT_EQ(0u, host_->audio_devices_.size());
266 EXPECT_EQ(1u, host_->video_devices_.size());
267 EXPECT_EQ(1u, host_->NumberOfStreams());
268
269 host_->OnStopGeneratedStream(label);
270 EXPECT_EQ(0u, host_->NumberOfStreams());
271 }
272
273 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) { 238 TEST_F(MediaStreamDispatcherHostTest, GenerateThreeStreams) {
274 // This test opens three video capture devices. Two fake devices exists and it 239 // This test opens three video capture devices. Two fake devices exists and it
275 // is expected the last call to |Open()| will open the first device again, but 240 // is expected the last call to |Open()| will open the first device again, but
276 // with a different label. 241 // with a different label.
277 StreamOptions options(false, true); 242 StreamOptions options(false, true);
278 243
279 // Generate first stream. 244 // Generate first stream.
280 EXPECT_CALL(*host_, GetMediaObserver()) 245 EXPECT_CALL(*host_, GetMediaObserver())
281 .WillRepeatedly(Return(media_observer_.get())); 246 .WillRepeatedly(Return(media_observer_.get()));
282 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); 247 EXPECT_CALL(*host_, OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Calling OnChannelClosing() to cancel all the pending/generated streams. 361 // Calling OnChannelClosing() to cancel all the pending/generated streams.
397 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _)) 362 EXPECT_CALL(*media_observer_.get(), OnCaptureDevicesClosed(_, _, _))
398 .Times(3); 363 .Times(3);
399 host_->OnChannelClosing(); 364 host_->OnChannelClosing();
400 365
401 // Streams should have been cleaned up. 366 // Streams should have been cleaned up.
402 EXPECT_EQ(host_->NumberOfStreams(), 0u); 367 EXPECT_EQ(host_->NumberOfStreams(), 0u);
403 } 368 }
404 369
405 }; // namespace media_stream 370 }; // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698