Roll src/third_party/WebKit a452221:9ff6d11 (svn 202117:202119)
[chromium-blink-merge.git] / content / renderer / media / mock_media_stream_registry.cc
blobfdd0c7cc3fa2ae7ba69e29ab64eaac32c796682e
1 // Copyright (c) 2013 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.
5 #include "content/renderer/media/mock_media_stream_registry.h"
7 #include <string>
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/renderer/media/media_stream.h"
11 #include "content/renderer/media/media_stream_video_track.h"
12 #include "content/renderer/media/mock_media_stream_video_source.h"
13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
15 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/WebVector.h"
18 namespace content {
20 static const char kTestStreamLabel[] = "stream_label";
22 MockMediaStreamRegistry::MockMediaStreamRegistry() {}
24 void MockMediaStreamRegistry::Init(const std::string& stream_url) {
25 stream_url_ = stream_url;
26 const blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks;
27 const blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks;
28 const blink::WebString label(kTestStreamLabel);
29 test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks);
30 test_stream_.setExtraData(new MediaStream(test_stream_));
33 void MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) {
34 blink::WebMediaStreamSource blink_source;
35 blink_source.initialize("mock video source id",
36 blink::WebMediaStreamSource::TypeVideo,
37 "mock video source name",
38 false /* remote */, true /* readonly */);
39 MockMediaStreamVideoSource* native_source =
40 new MockMediaStreamVideoSource(false);
41 blink_source.setExtraData(native_source);
42 blink::WebMediaStreamTrack blink_track;
43 blink_track.initialize(base::UTF8ToUTF16(track_id), blink_source);
44 blink::WebMediaConstraints constraints;
45 constraints.initialize();
47 MediaStreamVideoTrack* native_track =
48 new MediaStreamVideoTrack(native_source,
49 constraints,
50 MediaStreamVideoSource::ConstraintsCallback(),
51 true);
52 blink_track.setExtraData(native_track);
53 test_stream_.addTrack(blink_track);
56 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream(
57 const std::string& url) {
58 return (url != stream_url_) ? blink::WebMediaStream() : test_stream_;
61 } // namespace content