| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "content/browser/media/capture/screen_capture_device_android.h" |
| 6 |
| 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 using ::testing::_; |
| 11 |
| 12 namespace content { |
| 13 namespace { |
| 14 |
| 15 const int kFrameRate = 30; |
| 16 |
| 17 class MockDeviceClient : public media::VideoCaptureDevice::Client { |
| 18 public: |
| 19 MOCK_METHOD6(OnIncomingCapturedData, |
| 20 void(const uint8_t* data, |
| 21 int length, |
| 22 const media::VideoCaptureFormat& frame_format, |
| 23 int rotation, |
| 24 base::TimeTicks reference_time, |
| 25 base::TimeDelta tiemstamp)); |
| 26 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
| 27 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 28 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
| 29 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); |
| 30 MOCK_METHOD2(OnError, |
| 31 void(const tracked_objects::Location& from_here, |
| 32 const std::string& reason)); |
| 33 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); |
| 34 |
| 35 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. |
| 36 std::unique_ptr<Buffer> ReserveOutputBuffer( |
| 37 const gfx::Size& dimensions, |
| 38 media::VideoPixelFormat format, |
| 39 media::VideoPixelStorage storage) override { |
| 40 EXPECT_EQ(media::PIXEL_FORMAT_I420, format); |
| 41 EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage); |
| 42 DoReserveOutputBuffer(); |
| 43 return std::unique_ptr<Buffer>(); |
| 44 } |
| 45 void OnIncomingCapturedBuffer(std::unique_ptr<Buffer> buffer, |
| 46 const media::VideoCaptureFormat& frame_format, |
| 47 base::TimeTicks reference_time, |
| 48 base::TimeDelta timestamp) override { |
| 49 DoOnIncomingCapturedBuffer(); |
| 50 } |
| 51 void OnIncomingCapturedVideoFrame( |
| 52 std::unique_ptr<Buffer> buffer, |
| 53 const scoped_refptr<media::VideoFrame>& frame) override { |
| 54 DoOnIncomingCapturedVideoFrame(); |
| 55 } |
| 56 std::unique_ptr<Buffer> ResurrectLastOutputBuffer( |
| 57 const gfx::Size& dimensions, |
| 58 media::VideoPixelFormat format, |
| 59 media::VideoPixelStorage storage) override { |
| 60 EXPECT_EQ(media::PIXEL_FORMAT_I420, format); |
| 61 EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage); |
| 62 DoResurrectLastOutputBuffer(); |
| 63 return std::unique_ptr<Buffer>(); |
| 64 } |
| 65 }; |
| 66 |
| 67 class ScreenCaptureDeviceAndroidTest : public testing::Test { |
| 68 public: |
| 69 ScreenCaptureDeviceAndroidTest() {} |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureDeviceAndroidTest); |
| 73 }; |
| 74 |
| 75 TEST_F(ScreenCaptureDeviceAndroidTest, ConstructionDestruction) { |
| 76 std::unique_ptr<media::VideoCaptureDevice> capture_device = |
| 77 base::MakeUnique<ScreenCaptureDeviceAndroid>(); |
| 78 } |
| 79 |
| 80 // Place holder. Currently user input result is required to start |
| 81 // MediaProjection, so we can't start a unittest that really starts capture. |
| 82 TEST_F(ScreenCaptureDeviceAndroidTest, DISABLED_StartAndStop) { |
| 83 std::unique_ptr<media::VideoCaptureDevice> capture_device = |
| 84 base::MakeUnique<ScreenCaptureDeviceAndroid>(); |
| 85 ASSERT_TRUE(capture_device); |
| 86 |
| 87 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
| 88 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 89 |
| 90 media::VideoCaptureParams capture_params; |
| 91 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 92 capture_params.requested_format.frame_rate = kFrameRate; |
| 93 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 94 capture_device->AllocateAndStart(capture_params, std::move(client)); |
| 95 capture_device->StopAndDeAllocate(); |
| 96 } |
| 97 |
| 98 } // namespace |
| 99 } // namespace Content |
| OLD | NEW |