Fix crash on app list start page contents not existing.
[chromium-blink-merge.git] / content / renderer / media / mock_media_stream_registry.cc
blobdeb60fc5e052ba329213190715843bb5dd68d386
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 false /* remote */, true /* readonly */);
40 MockMediaStreamVideoSource* native_source =
41 new MockMediaStreamVideoSource(false);
42 blink_source.setExtraData(native_source);
43 blink::WebMediaStreamTrack blink_track;
44 blink_track.initialize(base::UTF8ToUTF16(track_id), blink_source);
45 blink::WebMediaConstraints constraints;
46 constraints.initialize();
48 MediaStreamVideoTrack* native_track =
49 new MediaStreamVideoTrack(native_source,
50 constraints,
51 MediaStreamVideoSource::ConstraintsCallback(),
52 true);
53 blink_track.setExtraData(native_track);
54 test_stream_.addTrack(blink_track);
57 blink::WebMediaStream MockMediaStreamRegistry::GetMediaStream(
58 const std::string& url) {
59 if (url != stream_url_) {
60 return blink::WebMediaStream();
62 return test_stream_;
65 const blink::WebMediaStream MockMediaStreamRegistry::test_stream() const {
66 return test_stream_;
69 } // namespace content