Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: content/renderer/media/media_stream_video_capture_source_unittest.cc

Issue 883293005: Cast: Basic cast_receiver API for chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback_helpers.h" 6 #include "base/callback_helpers.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/child/child_process.h" 10 #include "content/child/child_process.h"
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info) 24 explicit MockVideoCapturerDelegate(const StreamDeviceInfo& device_info)
25 : VideoCapturerDelegate(device_info) {} 25 : VideoCapturerDelegate(device_info) {}
26 26
27 MOCK_METHOD3(StartCapture, 27 MOCK_METHOD3(StartCapture,
28 void(const media::VideoCaptureParams& params, 28 void(const media::VideoCaptureParams& params,
29 const VideoCaptureDeliverFrameCB& new_frame_callback, 29 const VideoCaptureDeliverFrameCB& new_frame_callback,
30 const RunningCallback& running_callback)); 30 const RunningCallback& running_callback));
31 MOCK_METHOD0(StopCapture, void()); 31 MOCK_METHOD0(StopCapture, void());
32 32
33 protected:
33 virtual ~MockVideoCapturerDelegate() {} 34 virtual ~MockVideoCapturerDelegate() {}
34 }; 35 };
35 36
36 class MediaStreamVideoCapturerSourceTest : public testing::Test { 37 class MediaStreamVideoCapturerSourceTest : public testing::Test {
37 public: 38 public:
38 MediaStreamVideoCapturerSourceTest() 39 MediaStreamVideoCapturerSourceTest()
39 : child_process_(new ChildProcess()), 40 : child_process_(new ChildProcess()),
40 source_(NULL), 41 source_(NULL),
41 delegate_(NULL), 42 delegate_(NULL),
42 source_stopped_(false) { 43 source_stopped_(false) {
43 } 44 }
44 45
45 void TearDown() override { 46 void TearDown() override {
46 webkit_source_.reset(); 47 webkit_source_.reset();
47 blink::WebHeap::collectAllGarbageForTesting(); 48 blink::WebHeap::collectAllGarbageForTesting();
48 } 49 }
49 50
50 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) { 51 void InitWithDeviceInfo(const StreamDeviceInfo& device_info) {
51 scoped_ptr<MockVideoCapturerDelegate> delegate( 52 scoped_refptr<MockVideoCapturerDelegate> delegate(
52 new MockVideoCapturerDelegate(device_info)); 53 new MockVideoCapturerDelegate(device_info));
53 delegate_ = delegate.get(); 54 delegate_ = delegate.get();
54 source_ = new MediaStreamVideoCapturerSource( 55 source_ = new MediaStreamVideoCapturerSource(
55 device_info, 56 device_info,
56 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, 57 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped,
57 base::Unretained(this)), 58 base::Unretained(this)),
58 delegate.Pass()); 59 delegate);
59 60
60 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), 61 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"),
61 blink::WebMediaStreamSource::TypeVideo, 62 blink::WebMediaStreamSource::TypeVideo,
62 base::UTF8ToUTF16("dummy_source_name"), 63 base::UTF8ToUTF16("dummy_source_name"),
63 false /* remote */ , true /* readonly */); 64 false /* remote */ , true /* readonly */);
64 webkit_source_.setExtraData(source_); 65 webkit_source_.setExtraData(source_);
65 webkit_source_id_ = webkit_source_.id(); 66 webkit_source_id_ = webkit_source_.id();
66 } 67 }
67 68
68 blink::WebMediaStreamTrack StartSource() { 69 blink::WebMediaStreamTrack StartSource() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 testing::_, 129 testing::_,
129 testing::_)).Times(1); 130 testing::_)).Times(1);
130 blink::WebMediaStreamTrack track = StartSource(); 131 blink::WebMediaStreamTrack track = StartSource();
131 // When the track goes out of scope, the source will be stopped. 132 // When the track goes out of scope, the source will be stopped.
132 EXPECT_CALL(mock_delegate(), StopCapture()); 133 EXPECT_CALL(mock_delegate(), StopCapture());
133 } 134 }
134 135
135 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) { 136 TEST_F(MediaStreamVideoCapturerSourceTest, Ended) {
136 StreamDeviceInfo device_info; 137 StreamDeviceInfo device_info;
137 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE; 138 device_info.device.type = MEDIA_DESKTOP_VIDEO_CAPTURE;
138 scoped_ptr<VideoCapturerDelegate> delegate( 139 scoped_refptr<VideoCapturerDelegate> delegate(
139 new VideoCapturerDelegate(device_info)); 140 new VideoCapturerDelegate(device_info));
140 VideoCapturerDelegate* delegate_ptr = delegate.get(); 141 VideoCapturerDelegate* delegate_ptr = delegate.get();
141 source_ = new MediaStreamVideoCapturerSource( 142 source_ = new MediaStreamVideoCapturerSource(
142 device_info, 143 device_info,
143 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped, 144 base::Bind(&MediaStreamVideoCapturerSourceTest::OnSourceStopped,
144 base::Unretained(this)), 145 base::Unretained(this)),
145 delegate.Pass()); 146 delegate);
146 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"), 147 webkit_source_.initialize(base::UTF8ToUTF16("dummy_source_id"),
147 blink::WebMediaStreamSource::TypeVideo, 148 blink::WebMediaStreamSource::TypeVideo,
148 base::UTF8ToUTF16("dummy_source_name"), 149 base::UTF8ToUTF16("dummy_source_name"),
149 false /* remote */ , true /* readonly */); 150 false /* remote */ , true /* readonly */);
150 webkit_source_.setExtraData(source_); 151 webkit_source_.setExtraData(source_);
151 webkit_source_id_ = webkit_source_.id(); 152 webkit_source_id_ = webkit_source_.id();
152 blink::WebMediaStreamTrack track = StartSource(); 153 blink::WebMediaStreamTrack track = StartSource();
153 message_loop_.RunUntilIdle(); 154 message_loop_.RunUntilIdle();
154 155
155 delegate_ptr->OnStateUpdateOnRenderThread(VIDEO_CAPTURE_STATE_STARTED); 156 delegate_ptr->OnStateUpdateOnRenderThread(VIDEO_CAPTURE_STATE_STARTED);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 197
197 EXPECT_CALL(mock_delegate(), StartCapture( 198 EXPECT_CALL(mock_delegate(), StartCapture(
198 testing::_, 199 testing::_,
199 testing::_, 200 testing::_,
200 testing::_)) 201 testing::_))
201 .Times(1) 202 .Times(1)
202 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb), 203 .WillOnce(testing::DoAll(testing::SaveArg<1>(&deliver_frame_cb),
203 testing::SaveArg<2>(&running_cb))); 204 testing::SaveArg<2>(&running_cb)));
204 EXPECT_CALL(mock_delegate(), StopCapture()); 205 EXPECT_CALL(mock_delegate(), StopCapture());
205 blink::WebMediaStreamTrack track = StartSource(); 206 blink::WebMediaStreamTrack track = StartSource();
206 running_cb.Run(MEDIA_DEVICE_OK); 207 running_cb.Run(true);
207 208
208 base::RunLoop run_loop; 209 base::RunLoop run_loop;
209 base::TimeTicks reference_capture_time = 210 base::TimeTicks reference_capture_time =
210 base::TimeTicks::FromInternalValue(60013); 211 base::TimeTicks::FromInternalValue(60013);
211 base::TimeTicks capture_time; 212 base::TimeTicks capture_time;
212 FakeMediaStreamVideoSink fake_sink( 213 FakeMediaStreamVideoSink fake_sink(
213 &capture_time, 214 &capture_time,
214 media::BindToCurrentLoop(run_loop.QuitClosure())); 215 media::BindToCurrentLoop(run_loop.QuitClosure()));
215 FakeMediaStreamVideoSink::AddToVideoTrack( 216 FakeMediaStreamVideoSink::AddToVideoTrack(
216 &fake_sink, 217 &fake_sink,
217 base::Bind(&FakeMediaStreamVideoSink::OnVideoFrame, 218 base::Bind(&FakeMediaStreamVideoSink::OnVideoFrame,
218 base::Unretained(&fake_sink)), 219 base::Unretained(&fake_sink)),
219 track); 220 track);
220 child_process_->io_message_loop()->PostTask( 221 child_process_->io_message_loop()->PostTask(
221 FROM_HERE, 222 FROM_HERE,
222 base::Bind(deliver_frame_cb, 223 base::Bind(deliver_frame_cb,
223 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)), 224 media::VideoFrame::CreateBlackFrame(gfx::Size(2, 2)),
224 media::VideoCaptureFormat(), 225 media::VideoCaptureFormat(),
225 reference_capture_time)); 226 reference_capture_time));
226 run_loop.Run(); 227 run_loop.Run();
227 FakeMediaStreamVideoSink::RemoveFromVideoTrack(&fake_sink, track); 228 FakeMediaStreamVideoSink::RemoveFromVideoTrack(&fake_sink, track);
228 EXPECT_EQ(reference_capture_time, capture_time); 229 EXPECT_EQ(reference_capture_time, capture_time);
229 } 230 }
230 231
231 } // namespace content 232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698