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

Side by Side Diff: content/renderer/media/video_capture_impl_manager_unittest.cc

Issue 120893002: Eliminate video capture thread in renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git cl upload Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/memory/ref_counted.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "content/child/child_process.h"
10 #include "content/renderer/media/video_capture_impl_manager.h"
11 #include "content/renderer/media/video_capture_message_filter.h"
12 #include "media/base/bind_to_loop.h"
13 #include "media/video/capture/mock_video_capture_event_handler.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using ::testing::_;
18 using ::testing::DoAll;
19 using ::testing::SaveArg;
20 using media::BindToCurrentLoop;
21 using media::MockVideoCaptureEventHandler;
22
23 namespace content {
24
25 ACTION_P(RunClosure, closure) {
26 closure.Run();
27 }
28
29 class VideoCaptureImplManagerTest : public ::testing::Test {
30 public:
31 VideoCaptureImplManagerTest() {
32 params_.requested_format = media::VideoCaptureFormat(
33 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
34 child_process_.reset(new ChildProcess());
35 }
36
37 void FakeChannelSetup() {
38 scoped_refptr<base::MessageLoopProxy> loop =
39 child_process_->io_message_loop_proxy();
40 if (!loop->BelongsToCurrentThread()) {
41 loop->PostTask(
42 FROM_HERE,
43 base::Bind(
44 &VideoCaptureImplManagerTest::FakeChannelSetup,
45 base::Unretained(this)));
46 return;
47 }
48 manager_.video_capture_message_filter()->OnFilterAdded(NULL);
49 }
50
51 void Quit(base::RunLoop* run_loop) {
52 message_loop_.PostTask(FROM_HERE, run_loop->QuitClosure());
53 }
54
55 protected:
56 base::MessageLoop message_loop_;
57 scoped_ptr<ChildProcess> child_process_;
58 media::VideoCaptureParams params_;
59 VideoCaptureImplManager manager_;
60
61 private:
62 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest);
63 };
64
65 // Multiple clients with the same session id. There is only one
66 // media::VideoCapture object.
67 TEST_F(VideoCaptureImplManagerTest, MultipleClients) {
68 scoped_ptr<MockVideoCaptureEventHandler> client1(
69 new MockVideoCaptureEventHandler);
70 scoped_ptr<MockVideoCaptureEventHandler> client2(
71 new MockVideoCaptureEventHandler);
72
73 media::VideoCapture* device1 = NULL;
74 media::VideoCapture* device2 = NULL;
75
76 scoped_ptr<VideoCaptureHandle> handle1;
77 scoped_ptr<VideoCaptureHandle> handle2;
78 {
79 base::RunLoop run_loop;
80 base::Closure quit_closure = BindToCurrentLoop(
81 run_loop.QuitClosure());
82
83 EXPECT_CALL(*client1, OnStarted(_)).WillOnce(SaveArg<0>(&device1));
84 EXPECT_CALL(*client2, OnStarted(_)).WillOnce(
85 DoAll(
86 SaveArg<0>(&device2),
87 RunClosure(quit_closure)));
88 handle1 = manager_.UseDevice(1);
89 handle2 = manager_.UseDevice(1);
90 handle1->StartCapture(client1.get(), params_);
91 handle2->StartCapture(client2.get(), params_);
92 FakeChannelSetup();
93 run_loop.Run();
94 }
95
96 {
97 base::RunLoop run_loop;
98 base::Closure quit_closure = BindToCurrentLoop(
99 run_loop.QuitClosure());
100
101 EXPECT_CALL(*client1, OnStopped(_));
102 EXPECT_CALL(*client1, OnRemoved(_));
103 EXPECT_CALL(*client2, OnStopped(_));
104 EXPECT_CALL(*client2, OnRemoved(_)).WillOnce(
105 RunClosure(quit_closure));
106 handle1->StopCapture(client1.get());
107 handle2->StopCapture(client2.get());
108 run_loop.Run();
109 }
110
111 EXPECT_TRUE(device1 == device2);
112 }
113
114 // Two clients at different time. There are two media::VideoCapture
115 // objects created.
116 TEST_F(VideoCaptureImplManagerTest, ConsecutiveClients) {
117 scoped_ptr<MockVideoCaptureEventHandler> client1(
118 new MockVideoCaptureEventHandler);
119 scoped_ptr<MockVideoCaptureEventHandler> client2(
120 new MockVideoCaptureEventHandler);
121
122 media::VideoCapture* device1 = NULL;
123 media::VideoCapture* device2 = NULL;
124
125 // Start and stop the device for |handle1|.
126 scoped_ptr<VideoCaptureHandle> handle1 = manager_.UseDevice(1);
127 {
128 base::RunLoop run_loop;
129 base::Closure quit_closure = BindToCurrentLoop(
130 run_loop.QuitClosure());
131
132 EXPECT_CALL(*client1, OnStarted(_)).WillOnce(
133 DoAll(
134 SaveArg<0>(&device1),
135 RunClosure(quit_closure)));
136 handle1->StartCapture(client1.get(), params_);
137 FakeChannelSetup();
138 run_loop.Run();
139 }
140
141 {
142 base::RunLoop run_loop;
143 base::Closure quit_closure = BindToCurrentLoop(
144 run_loop.QuitClosure());
145
146 EXPECT_CALL(*client1, OnStopped(_));
147 EXPECT_CALL(*client1, OnRemoved(_)).WillOnce(
148 RunClosure(quit_closure));
149 handle1->StopCapture(client1.get());
150 run_loop.Run();
151 }
152
153 // This will cause the media::VideoCapture object to be destroyed.
154 {
155 base::RunLoop run_loop;
156 handle1.reset();
157 run_loop.RunUntilIdle();
158 }
159
160 // Start and stop the device for |handle2| with the same session id.
161 scoped_ptr<VideoCaptureHandle> handle2 = manager_.UseDevice(1);
162 {
163 base::RunLoop run_loop;
164 base::Closure quit_closure = BindToCurrentLoop(
165 run_loop.QuitClosure());
166
167 EXPECT_CALL(*client2, OnStarted(_)).WillOnce(
168 DoAll(
169 SaveArg<0>(&device2),
170 RunClosure(quit_closure)));
171 handle2->StartCapture(client2.get(), params_);
172 FakeChannelSetup();
173 run_loop.Run();
174 }
175
176 {
177 base::RunLoop run_loop;
178 base::Closure quit_closure = BindToCurrentLoop(
179 run_loop.QuitClosure());
180
181 EXPECT_CALL(*client2, OnStopped(_));
182 EXPECT_CALL(*client2, OnRemoved(_)).WillOnce(
183 RunClosure(quit_closure));
184 handle2->StopCapture(client2.get());
185 run_loop.Run();
186 }
187 handle2.reset();
Ami GONE FROM CHROMIUM 2014/01/08 01:43:58 Where does that verification happen?
Alpha Left Google 2014/01/08 22:30:50 I meant the test was supposed to verify that VCI i
188 }
189
190 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698