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

Side by Side Diff: media/capture/service/stream_impl_unittest.cc

Issue 1699553002: Mojo Video Capture service in media/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added missing BUILD deps Created 4 years, 9 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/run_loop.h"
7 #include "media/capture/service/mock_stream_client.h"
8 #include "media/capture/service/mojo_video_frame.h"
9 #include "media/capture/service/stream_impl.h"
10 #include "mojo/public/cpp/system/buffer.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using ::testing::_;
15 using ::testing::AllOf;
16 using ::testing::InSequence;
17 using ::testing::Field;
18 using ::testing::Property;
19
20 namespace media {
21
22 namespace {
23
24 ACTION_P(RunClosure, closure) {
25 closure.Run();
26 }
27
28 } // anonymous namespace
29
30 class StreamImplTest : public testing::Test {
31 public:
32 StreamImplTest()
33 : stream_impl_(new StreamImpl(
34 mojo::GetProxy(&stream_ptr_),
35 base::Bind(&StreamImplTest::StartCallback, base::Unretained(this)),
36 base::Bind(&StreamImplTest::StopCallback, base::Unretained(this)),
37 base::Bind(&StreamImplTest::ErrorCallback,
38 base::Unretained(this)))) {}
39
40 void SetUp() override {}
41 void TearDown() override {}
42
43 MOCK_METHOD0(StartCallback, void());
44 MOCK_METHOD0(StopCallback, void());
45 MOCK_METHOD0(ErrorCallback, void());
46 MOCK_METHOD0(OnRelease, void());
47
48 void OnFrame(const scoped_refptr<MojoVideoFrame>& frame,
49 const base::TimeTicks& timestamp) {
50 stream_impl_->OnFrame(frame, timestamp);
51 }
52 void OnError(const std::string& reason) { stream_impl_->OnError(reason); }
53
54 void StartAndExpectStartCallback() {
55 EXPECT_CALL(*this, StartCallback()).Times(1);
56 video_capture::StreamClientPtr le_client =
57 stream_client_impl_.CreateProxy();
58 stream_impl_->Start(std::move(le_client));
59 }
60
61 protected:
62 // This is needed for the Binding's Router's HandleWatcher :)
63 const base::MessageLoop loop_;
64
65 video_capture::StreamPtr stream_ptr_;
66 // The class under test.
67 const scoped_ptr<StreamImpl> stream_impl_;
68
69 // The mock of the (remote) video capture client.
70 MockStreamClient stream_client_impl_;
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(StreamImplTest);
74 };
75
76 TEST_F(StreamImplTest, CreateAndStartAndDestroy) {
77 StartAndExpectStartCallback();
78 }
79
80 // Tests the connection
81 // OnFrame() --> (NotifyFrameAvailable()) --> client's FrameAvailable().
82 TEST_F(StreamImplTest, OnFramePingsFrameAvailable) {
83 InSequence s;
84 StartAndExpectStartCallback();
85
86 const gfx::Size kFrameSize(10, 10);
87 const scoped_refptr<MojoVideoFrame> le_frame =
88 MojoVideoFrame::CreateMojoVideoFrame(kFrameSize, base::TimeDelta());
89 le_frame->AddDestructionObserver(
90 base::Bind(&StreamImplTest::OnRelease, base::Unretained(this)));
91 const base::TimeTicks now = base::TimeTicks::Now();
92
93 base::RunLoop run_loop;
94 base::Closure quit_closure = run_loop.QuitClosure();
95 EXPECT_CALL(
96 stream_client_impl_,
97 DoFrameAvailable(AllOf(Field(&video_capture::FrameInfo::storage_size,
98 le_frame->mapped_size()),
99 Field(&video_capture::FrameInfo::pixel_format,
100 static_cast<media::interfaces::VideoFormat>(
101 le_frame->format())),
102 Field(&video_capture::FrameInfo::timestamp,
103 now.ToInternalValue())),
104 _))
105 .Times(1)
106 .WillOnce(RunClosure(quit_closure));
107 EXPECT_CALL(*this, OnRelease()).Times(1);
108
109 OnFrame(le_frame, now);
110 run_loop.Run();
111 }
112
113 // Tests the connection
114 // OnError() --> (NotifyError()) --> client's and owners' Error().
115 TEST_F(StreamImplTest, OnErrorPingsError) {
116 InSequence s;
117 StartAndExpectStartCallback();
118
119 const std::string kErrorMessage("big error!");
120 base::RunLoop run_loop;
121 base::Closure quit_closure = run_loop.QuitClosure();
122
123 EXPECT_CALL(*this, ErrorCallback()).Times(1);
124 EXPECT_CALL(
125 stream_client_impl_,
126 Error(Property(&mojo::String::To<std::string>, kErrorMessage.c_str())))
127 .Times(1)
128 .WillOnce(RunClosure(quit_closure));
129 OnError(kErrorMessage);
130 run_loop.Run();
131 }
132
133 // Tests the connection Stop() --> Stop Callback.
134 TEST_F(StreamImplTest, StopPingsStopCallback) {
135 StartAndExpectStartCallback();
136 stream_impl_->Pause();
137 stream_impl_->Resume();
138
139 EXPECT_CALL(*this, ErrorCallback()).Times(0);
140 EXPECT_CALL(*this, StopCallback()).Times(1);
141 stream_impl_->Stop();
142 base::RunLoop().RunUntilIdle();
143 }
144
145 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698