- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / media / mock_media_stream_dispatcher.cc
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/stringprintf.h"
8 #include "content/public/common/media_stream_request.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
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
22 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {}
23
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_ = base::StringPrintf("%s%d","local_stream",request_id);
32   audio_array_.clear();
33   video_array_.clear();
34
35   if (IsAudioMediaType(components.audio_type)) {
36     StreamDeviceInfo audio;
37     audio.device.id = "audio_device_id";
38     audio.device.name = "microphone";
39     audio.device.type = components.audio_type;
40     audio.session_id = session_id_;
41     audio_array_.push_back(audio);
42   }
43   if (IsVideoMediaType(components.video_type)) {
44     StreamDeviceInfo video;
45     video.device.id = "video_device_id";
46     video.device.name = "usb video camera";
47     video.device.type = components.video_type;
48     video.session_id = session_id_;
49     video_array_.push_back(video);
50   }
51   ++request_stream_counter_;
52 }
53
54 void MockMediaStreamDispatcher::CancelGenerateStream(
55   int request_id,
56   const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) {
57   EXPECT_EQ(request_id, request_id_);
58 }
59
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
73 bool MockMediaStreamDispatcher::IsStream(const std::string& label) {
74   return true;
75 }
76
77 int MockMediaStreamDispatcher::video_session_id(const std::string& label,
78                                                 int index) {
79   return -1;
80 }
81
82 int MockMediaStreamDispatcher::audio_session_id(const std::string& label,
83                                                 int index) {
84   return -1;
85 }
86
87 }  // namespace content