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

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

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 (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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10
11 #include <algorithm> 10 #include <algorithm>
12 #include <string> 11 #include <string>
12 #include <utility>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/test/test_timeouts.h" 16 #include "base/test/test_timeouts.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" 21 #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
22 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 22 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 const gfx::Size size_for_even_frames_; 247 const gfx::Size size_for_even_frames_;
248 const gfx::Size size_for_odd_frames_; 248 const gfx::Size size_for_odd_frames_;
249 int frame_count_; 249 int frame_count_;
250 }; 250 };
251 251
252 } // namespace 252 } // namespace
253 253
254 class DesktopCaptureDeviceTest : public testing::Test { 254 class DesktopCaptureDeviceTest : public testing::Test {
255 public: 255 public:
256 void CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer> capturer) { 256 void CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer> capturer) {
257 capture_device_.reset( 257 capture_device_.reset(new DesktopCaptureDevice(
258 new DesktopCaptureDevice(capturer.Pass(), DesktopMediaID::TYPE_SCREEN)); 258 std::move(capturer), DesktopMediaID::TYPE_SCREEN));
259 } 259 }
260 260
261 void CopyFrame(const uint8_t* frame, int size, 261 void CopyFrame(const uint8_t* frame, int size,
262 const media::VideoCaptureFormat&, int, base::TimeTicks) { 262 const media::VideoCaptureFormat&, int, base::TimeTicks) {
263 ASSERT_TRUE(output_frame_.get() != NULL); 263 ASSERT_TRUE(output_frame_.get() != NULL);
264 ASSERT_EQ(output_frame_->stride() * output_frame_->size().height(), size); 264 ASSERT_EQ(output_frame_->stride() * output_frame_->size().height(), size);
265 memcpy(output_frame_->data(), frame, size); 265 memcpy(output_frame_->data(), frame, size);
266 } 266 }
267 267
268 protected: 268 protected:
269 scoped_ptr<DesktopCaptureDevice> capture_device_; 269 scoped_ptr<DesktopCaptureDevice> capture_device_;
270 scoped_ptr<webrtc::DesktopFrame> output_frame_; 270 scoped_ptr<webrtc::DesktopFrame> output_frame_;
271 }; 271 };
272 272
273 // There is currently no screen capturer implementation for ozone. So disable 273 // There is currently no screen capturer implementation for ozone. So disable
274 // the test that uses a real screen-capturer instead of FakeScreenCapturer. 274 // the test that uses a real screen-capturer instead of FakeScreenCapturer.
275 // http://crbug.com/260318 275 // http://crbug.com/260318
276 #if defined(USE_OZONE) 276 #if defined(USE_OZONE)
277 #define MAYBE_Capture DISABLED_Capture 277 #define MAYBE_Capture DISABLED_Capture
278 #else 278 #else
279 #define MAYBE_Capture Capture 279 #define MAYBE_Capture Capture
280 #endif 280 #endif
281 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) { 281 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) {
282 scoped_ptr<webrtc::DesktopCapturer> capturer( 282 scoped_ptr<webrtc::DesktopCapturer> capturer(
283 webrtc::ScreenCapturer::Create( 283 webrtc::ScreenCapturer::Create(
284 webrtc::DesktopCaptureOptions::CreateDefault())); 284 webrtc::DesktopCaptureOptions::CreateDefault()));
285 CreateScreenCaptureDevice(capturer.Pass()); 285 CreateScreenCaptureDevice(std::move(capturer));
286 286
287 media::VideoCaptureFormat format; 287 media::VideoCaptureFormat format;
288 base::WaitableEvent done_event(false, false); 288 base::WaitableEvent done_event(false, false);
289 int frame_size; 289 int frame_size;
290 290
291 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 291 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
292 EXPECT_CALL(*client, OnError(_, _)).Times(0); 292 EXPECT_CALL(*client, OnError(_, _)).Times(0);
293 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly( 293 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
294 DoAll(SaveArg<1>(&frame_size), 294 DoAll(SaveArg<1>(&frame_size),
295 SaveArg<2>(&format), 295 SaveArg<2>(&format),
296 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 296 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
297 297
298 media::VideoCaptureParams capture_params; 298 media::VideoCaptureParams capture_params;
299 capture_params.requested_format.frame_size.SetSize(640, 480); 299 capture_params.requested_format.frame_size.SetSize(640, 480);
300 capture_params.requested_format.frame_rate = kFrameRate; 300 capture_params.requested_format.frame_rate = kFrameRate;
301 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 301 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
302 capture_device_->AllocateAndStart(capture_params, client.Pass()); 302 capture_device_->AllocateAndStart(capture_params, std::move(client));
303 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 303 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
304 capture_device_->StopAndDeAllocate(); 304 capture_device_->StopAndDeAllocate();
305 305
306 EXPECT_GT(format.frame_size.width(), 0); 306 EXPECT_GT(format.frame_size.width(), 0);
307 EXPECT_GT(format.frame_size.height(), 0); 307 EXPECT_GT(format.frame_size.height(), 0);
308 EXPECT_EQ(kFrameRate, format.frame_rate); 308 EXPECT_EQ(kFrameRate, format.frame_rate);
309 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); 309 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
310 310
311 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); 311 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size);
312 } 312 }
(...skipping 17 matching lines...) Expand all
330 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 330 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
331 331
332 media::VideoCaptureParams capture_params; 332 media::VideoCaptureParams capture_params;
333 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 333 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
334 kTestFrameHeight1); 334 kTestFrameHeight1);
335 capture_params.requested_format.frame_rate = kFrameRate; 335 capture_params.requested_format.frame_rate = kFrameRate;
336 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 336 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
337 capture_params.resolution_change_policy = 337 capture_params.resolution_change_policy =
338 media::RESOLUTION_POLICY_FIXED_RESOLUTION; 338 media::RESOLUTION_POLICY_FIXED_RESOLUTION;
339 339
340 capture_device_->AllocateAndStart(capture_params, client.Pass()); 340 capture_device_->AllocateAndStart(capture_params, std::move(client));
341 341
342 // Capture at least two frames, to ensure that the source frame size has 342 // Capture at least two frames, to ensure that the source frame size has
343 // changed to two different sizes while capturing. The mock for 343 // changed to two different sizes while capturing. The mock for
344 // OnIncomingCapturedData() will use FormatChecker to examine the format of 344 // OnIncomingCapturedData() will use FormatChecker to examine the format of
345 // each frame being delivered. 345 // each frame being delivered.
346 for (int i = 0; i < 2; ++i) { 346 for (int i = 0; i < 2; ++i) {
347 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 347 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
348 done_event.Reset(); 348 done_event.Reset();
349 } 349 }
350 350
(...skipping 23 matching lines...) Expand all
374 ASSERT_GE(high_def_16_by_9.width(), 374 ASSERT_GE(high_def_16_by_9.width(),
375 std::max(kTestFrameWidth1, kTestFrameWidth2)); 375 std::max(kTestFrameWidth1, kTestFrameWidth2));
376 ASSERT_GE(high_def_16_by_9.height(), 376 ASSERT_GE(high_def_16_by_9.height(),
377 std::max(kTestFrameHeight1, kTestFrameHeight2)); 377 std::max(kTestFrameHeight1, kTestFrameHeight2));
378 capture_params.requested_format.frame_size = high_def_16_by_9; 378 capture_params.requested_format.frame_size = high_def_16_by_9;
379 capture_params.requested_format.frame_rate = kFrameRate; 379 capture_params.requested_format.frame_rate = kFrameRate;
380 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 380 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
381 capture_params.resolution_change_policy = 381 capture_params.resolution_change_policy =
382 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; 382 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO;
383 383
384 capture_device_->AllocateAndStart( 384 capture_device_->AllocateAndStart(capture_params, std::move(client));
385 capture_params, client.Pass());
386 385
387 // Capture at least three frames, to ensure that the source frame size has 386 // Capture at least three frames, to ensure that the source frame size has
388 // changed to two different sizes while capturing. The mock for 387 // changed to two different sizes while capturing. The mock for
389 // OnIncomingCapturedData() will use FormatChecker to examine the format of 388 // OnIncomingCapturedData() will use FormatChecker to examine the format of
390 // each frame being delivered. 389 // each frame being delivered.
391 for (int i = 0; i < 3; ++i) { 390 for (int i = 0; i < 3; ++i) {
392 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 391 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
393 done_event.Reset(); 392 done_event.Reset();
394 } 393 }
395 394
(...skipping 23 matching lines...) Expand all
419 ASSERT_GE(high_def_16_by_9.width(), 418 ASSERT_GE(high_def_16_by_9.width(),
420 std::max(kTestFrameWidth1, kTestFrameWidth2)); 419 std::max(kTestFrameWidth1, kTestFrameWidth2));
421 ASSERT_GE(high_def_16_by_9.height(), 420 ASSERT_GE(high_def_16_by_9.height(),
422 std::max(kTestFrameHeight1, kTestFrameHeight2)); 421 std::max(kTestFrameHeight1, kTestFrameHeight2));
423 capture_params.requested_format.frame_size = high_def_16_by_9; 422 capture_params.requested_format.frame_size = high_def_16_by_9;
424 capture_params.requested_format.frame_rate = kFrameRate; 423 capture_params.requested_format.frame_rate = kFrameRate;
425 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 424 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
426 capture_params.resolution_change_policy = 425 capture_params.resolution_change_policy =
427 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; 426 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT;
428 427
429 capture_device_->AllocateAndStart( 428 capture_device_->AllocateAndStart(capture_params, std::move(client));
430 capture_params, client.Pass());
431 429
432 // Capture at least three frames, to ensure that the source frame size has 430 // Capture at least three frames, to ensure that the source frame size has
433 // changed to two different sizes while capturing. The mock for 431 // changed to two different sizes while capturing. The mock for
434 // OnIncomingCapturedData() will use FormatChecker to examine the format of 432 // OnIncomingCapturedData() will use FormatChecker to examine the format of
435 // each frame being delivered. 433 // each frame being delivered.
436 for (int i = 0; i < 3; ++i) { 434 for (int i = 0; i < 3; ++i) {
437 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 435 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
438 done_event.Reset(); 436 done_event.Reset();
439 } 437 }
440 438
(...skipping 20 matching lines...) Expand all
461 SaveArg<1>(&frame_size), 459 SaveArg<1>(&frame_size),
462 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 460 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
463 461
464 media::VideoCaptureParams capture_params; 462 media::VideoCaptureParams capture_params;
465 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 463 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
466 kTestFrameHeight1); 464 kTestFrameHeight1);
467 capture_params.requested_format.frame_rate = kFrameRate; 465 capture_params.requested_format.frame_rate = kFrameRate;
468 capture_params.requested_format.pixel_format = 466 capture_params.requested_format.pixel_format =
469 media::PIXEL_FORMAT_I420; 467 media::PIXEL_FORMAT_I420;
470 468
471 capture_device_->AllocateAndStart(capture_params, client.Pass()); 469 capture_device_->AllocateAndStart(capture_params, std::move(client));
472 470
473 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 471 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
474 done_event.Reset(); 472 done_event.Reset();
475 capture_device_->StopAndDeAllocate(); 473 capture_device_->StopAndDeAllocate();
476 474
477 // Verifies that |output_frame_| has the same data as a packed frame of the 475 // Verifies that |output_frame_| has the same data as a packed frame of the
478 // same size. 476 // same size.
479 scoped_ptr<webrtc::BasicDesktopFrame> expected_frame(CreateBasicFrame( 477 scoped_ptr<webrtc::BasicDesktopFrame> expected_frame(CreateBasicFrame(
480 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); 478 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)));
481 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(), 479 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(),
(...skipping 21 matching lines...) Expand all
503 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame), 501 DoAll(Invoke(this, &DesktopCaptureDeviceTest::CopyFrame),
504 SaveArg<1>(&frame_size), 502 SaveArg<1>(&frame_size),
505 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 503 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
506 504
507 media::VideoCaptureParams capture_params; 505 media::VideoCaptureParams capture_params;
508 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 506 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
509 kTestFrameHeight1); 507 kTestFrameHeight1);
510 capture_params.requested_format.frame_rate = kFrameRate; 508 capture_params.requested_format.frame_rate = kFrameRate;
511 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 509 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
512 510
513 capture_device_->AllocateAndStart(capture_params, client.Pass()); 511 capture_device_->AllocateAndStart(capture_params, std::move(client));
514 512
515 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 513 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
516 done_event.Reset(); 514 done_event.Reset();
517 capture_device_->StopAndDeAllocate(); 515 capture_device_->StopAndDeAllocate();
518 516
519 // Verifies that |output_frame_| has the same pixel values as the inverted 517 // Verifies that |output_frame_| has the same pixel values as the inverted
520 // frame. 518 // frame.
521 scoped_ptr<webrtc::DesktopFrame> inverted_frame( 519 scoped_ptr<webrtc::DesktopFrame> inverted_frame(
522 new InvertedDesktopFrame(CreateBasicFrame( 520 new InvertedDesktopFrame(CreateBasicFrame(
523 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)))); 521 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))));
524 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(), 522 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(),
525 frame_size); 523 frame_size);
526 for (int i = 0; i < output_frame_->size().height(); ++i) { 524 for (int i = 0; i < output_frame_->size().height(); ++i) {
527 EXPECT_EQ(0, 525 EXPECT_EQ(0,
528 memcmp(inverted_frame->data() + i * inverted_frame->stride(), 526 memcmp(inverted_frame->data() + i * inverted_frame->stride(),
529 output_frame_->data() + i * output_frame_->stride(), 527 output_frame_->data() + i * output_frame_->stride(),
530 output_frame_->stride())); 528 output_frame_->stride()));
531 } 529 }
532 } 530 }
533 531
534 } // namespace content 532 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698