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

Unified Diff: services/video_capture/fake_device_unittest.cc

Issue 2486543002: [Mojo Video Capture] Add test ReceiveFramesFromFakeCaptureDevice (Closed)
Patch Set: Created 4 years, 1 month 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
Index: services/video_capture/fake_device_unittest.cc
diff --git a/services/video_capture/fake_device_unittest.cc b/services/video_capture/fake_device_unittest.cc
index 3012e8e4366b7ef9f1f4dcf07d28383efaaf6e88..b2fbb2f6e394cee24e58c9886869b60316f4bed2 100644
--- a/services/video_capture/fake_device_unittest.cc
+++ b/services/video_capture/fake_device_unittest.cc
@@ -4,6 +4,8 @@
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
+#include "media/base/video_frame.h"
+#include "media/mojo/common/media_type_converters.h"
#include "services/video_capture/fake_device_test.h"
#include "services/video_capture/mock_video_frame_receiver.h"
#include "services/video_capture/public/cpp/video_capture_settings.h"
@@ -11,6 +13,7 @@
#include "services/video_capture/video_capture_service_test.h"
using testing::_;
+using testing::Invoke;
using testing::InvokeWithoutArgs;
namespace video_capture {
@@ -43,4 +46,67 @@ TEST_F(FakeDeviceTest, FrameCallbacksArrive) {
wait_loop.Run();
}
+struct FrameInfo {
+ gfx::Size size;
+ media::VideoPixelFormat pixel_format;
+ media::VideoFrame::StorageType storage_type;
+ bool is_mappable;
+ base::TimeDelta timestamp;
+};
mcasas 2016/11/09 23:50:29 Move this struct to an anonymous namespace inside
chfremer 2016/11/10 00:28:48 Done.
+
+// Tests that frames received from a fake capture device match the requested
+// format and have increasing timestamps.
+TEST_F(FakeDeviceTest, ReceiveFramesFromFakeCaptureDevice) {
+ // Set up a mock VideoFrameReceiver
+ base::RunLoop wait_loop;
+ mojom::VideoFrameReceiverPtr receiver_proxy;
+ constexpr int num_frames_to_receive = 2;
+ FrameInfo received_frame_infos[num_frames_to_receive];
+ int received_frame_count = 0;
+ MockVideoFrameReceiver receiver(mojo::GetProxy(&receiver_proxy));
+ EXPECT_CALL(receiver, OnIncomingCapturedVideoFramePtr(_))
+ .WillRepeatedly(
+ Invoke([&received_frame_infos, &received_frame_count,
+ &num_frames_to_receive, &wait_loop](
+ const media::mojom::VideoFramePtr* frame) {
+ if (received_frame_count >= num_frames_to_receive) {
+ return;
+ }
mcasas 2016/11/09 23:50:29 No {} for one-line bodies. Same for l.84, l.106
chfremer 2016/11/10 00:28:48 Done.
+ auto video_frame = frame->To<scoped_refptr<media::VideoFrame>>();
+ auto& frame_info = received_frame_infos[received_frame_count];
+ frame_info.pixel_format = video_frame->format();
+ frame_info.storage_type = video_frame->storage_type();
+ frame_info.is_mappable = video_frame->IsMappable();
+ frame_info.size = video_frame->natural_size();
+ frame_info.timestamp = video_frame->timestamp();
+ received_frame_count += 1;
+ if (received_frame_count == num_frames_to_receive) {
+ wait_loop.Quit();
+ }
+ }));
+
+ fake_device_proxy_->Start(
+ requestable_settings_, std::move(receiver_proxy));
+
+ wait_loop.Run();
+
+ base::TimeDelta previous_timestamp;
+ for (int i = 0; i < num_frames_to_receive; i++) {
+ auto& frame_info = received_frame_infos[i];
+ // Service is expected to always output I420
+ ASSERT_EQ(media::PIXEL_FORMAT_I420, frame_info.pixel_format);
+ // Service is expected to always use STORAGE_MOJO_SHARED_BUFFER
+ ASSERT_EQ(media::VideoFrame::STORAGE_MOJO_SHARED_BUFFER,
+ frame_info.storage_type);
+ ASSERT_TRUE(frame_info.is_mappable);
+ ASSERT_EQ(requestable_settings_.format.frame_size,
+ frame_info.size);
+ // Timestamps are expected to increase
+ if (i > 0) {
+ ASSERT_GT(frame_info.timestamp, previous_timestamp);
mcasas 2016/11/09 23:50:29 nit: ASSERT_* will stop the test in its tracks, wh
chfremer 2016/11/10 00:28:48 Very nice. I didn't know about EXPECT_*. Thanks. D
+ }
+ previous_timestamp = frame_info.timestamp;
+ }
+}
+
} // namespace video_capture

Powered by Google App Engine
This is Rietveld 408576698