Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / media / mock_media_stream_registry.cc
blob53bf948479ab675957016f96d2c7e09e0229f4b8
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() {
25 void MockMediaStreamRegistry::Init(const std::string& stream_url) {
26 stream_url_ = stream_url;
27 blink::WebVector<blink::WebMediaStreamTrack> webkit_audio_tracks;
28 blink::WebVector<blink::WebMediaStreamTrack> webkit_video_tracks;
29 blink::WebString label(kTestStreamLabel);
30 test_stream_.initialize(label, webkit_audio_tracks, webkit_video_tracks);
31 test_stream_.setExtraData(new MediaStream(test_stream_));
34 void MockMediaStreamRegistry::AddVideoTrack(const std::string& track_id) {
35 blink::WebMediaStreamSource blink_source;
36 blink_source.initialize("mock video source id",
37 blink::WebMediaStreamSource::TypeVideo,
38 "mock video source name");
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 if (url != stream_url_) {
59 return blink::WebMediaStream();
61 return test_stream_;
64 const blink::WebMediaStream MockMediaStreamRegistry::test_stream() const {
65 return test_stream_;
68 } // namespace content