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

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

Issue 2407623002: VideoCapture: migrate last Renderer-->Host msg and start Host-->Renderer migration (Closed)
Patch Set: Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "content/child/child_process.h" 10 #include "content/child/child_process.h"
11 #include "content/common/media/video_capture_messages.h" 11 #include "content/common/media/video_capture_messages.h"
12 #include "content/common/video_capture.mojom.h" 12 #include "content/common/video_capture.mojom.h"
13 #include "content/renderer/media/video_capture_impl.h" 13 #include "content/renderer/media/video_capture_impl.h"
14 #include "media/base/bind_to_current_loop.h" 14 #include "media/base/bind_to_current_loop.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using ::testing::_; 18 using ::testing::_;
19 using ::testing::Invoke; 19 using ::testing::Invoke;
20 using ::testing::InvokeWithoutArgs;
20 using ::testing::SaveArg; 21 using ::testing::SaveArg;
21 using ::testing::WithArgs; 22 using ::testing::WithArgs;
22 23
23 namespace content { 24 namespace content {
24 25
25 const int kSessionId = 1; 26 const int kSessionId = 1;
26 27
27 void RunEmptyFormatsCallback(const VideoCaptureDeviceFormatsCB& callback) { 28 void RunEmptyFormatsCallback(const VideoCaptureDeviceFormatsCB& callback) {
28 media::VideoCaptureFormats formats; 29 media::VideoCaptureFormats formats;
29 callback.Run(formats); 30 callback.Run(formats);
30 } 31 }
31 32
32 // Mock implementation of the Mojo service. TODO(mcasas): Replace completely 33 // Mock implementation of the Mojo service. TODO(mcasas): Replace completely
33 // MockVideoCaptureMessageFilter, https://crbug.com/651897 34 // MockVideoCaptureMessageFilter, https://crbug.com/651897
34 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { 35 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost {
35 public: 36 public:
36 MockMojoVideoCaptureHost() { 37 MockMojoVideoCaptureHost() : released_buffer_count_(0) {
37 ON_CALL(*this, GetDeviceSupportedFormats(_, _, _)) 38 ON_CALL(*this, GetDeviceSupportedFormats(_, _, _))
38 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback))); 39 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback)));
39 ON_CALL(*this, GetDeviceFormatsInUse(_, _, _)) 40 ON_CALL(*this, GetDeviceFormatsInUse(_, _, _))
40 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback))); 41 .WillByDefault(WithArgs<2>(Invoke(RunEmptyFormatsCallback)));
42 ON_CALL(*this, ReleaseBuffer(_, _, _, _))
43 .WillByDefault(InvokeWithoutArgs(
44 this, &MockMojoVideoCaptureHost::increase_released_buffer_count));
41 } 45 }
42 46
43 MOCK_METHOD3(Start, void(int32_t, int32_t, const media::VideoCaptureParams&)); 47 // Start() can't be mocked directly due to move-only |observer|.
48 void Start(int32_t device_id,
49 int32_t session_id,
50 const media::VideoCaptureParams& params,
51 mojom::VideoCaptureObserverPtr observer) override {
52 DoStart(device_id, session_id, params);
53 }
54 MOCK_METHOD3(DoStart,
55 void(int32_t, int32_t, const media::VideoCaptureParams&));
44 MOCK_METHOD1(Stop, void(int32_t)); 56 MOCK_METHOD1(Stop, void(int32_t));
45 MOCK_METHOD1(Pause, void(int32_t)); 57 MOCK_METHOD1(Pause, void(int32_t));
46 MOCK_METHOD3(Resume, 58 MOCK_METHOD3(Resume,
47 void(int32_t, int32_t, const media::VideoCaptureParams&)); 59 void(int32_t, int32_t, const media::VideoCaptureParams&));
48 MOCK_METHOD1(RequestRefreshFrame, void(int32_t)); 60 MOCK_METHOD1(RequestRefreshFrame, void(int32_t));
61 MOCK_METHOD4(ReleaseBuffer,
62 void(int32_t, int32_t, const gpu::SyncToken&, double));
49 MOCK_METHOD3(GetDeviceSupportedFormats, 63 MOCK_METHOD3(GetDeviceSupportedFormats,
50 void(int32_t, 64 void(int32_t,
51 int32_t, 65 int32_t,
52 const GetDeviceSupportedFormatsCallback&)); 66 const GetDeviceSupportedFormatsCallback&));
53 MOCK_METHOD3(GetDeviceFormatsInUse, 67 MOCK_METHOD3(GetDeviceFormatsInUse,
54 void(int32_t, int32_t, const GetDeviceFormatsInUseCallback&)); 68 void(int32_t, int32_t, const GetDeviceFormatsInUseCallback&));
55 69
70 int released_buffer_count() const { return released_buffer_count_; }
71 void increase_released_buffer_count() { released_buffer_count_++; }
72
56 private: 73 private:
74 int released_buffer_count_;
75
57 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); 76 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost);
58 }; 77 };
59 78
60 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { 79 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
61 public: 80 public:
62 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} 81 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {}
63 82
64 // Filter implementation. 83 // Filter implementation.
65 MOCK_METHOD1(Send, bool(IPC::Message* message)); 84 MOCK_METHOD1(Send, bool(IPC::Message* message));
66 85
67 protected: 86 protected:
68 virtual ~MockVideoCaptureMessageFilter() {} 87 virtual ~MockVideoCaptureMessageFilter() {}
69 88
70 private: 89 private:
71 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); 90 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter);
72 }; 91 };
73 92
74 class VideoCaptureImplTest : public ::testing::Test { 93 class VideoCaptureImplTest : public ::testing::Test {
75 public: 94 public:
76 class MockVideoCaptureImpl : public VideoCaptureImpl {
77 public:
78 MockVideoCaptureImpl(const media::VideoCaptureSessionId id,
79 VideoCaptureMessageFilter* filter)
80 : VideoCaptureImpl(id, filter, base::ThreadTaskRunnerHandle::Get()),
81 received_buffer_count_(0) {}
82 ~MockVideoCaptureImpl() override {}
83
84 void Send(IPC::Message* message) override {
85 bool handled = true;
86 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureImpl, *message)
87 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady,
88 DeviceReceiveEmptyBuffer)
89 IPC_MESSAGE_UNHANDLED(handled = false)
90 IPC_END_MESSAGE_MAP()
91 EXPECT_TRUE(handled);
92 delete message;
93 }
94
95 void DeviceReceiveEmptyBuffer(int device_id,
96 int buffer_id,
97 const gpu::SyncToken& release_sync_token,
98 double consumer_resource_utilization) {
99 received_buffer_count_++;
100 }
101
102 void ReceiveStateChangeMessage(VideoCaptureState state) {
103 OnStateChanged(state);
104 }
105
106 int received_buffer_count() const { return received_buffer_count_; }
107
108 private:
109 int received_buffer_count_;
110 };
111
112 VideoCaptureImplTest() 95 VideoCaptureImplTest()
113 : message_filter_(new MockVideoCaptureMessageFilter), 96 : message_filter_(new MockVideoCaptureMessageFilter),
114 video_capture_impl_( 97 video_capture_impl_(
115 new MockVideoCaptureImpl(kSessionId, message_filter_.get())) { 98 new VideoCaptureImpl(kSessionId,
99 message_filter_.get(),
100 base::ThreadTaskRunnerHandle::Get())) {
116 params_small_.requested_format = media::VideoCaptureFormat( 101 params_small_.requested_format = media::VideoCaptureFormat(
117 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); 102 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
118 params_large_.requested_format = media::VideoCaptureFormat( 103 params_large_.requested_format = media::VideoCaptureFormat(
119 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 104 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
120 105
121 video_capture_impl_->SetVideoCaptureHostForTesting( 106 video_capture_impl_->SetVideoCaptureHostForTesting(
122 &mock_video_capture_host_); 107 &mock_video_capture_host_);
123 video_capture_impl_->device_id_ = 2; 108 video_capture_impl_->device_id_ = 2;
124 } 109 }
125 110
126 protected: 111 protected:
112 // These four mocks are used to create callbacks for the different oeprations.
127 MOCK_METHOD2(OnFrameReady, 113 MOCK_METHOD2(OnFrameReady,
128 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); 114 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks));
129 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState)); 115 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState));
130 MOCK_METHOD1(OnDeviceFormatsInUse, void(const media::VideoCaptureFormats&)); 116 MOCK_METHOD1(OnDeviceFormatsInUse, void(const media::VideoCaptureFormats&));
131 MOCK_METHOD1(OnDeviceSupportedFormats, 117 MOCK_METHOD1(OnDeviceSupportedFormats,
132 void(const media::VideoCaptureFormats&)); 118 void(const media::VideoCaptureFormats&));
133 119
134 void StartCapture(int client_id, const media::VideoCaptureParams& params) { 120 void StartCapture(int client_id, const media::VideoCaptureParams& params) {
135 video_capture_impl_->StartCapture( 121 video_capture_impl_->StartCapture(
136 client_id, params, base::Bind(&VideoCaptureImplTest::OnStateUpdate, 122 client_id, params, base::Bind(&VideoCaptureImplTest::OnStateUpdate,
(...skipping 10 matching lines...) Expand all
147 video_capture_impl_->OnBufferCreated( 133 video_capture_impl_->OnBufferCreated(
148 base::SharedMemory::DuplicateHandle(shm.handle()), 134 base::SharedMemory::DuplicateHandle(shm.handle()),
149 shm.mapped_size(), buffer_id); 135 shm.mapped_size(), buffer_id);
150 } 136 }
151 137
152 void BufferReceived(int buffer_id, const gfx::Size& size) { 138 void BufferReceived(int buffer_id, const gfx::Size& size) {
153 base::TimeTicks now = base::TimeTicks::Now(); 139 base::TimeTicks now = base::TimeTicks::Now();
154 base::TimeDelta timestamp = now - base::TimeTicks(); 140 base::TimeDelta timestamp = now - base::TimeTicks();
155 141
156 media::VideoFrameMetadata frame_metadata; 142 media::VideoFrameMetadata frame_metadata;
157 frame_metadata.SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, 143 frame_metadata.SetTimeTicks(media::VideoFrameMetadata::REFERENCE_TIME, now);
158 now);
159 base::DictionaryValue metadata; 144 base::DictionaryValue metadata;
160 frame_metadata.MergeInternalValuesInto(&metadata); 145 frame_metadata.MergeInternalValuesInto(&metadata);
161 146
162 video_capture_impl_->OnBufferReceived( 147 video_capture_impl_->OnBufferReceived(
163 buffer_id, timestamp, metadata, media::PIXEL_FORMAT_I420, 148 buffer_id, timestamp, metadata, media::PIXEL_FORMAT_I420,
164 media::VideoFrame::STORAGE_SHMEM, size, gfx::Rect(size)); 149 media::VideoFrame::STORAGE_SHMEM, size, gfx::Rect(size));
165 } 150 }
166 151
167 void BufferDestroyed(int buffer_id) { 152 void BufferDestroyed(int buffer_id) {
168 video_capture_impl_->OnBufferDestroyed(buffer_id); 153 video_capture_impl_->OnBufferDestroyed(buffer_id);
169 } 154 }
170 155
171 void GetDeviceSupportedFormats() { 156 void GetDeviceSupportedFormats() {
172 const base::Callback<void(const media::VideoCaptureFormats&)> 157 const base::Callback<void(const media::VideoCaptureFormats&)>
173 callback = base::Bind( 158 callback = base::Bind(
174 &VideoCaptureImplTest::OnDeviceSupportedFormats, 159 &VideoCaptureImplTest::OnDeviceSupportedFormats,
175 base::Unretained(this)); 160 base::Unretained(this));
176 video_capture_impl_->GetDeviceSupportedFormats(callback); 161 video_capture_impl_->GetDeviceSupportedFormats(callback);
177 } 162 }
178 163
179 void GetDeviceFormatsInUse() { 164 void GetDeviceFormatsInUse() {
180 const base::Callback<void(const media::VideoCaptureFormats&)> 165 const base::Callback<void(const media::VideoCaptureFormats&)>
181 callback = base::Bind( 166 callback = base::Bind(
182 &VideoCaptureImplTest::OnDeviceFormatsInUse, 167 &VideoCaptureImplTest::OnDeviceFormatsInUse,
183 base::Unretained(this)); 168 base::Unretained(this));
184 video_capture_impl_->GetDeviceFormatsInUse(callback); 169 video_capture_impl_->GetDeviceFormatsInUse(callback);
185 } 170 }
186 171
172 void OnStateChanged(mojom::VideoCaptureState state) {
173 video_capture_impl_->OnStateChanged(state);
174 }
175
187 const base::MessageLoop message_loop_; 176 const base::MessageLoop message_loop_;
188 const ChildProcess child_process_; 177 const ChildProcess child_process_;
189 const scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; 178 const scoped_refptr<MockVideoCaptureMessageFilter> message_filter_;
190 std::unique_ptr<MockVideoCaptureImpl> video_capture_impl_; 179 const std::unique_ptr<VideoCaptureImpl> video_capture_impl_;
191 MockMojoVideoCaptureHost mock_video_capture_host_; 180 MockMojoVideoCaptureHost mock_video_capture_host_;
192 media::VideoCaptureParams params_small_; 181 media::VideoCaptureParams params_small_;
193 media::VideoCaptureParams params_large_; 182 media::VideoCaptureParams params_large_;
194 183
195 private: 184 private:
196 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); 185 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest);
197 }; 186 };
198 187
199 TEST_F(VideoCaptureImplTest, Simple) { 188 TEST_F(VideoCaptureImplTest, Simple) {
200 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); 189 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
201 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); 190 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED));
202 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 191 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_));
203 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 192 EXPECT_CALL(mock_video_capture_host_, Stop(_));
204 193
205 StartCapture(0, params_small_); 194 StartCapture(0, params_small_);
206 StopCapture(0); 195 StopCapture(0);
207 } 196 }
208 197
209 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) { 198 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) {
210 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 199 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2);
211 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 200 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2);
212 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 201 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_));
chfremer 2016/10/10 18:57:19 Here and in the two tests below, why do we only ex
mcasas 2016/10/10 19:39:44 It's misleading, but due to the current implementa
213 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 202 EXPECT_CALL(mock_video_capture_host_, Stop(_));
214 203
215 StartCapture(0, params_small_); 204 StartCapture(0, params_small_);
216 StopCapture(0); 205 StopCapture(0);
217 StartCapture(1, params_small_); 206 StartCapture(1, params_small_);
218 StopCapture(1); 207 StopCapture(1);
219 } 208 }
220 209
221 TEST_F(VideoCaptureImplTest, LargeAndSmall) { 210 TEST_F(VideoCaptureImplTest, LargeAndSmall) {
222 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 211 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2);
223 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 212 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2);
224 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_large_)); 213 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_large_));
225 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 214 EXPECT_CALL(mock_video_capture_host_, Stop(_));
226 215
227 StartCapture(0, params_large_); 216 StartCapture(0, params_large_);
228 StopCapture(0); 217 StopCapture(0);
229 StartCapture(1, params_small_); 218 StartCapture(1, params_small_);
230 StopCapture(1); 219 StopCapture(1);
231 } 220 }
232 221
233 TEST_F(VideoCaptureImplTest, SmallAndLarge) { 222 TEST_F(VideoCaptureImplTest, SmallAndLarge) {
234 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 223 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2);
235 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 224 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2);
236 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 225 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_));
237 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 226 EXPECT_CALL(mock_video_capture_host_, Stop(_));
238 227
239 StartCapture(0, params_small_); 228 StartCapture(0, params_small_);
240 StopCapture(0); 229 StopCapture(0);
241 StartCapture(1, params_large_); 230 StartCapture(1, params_large_);
242 StopCapture(1); 231 StopCapture(1);
243 } 232 }
244 233
245 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in 234 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in
246 // the provided callback. 235 // the provided callback.
(...skipping 29 matching lines...) Expand all
276 265
277 TEST_F(VideoCaptureImplTest, BufferReceived) { 266 TEST_F(VideoCaptureImplTest, BufferReceived) {
278 base::SharedMemory shm; 267 base::SharedMemory shm;
279 const size_t frame_size = media::VideoFrame::AllocationSize( 268 const size_t frame_size = media::VideoFrame::AllocationSize(
280 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size); 269 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size);
281 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); 270 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size));
282 271
283 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); 272 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
284 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); 273 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED));
285 EXPECT_CALL(*this, OnFrameReady(_, _)); 274 EXPECT_CALL(*this, OnFrameReady(_, _));
286 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 275 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_));
287 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 276 EXPECT_CALL(mock_video_capture_host_, Stop(_));
277 EXPECT_CALL(mock_video_capture_host_, ReleaseBuffer(_, _, _, _)).Times(0);
288 278
289 StartCapture(0, params_small_); 279 StartCapture(0, params_small_);
290 NewBuffer(0, shm); 280 NewBuffer(0, shm);
291 BufferReceived(0, params_small_.requested_format.frame_size); 281 BufferReceived(0, params_small_.requested_format.frame_size);
292 StopCapture(0); 282 StopCapture(0);
293 BufferDestroyed(0); 283 BufferDestroyed(0);
284
285 EXPECT_EQ(mock_video_capture_host_.released_buffer_count(), 0);
chfremer 2016/10/10 18:57:19 I am confused by this test case. We simulate that
mcasas 2016/10/10 19:39:44 VideoCaptureImpl's client has a callback to releas
294 } 286 }
295 287
296 TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) { 288 TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) {
297 base::SharedMemory shm; 289 base::SharedMemory shm;
298 const size_t frame_size = media::VideoFrame::AllocationSize( 290 const size_t frame_size = media::VideoFrame::AllocationSize(
299 media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size); 291 media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size);
300 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); 292 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size));
301 293
302 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); 294 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
303 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); 295 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED));
304 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0); 296 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0);
305 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_large_)); 297 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_large_));
306 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 298 EXPECT_CALL(mock_video_capture_host_, Stop(_));
299 EXPECT_CALL(mock_video_capture_host_, ReleaseBuffer(_, _, _, _));
307 300
308 StartCapture(0, params_large_); 301 StartCapture(0, params_large_);
309 NewBuffer(0, shm); 302 NewBuffer(0, shm);
310 StopCapture(0); 303 StopCapture(0);
304 // A buffer received after StopCapture() triggers an instant ReleaseBuffer().
311 BufferReceived(0, params_large_.requested_format.frame_size); 305 BufferReceived(0, params_large_.requested_format.frame_size);
312 BufferDestroyed(0); 306 BufferDestroyed(0);
313 307
314 EXPECT_EQ(this->video_capture_impl_->received_buffer_count(), 1); 308 EXPECT_EQ(mock_video_capture_host_.released_buffer_count(), 1);
315 } 309 }
316 310
317 TEST_F(VideoCaptureImplTest, AlreadyStarted) { 311 TEST_F(VideoCaptureImplTest, AlreadyStarted) {
318 media::VideoCaptureParams params = {}; 312 media::VideoCaptureParams params = {};
319 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); 313 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2);
320 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); 314 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2);
321 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, _)) 315 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, _))
322 .WillOnce(SaveArg<2>(&params)); 316 .WillOnce(SaveArg<2>(&params));
323 EXPECT_CALL(mock_video_capture_host_, Stop(_)); 317 EXPECT_CALL(mock_video_capture_host_, Stop(_));
324 318
325 StartCapture(0, params_small_); 319 StartCapture(0, params_small_);
326 StartCapture(1, params_large_); 320 StartCapture(1, params_large_);
327 StopCapture(0); 321 StopCapture(0);
328 StopCapture(1); 322 StopCapture(1);
329 DCHECK(params.requested_format == params_small_.requested_format); 323 DCHECK(params.requested_format == params_small_.requested_format);
330 } 324 }
331 325
332 TEST_F(VideoCaptureImplTest, EndedBeforeStop) { 326 TEST_F(VideoCaptureImplTest, EndedBeforeStop) {
333 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); 327 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
334 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); 328 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED));
335 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 329 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_));
336 330
337 StartCapture(0, params_small_); 331 StartCapture(0, params_small_);
338 332
339 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ENDED); 333 OnStateChanged(mojom::VideoCaptureState::ENDED);
340 334
341 StopCapture(0); 335 StopCapture(0);
342 } 336 }
343 337
344 TEST_F(VideoCaptureImplTest, ErrorBeforeStop) { 338 TEST_F(VideoCaptureImplTest, ErrorBeforeStop) {
345 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); 339 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
346 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_ERROR)); 340 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_ERROR));
347 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); 341 EXPECT_CALL(mock_video_capture_host_, DoStart(_, kSessionId, params_small_));
348 342
349 StartCapture(0, params_small_); 343 StartCapture(0, params_small_);
350 344
351 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR); 345 OnStateChanged(mojom::VideoCaptureState::FAILED);
352 346
353 StopCapture(0); 347 StopCapture(0);
354 } 348 }
355 349
356 } // namespace content 350 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698