OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/location.h" | 6 #include "base/location.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
11 #include "media/capture/webm_muxer.h" | 11 #include "media/capture/webm_muxer.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using ::testing::_; | 15 using ::testing::_; |
16 using ::testing::AtLeast; | 16 using ::testing::AtLeast; |
17 using ::testing::Mock; | 17 using ::testing::Mock; |
| 18 using ::testing::TestWithParam; |
| 19 using ::testing::Values; |
18 using ::testing::WithArgs; | 20 using ::testing::WithArgs; |
19 | 21 |
20 namespace media { | 22 namespace media { |
21 | 23 |
22 class WebmMuxerTest : public testing::Test { | 24 class WebmMuxerTest : public TestWithParam<VideoCodec> { |
23 public: | 25 public: |
24 WebmMuxerTest() | 26 WebmMuxerTest() |
25 : webm_muxer_(base::Bind(&WebmMuxerTest::WriteCallback, | 27 : webm_muxer_( |
26 base::Unretained(this))), | 28 GetParam() /* codec */, |
| 29 base::Bind(&WebmMuxerTest::WriteCallback, base::Unretained(this))), |
27 last_encoded_length_(0), | 30 last_encoded_length_(0), |
28 accumulated_position_(0) { | 31 accumulated_position_(0) { |
29 EXPECT_EQ(webm_muxer_.Position(), 0); | 32 EXPECT_EQ(webm_muxer_.Position(), 0); |
30 const mkvmuxer::int64 kRandomNewPosition = 333; | 33 const mkvmuxer::int64 kRandomNewPosition = 333; |
31 EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); | 34 EXPECT_EQ(webm_muxer_.Position(kRandomNewPosition), -1); |
32 EXPECT_FALSE(webm_muxer_.Seekable()); | 35 EXPECT_FALSE(webm_muxer_.Seekable()); |
33 } | 36 } |
34 | 37 |
35 MOCK_METHOD1(WriteCallback, void(base::StringPiece)); | 38 MOCK_METHOD1(WriteCallback, void(base::StringPiece)); |
36 | 39 |
(...skipping 18 matching lines...) Expand all Loading... |
55 | 58 |
56 size_t last_encoded_length_; | 59 size_t last_encoded_length_; |
57 int64_t accumulated_position_; | 60 int64_t accumulated_position_; |
58 | 61 |
59 private: | 62 private: |
60 DISALLOW_COPY_AND_ASSIGN(WebmMuxerTest); | 63 DISALLOW_COPY_AND_ASSIGN(WebmMuxerTest); |
61 }; | 64 }; |
62 | 65 |
63 // Checks that the WriteCallback is called with appropriate params when | 66 // Checks that the WriteCallback is called with appropriate params when |
64 // WebmMuxer::Write() method is called. | 67 // WebmMuxer::Write() method is called. |
65 TEST_F(WebmMuxerTest, Write) { | 68 TEST_P(WebmMuxerTest, Write) { |
66 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); | 69 const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); |
67 | 70 |
68 EXPECT_CALL(*this, WriteCallback(encoded_data)); | 71 EXPECT_CALL(*this, WriteCallback(encoded_data)); |
69 WebmMuxerWrite(encoded_data.data(), encoded_data.size()); | 72 WebmMuxerWrite(encoded_data.data(), encoded_data.size()); |
70 | 73 |
71 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); | 74 EXPECT_EQ(GetWebmMuxerPosition(), static_cast<int64_t>(encoded_data.size())); |
72 } | 75 } |
73 | 76 |
74 // This test sends two frames and checks that the WriteCallback is called with | 77 // This test sends two frames and checks that the WriteCallback is called with |
75 // appropriate params in both cases. | 78 // appropriate params in both cases. |
76 TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { | 79 TEST_P(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
77 const gfx::Size frame_size(160, 80); | 80 const gfx::Size frame_size(160, 80); |
78 const scoped_refptr<VideoFrame> video_frame = | 81 const scoped_refptr<VideoFrame> video_frame = |
79 VideoFrame::CreateBlackFrame(frame_size); | 82 VideoFrame::CreateBlackFrame(frame_size); |
80 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); | 83 const std::string encoded_data("abcdefghijklmnopqrstuvwxyz"); |
81 | 84 |
82 EXPECT_CALL(*this, WriteCallback(_)) | 85 EXPECT_CALL(*this, WriteCallback(_)) |
83 .Times(AtLeast(1)) | 86 .Times(AtLeast(1)) |
84 .WillRepeatedly(WithArgs<0>( | 87 .WillRepeatedly(WithArgs<0>( |
85 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); | 88 Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
86 webm_muxer_.OnEncodedVideo(video_frame, | 89 webm_muxer_.OnEncodedVideo(video_frame, |
(...skipping 21 matching lines...) Expand all Loading... |
108 // The second time around the callbacks should include a SimpleBlock header, | 111 // The second time around the callbacks should include a SimpleBlock header, |
109 // namely the track index, a timestamp and a flags byte, for a total of 6B. | 112 // namely the track index, a timestamp and a flags byte, for a total of 6B. |
110 EXPECT_EQ(last_encoded_length_, encoded_data.size()); | 113 EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
111 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); | 114 EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
112 const uint32_t kSimpleBlockSize = 6u; | 115 const uint32_t kSimpleBlockSize = 6u; |
113 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + | 116 EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
114 encoded_data.size()), | 117 encoded_data.size()), |
115 accumulated_position_); | 118 accumulated_position_); |
116 } | 119 } |
117 | 120 |
| 121 INSTANTIATE_TEST_CASE_P(, WebmMuxerTest, Values(kCodecVP8, kCodecVP9)); |
| 122 |
118 } // namespace media | 123 } // namespace media |
OLD | NEW |