OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/screen_capture_device_android.h" | 5 #include "content/browser/media/capture/screen_capture_device_android.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 using ::testing::_; | 11 using ::testing::_; |
| 12 using ::testing::AtMost; |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 namespace { | 15 namespace { |
15 | 16 |
16 const int kFrameRate = 30; | 17 const int kFrameRate = 30; |
17 | 18 |
18 class MockDeviceClient : public media::VideoCaptureDevice::Client { | 19 class MockDeviceClient : public media::VideoCaptureDevice::Client { |
19 public: | 20 public: |
20 MOCK_METHOD7(OnIncomingCapturedData, | 21 MOCK_METHOD7(OnIncomingCapturedData, |
21 void(const uint8_t* data, | 22 void(const uint8_t* data, |
22 int length, | 23 int length, |
23 const media::VideoCaptureFormat& frame_format, | 24 const media::VideoCaptureFormat& frame_format, |
24 int rotation, | 25 int rotation, |
25 base::TimeTicks reference_time, | 26 base::TimeTicks reference_time, |
26 base::TimeDelta tiemstamp, | 27 base::TimeDelta tiemstamp, |
27 int frame_feedback_id)); | 28 int frame_feedback_id)); |
28 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); | 29 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); |
29 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 30 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
30 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); | 31 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); |
31 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); | 32 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); |
32 MOCK_METHOD2(OnError, | 33 MOCK_METHOD2(OnError, |
33 void(const tracked_objects::Location& from_here, | 34 void(const tracked_objects::Location& from_here, |
34 const std::string& reason)); | 35 const std::string& reason)); |
35 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); | 36 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); |
| 37 MOCK_METHOD0(OnStarted, void(void)); |
36 | 38 |
37 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. | 39 // Trampoline methods to workaround GMOCK problems with std::unique_ptr<>. |
38 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, | 40 Buffer ReserveOutputBuffer(const gfx::Size& dimensions, |
39 media::VideoPixelFormat format, | 41 media::VideoPixelFormat format, |
40 media::VideoPixelStorage storage, | 42 media::VideoPixelStorage storage, |
41 int frame_feedback_id) override { | 43 int frame_feedback_id) override { |
42 EXPECT_EQ(media::PIXEL_FORMAT_I420, format); | 44 EXPECT_EQ(media::PIXEL_FORMAT_I420, format); |
43 EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage); | 45 EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage); |
44 DoReserveOutputBuffer(); | 46 DoReserveOutputBuffer(); |
45 return Buffer(); | 47 return Buffer(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 87 |
86 // Place holder. Currently user input result is required to start | 88 // Place holder. Currently user input result is required to start |
87 // MediaProjection, so we can't start a unittest that really starts capture. | 89 // MediaProjection, so we can't start a unittest that really starts capture. |
88 TEST_F(ScreenCaptureDeviceAndroidTest, DISABLED_StartAndStop) { | 90 TEST_F(ScreenCaptureDeviceAndroidTest, DISABLED_StartAndStop) { |
89 std::unique_ptr<media::VideoCaptureDevice> capture_device = | 91 std::unique_ptr<media::VideoCaptureDevice> capture_device = |
90 base::MakeUnique<ScreenCaptureDeviceAndroid>(); | 92 base::MakeUnique<ScreenCaptureDeviceAndroid>(); |
91 ASSERT_TRUE(capture_device); | 93 ASSERT_TRUE(capture_device); |
92 | 94 |
93 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 95 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
94 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 96 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 97 // |STARTED| is reported asynchronously, which may not be got if capture |
| 98 // is stopped immediately. |
| 99 EXPECT_CALL(*client, OnStarted()).Times(AtMost(1)); |
95 | 100 |
96 media::VideoCaptureParams capture_params; | 101 media::VideoCaptureParams capture_params; |
97 capture_params.requested_format.frame_size.SetSize(640, 480); | 102 capture_params.requested_format.frame_size.SetSize(640, 480); |
98 capture_params.requested_format.frame_rate = kFrameRate; | 103 capture_params.requested_format.frame_rate = kFrameRate; |
99 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 104 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
100 capture_device->AllocateAndStart(capture_params, std::move(client)); | 105 capture_device->AllocateAndStart(capture_params, std::move(client)); |
101 capture_device->StopAndDeAllocate(); | 106 capture_device->StopAndDeAllocate(); |
102 } | 107 } |
103 | 108 |
104 } // namespace | 109 } // namespace |
105 } // namespace Content | 110 } // namespace Content |
OLD | NEW |