Home | History | Annotate | Download | only in media
      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_stream_counter_(0) {
     18 }
     19 
     20 MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {}
     21 
     22 void MockMediaStreamDispatcher::GenerateStream(
     23     int request_id,
     24     const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler,
     25     const StreamOptions& components,
     26     const GURL& url) {
     27   request_id_ = request_id;
     28 
     29   stream_label_ = base::StringPrintf("%s%d","local_stream",request_id);
     30   audio_array_.clear();
     31   video_array_.clear();
     32 
     33   if (IsAudioMediaType(components.audio_type)) {
     34     StreamDeviceInfo audio;
     35     audio.device.id = "audio_device_id";
     36     audio.device.name = "microphone";
     37     audio.device.type = components.audio_type;
     38     audio.session_id = request_id;
     39     audio_array_.push_back(audio);
     40   }
     41   if (IsVideoMediaType(components.video_type)) {
     42     StreamDeviceInfo video;
     43     video.device.id = "video_device_id";
     44     video.device.name = "usb video camera";
     45     video.device.type = components.video_type;
     46     video.session_id = request_id;
     47     video_array_.push_back(video);
     48   }
     49   ++request_stream_counter_;
     50 }
     51 
     52 void MockMediaStreamDispatcher::CancelGenerateStream(
     53   int request_id,
     54   const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) {
     55   EXPECT_EQ(request_id, request_id_);
     56 }
     57 
     58 void MockMediaStreamDispatcher::StopStream(const std::string& label) {
     59   ++stop_stream_counter_;
     60 }
     61 
     62 bool MockMediaStreamDispatcher::IsStream(const std::string& label) {
     63   return true;
     64 }
     65 
     66 int MockMediaStreamDispatcher::video_session_id(const std::string& label,
     67                                                 int index) {
     68   return -1;
     69 }
     70 
     71 int MockMediaStreamDispatcher::audio_session_id(const std::string& label,
     72                                                 int index) {
     73   return -1;
     74 }
     75 
     76 }  // namespace content
     77