Commit 4002a79f authored by perkj's avatar perkj Committed by Commit bot

Updated the MockWebRtcPeerConnectionHandler object used in blink Layouttests.

This cl change the mock to create remote mediastreams based on the mediastreams that have been added as local mediastreams. The remote streams are updated once RTCPeerConnection::setRemoteDescription is called. The purpose is to be able to test remote mediastreams in blink layouttests.

BUG=417245

Review URL: https://codereview.chromium.org/597283006

Cr-Commit-Position: refs/heads/master@{#299069}
parent 98ce5ad6
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "content/shell/renderer/test_runner/web_test_delegate.h" #include "content/shell/renderer/test_runner/web_test_delegate.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.h" #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
#include "third_party/WebKit/public/platform/WebMediaStream.h" #include "third_party/WebKit/public/platform/WebMediaStream.h"
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
#include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
#include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h" #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h"
...@@ -147,6 +148,9 @@ class RemoteDataChannelTask ...@@ -147,6 +148,9 @@ class RemoteDataChannelTask
MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() { MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() {
} }
MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {
}
MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(
WebRTCPeerConnectionHandlerClient* client, WebRTCPeerConnectionHandlerClient* client,
TestInterfaces* interfaces) TestInterfaces* interfaces)
...@@ -223,7 +227,9 @@ void MockWebRTCPeerConnectionHandler::setLocalDescription( ...@@ -223,7 +227,9 @@ void MockWebRTCPeerConnectionHandler::setLocalDescription(
void MockWebRTCPeerConnectionHandler::setRemoteDescription( void MockWebRTCPeerConnectionHandler::setRemoteDescription(
const WebRTCVoidRequest& request, const WebRTCVoidRequest& request,
const WebRTCSessionDescription& remote_description) { const WebRTCSessionDescription& remote_description) {
if (!remote_description.isNull() && remote_description.sdp() == "remote") { if (!remote_description.isNull() && remote_description.sdp() == "remote") {
UpdateRemoteStreams();
remote_description_ = remote_description; remote_description_ = remote_description;
interfaces_->GetDelegate()->PostTask( interfaces_->GetDelegate()->PostTask(
new RTCVoidRequestTask(this, request, true)); new RTCVoidRequestTask(this, request, true));
...@@ -232,6 +238,84 @@ void MockWebRTCPeerConnectionHandler::setRemoteDescription( ...@@ -232,6 +238,84 @@ void MockWebRTCPeerConnectionHandler::setRemoteDescription(
new RTCVoidRequestTask(this, request, false)); new RTCVoidRequestTask(this, request, false));
} }
void MockWebRTCPeerConnectionHandler::UpdateRemoteStreams() {
// Find all removed streams.
// Set the readyState of the remote tracks to ended, remove them from the
// stream and notify the client.
StreamMap::iterator removed_it = remote_streams_.begin();
while (removed_it != remote_streams_.end()) {
if (local_streams_.find(removed_it->first) != local_streams_.end()) {
removed_it++;
continue;
}
// The stream have been removed. Loop through all tracks and set the
// source as ended and remove them from the stream.
blink::WebMediaStream stream = removed_it->second;
blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
stream.audioTracks(audio_tracks);
for (size_t i = 0; i < audio_tracks.size(); ++i) {
audio_tracks[i].source().setReadyState(
blink::WebMediaStreamSource::ReadyStateEnded);
stream.removeTrack(audio_tracks[i]);
}
blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
stream.videoTracks(video_tracks);
for (size_t i = 0; i < video_tracks.size(); ++i) {
video_tracks[i].source().setReadyState(
blink::WebMediaStreamSource::ReadyStateEnded);
stream.removeTrack(video_tracks[i]);
}
client_->didRemoveRemoteStream(stream);
remote_streams_.erase(removed_it++);
}
// Find all new streams;
// Create new sources and tracks and notify the client about the new stream.
StreamMap::iterator added_it = local_streams_.begin();
while (added_it != local_streams_.end()) {
if (remote_streams_.find(added_it->first) != remote_streams_.end()) {
added_it++;
continue;
}
const blink::WebMediaStream& stream = added_it->second;
blink::WebVector<blink::WebMediaStreamTrack> local_audio_tracks;
stream.audioTracks(local_audio_tracks);
blink::WebVector<blink::WebMediaStreamTrack>
remote_audio_tracks(local_audio_tracks.size());
for (size_t i = 0; i < local_audio_tracks.size(); ++i) {
blink::WebMediaStreamSource webkit_source;
webkit_source.initialize(local_audio_tracks[i].id(),
blink::WebMediaStreamSource::TypeAudio,
local_audio_tracks[i].id());
remote_audio_tracks[i].initialize(webkit_source);
}
blink::WebVector<blink::WebMediaStreamTrack> local_video_tracks;
stream.videoTracks(local_video_tracks);
blink::WebVector<blink::WebMediaStreamTrack>
remote_video_tracks(local_video_tracks.size());
for (size_t i = 0; i < local_video_tracks.size(); ++i) {
blink::WebMediaStreamSource webkit_source;
webkit_source.initialize(local_video_tracks[i].id(),
blink::WebMediaStreamSource::TypeVideo,
local_video_tracks[i].id());
remote_video_tracks[i].initialize(webkit_source);
}
blink::WebMediaStream new_remote_stream;
new_remote_stream.initialize(remote_audio_tracks,
remote_video_tracks);
remote_streams_[added_it->first] = new_remote_stream;
client_->didAddRemoteStream(new_remote_stream);
++added_it;
}
}
WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() { WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription() {
return local_description_; return local_description_;
} }
...@@ -263,14 +347,18 @@ bool MockWebRTCPeerConnectionHandler::addICECandidate( ...@@ -263,14 +347,18 @@ bool MockWebRTCPeerConnectionHandler::addICECandidate(
bool MockWebRTCPeerConnectionHandler::addStream( bool MockWebRTCPeerConnectionHandler::addStream(
const WebMediaStream& stream, const WebMediaStream& stream,
const WebMediaConstraints& constraints) { const WebMediaConstraints& constraints) {
if (local_streams_.find(stream.id().utf8()) != local_streams_.end())
return false;
++stream_count_; ++stream_count_;
client_->negotiationNeeded(); client_->negotiationNeeded();
local_streams_[stream.id().utf8()] = stream;
return true; return true;
} }
void MockWebRTCPeerConnectionHandler::removeStream( void MockWebRTCPeerConnectionHandler::removeStream(
const WebMediaStream& stream) { const WebMediaStream& stream) {
--stream_count_; --stream_count_;
local_streams_.erase(stream.id().utf8());
client_->negotiationNeeded(); client_->negotiationNeeded();
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_ #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_
#include <map>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "content/shell/renderer/test_runner/web_task.h" #include "content/shell/renderer/test_runner/web_task.h"
#include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandler.h" #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandler.h"
...@@ -26,6 +28,7 @@ class MockWebRTCPeerConnectionHandler ...@@ -26,6 +28,7 @@ class MockWebRTCPeerConnectionHandler
MockWebRTCPeerConnectionHandler( MockWebRTCPeerConnectionHandler(
blink::WebRTCPeerConnectionHandlerClient* client, blink::WebRTCPeerConnectionHandlerClient* client,
TestInterfaces* interfaces); TestInterfaces* interfaces);
virtual ~MockWebRTCPeerConnectionHandler();
// WebRTCPeerConnectionHandler related methods // WebRTCPeerConnectionHandler related methods
virtual bool initialize( virtual bool initialize(
...@@ -75,6 +78,12 @@ class MockWebRTCPeerConnectionHandler ...@@ -75,6 +78,12 @@ class MockWebRTCPeerConnectionHandler
private: private:
MockWebRTCPeerConnectionHandler(); MockWebRTCPeerConnectionHandler();
// UpdateRemoteStreams uses the collection of |local_streams_| to create
// remote MediaStreams with the same number of tracks and notifies |client_|
// about added and removed streams. It's triggered when setRemoteDescription
// is called.
void UpdateRemoteStreams();
blink::WebRTCPeerConnectionHandlerClient* client_; blink::WebRTCPeerConnectionHandlerClient* client_;
bool stopped_; bool stopped_;
WebTaskList task_list_; WebTaskList task_list_;
...@@ -82,6 +91,9 @@ class MockWebRTCPeerConnectionHandler ...@@ -82,6 +91,9 @@ class MockWebRTCPeerConnectionHandler
blink::WebRTCSessionDescription remote_description_; blink::WebRTCSessionDescription remote_description_;
int stream_count_; int stream_count_;
TestInterfaces* interfaces_; TestInterfaces* interfaces_;
typedef std::map<std::string, blink::WebMediaStream> StreamMap;
StreamMap local_streams_;
StreamMap remote_streams_;
DISALLOW_COPY_AND_ASSIGN(MockWebRTCPeerConnectionHandler); DISALLOW_COPY_AND_ASSIGN(MockWebRTCPeerConnectionHandler);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment