| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| 11 #include "content/renderer/media/media_recorder_handler.h" | 11 #include "content/renderer/media/media_recorder_handler.h" |
| 12 #include "content/renderer/media/mock_media_stream_registry.h" | 12 #include "content/renderer/media/mock_media_stream_registry.h" |
| 13 #include "media/audio/simple_sources.h" | 13 #include "media/audio/simple_sources.h" |
| 14 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
| 15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h" | 18 #include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/web/WebHeap.h" | 20 #include "third_party/WebKit/public/web/WebHeap.h" |
| 21 | 21 |
| 22 using ::testing::_; | 22 using ::testing::_; |
| 23 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
| 24 using ::testing::InSequence; | 24 using ::testing::InSequence; |
| 25 using ::testing::Ge; |
| 25 using ::testing::Gt; | 26 using ::testing::Gt; |
| 26 using ::testing::Lt; | 27 using ::testing::Lt; |
| 27 using ::testing::Mock; | 28 using ::testing::Mock; |
| 28 using ::testing::TestWithParam; | 29 using ::testing::TestWithParam; |
| 29 using ::testing::ValuesIn; | 30 using ::testing::ValuesIn; |
| 30 | 31 |
| 31 using blink::WebString; | 32 using blink::WebString; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 | 35 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 const bool has_audio; | 53 const bool has_audio; |
| 53 const char* const mime_type; | 54 const char* const mime_type; |
| 54 const char* const codecs; | 55 const char* const codecs; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 // Array of valid combinations of video/audio/codecs and expected collected | 58 // Array of valid combinations of video/audio/codecs and expected collected |
| 58 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. | 59 // encoded sizes to use for parameterizing MediaRecorderHandlerTest. |
| 59 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { | 60 static const MediaRecorderTestParams kMediaRecorderTestParams[] = { |
| 60 {true, false, "video/webm", "vp8"}, | 61 {true, false, "video/webm", "vp8"}, |
| 61 {true, false, "video/webm", "vp9"}, | 62 {true, false, "video/webm", "vp9"}, |
| 63 {true, false, "video/webm", "h264"}, |
| 62 {false, true, "video/webm", "vp8"}}; | 64 {false, true, "video/webm", "vp8"}}; |
| 63 | 65 |
| 64 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, | 66 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, |
| 65 public blink::WebMediaRecorderHandlerClient { | 67 public blink::WebMediaRecorderHandlerClient { |
| 66 public: | 68 public: |
| 67 MediaRecorderHandlerTest() | 69 MediaRecorderHandlerTest() |
| 68 : media_recorder_handler_(new MediaRecorderHandler()), | 70 : media_recorder_handler_(new MediaRecorderHandler()), |
| 69 audio_source_(kTestAudioChannels, | 71 audio_source_(kTestAudioChannels, |
| 70 440 /* freq */, | 72 440 /* freq */, |
| 71 kTestAudioSampleRate) { | 73 kTestAudioSampleRate) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 mime_type_video_uppercase, WebString())); | 151 mime_type_video_uppercase, WebString())); |
| 150 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); | 152 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); |
| 151 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 153 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 152 mime_type_video, example_good_codecs_1)); | 154 mime_type_video, example_good_codecs_1)); |
| 153 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); | 155 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); |
| 154 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 156 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 155 mime_type_video, example_good_codecs_2)); | 157 mime_type_video, example_good_codecs_2)); |
| 156 const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); | 158 const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); |
| 157 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 159 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 158 mime_type_video, example_good_codecs_3)); | 160 mime_type_video, example_good_codecs_3)); |
| 161 const WebString example_good_codecs_4(base::UTF8ToUTF16("H264,opus")); |
| 162 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 163 mime_type_video, example_good_codecs_4)); |
| 159 | 164 |
| 160 const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); | 165 const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); |
| 161 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 166 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 162 mime_type_video, example_unsupported_codecs_1)); | 167 mime_type_video, example_unsupported_codecs_1)); |
| 163 | 168 |
| 164 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); | 169 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); |
| 165 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 170 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 166 mime_type_audio, WebString())); | 171 mime_type_audio, WebString())); |
| 167 const WebString example_good_codecs_4(base::UTF8ToUTF16("opus")); | 172 const WebString example_good_codecs_5(base::UTF8ToUTF16("opus")); |
| 168 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | |
| 169 mime_type_audio, example_good_codecs_4)); | |
| 170 const WebString example_good_codecs_5(base::UTF8ToUTF16("OpUs")); | |
| 171 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 173 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 172 mime_type_audio, example_good_codecs_5)); | 174 mime_type_audio, example_good_codecs_5)); |
| 175 const WebString example_good_codecs_6(base::UTF8ToUTF16("OpUs")); |
| 176 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 177 mime_type_audio, example_good_codecs_6)); |
| 173 | 178 |
| 174 const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); | 179 const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); |
| 175 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 180 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 176 mime_type_audio, example_unsupported_codecs_2)); | 181 mime_type_audio, example_unsupported_codecs_2)); |
| 177 } | 182 } |
| 178 | 183 |
| 179 // Checks that the initialization-destruction sequence works fine. | 184 // Checks that the initialization-destruction sequence works fine. |
| 180 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { | 185 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { |
| 181 AddTracks(); | 186 AddTracks(); |
| 182 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 187 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 219 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| 215 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); | 220 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); |
| 216 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 221 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 217 mime_type, codecs, 0, 0)); | 222 mime_type, codecs, 0, 0)); |
| 218 EXPECT_TRUE(media_recorder_handler_->start()); | 223 EXPECT_TRUE(media_recorder_handler_->start()); |
| 219 | 224 |
| 220 InSequence s; | 225 InSequence s; |
| 221 const scoped_refptr<media::VideoFrame> video_frame = | 226 const scoped_refptr<media::VideoFrame> video_frame = |
| 222 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 227 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 223 | 228 |
| 224 const size_t kEncodedSizeThreshold = 16; | 229 const size_t kEncodedSizeThreshold = 14; |
| 225 { | 230 { |
| 226 base::RunLoop run_loop; | 231 base::RunLoop run_loop; |
| 227 base::Closure quit_closure = run_loop.QuitClosure(); | 232 base::Closure quit_closure = run_loop.QuitClosure(); |
| 228 // writeData() is pinged a number of times as the WebM header is written; | 233 // writeData() is pinged a number of times as the WebM header is written; |
| 229 // the last time it is called it has the encoded data. | 234 // the last time it is called it has the encoded data. |
| 230 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 235 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) |
| 231 .Times(AtLeast(1)); | 236 .Times(AtLeast(1)); |
| 232 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 237 EXPECT_CALL(*this, writeData(_, Ge(kEncodedSizeThreshold), _)) |
| 233 .Times(1) | 238 .Times(1) |
| 234 .WillOnce(RunClosure(quit_closure)); | 239 .WillOnce(RunClosure(quit_closure)); |
| 235 | 240 |
| 236 OnVideoFrameForTesting(video_frame); | 241 OnVideoFrameForTesting(video_frame); |
| 237 run_loop.Run(); | 242 run_loop.Run(); |
| 238 } | 243 } |
| 239 Mock::VerifyAndClearExpectations(this); | 244 Mock::VerifyAndClearExpectations(this); |
| 240 | 245 |
| 241 { | 246 { |
| 242 base::RunLoop run_loop; | 247 base::RunLoop run_loop; |
| 243 base::Closure quit_closure = run_loop.QuitClosure(); | 248 base::Closure quit_closure = run_loop.QuitClosure(); |
| 244 // The second time around writeData() is called a number of times to write | 249 // The second time around writeData() is called a number of times to write |
| 245 // the WebM frame header, and then is pinged with the encoded data. | 250 // the WebM frame header, and then is pinged with the encoded data. |
| 246 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 251 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) |
| 247 .Times(AtLeast(1)); | 252 .Times(AtLeast(1)); |
| 248 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 253 EXPECT_CALL(*this, writeData(_, Ge(kEncodedSizeThreshold), _)) |
| 249 .Times(1) | 254 .Times(1) |
| 250 .WillOnce(RunClosure(quit_closure)); | 255 .WillOnce(RunClosure(quit_closure)); |
| 251 | 256 |
| 252 OnVideoFrameForTesting(video_frame); | 257 OnVideoFrameForTesting(video_frame); |
| 253 run_loop.Run(); | 258 run_loop.Run(); |
| 254 } | 259 } |
| 255 | 260 |
| 256 media_recorder_handler_->stop(); | 261 media_recorder_handler_->stop(); |
| 257 | 262 |
| 258 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 263 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 327 } |
| 323 | 328 |
| 324 media_recorder_handler_->stop(); | 329 media_recorder_handler_->stop(); |
| 325 | 330 |
| 326 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 331 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| 327 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); | 332 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); |
| 328 media_recorder_handler_.reset(); | 333 media_recorder_handler_.reset(); |
| 329 } | 334 } |
| 330 | 335 |
| 331 } // namespace content | 336 } // namespace content |
| OLD | NEW |