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

Side by Side Diff: content/browser/media/capture/desktop_capture_device_unittest.cc

Issue 268123003: Enables using the magnification API for screen capturing on Windows under a Finch experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « content/browser/media/capture/desktop_capture_device.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 "content/browser/media/capture/desktop_capture_device.h" 5 #include "content/browser/media/capture/desktop_capture_device.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/sequenced_task_runner.h" 8 #include "base/sequenced_task_runner.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
11 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/threading/thread.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
16 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 17 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
17 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" 18 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
18 19
19 using ::testing::_; 20 using ::testing::_;
20 using ::testing::AnyNumber; 21 using ::testing::AnyNumber;
21 using ::testing::DoAll; 22 using ::testing::DoAll;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 virtual bool SelectScreen(webrtc::ScreenId id) OVERRIDE { 126 virtual bool SelectScreen(webrtc::ScreenId id) OVERRIDE {
126 return false; 127 return false;
127 } 128 }
128 129
129 private: 130 private:
130 Callback* callback_; 131 Callback* callback_;
131 int frame_index_; 132 int frame_index_;
132 bool generate_inverted_frames_; 133 bool generate_inverted_frames_;
133 }; 134 };
134 135
136 } // namespace
137
135 class DesktopCaptureDeviceTest : public testing::Test { 138 class DesktopCaptureDeviceTest : public testing::Test {
136 public: 139 public:
137 virtual void SetUp() OVERRIDE { 140 virtual void SetUp() OVERRIDE {
138 worker_pool_ = new base::SequencedWorkerPool(3, "TestCaptureThread"); 141 worker_pool_ = new base::SequencedWorkerPool(3, "TestCaptureThread");
139 } 142 }
140 143
144 void CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer> capturer) {
145 capture_device_.reset(new DesktopCaptureDevice(
146 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
147 thread_.Pass(),
148 capturer.Pass(),
149 DesktopMediaID::TYPE_SCREEN));
150 }
151
141 protected: 152 protected:
142 scoped_refptr<base::SequencedWorkerPool> worker_pool_; 153 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
154 scoped_ptr<base::Thread> thread_;
155 scoped_ptr<DesktopCaptureDevice> capture_device_;
143 }; 156 };
144 157
145 } // namespace
146
147 // There is currently no screen capturer implementation for ozone. So disable 158 // There is currently no screen capturer implementation for ozone. So disable
148 // the test that uses a real screen-capturer instead of FakeScreenCapturer. 159 // the test that uses a real screen-capturer instead of FakeScreenCapturer.
149 // http://crbug.com/260318 160 // http://crbug.com/260318
150 #if defined(USE_OZONE) 161 #if defined(USE_OZONE)
151 #define MAYBE_Capture DISABLED_Capture 162 #define MAYBE_Capture DISABLED_Capture
152 #else 163 #else
153 #define MAYBE_Capture Capture 164 #define MAYBE_Capture Capture
154 #endif 165 #endif
155 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) { 166 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) {
156 scoped_ptr<webrtc::DesktopCapturer> capturer( 167 scoped_ptr<webrtc::DesktopCapturer> capturer(
157 webrtc::ScreenCapturer::Create()); 168 webrtc::ScreenCapturer::Create());
158 DesktopCaptureDevice capture_device( 169 CreateScreenCaptureDevice(capturer.Pass());
159 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 170
160 capturer.Pass(),
161 DesktopMediaID::TYPE_SCREEN);
162 media::VideoCaptureFormat format; 171 media::VideoCaptureFormat format;
163 base::WaitableEvent done_event(false, false); 172 base::WaitableEvent done_event(false, false);
164 int frame_size; 173 int frame_size;
165 174
166 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 175 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
167 EXPECT_CALL(*client, OnError(_)).Times(0); 176 EXPECT_CALL(*client, OnError(_)).Times(0);
168 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 177 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
169 DoAll(SaveArg<1>(&frame_size), 178 DoAll(SaveArg<1>(&frame_size),
170 SaveArg<2>(&format), 179 SaveArg<2>(&format),
171 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 180 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
172 181
173 media::VideoCaptureParams capture_params; 182 media::VideoCaptureParams capture_params;
174 capture_params.requested_format.frame_size.SetSize(640, 480); 183 capture_params.requested_format.frame_size.SetSize(640, 480);
175 capture_params.requested_format.frame_rate = kFrameRate; 184 capture_params.requested_format.frame_rate = kFrameRate;
176 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 185 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
177 capture_params.allow_resolution_change = false; 186 capture_params.allow_resolution_change = false;
178 capture_device.AllocateAndStart( 187 capture_device_->AllocateAndStart(
179 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 188 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
180 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 189 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
181 capture_device.StopAndDeAllocate(); 190 capture_device_->StopAndDeAllocate();
182 191
183 EXPECT_GT(format.frame_size.width(), 0); 192 EXPECT_GT(format.frame_size.width(), 0);
184 EXPECT_GT(format.frame_size.height(), 0); 193 EXPECT_GT(format.frame_size.height(), 0);
185 EXPECT_EQ(kFrameRate, format.frame_rate); 194 EXPECT_EQ(kFrameRate, format.frame_rate);
186 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); 195 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
187 196
188 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); 197 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size);
189 worker_pool_->FlushForTesting(); 198 worker_pool_->FlushForTesting();
190 } 199 }
191 200
192 // Test that screen capturer behaves correctly if the source frame size changes 201 // Test that screen capturer behaves correctly if the source frame size changes
193 // but the caller cannot cope with variable resolution output. 202 // but the caller cannot cope with variable resolution output.
194 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { 203 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) {
195 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); 204 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
196 205
197 DesktopCaptureDevice capture_device( 206 CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
198 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
199 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer),
200 DesktopMediaID::TYPE_SCREEN);
201 207
202 media::VideoCaptureFormat format; 208 media::VideoCaptureFormat format;
203 base::WaitableEvent done_event(false, false); 209 base::WaitableEvent done_event(false, false);
204 int frame_size; 210 int frame_size;
205 211
206 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 212 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
207 EXPECT_CALL(*client, OnError(_)).Times(0); 213 EXPECT_CALL(*client, OnError(_)).Times(0);
208 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 214 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
209 DoAll(SaveArg<1>(&frame_size), 215 DoAll(SaveArg<1>(&frame_size),
210 SaveArg<2>(&format), 216 SaveArg<2>(&format),
211 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 217 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
212 218
213 media::VideoCaptureParams capture_params; 219 media::VideoCaptureParams capture_params;
214 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 220 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
215 kTestFrameHeight1); 221 kTestFrameHeight1);
216 capture_params.requested_format.frame_rate = kFrameRate; 222 capture_params.requested_format.frame_rate = kFrameRate;
217 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 223 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
218 capture_params.allow_resolution_change = false; 224 capture_params.allow_resolution_change = false;
219 225
220 capture_device.AllocateAndStart( 226 capture_device_->AllocateAndStart(
221 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 227 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
222 228
223 // Capture at least two frames, to ensure that the source frame size has 229 // Capture at least two frames, to ensure that the source frame size has
224 // changed while capturing. 230 // changed while capturing.
225 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 231 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
226 done_event.Reset(); 232 done_event.Reset();
227 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
228 234
229 capture_device.StopAndDeAllocate(); 235 capture_device_->StopAndDeAllocate();
230 236
231 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); 237 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
232 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); 238 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
233 EXPECT_EQ(kFrameRate, format.frame_rate); 239 EXPECT_EQ(kFrameRate, format.frame_rate);
234 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); 240 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
235 241
236 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); 242 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size);
237 worker_pool_->FlushForTesting(); 243 worker_pool_->FlushForTesting();
238 } 244 }
239 245
240 // Test that screen capturer behaves correctly if the source frame size changes 246 // Test that screen capturer behaves correctly if the source frame size changes
241 // and the caller can cope with variable resolution output. 247 // and the caller can cope with variable resolution output.
242 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { 248 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) {
243 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); 249 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
244 250
245 DesktopCaptureDevice capture_device( 251 CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
246 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
247 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer),
248 DesktopMediaID::TYPE_SCREEN);
249 252
250 media::VideoCaptureFormat format; 253 media::VideoCaptureFormat format;
251 base::WaitableEvent done_event(false, false); 254 base::WaitableEvent done_event(false, false);
252 255
253 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 256 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
254 EXPECT_CALL(*client, OnError(_)).Times(0); 257 EXPECT_CALL(*client, OnError(_)).Times(0);
255 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 258 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
256 DoAll(SaveArg<2>(&format), 259 DoAll(SaveArg<2>(&format),
257 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 260 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
258 261
259 media::VideoCaptureParams capture_params; 262 media::VideoCaptureParams capture_params;
260 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2, 263 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2,
261 kTestFrameHeight2); 264 kTestFrameHeight2);
262 capture_params.requested_format.frame_rate = kFrameRate; 265 capture_params.requested_format.frame_rate = kFrameRate;
263 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 266 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
264 capture_params.allow_resolution_change = false; 267 capture_params.allow_resolution_change = false;
265 268
266 capture_device.AllocateAndStart( 269 capture_device_->AllocateAndStart(
267 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 270 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
268 271
269 // Capture at least three frames, to ensure that the source frame size has 272 // Capture at least three frames, to ensure that the source frame size has
270 // changed at least twice while capturing. 273 // changed at least twice while capturing.
271 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 274 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
272 done_event.Reset(); 275 done_event.Reset();
273 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 276 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
274 done_event.Reset(); 277 done_event.Reset();
275 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 278 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
276 279
277 capture_device.StopAndDeAllocate(); 280 capture_device_->StopAndDeAllocate();
278 281
279 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); 282 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
280 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); 283 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
281 EXPECT_EQ(kFrameRate, format.frame_rate); 284 EXPECT_EQ(kFrameRate, format.frame_rate);
282 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); 285 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
283 worker_pool_->FlushForTesting(); 286 worker_pool_->FlushForTesting();
284 } 287 }
285 288
286 } // namespace content 289 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/capture/desktop_capture_device.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698