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

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 6859402a4285af1b115de1e6b2715e142e94009f..b54ad35352ffebc9fe30acbd7cfba1973889b3b3 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"
@@ -38,7 +39,7 @@ class VideoCaptureImplTest : public ::testing::Test {
public:
MockVideoCaptureImpl(const media::VideoCaptureSessionId id,
VideoCaptureMessageFilter* filter)
- : VideoCaptureImpl(id, filter) {
+ : VideoCaptureImpl(id, filter), buffer_received_(0) {
}
~MockVideoCaptureImpl() override {}
@@ -81,7 +82,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) {
+ buffer_received_++;
+ }
void DeviceGetSupportedFormats(int device_id,
media::VideoCaptureSessionId session_id) {
@@ -106,6 +109,9 @@ class VideoCaptureImplTest : public ::testing::Test {
private:
media::VideoCaptureParams capture_params_;
+
+ public:
+ int buffer_received_;
ajose 2015/08/24 17:46:31 s/buffer_received/buffers_received/ ? Also consid
msu.koo 2015/08/25 00:45:23 Done.
};
VideoCaptureImplTest() {
@@ -153,6 +159,25 @@ class VideoCaptureImplTest : public ::testing::Test {
base::Unretained(this)));
}
+ 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) {
+ base::DictionaryValue metadata;
+ gpu::MailboxHolder mailbox;
+ video_capture_impl_->OnBufferReceived(
+ buffer_id, base::TimeTicks::Now(), base::DictionaryValue(),
+ media::PIXEL_FORMAT_I420, media::VideoFrame::STORAGE_SHMEM, size,
+ gfx::Rect(size.width(), size.height()), mailbox);
+ }
+
+ void BufferDestroyed(int buffer_id) {
+ video_capture_impl_->OnBufferDestroyed(buffer_id);
+ }
+
void StopCapture(int client_id) {
video_capture_impl_->StopCapture(client_id);
}
@@ -282,6 +307,48 @@ TEST_F(VideoCaptureImplTest, AlreadyStarted) {
params_small_.requested_format.frame_size);
}
+TEST_F(VideoCaptureImplTest, BufferReceived) {
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(1);
+ EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(1);
+ EXPECT_CALL(*this, OnFrameReady(_, _));
+
+ // Create a fake shared memory for buffer.
+ base::SharedMemory shm;
+ size_t i420_frame_size = media::VideoFrame::AllocationSize(
+ media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size);
+ ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size));
+
+ Init();
+ StartCapture(0, params_large_);
+ NewBuffer(0, shm);
+ BufferReceived(0, params_large_.requested_format.frame_size);
+ StopCapture(0);
+ BufferDestroyed(0);
+ DeInit();
+}
ajose 2015/08/24 17:46:31 EXPECT_EQ(this->video_capture_impl_->buffer_receiv
msu.koo 2015/08/25 00:45:23 I think this line is not required on this unittest
+
+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(
+ media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size);
+ ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size));
+
+ Init();
+ StartCapture(0, params_large_);
+ NewBuffer(0, shm);
+ StopCapture(0);
+ BufferReceived(0, params_large_.requested_format.frame_size);
+ BufferDestroyed(0);
+ DeInit();
+
+ EXPECT_EQ(this->video_capture_impl_->buffer_received_, 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