| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 EXPECT_FALSE(media_recorder_handler_->recording_); | 78 EXPECT_FALSE(media_recorder_handler_->recording_); |
| 79 | 79 |
| 80 registry_.Init(kTestStreamUrl); | 80 registry_.Init(kTestStreamUrl); |
| 81 } | 81 } |
| 82 | 82 |
| 83 ~MediaRecorderHandlerTest() { | 83 ~MediaRecorderHandlerTest() { |
| 84 registry_.reset(); | 84 registry_.reset(); |
| 85 blink::WebHeap::collectAllGarbageForTesting(); | 85 blink::WebHeap::collectAllGarbageForTesting(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 MOCK_METHOD3(writeData, void(const char*, size_t, bool)); | 88 MOCK_METHOD4(writeData, void(const char*, size_t, bool, double)); |
| 89 MOCK_METHOD1(onError, void(const WebString& message)); | 89 MOCK_METHOD1(onError, void(const WebString& message)); |
| 90 | 90 |
| 91 bool recording() const { return media_recorder_handler_->recording_; } | 91 bool recording() const { return media_recorder_handler_->recording_; } |
| 92 bool hasVideoRecorders() const { | 92 bool hasVideoRecorders() const { |
| 93 return !media_recorder_handler_->video_recorders_.empty(); | 93 return !media_recorder_handler_->video_recorders_.empty(); |
| 94 } | 94 } |
| 95 bool hasAudioRecorders() const { | 95 bool hasAudioRecorders() const { |
| 96 return !media_recorder_handler_->audio_recorders_.empty(); | 96 return !media_recorder_handler_->audio_recorders_.empty(); |
| 97 } | 97 } |
| 98 | 98 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 202 |
| 203 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); | 203 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); |
| 204 EXPECT_TRUE(hasAudioRecorders() || !GetParam().has_audio); | 204 EXPECT_TRUE(hasAudioRecorders() || !GetParam().has_audio); |
| 205 | 205 |
| 206 media_recorder_handler_->stop(); | 206 media_recorder_handler_->stop(); |
| 207 EXPECT_FALSE(recording()); | 207 EXPECT_FALSE(recording()); |
| 208 EXPECT_FALSE(hasVideoRecorders()); | 208 EXPECT_FALSE(hasVideoRecorders()); |
| 209 EXPECT_FALSE(hasAudioRecorders()); | 209 EXPECT_FALSE(hasAudioRecorders()); |
| 210 | 210 |
| 211 // Expect a last call on destruction. | 211 // Expect a last call on destruction. |
| 212 EXPECT_CALL(*this, writeData(_, _, true)).Times(1); | 212 EXPECT_CALL(*this, writeData(_, _, true, _)).Times(1); |
| 213 media_recorder_handler_.reset(); | 213 media_recorder_handler_.reset(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). | 216 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). |
| 217 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { | 217 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { |
| 218 // Video-only test. | 218 // Video-only test. |
| 219 if (GetParam().has_audio) | 219 if (GetParam().has_audio) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 AddTracks(); | 222 AddTracks(); |
| 223 | 223 |
| 224 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 224 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); |
| 225 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); | 225 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); |
| 226 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 226 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 227 mime_type, codecs, 0, 0)); | 227 mime_type, codecs, 0, 0)); |
| 228 EXPECT_TRUE(media_recorder_handler_->start(0)); | 228 EXPECT_TRUE(media_recorder_handler_->start(0)); |
| 229 | 229 |
| 230 InSequence s; | 230 InSequence s; |
| 231 const scoped_refptr<media::VideoFrame> video_frame = | 231 const scoped_refptr<media::VideoFrame> video_frame = |
| 232 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 232 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 233 | 233 |
| 234 { | 234 { |
| 235 const size_t kEncodedSizeThreshold = 16; | 235 const size_t kEncodedSizeThreshold = 16; |
| 236 base::RunLoop run_loop; | 236 base::RunLoop run_loop; |
| 237 base::Closure quit_closure = run_loop.QuitClosure(); | 237 base::Closure quit_closure = run_loop.QuitClosure(); |
| 238 // writeData() is pinged a number of times as the WebM header is written; | 238 // writeData() is pinged a number of times as the WebM header is written; |
| 239 // the last time it is called it has the encoded data. | 239 // the last time it is called it has the encoded data. |
| 240 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 240 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _, _)) |
| 241 .Times(AtLeast(1)); | 241 .Times(AtLeast(1)); |
| 242 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 242 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _, _)) |
| 243 .Times(1) | 243 .Times(1) |
| 244 .WillOnce(RunClosure(quit_closure)); | 244 .WillOnce(RunClosure(quit_closure)); |
| 245 | 245 |
| 246 OnVideoFrameForTesting(video_frame); | 246 OnVideoFrameForTesting(video_frame); |
| 247 run_loop.Run(); | 247 run_loop.Run(); |
| 248 } | 248 } |
| 249 Mock::VerifyAndClearExpectations(this); | 249 Mock::VerifyAndClearExpectations(this); |
| 250 | 250 |
| 251 { | 251 { |
| 252 const size_t kEncodedSizeThreshold = 13; | 252 const size_t kEncodedSizeThreshold = 13; |
| 253 base::RunLoop run_loop; | 253 base::RunLoop run_loop; |
| 254 base::Closure quit_closure = run_loop.QuitClosure(); | 254 base::Closure quit_closure = run_loop.QuitClosure(); |
| 255 // The second time around writeData() is called a number of times to write | 255 // The second time around writeData() is called a number of times to write |
| 256 // the WebM frame header, and then is pinged with the encoded data. | 256 // the WebM frame header, and then is pinged with the encoded data. |
| 257 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 257 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _, _)) |
| 258 .Times(AtLeast(1)); | 258 .Times(AtLeast(1)); |
| 259 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 259 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _, _)) |
| 260 .Times(1) | 260 .Times(1) |
| 261 .WillOnce(RunClosure(quit_closure)); | 261 .WillOnce(RunClosure(quit_closure)); |
| 262 | 262 |
| 263 OnVideoFrameForTesting(video_frame); | 263 OnVideoFrameForTesting(video_frame); |
| 264 run_loop.Run(); | 264 run_loop.Run(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 media_recorder_handler_->stop(); | 267 media_recorder_handler_->stop(); |
| 268 | 268 |
| 269 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 269 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| 270 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); | 270 EXPECT_CALL(*this, writeData(nullptr, 0, true, _)).Times(1); |
| 271 media_recorder_handler_.reset(); | 271 media_recorder_handler_.reset(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 INSTANTIATE_TEST_CASE_P(, | 274 INSTANTIATE_TEST_CASE_P(, |
| 275 MediaRecorderHandlerTest, | 275 MediaRecorderHandlerTest, |
| 276 ValuesIn(kMediaRecorderTestParams)); | 276 ValuesIn(kMediaRecorderTestParams)); |
| 277 | 277 |
| 278 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). | 278 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). |
| 279 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { | 279 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { |
| 280 // Audio-only test. | 280 // Audio-only test. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 297 kTestAudioSampleRate, kTestAudioBitsPerSample, | 297 kTestAudioSampleRate, kTestAudioBitsPerSample, |
| 298 kTestAudioSampleRate * kTestAudioBufferDurationMs / 1000); | 298 kTestAudioSampleRate * kTestAudioBufferDurationMs / 1000); |
| 299 SetAudioFormatForTesting(params); | 299 SetAudioFormatForTesting(params); |
| 300 | 300 |
| 301 const size_t kEncodedSizeThreshold = 24; | 301 const size_t kEncodedSizeThreshold = 24; |
| 302 { | 302 { |
| 303 base::RunLoop run_loop; | 303 base::RunLoop run_loop; |
| 304 base::Closure quit_closure = run_loop.QuitClosure(); | 304 base::Closure quit_closure = run_loop.QuitClosure(); |
| 305 // writeData() is pinged a number of times as the WebM header is written; | 305 // writeData() is pinged a number of times as the WebM header is written; |
| 306 // the last time it is called it has the encoded data. | 306 // the last time it is called it has the encoded data. |
| 307 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 307 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _, _)) |
| 308 .Times(AtLeast(1)); | 308 .Times(AtLeast(1)); |
| 309 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 309 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _, _)) |
| 310 .Times(1) | 310 .Times(1) |
| 311 .WillOnce(RunClosure(quit_closure)); | 311 .WillOnce(RunClosure(quit_closure)); |
| 312 | 312 |
| 313 for (int i = 0; i < kRatioOpusToTestAudioBuffers; ++i) | 313 for (int i = 0; i < kRatioOpusToTestAudioBuffers; ++i) |
| 314 OnAudioBusForTesting(*audio_bus1); | 314 OnAudioBusForTesting(*audio_bus1); |
| 315 run_loop.Run(); | 315 run_loop.Run(); |
| 316 } | 316 } |
| 317 Mock::VerifyAndClearExpectations(this); | 317 Mock::VerifyAndClearExpectations(this); |
| 318 | 318 |
| 319 { | 319 { |
| 320 base::RunLoop run_loop; | 320 base::RunLoop run_loop; |
| 321 base::Closure quit_closure = run_loop.QuitClosure(); | 321 base::Closure quit_closure = run_loop.QuitClosure(); |
| 322 // The second time around writeData() is called a number of times to write | 322 // The second time around writeData() is called a number of times to write |
| 323 // the WebM frame header, and then is pinged with the encoded data. | 323 // the WebM frame header, and then is pinged with the encoded data. |
| 324 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _)) | 324 EXPECT_CALL(*this, writeData(_, Lt(kEncodedSizeThreshold), _, _)) |
| 325 .Times(AtLeast(1)); | 325 .Times(AtLeast(1)); |
| 326 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _)) | 326 EXPECT_CALL(*this, writeData(_, Gt(kEncodedSizeThreshold), _, _)) |
| 327 .Times(1) | 327 .Times(1) |
| 328 .WillOnce(RunClosure(quit_closure)); | 328 .WillOnce(RunClosure(quit_closure)); |
| 329 | 329 |
| 330 for (int i = 0; i < kRatioOpusToTestAudioBuffers; ++i) | 330 for (int i = 0; i < kRatioOpusToTestAudioBuffers; ++i) |
| 331 OnAudioBusForTesting(*audio_bus2); | 331 OnAudioBusForTesting(*audio_bus2); |
| 332 run_loop.Run(); | 332 run_loop.Run(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 media_recorder_handler_->stop(); | 335 media_recorder_handler_->stop(); |
| 336 | 336 |
| 337 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 337 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| 338 EXPECT_CALL(*this, writeData(nullptr, 0, true)).Times(1); | 338 EXPECT_CALL(*this, writeData(nullptr, 0, true, _)).Times(1); |
| 339 media_recorder_handler_.reset(); | 339 media_recorder_handler_.reset(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 } // namespace content | 342 } // namespace content |
| OLD | NEW |