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

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: comments 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.h"
11 #include "content/renderer/media/video_capture_impl_manager.h"
12 #include "content/renderer/media/video_capture_message_filter.h"
13 #include "media/base/bind_to_loop.h"
14 #include "media/video/capture/mock_video_capture_event_handler.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 using ::testing::_;
19 using ::testing::DoAll;
20 using ::testing::SaveArg;
21 using media::BindToCurrentLoop;
22 using media::MockVideoCaptureEventHandler;
23
24 namespace content {
25
26 ACTION_P(RunClosure, closure) {
27 closure.Run();
28 }
29
30
31 class MockVideoCaptureImpl : public VideoCaptureImpl {
32 public:
33 MockVideoCaptureImpl(media::VideoCaptureSessionId session_id,
34 VideoCaptureMessageFilter* filter)
35 : VideoCaptureImpl(session_id, filter) {
36 }
37
38 virtual ~MockVideoCaptureImpl() {
39 Destruct();
40 }
41
42 MOCK_METHOD0(Destruct, void());
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl);
46 };
47
48 class MockVideoCaptureImplManager : public VideoCaptureImplManager {
49 public:
50 MockVideoCaptureImplManager() {}
51
52 protected:
53 virtual VideoCaptureImpl* CreateVideoCaptureImpl(
54 media::VideoCaptureSessionId id,
55 VideoCaptureMessageFilter* filter) const OVERRIDE {
56 return new MockVideoCaptureImpl(id, filter);
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager);
61 };
62
63 class VideoCaptureImplManagerTest : public ::testing::Test {
64 public:
65 VideoCaptureImplManagerTest() {
66 params_.requested_format = media::VideoCaptureFormat(
67 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
68 child_process_.reset(new ChildProcess());
69 }
70
71 void FakeChannelSetup() {
72 scoped_refptr<base::MessageLoopProxy> loop =
73 child_process_->io_message_loop_proxy();
74 if (!loop->BelongsToCurrentThread()) {
75 loop->PostTask(
76 FROM_HERE,
77 base::Bind(
78 &VideoCaptureImplManagerTest::FakeChannelSetup,
79 base::Unretained(this)));
80 return;
81 }
82 manager_.video_capture_message_filter()->OnFilterAdded(NULL);
83 }
84
85 void Quit(base::RunLoop* run_loop) {
86 message_loop_.PostTask(FROM_HERE, run_loop->QuitClosure());
87 }
88
89 protected:
90 base::MessageLoop message_loop_;
91 scoped_ptr<ChildProcess> child_process_;
92 media::VideoCaptureParams params_;
93 MockVideoCaptureImplManager manager_;
94
95 private:
96 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest);
97 };
98
99 // Multiple clients with the same session id. There is only one
100 // media::VideoCapture object.
101 TEST_F(VideoCaptureImplManagerTest, MultipleClients) {
102 scoped_ptr<MockVideoCaptureEventHandler> client1(
103 new MockVideoCaptureEventHandler);
104 scoped_ptr<MockVideoCaptureEventHandler> client2(
105 new MockVideoCaptureEventHandler);
106
107 media::VideoCapture* device1 = NULL;
108 media::VideoCapture* device2 = NULL;
109
110 scoped_ptr<VideoCaptureHandle> handle1;
111 scoped_ptr<VideoCaptureHandle> handle2;
112 {
113 base::RunLoop run_loop;
114 base::Closure quit_closure = BindToCurrentLoop(
115 run_loop.QuitClosure());
116
117 EXPECT_CALL(*client1, OnStarted(_)).WillOnce(SaveArg<0>(&device1));
118 EXPECT_CALL(*client2, OnStarted(_)).WillOnce(
119 DoAll(
120 SaveArg<0>(&device2),
121 RunClosure(quit_closure)));
122 handle1 = manager_.UseDevice(1);
123 handle2 = manager_.UseDevice(1);
124 handle1->StartCapture(client1.get(), params_);
125 handle2->StartCapture(client2.get(), params_);
126 FakeChannelSetup();
127 run_loop.Run();
128 }
129
130 {
131 base::RunLoop run_loop;
132 base::Closure quit_closure = BindToCurrentLoop(
133 run_loop.QuitClosure());
134
135 EXPECT_CALL(*client1, OnStopped(_));
136 EXPECT_CALL(*client1, OnRemoved(_));
137 EXPECT_CALL(*client2, OnStopped(_));
138 EXPECT_CALL(*client2, OnRemoved(_)).WillOnce(
139 RunClosure(quit_closure));
140 handle1->StopCapture(client1.get());
141 handle2->StopCapture(client2.get());
142 run_loop.Run();
143 }
144
145 EXPECT_TRUE(device1 == device2);
146 EXPECT_CALL(*static_cast<MockVideoCaptureImpl*>(device1), Destruct());
147 }
148
149 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698