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

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

Issue 960103002: Rename VideoCaptureImplManager to VideoCaptureService Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix some nits Created 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/child/child_process.h" 10 #include "content/child/child_process.h"
11 #include "content/renderer/media/video_capture_impl.h" 11 #include "content/renderer/media/video_capture_impl.h"
12 #include "content/renderer/media/video_capture_impl_manager.h"
13 #include "content/renderer/media/video_capture_message_filter.h" 12 #include "content/renderer/media/video_capture_message_filter.h"
13 #include "content/renderer/media/video_capture_service.h"
14 #include "media/base/bind_to_current_loop.h" 14 #include "media/base/bind_to_current_loop.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using ::testing::_; 18 using ::testing::_;
19 using ::testing::DoAll; 19 using ::testing::DoAll;
20 using ::testing::SaveArg; 20 using ::testing::SaveArg;
21 using media::BindToCurrentLoop; 21 using media::BindToCurrentLoop;
22 22
23 namespace content { 23 namespace content {
(...skipping 12 matching lines...) Expand all
36 } 36 }
37 37
38 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); } 38 ~MockVideoCaptureImpl() override { destruct_callback_.Run(); }
39 39
40 private: 40 private:
41 base::Closure destruct_callback_; 41 base::Closure destruct_callback_;
42 42
43 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl); 43 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImpl);
44 }; 44 };
45 45
46 class MockVideoCaptureImplManager : public VideoCaptureImplManager { 46 class MockVideoCaptureService : public VideoCaptureService {
47 public: 47 public:
48 explicit MockVideoCaptureImplManager( 48 explicit MockVideoCaptureService(
49 base::Closure destruct_video_capture_callback) 49 base::Closure destruct_video_capture_callback)
50 : destruct_video_capture_callback_( 50 : destruct_video_capture_callback_(
51 destruct_video_capture_callback) {} 51 destruct_video_capture_callback) {}
52 ~MockVideoCaptureImplManager() override {} 52 ~MockVideoCaptureService() override {}
53 53
54 protected: 54 protected:
55 VideoCaptureImpl* CreateVideoCaptureImplForTesting( 55 VideoCaptureImpl* CreateVideoCaptureImplForTesting(
56 media::VideoCaptureSessionId id, 56 media::VideoCaptureSessionId id,
57 VideoCaptureMessageFilter* filter) const override { 57 VideoCaptureMessageFilter* filter) const override {
58 return new MockVideoCaptureImpl(id, 58 return new MockVideoCaptureImpl(id,
59 filter, 59 filter,
60 destruct_video_capture_callback_); 60 destruct_video_capture_callback_);
61 } 61 }
62 62
63 private: 63 private:
64 base::Closure destruct_video_capture_callback_; 64 base::Closure destruct_video_capture_callback_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureImplManager); 66 DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureService);
67 }; 67 };
68 68
69 class VideoCaptureImplManagerTest : public ::testing::Test { 69 class VideoCaptureServiceTest : public ::testing::Test {
70 public: 70 public:
71 VideoCaptureImplManagerTest() 71 VideoCaptureServiceTest()
72 : manager_(new MockVideoCaptureImplManager( 72 : manager_(new MockVideoCaptureService(
73 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) { 73 BindToCurrentLoop(cleanup_run_loop_.QuitClosure()))) {
74 params_.requested_format = media::VideoCaptureFormat( 74 params_.requested_format = media::VideoCaptureFormat(
75 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); 75 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420);
76 child_process_.reset(new ChildProcess()); 76 child_process_.reset(new ChildProcess());
77 } 77 }
78 78
79 void FakeChannelSetup() { 79 void FakeChannelSetup() {
80 scoped_refptr<base::MessageLoopProxy> loop = 80 scoped_refptr<base::MessageLoopProxy> loop =
81 child_process_->io_message_loop_proxy(); 81 child_process_->io_message_loop_proxy();
82 if (!loop->BelongsToCurrentThread()) { 82 if (!loop->BelongsToCurrentThread()) {
83 loop->PostTask( 83 loop->PostTask(
84 FROM_HERE, 84 FROM_HERE,
85 base::Bind( 85 base::Bind(
86 &VideoCaptureImplManagerTest::FakeChannelSetup, 86 &VideoCaptureServiceTest::FakeChannelSetup,
87 base::Unretained(this))); 87 base::Unretained(this)));
88 return; 88 return;
89 } 89 }
90 manager_->video_capture_message_filter()->OnFilterAdded(NULL); 90 manager_->video_capture_message_filter()->OnFilterAdded(NULL);
91 } 91 }
92 92
93 protected: 93 protected:
94 MOCK_METHOD3(OnFrameReady, 94 MOCK_METHOD3(OnFrameReady,
95 void(const scoped_refptr<media::VideoFrame>&, 95 void(const scoped_refptr<media::VideoFrame>&,
96 const media::VideoCaptureFormat&, 96 const media::VideoCaptureFormat&,
(...skipping 10 matching lines...) Expand all
107 OnStopped(); 107 OnStopped();
108 break; 108 break;
109 default: 109 default:
110 NOTREACHED(); 110 NOTREACHED();
111 } 111 }
112 } 112 }
113 113
114 base::Closure StartCapture(const media::VideoCaptureParams& params) { 114 base::Closure StartCapture(const media::VideoCaptureParams& params) {
115 return manager_->StartCapture( 115 return manager_->StartCapture(
116 0, params, 116 0, params,
117 base::Bind(&VideoCaptureImplManagerTest::OnStateUpdate, 117 base::Bind(&VideoCaptureServiceTest::OnStateUpdate,
118 base::Unretained(this)), 118 base::Unretained(this)),
119 base::Bind(&VideoCaptureImplManagerTest::OnFrameReady, 119 base::Bind(&VideoCaptureServiceTest::OnFrameReady,
120 base::Unretained(this))); 120 base::Unretained(this)));
121 } 121 }
122 122
123 base::MessageLoop message_loop_; 123 base::MessageLoop message_loop_;
124 scoped_ptr<ChildProcess> child_process_; 124 scoped_ptr<ChildProcess> child_process_;
125 media::VideoCaptureParams params_; 125 media::VideoCaptureParams params_;
126 base::RunLoop cleanup_run_loop_; 126 base::RunLoop cleanup_run_loop_;
127 scoped_ptr<MockVideoCaptureImplManager> manager_; 127 scoped_ptr<MockVideoCaptureService> manager_;
128 128
129 private: 129 private:
130 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManagerTest); 130 DISALLOW_COPY_AND_ASSIGN(VideoCaptureServiceTest);
131 }; 131 };
132 132
133 // Multiple clients with the same session id. There is only one 133 // Multiple clients with the same session id. There is only one
134 // media::VideoCapture object. 134 // media::VideoCapture object.
135 TEST_F(VideoCaptureImplManagerTest, MultipleClients) { 135 TEST_F(VideoCaptureServiceTest, MultipleClients) {
136 base::Closure release_cb1 = manager_->UseDevice(0); 136 base::Closure release_cb1 = manager_->UseDevice(0);
137 base::Closure release_cb2 = manager_->UseDevice(0); 137 base::Closure release_cb2 = manager_->UseDevice(0);
138 base::Closure stop_cb1, stop_cb2; 138 base::Closure stop_cb1, stop_cb2;
139 { 139 {
140 base::RunLoop run_loop; 140 base::RunLoop run_loop;
141 base::Closure quit_closure = BindToCurrentLoop( 141 base::Closure quit_closure = BindToCurrentLoop(
142 run_loop.QuitClosure()); 142 run_loop.QuitClosure());
143 EXPECT_CALL(*this, OnStarted()).WillOnce( 143 EXPECT_CALL(*this, OnStarted()).WillOnce(
144 RunClosure(quit_closure)); 144 RunClosure(quit_closure));
145 EXPECT_CALL(*this, OnStarted()).RetiresOnSaturation(); 145 EXPECT_CALL(*this, OnStarted()).RetiresOnSaturation();
(...skipping 13 matching lines...) Expand all
159 stop_cb1.Run(); 159 stop_cb1.Run();
160 stop_cb2.Run(); 160 stop_cb2.Run();
161 run_loop.Run(); 161 run_loop.Run();
162 } 162 }
163 163
164 release_cb1.Run(); 164 release_cb1.Run();
165 release_cb2.Run(); 165 release_cb2.Run();
166 cleanup_run_loop_.Run(); 166 cleanup_run_loop_.Run();
167 } 167 }
168 168
169 TEST_F(VideoCaptureImplManagerTest, NoLeak) { 169 TEST_F(VideoCaptureServiceTest, NoLeak) {
170 manager_->UseDevice(0).Reset(); 170 manager_->UseDevice(0).Reset();
171 manager_.reset(); 171 manager_.reset();
172 cleanup_run_loop_.Run(); 172 cleanup_run_loop_.Run();
173 } 173 }
174 174
175 } // namespace content 175 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698