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

Unified Diff: content/renderer/media/video_capture_impl_unittest.cc

Issue 1314483003: Improve VideoCaptureImpl unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/video_capture_impl_unittest.cc
diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc
index 3860080eb49afaf388d0fdba44ebf60e4d70cd4c..02c809627c86b667a0d4688a33eb4ce3ff9bbdad 100644
--- a/content/renderer/media/video_capture_impl_unittest.cc
+++ b/content/renderer/media/video_capture_impl_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h"
#include "content/child/child_process.h"
#include "content/common/media/video_capture_messages.h"
@@ -34,13 +35,41 @@ class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter {
DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter);
};
-class VideoCaptureImplTest : public ::testing::Test {
+struct BufferReceivedTestArg {
+ BufferReceivedTestArg(int buffer_id,
+ media::VideoPixelFormat pixel_format,
+ media::VideoCapturePixelFormat capture_pixel_format,
+ const gfx::Size& coded_size,
+ const gpu::MailboxHolder& mailbox_holder)
+ : buffer_id(buffer_id), pixel_format(pixel_format),
+ capture_pixel_format(capture_pixel_format), coded_size(coded_size),
+ mailbox_holder(mailbox_holder) {}
+
+ int buffer_id;
+ media::VideoPixelFormat pixel_format;
+ media::VideoCapturePixelFormat capture_pixel_format;
+ const gfx::Size coded_size;
+ const gpu::MailboxHolder mailbox_holder;
+};
mcasas 2015/08/31 17:33:26 Prefer struct Bla { // ... } kBlas[] = { // .
msu.koo 2015/09/01 05:25:01 Moved |kBufferFormats| to INSTANTIATE_TEST_CASE_P
+
+static const BufferReceivedTestArg kBufferFormats[] = {
+ BufferReceivedTestArg(0, media::PIXEL_FORMAT_I420,
mcasas 2015/08/31 17:33:26 |buffer_id| and |coded_size| are common among the
msu.koo 2015/09/01 05:25:01 I basically agree with your opinion, but these var
mcasas 2015/09/01 18:09:53 Ah, we'll extend it when the moment comes, no dead
msu.koo 2015/09/02 08:38:10 Done.
+ media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
+ gfx::Size(1280, 720),
+ gpu::MailboxHolder()),
+ BufferReceivedTestArg(0, media::PIXEL_FORMAT_ARGB,
+ media::VIDEO_CAPTURE_PIXEL_FORMAT_ARGB,
+ gfx::Size(1280, 720),
+ gpu::MailboxHolder(gpu::Mailbox::Generate(), 0, 0))};
+
+class VideoCaptureImplTest :
+ public ::testing::TestWithParam<BufferReceivedTestArg> {
public:
class MockVideoCaptureImpl : public VideoCaptureImpl {
public:
MockVideoCaptureImpl(const media::VideoCaptureSessionId id,
VideoCaptureMessageFilter* filter)
- : VideoCaptureImpl(id, filter) {
+ : VideoCaptureImpl(id, filter), received_buffer_counts_(0) {
}
~MockVideoCaptureImpl() override {}
@@ -84,7 +113,9 @@ class VideoCaptureImplTest : public ::testing::Test {
void DeviceReceiveEmptyBuffer(int device_id,
int buffer_id,
uint32 sync_point,
- double consumer_resource_utilization) {}
+ double consumer_resource_utilization) {
+ received_buffer_counts_++;
+ }
void DeviceGetSupportedFormats(int device_id,
media::VideoCaptureSessionId session_id) {
@@ -106,8 +137,11 @@ class VideoCaptureImplTest : public ::testing::Test {
return capture_params_;
}
+ int GetReceivedBufferCounts() const { return received_buffer_counts_; }
mcasas 2015/08/31 17:33:26 s/GetReceivedBufferCounts()/received_buffer_count(
msu.koo 2015/09/01 05:25:01 Done.
+
private:
media::VideoCaptureParams capture_params_;
+ int received_buffer_counts_;
mcasas 2015/08/31 17:33:26 s/received_buffer_counts_/received_buffer_count_/
msu.koo 2015/09/01 05:25:01 Done.
};
VideoCaptureImplTest() {
@@ -154,6 +188,25 @@ class VideoCaptureImplTest : public ::testing::Test {
void StopCapture() { video_capture_impl_->StopCapture(); }
+ void NewBuffer(int buffer_id, const base::SharedMemory& shm) {
+ video_capture_impl_->OnBufferCreated(
+ base::SharedMemory::DuplicateHandle(shm.handle()),
+ shm.mapped_size(), buffer_id);
+ }
+
+ void BufferReceived(int buffer_id, const gfx::Size& size,
+ media::VideoPixelFormat pixel_format,
+ const gpu::MailboxHolder& mailbox_holder) {
+ video_capture_impl_->OnBufferReceived(
+ buffer_id, base::TimeTicks::Now(), base::DictionaryValue(),
+ pixel_format, media::VideoFrame::STORAGE_SHMEM, size,
+ gfx::Rect(size), mailbox_holder);
+ }
+
+ void BufferDestroyed(int buffer_id) {
+ video_capture_impl_->OnBufferDestroyed(buffer_id);
+ }
+
void DeInit() {
video_capture_impl_->DeInit();
}
@@ -228,6 +281,60 @@ TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) {
DeInit();
}
+TEST_P(VideoCaptureImplTest, BufferReceivedWithFormat) {
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
+ EXPECT_CALL(*this, OnFrameReady(_, _)).Times(1);
+
+ const BufferReceivedTestArg& buffer_arg = GetParam();
+
+ // Create a fake shared memory for buffer.
+ base::SharedMemory shm;
+ const size_t frame_size = media::VideoFrame::AllocationSize(
+ buffer_arg.pixel_format, buffer_arg.coded_size);
+ ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size));
+
+ media::VideoCaptureParams params;
+ params.requested_format = media::VideoCaptureFormat(
+ buffer_arg.coded_size, 30, buffer_arg.capture_pixel_format);
+
+ Init();
+ StartCapture(params);
+ NewBuffer(buffer_arg.buffer_id, shm);
+ BufferReceived(buffer_arg.buffer_id, buffer_arg.coded_size,
+ buffer_arg.pixel_format, buffer_arg.mailbox_holder);
+ StopCapture();
+ BufferDestroyed(buffer_arg.buffer_id);
+ DeInit();
+}
+
+INSTANTIATE_TEST_CASE_P(I420AndARGB,
+ VideoCaptureImplTest,
+ testing::ValuesIn(kBufferFormats));
mcasas 2015/08/31 17:33:26 You can also bring |kBufferFormats| here .
msu.koo 2015/09/01 05:25:01 Done.
+
+TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) {
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
+ EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0);
+
+ // Create a fake shared memory for buffer.
+ base::SharedMemory shm;
+ size_t i420_frame_size = media::VideoFrame::AllocationSize(
mcasas 2015/08/31 17:33:26 const
msu.koo 2015/09/01 05:25:01 Done.
+ media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size);
+ ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size));
+
+ Init();
+ StartCapture(params_large_);
+ NewBuffer(0, shm);
+ StopCapture();
+ BufferReceived(0, params_large_.requested_format.frame_size,
+ media::PIXEL_FORMAT_I420, gpu::MailboxHolder());
+ BufferDestroyed(0);
+ DeInit();
+
+ EXPECT_EQ(this->video_capture_impl_->GetReceivedBufferCounts(), 1);
+}
+
TEST_F(VideoCaptureImplTest, EndedBeforeStop) {
EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED));
EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698