Switch RendererDidNavigateInPage to use unique id.
[chromium-blink-merge.git] / components / test_runner / mock_web_media_stream_center.cc
blobe63a91fdc02851f245615b939b944dea85882024
1 // Copyright 2014 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 "components/test_runner/mock_web_media_stream_center.h"
7 #include "base/logging.h"
8 #include "components/test_runner/test_interfaces.h"
9 #include "components/test_runner/web_test_delegate.h"
10 #include "third_party/WebKit/public/platform/WebAudioDestinationConsumer.h"
11 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h"
12 #include "third_party/WebKit/public/platform/WebMediaStream.h"
13 #include "third_party/WebKit/public/platform/WebMediaStreamCenterClient.h"
14 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h"
17 #include "third_party/WebKit/public/platform/WebSourceInfo.h"
18 #include "third_party/WebKit/public/platform/WebVector.h"
20 namespace test_runner {
22 namespace {
23 class NewTrackTask : public WebMethodTask<MockWebMediaStreamCenter> {
24 public:
25 NewTrackTask(MockWebMediaStreamCenter* object,
26 const blink::WebMediaStream& stream)
27 : WebMethodTask<MockWebMediaStreamCenter>(object), stream_(stream) {
28 DCHECK(!stream_.isNull());
31 ~NewTrackTask() override {}
33 void RunIfValid() override {
34 blink::WebMediaStreamSource source;
35 blink::WebMediaStreamTrack track;
36 source.initialize("MagicVideoDevice#1",
37 blink::WebMediaStreamSource::TypeVideo,
38 "Magic video track",
39 false /* remote */, true /* readonly */);
40 track.initialize(source);
41 stream_.addTrack(track);
44 private:
45 blink::WebMediaStream stream_;
47 DISALLOW_COPY_AND_ASSIGN(NewTrackTask);
50 class MockWebAudioDestinationConsumer
51 : public blink::WebAudioDestinationConsumer {
52 public:
53 MockWebAudioDestinationConsumer() {}
54 virtual ~MockWebAudioDestinationConsumer() {}
55 virtual void setFormat(size_t number_of_channels, float sample_rate) {}
56 virtual void consumeAudio(const blink::WebVector<const float*>&,
57 size_t number_of_frames) {}
59 DISALLOW_COPY_AND_ASSIGN(MockWebAudioDestinationConsumer);
62 } // namespace
64 MockWebMediaStreamCenter::MockWebMediaStreamCenter(
65 blink::WebMediaStreamCenterClient* client,
66 TestInterfaces* interfaces)
67 : interfaces_(interfaces) {
70 MockWebMediaStreamCenter::~MockWebMediaStreamCenter() {
73 void MockWebMediaStreamCenter::didEnableMediaStreamTrack(
74 const blink::WebMediaStreamTrack& track) {
75 track.source().setReadyState(blink::WebMediaStreamSource::ReadyStateLive);
78 void MockWebMediaStreamCenter::didDisableMediaStreamTrack(
79 const blink::WebMediaStreamTrack& track) {
80 track.source().setReadyState(blink::WebMediaStreamSource::ReadyStateMuted);
83 bool MockWebMediaStreamCenter::didAddMediaStreamTrack(
84 const blink::WebMediaStream& stream,
85 const blink::WebMediaStreamTrack& track) {
86 return true;
89 bool MockWebMediaStreamCenter::didRemoveMediaStreamTrack(
90 const blink::WebMediaStream& stream,
91 const blink::WebMediaStreamTrack& track) {
92 return true;
95 void MockWebMediaStreamCenter::didStopLocalMediaStream(
96 const blink::WebMediaStream& stream) {
97 blink::WebVector<blink::WebMediaStreamTrack> tracks;
98 stream.audioTracks(tracks);
99 for (size_t i = 0; i < tracks.size(); ++i)
100 tracks[i].source().setReadyState(
101 blink::WebMediaStreamSource::ReadyStateEnded);
102 stream.videoTracks(tracks);
103 for (size_t i = 0; i < tracks.size(); ++i)
104 tracks[i].source().setReadyState(
105 blink::WebMediaStreamSource::ReadyStateEnded);
108 bool MockWebMediaStreamCenter::didStopMediaStreamTrack(
109 const blink::WebMediaStreamTrack& track) {
110 track.source().setReadyState(blink::WebMediaStreamSource::ReadyStateEnded);
111 return true;
114 void MockWebMediaStreamCenter::didCreateMediaStream(
115 blink::WebMediaStream& stream) {
116 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
117 stream.audioTracks(audio_tracks);
118 for (size_t i = 0; i < audio_tracks.size(); ++i) {
119 blink::WebMediaStreamSource source = audio_tracks[i].source();
120 if (source.requiresAudioConsumer()) {
121 MockWebAudioDestinationConsumer* consumer =
122 new MockWebAudioDestinationConsumer();
123 source.addAudioConsumer(consumer);
124 source.removeAudioConsumer(consumer);
125 delete consumer;
128 interfaces_->GetDelegate()->PostTask(new NewTrackTask(this, stream));
131 blink::WebAudioSourceProvider*
132 MockWebMediaStreamCenter::createWebAudioSourceFromMediaStreamTrack(
133 const blink::WebMediaStreamTrack& track) {
134 return NULL;
137 } // namespace test_runner