summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorperkj <perkj@chromium.org>2014-10-09 23:53:44 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-10 06:53:56 +0000
commit4002a79ff025a89a95670c66b04d407ee980534b (patch)
treec068368f847b95b3e7f1884feff18ca89dc8fc59
parent98ce5ad6bdd2cd058c21f19b997032f3b958cb73 (diff)
downloadchromium_src-4002a79ff025a89a95670c66b04d407ee980534b.zip
chromium_src-4002a79ff025a89a95670c66b04d407ee980534b.tar.gz
chromium_src-4002a79ff025a89a95670c66b04d407ee980534b.tar.bz2
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}
-rw-r--r--content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc88
-rw-r--r--content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h12
2 files changed, 100 insertions, 0 deletions
diff --git a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc
index 720e62b..34e889f 100644
--- a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc
+++ b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.cc
@@ -11,6 +11,7 @@
#include "content/shell/renderer/test_runner/web_test_delegate.h"
#include "third_party/WebKit/public/platform/WebMediaConstraints.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/WebRTCDataChannelInit.h"
#include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h"
@@ -147,6 +148,9 @@ class RemoteDataChannelTask
MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() {
}
+MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {
+}
+
MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(
WebRTCPeerConnectionHandlerClient* client,
TestInterfaces* interfaces)
@@ -223,7 +227,9 @@ void MockWebRTCPeerConnectionHandler::setLocalDescription(
void MockWebRTCPeerConnectionHandler::setRemoteDescription(
const WebRTCVoidRequest& request,
const WebRTCSessionDescription& remote_description) {
+
if (!remote_description.isNull() && remote_description.sdp() == "remote") {
+ UpdateRemoteStreams();
remote_description_ = remote_description;
interfaces_->GetDelegate()->PostTask(
new RTCVoidRequestTask(this, request, true));
@@ -232,6 +238,84 @@ void MockWebRTCPeerConnectionHandler::setRemoteDescription(
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() {
return local_description_;
}
@@ -263,14 +347,18 @@ bool MockWebRTCPeerConnectionHandler::addICECandidate(
bool MockWebRTCPeerConnectionHandler::addStream(
const WebMediaStream& stream,
const WebMediaConstraints& constraints) {
+ if (local_streams_.find(stream.id().utf8()) != local_streams_.end())
+ return false;
++stream_count_;
client_->negotiationNeeded();
+ local_streams_[stream.id().utf8()] = stream;
return true;
}
void MockWebRTCPeerConnectionHandler::removeStream(
const WebMediaStream& stream) {
--stream_count_;
+ local_streams_.erase(stream.id().utf8());
client_->negotiationNeeded();
}
diff --git a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h
index 96cc36e..85f9823 100644
--- a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h
+++ b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h
@@ -5,6 +5,8 @@
#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_
+#include <map>
+
#include "base/basictypes.h"
#include "content/shell/renderer/test_runner/web_task.h"
#include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandler.h"
@@ -26,6 +28,7 @@ class MockWebRTCPeerConnectionHandler
MockWebRTCPeerConnectionHandler(
blink::WebRTCPeerConnectionHandlerClient* client,
TestInterfaces* interfaces);
+ virtual ~MockWebRTCPeerConnectionHandler();
// WebRTCPeerConnectionHandler related methods
virtual bool initialize(
@@ -75,6 +78,12 @@ class MockWebRTCPeerConnectionHandler
private:
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_;
bool stopped_;
WebTaskList task_list_;
@@ -82,6 +91,9 @@ class MockWebRTCPeerConnectionHandler
blink::WebRTCSessionDescription remote_description_;
int stream_count_;
TestInterfaces* interfaces_;
+ typedef std::map<std::string, blink::WebMediaStream> StreamMap;
+ StreamMap local_streams_;
+ StreamMap remote_streams_;
DISALLOW_COPY_AND_ASSIGN(MockWebRTCPeerConnectionHandler);
};