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

Unified Diff: components/video_capture/stream_impl_unittest.cc

Issue 1637793004: [WIP] Mojo Video Capture thingy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
Index: components/video_capture/stream_impl_unittest.cc
diff --git a/components/video_capture/stream_impl_unittest.cc b/components/video_capture/stream_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d369088fdfc410d1b28607c8540bb784fa31deea
--- /dev/null
+++ b/components/video_capture/stream_impl_unittest.cc
@@ -0,0 +1,195 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/run_loop.h"
+#include "components/video_capture/public/cpp/stream_client_impl.h"
+#include "components/video_capture/stream_impl.h"
+#include "media/base/video_frame.h"
+#include "mojo/public/c/system/buffer.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::AllOf;
+using ::testing::InSequence;
+using ::testing::Field;
+
+namespace video_capture {
+
+namespace {
+
+class MockStreamClient : public mojom::StreamClient {
+ public:
+ MockStreamClient() {}
+
+ // mojom::StreamClient. Use forwarders for move only types, see
+ // https://github.com/google/googletest/issues/395
+ MOCK_METHOD1(DoBufferCreated, void(mojom::FrameBufferInfo* info));
+ void BufferCreated(mojom::FrameBufferInfoPtr info) override {
+ DoBufferCreated(info.get());
+ }
+ MOCK_METHOD1(BufferDestroyed, void(int32_t buffer_id));
+ MOCK_METHOD2(DoFrameAvailable,
+ void(mojom::FrameInfo* info,
+ const FrameAvailableCallback& callback));
+ void FrameAvailable(mojom::FrameInfoPtr info,
+ const FrameAvailableCallback& callback) override {
+ DCHECK(false);
+ DoFrameAvailable(info.get(), callback);
+ callback.Run();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockStreamClient);
+};
+
+} // anonymous namespace
+
+class StreamImplTest : public testing::Test {
+ public:
+ StreamImplTest()
+ : stream_impl_(new StreamImpl(
+ mojo::GetProxy(&stream_ptr_),
+ base::Bind(&StreamImplTest::OnStart, base::Unretained(this)),
+ base::Bind(&StreamImplTest::OnStop, base::Unretained(this)))) {}
+
+ void SetUp() override {}
+ void TearDown() override {}
+
+ MOCK_METHOD0(OnStart, void());
+ MOCK_METHOD0(OnStop, void());
+ MOCK_METHOD0(OnRelease, void());
+
+ void OnFrame(const scoped_refptr<media::VideoFrame>& frame,
+ const base::TimeTicks& timestamp,
+ const base::Closure& release_callback) {
+ stream_impl_->OnFrame(frame, timestamp, release_callback);
+ }
+ void NotifyBufferCreated(int32_t id,
+ mojo::ScopedSharedBufferHandle handle,
+ size_t size) {
+ stream_impl_->NotifyBufferCreated(id, std::move(handle), size);
+ }
+ void NotifyBufferDestroyed(int32_t id) {
+ stream_impl_->NotifyBufferDestroyed(id);
+ }
+ void NotifyFrameAvailable(int32_t buffer_id,
+ const scoped_refptr<media::VideoFrame>& frame,
+ const base::TimeTicks& timestamp,
+ const base::Closure& release_callback) {
+ stream_impl_->NotifyFrameAvailable(buffer_id, frame, timestamp,
+ release_callback);
+ }
+ void StartAndExpectOnStart() {
+ EXPECT_CALL(*this, OnStart()).Times(1);
+ scoped_ptr<mojo::Binding<mojom::StreamClient>> binding(
Ken Rockot(use gerrit already) 2016/01/28 03:20:36 Binding takes ownership of its end of the message
+ new mojo::Binding<mojom::StreamClient>(&stream_client_impl_));
+ stream_impl_->Start(binding->CreateInterfacePtrAndBind());
+ }
+
+ protected:
+ // This is needed for the Binding's Router's HandleWatcher :)
+ const base::MessageLoop loop_;
+
+ mojom::StreamPtr stream_ptr_;
+ // The class under test.
+ scoped_ptr<StreamImpl> stream_impl_;
+
+ // The mock of the (remote) video capture client.
+ MockStreamClient stream_client_impl_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(StreamImplTest);
+};
+
+TEST_F(StreamImplTest, CreateAndDestroy) {
+}
+
+TEST_F(StreamImplTest, StartAndCreateAndDestroyBuffer) {
+ InSequence s;
+
+ StartAndExpectOnStart();
+
+ const int kBufferId = 123;
+ const int kBufferSize = 456;
+
+ MojoCreateSharedBufferOptions options;
+ options.struct_size = sizeof(options);
+ options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;
+ mojo::SharedBufferHandle buffer1;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoCreateSharedBuffer(&options, kBufferSize,
+ buffer1.mutable_value()));
+
+ // TODO(mcasas): SaveArg and compare EXPECT_CALLs argument.
+ EXPECT_CALL(stream_client_impl_, DoBufferCreated(_)).Times(1);
+ NotifyBufferCreated(kBufferId, mojo::ScopedSharedBufferHandle(buffer1),
+ kBufferSize);
+
+ EXPECT_CALL(stream_client_impl_, BufferDestroyed(kBufferId)).Times(1);
+ NotifyBufferDestroyed(kBufferId);
+}
Ken Rockot(use gerrit already) 2016/01/28 03:20:36 You do need to wait. Note that there's a separate
+
+// Tests the connection NotifyFrameAvailable() --> client's FrameAvailable().
+TEST_F(StreamImplTest, NotifyFrameAvailableSendsFrame) {
+ InSequence s;
+
+ StartAndExpectOnStart();
+
+ const int kBufferId = 123;
+ const scoped_refptr<media::VideoFrame> black_frame =
+ media::VideoFrame::CreateBlackFrame(gfx::Size(10, 10));
+ const base::TimeTicks now = base::TimeTicks::Now();
+
+ EXPECT_CALL(
+ stream_client_impl_,
+ DoFrameAvailable(
+ AllOf(Field(&mojom::FrameInfo::buffer_id, kBufferId),
+ Field(&mojom::FrameInfo::pixel_format,
+ static_cast<media::interfaces::VideoFormat>(
+ black_frame->format())),
+ Field(&mojom::FrameInfo::timestamp, now.ToInternalValue())),
+ _))
+ .Times(1);
+ EXPECT_CALL(*this, OnRelease()).Times(1);
+
+ NotifyFrameAvailable(
+ kBufferId, black_frame, now,
+ base::Bind(&StreamImplTest::OnRelease, base::Unretained(this)));
+
+ base::MessageLoop::current()->RunUntilIdle();
+}
+
+// Tests the connection OnFrame() --> (NotifyFrameAvailable()) --> client's
+// FrameAvailable(). This is a superset of the paths touched by the
+// NotifyFrameAvailableSendsFrame test.
+TEST_F(StreamImplTest, OnFrameSendsFrame) {
+ InSequence s;
+
+ StartAndExpectOnStart();
+
+ const scoped_refptr<media::VideoFrame> black_frame =
+ media::VideoFrame::CreateBlackFrame(gfx::Size(10, 10));
+ const base::TimeTicks now = base::TimeTicks::Now();
+
+ // TODO(mcasas): SaveArg and compare EXPECT_CALLs argument.
+ EXPECT_CALL(
+ stream_client_impl_,
+ DoFrameAvailable(
+ AllOf(Field(&mojom::FrameInfo::pixel_format,
+ static_cast<media::interfaces::VideoFormat>(
+ black_frame->format())),
+ Field(&mojom::FrameInfo::timestamp, now.ToInternalValue())),
+ _))
+ .Times(1);
+ EXPECT_CALL(*this, OnRelease()).Times(1);
+
+ OnFrame(black_frame, now,
+ base::Bind(&StreamImplTest::OnRelease, base::Unretained(this)));
+ base::MessageLoop::current()->RunUntilIdle();
+
+}
+
+} // namespace video_capture
« no previous file with comments | « components/video_capture/stream_impl.cc ('k') | content/browser/renderer_host/media/video_capture_device_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698