15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/renderer/media/mock_media_stream_dispatcher.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/strings/string_number_conversions.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/media_stream_request.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockMediaStreamDispatcher::MockMediaStreamDispatcher() 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : MediaStreamDispatcher(NULL), 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_id_(-1), 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_stream_counter_(0), 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) stop_audio_device_counter_(0), 188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) stop_video_device_counter_(0), 198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) session_id_(0) { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockMediaStreamDispatcher::~MockMediaStreamDispatcher() {} 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void MockMediaStreamDispatcher::GenerateStream( 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int request_id, 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const StreamOptions& components, 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url) { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request_id_ = request_id; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) stream_label_ = "local_stream" + base::IntToString(request_id); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) audio_array_.clear(); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) video_array_.clear(); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 35d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) if (components.audio_requested) { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StreamDeviceInfo audio; 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) audio.device.id = "audio_device_id" + base::IntToString(session_id_); 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) audio.device.name = "microphone"; 39d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) audio.device.type = MEDIA_DEVICE_AUDIO_CAPTURE; 408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) audio.session_id = session_id_; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) audio_array_.push_back(audio); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 43d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) if (components.video_requested) { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StreamDeviceInfo video; 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) video.device.id = "video_device_id" + base::IntToString(session_id_); 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) video.device.name = "usb video camera"; 47d57369da7c6519fef57db42085f7b42d4c8845c1Torne (Richard Coles) video.device.type = MEDIA_DEVICE_VIDEO_CAPTURE; 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) video.session_id = session_id_; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) video_array_.push_back(video); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ++request_stream_counter_; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid MockMediaStreamDispatcher::CancelGenerateStream( 557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch int request_id, 567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(request_id, request_id_); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void MockMediaStreamDispatcher::StopStreamDevice( 618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const StreamDeviceInfo& device_info) { 628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (IsAudioMediaType(device_info.device.type)) { 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ++stop_audio_device_counter_; 648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return; 658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (IsVideoMediaType(device_info.device.type)) { 678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ++stop_video_device_counter_; 688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return; 698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NOTREACHED(); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool MockMediaStreamDispatcher::IsStream(const std::string& label) { 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int MockMediaStreamDispatcher::video_session_id(const std::string& label, 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int index) { 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return -1; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int MockMediaStreamDispatcher::audio_session_id(const std::string& label, 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int index) { 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return -1; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 88