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
3 // found in the LICENSE file.
4
5 #include "content/renderer/media/mock_media_stream_dispatcher.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "content/public/common/media_stream_request.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
MockMediaStreamDispatcher()13 MockMediaStreamDispatcher::MockMediaStreamDispatcher()
14 : MediaStreamDispatcher(NULL),
15 request_id_(-1),
16 request_stream_counter_(0),
17 stop_audio_device_counter_(0),
18 stop_video_device_counter_(0),
19 session_id_(0) {
20 }
21
~MockMediaStreamDispatcher()22 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {}
23
GenerateStream(int request_id,const base::WeakPtr<MediaStreamDispatcherEventHandler> & event_handler,const StreamOptions & components,const GURL & url)24 void MockMediaStreamDispatcher::GenerateStream(
25 int request_id,
26 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler,
27 const StreamOptions& components,
28 const GURL& url) {
29 request_id_ = request_id;
30
31 stream_label_ = "local_stream" + base::IntToString(request_id);
32 audio_array_.clear();
33 video_array_.clear();
34
35 if (components.audio_requested) {
36 StreamDeviceInfo audio;
37 audio.device.id = "audio_device_id" + base::IntToString(session_id_);
38 audio.device.name = "microphone";
39 audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE;
40 audio.session_id = session_id_;
41 audio_array_.push_back(audio);
42 }
43 if (components.video_requested) {
44 StreamDeviceInfo video;
45 video.device.id = "video_device_id" + base::IntToString(session_id_);
46 video.device.name = "usb video camera";
47 video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE;
48 video.session_id = session_id_;
49 video_array_.push_back(video);
50 }
51 ++request_stream_counter_;
52 }
53
CancelGenerateStream(int request_id,const base::WeakPtr<MediaStreamDispatcherEventHandler> & event_handler)54 void MockMediaStreamDispatcher::CancelGenerateStream(
55 int request_id,
56 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) {
57 EXPECT_EQ(request_id, request_id_);
58 }
59
StopStreamDevice(const StreamDeviceInfo & device_info)60 void MockMediaStreamDispatcher::StopStreamDevice(
61 const StreamDeviceInfo& device_info) {
62 if (IsAudioMediaType(device_info.device.type)) {
63 ++stop_audio_device_counter_;
64 return;
65 }
66 if (IsVideoMediaType(device_info.device.type)) {
67 ++stop_video_device_counter_;
68 return;
69 }
70 NOTREACHED();
71 }
72
IsStream(const std::string & label)73 bool MockMediaStreamDispatcher::IsStream(const std::string& label) {
74 return true;
75 }
76
video_session_id(const std::string & label,int index)77 int MockMediaStreamDispatcher::video_session_id(const std::string& label,
78 int index) {
79 return -1;
80 }
81
audio_session_id(const std::string & label,int index)82 int MockMediaStreamDispatcher::audio_session_id(const std::string& label,
83 int index) {
84 return -1;
85 }
86
87 } // namespace content
88