| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // For generating test AudioBuses | 141 // For generating test AudioBuses |
| 142 media::SineWaveAudioSource audio_source_; | 142 media::SineWaveAudioSource audio_source_; |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandlerTest); | 145 DISALLOW_COPY_AND_ASSIGN(MediaRecorderHandlerTest); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // Checks that canSupportMimeType() works as expected, by sending supported | 148 // Checks that canSupportMimeType() works as expected, by sending supported |
| 149 // combinations and unsupported ones. | 149 // combinations and unsupported ones. |
| 150 TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) { | 150 TEST_F(MediaRecorderHandlerTest, CanSupportMimeType) { |
| 151 const WebString unsupported_mime_type(base::UTF8ToUTF16("video/mpeg")); | 151 const WebString unsupported_mime_type(WebString::fromASCII("video/mpeg")); |
| 152 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 152 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 153 unsupported_mime_type, WebString())); | 153 unsupported_mime_type, WebString())); |
| 154 | 154 |
| 155 const WebString mime_type_video(base::UTF8ToUTF16("video/webm")); | 155 const WebString mime_type_video(WebString::fromASCII("video/webm")); |
| 156 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 156 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 157 mime_type_video, WebString())); | 157 mime_type_video, WebString())); |
| 158 const WebString mime_type_video_uppercase(base::UTF8ToUTF16("video/WEBM")); | 158 const WebString mime_type_video_uppercase(WebString::fromASCII("video/WEBM")); |
| 159 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 159 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 160 mime_type_video_uppercase, WebString())); | 160 mime_type_video_uppercase, WebString())); |
| 161 const WebString example_good_codecs_1(base::UTF8ToUTF16("vp8")); | 161 const WebString example_good_codecs_1(WebString::fromASCII("vp8")); |
| 162 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 162 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 163 mime_type_video, example_good_codecs_1)); | 163 mime_type_video, example_good_codecs_1)); |
| 164 const WebString example_good_codecs_2(base::UTF8ToUTF16("vp9,opus")); | 164 const WebString example_good_codecs_2(WebString::fromASCII("vp9,opus")); |
| 165 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 165 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 166 mime_type_video, example_good_codecs_2)); | 166 mime_type_video, example_good_codecs_2)); |
| 167 const WebString example_good_codecs_3(base::UTF8ToUTF16("VP9,opus")); | 167 const WebString example_good_codecs_3(WebString::fromASCII("VP9,opus")); |
| 168 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 168 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 169 mime_type_video, example_good_codecs_3)); | 169 mime_type_video, example_good_codecs_3)); |
| 170 const WebString example_good_codecs_4(base::UTF8ToUTF16("H264")); | 170 const WebString example_good_codecs_4(WebString::fromASCII("H264")); |
| 171 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 171 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 172 mime_type_video, example_good_codecs_4)); | 172 mime_type_video, example_good_codecs_4)); |
| 173 | 173 |
| 174 const WebString example_unsupported_codecs_1(base::UTF8ToUTF16("daala")); | 174 const WebString example_unsupported_codecs_1(WebString::fromASCII("daala")); |
| 175 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 175 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 176 mime_type_video, example_unsupported_codecs_1)); | 176 mime_type_video, example_unsupported_codecs_1)); |
| 177 | 177 |
| 178 const WebString mime_type_audio(base::UTF8ToUTF16("audio/webm")); | 178 const WebString mime_type_audio(WebString::fromASCII("audio/webm")); |
| 179 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 179 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 180 mime_type_audio, WebString())); | 180 mime_type_audio, WebString())); |
| 181 const WebString example_good_codecs_5(base::UTF8ToUTF16("opus")); | 181 const WebString example_good_codecs_5(WebString::fromASCII("opus")); |
| 182 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 182 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 183 mime_type_audio, example_good_codecs_5)); | 183 mime_type_audio, example_good_codecs_5)); |
| 184 const WebString example_good_codecs_6(base::UTF8ToUTF16("OpUs")); | 184 const WebString example_good_codecs_6(WebString::fromASCII("OpUs")); |
| 185 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( | 185 EXPECT_TRUE(media_recorder_handler_->canSupportMimeType( |
| 186 mime_type_audio, example_good_codecs_6)); | 186 mime_type_audio, example_good_codecs_6)); |
| 187 | 187 |
| 188 const WebString example_unsupported_codecs_2(base::UTF8ToUTF16("vorbis")); | 188 const WebString example_unsupported_codecs_2(WebString::fromASCII("vorbis")); |
| 189 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( | 189 EXPECT_FALSE(media_recorder_handler_->canSupportMimeType( |
| 190 mime_type_audio, example_unsupported_codecs_2)); | 190 mime_type_audio, example_unsupported_codecs_2)); |
| 191 } | 191 } |
| 192 | 192 |
| 193 // Checks that the initialization-destruction sequence works fine. | 193 // Checks that the initialization-destruction sequence works fine. |
| 194 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { | 194 TEST_P(MediaRecorderHandlerTest, InitializeStartStop) { |
| 195 AddTracks(); | 195 AddTracks(); |
| 196 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 196 const WebString mime_type(WebString::fromASCII(GetParam().mime_type)); |
| 197 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); | 197 const WebString codecs(WebString::fromASCII(GetParam().codecs)); |
| 198 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 198 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 199 mime_type, codecs, 0, 0)); | 199 mime_type, codecs, 0, 0)); |
| 200 EXPECT_FALSE(recording()); | 200 EXPECT_FALSE(recording()); |
| 201 EXPECT_FALSE(hasVideoRecorders()); | 201 EXPECT_FALSE(hasVideoRecorders()); |
| 202 EXPECT_FALSE(hasAudioRecorders()); | 202 EXPECT_FALSE(hasAudioRecorders()); |
| 203 | 203 |
| 204 EXPECT_TRUE(media_recorder_handler_->start(0)); | 204 EXPECT_TRUE(media_recorder_handler_->start(0)); |
| 205 EXPECT_TRUE(recording()); | 205 EXPECT_TRUE(recording()); |
| 206 | 206 |
| 207 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); | 207 EXPECT_TRUE(hasVideoRecorders() || !GetParam().has_video); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). | 220 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). |
| 221 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { | 221 TEST_P(MediaRecorderHandlerTest, EncodeVideoFrames) { |
| 222 // Video-only test. | 222 // Video-only test. |
| 223 if (GetParam().has_audio) | 223 if (GetParam().has_audio) |
| 224 return; | 224 return; |
| 225 | 225 |
| 226 AddTracks(); | 226 AddTracks(); |
| 227 | 227 |
| 228 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 228 const WebString mime_type(WebString::fromASCII(GetParam().mime_type)); |
| 229 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); | 229 const WebString codecs(WebString::fromASCII(GetParam().codecs)); |
| 230 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 230 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 231 mime_type, codecs, 0, 0)); | 231 mime_type, codecs, 0, 0)); |
| 232 EXPECT_TRUE(media_recorder_handler_->start(0)); | 232 EXPECT_TRUE(media_recorder_handler_->start(0)); |
| 233 | 233 |
| 234 InSequence s; | 234 InSequence s; |
| 235 const scoped_refptr<media::VideoFrame> video_frame = | 235 const scoped_refptr<media::VideoFrame> video_frame = |
| 236 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 236 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 237 | 237 |
| 238 { | 238 { |
| 239 const size_t kEncodedSizeThreshold = 16; | 239 const size_t kEncodedSizeThreshold = 16; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 ValuesIn(kMediaRecorderTestParams)); | 280 ValuesIn(kMediaRecorderTestParams)); |
| 281 | 281 |
| 282 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). | 282 // Sends 2 frames and expect them as WebM contained encoded data in writeData(). |
| 283 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { | 283 TEST_P(MediaRecorderHandlerTest, EncodeAudioFrames) { |
| 284 // Audio-only test. | 284 // Audio-only test. |
| 285 if (GetParam().has_video) | 285 if (GetParam().has_video) |
| 286 return; | 286 return; |
| 287 | 287 |
| 288 AddTracks(); | 288 AddTracks(); |
| 289 | 289 |
| 290 const WebString mime_type(base::UTF8ToUTF16("audio/webm")); | 290 const WebString mime_type(WebString::fromASCII("audio/webm")); |
| 291 EXPECT_TRUE(media_recorder_handler_->initialize( | 291 EXPECT_TRUE(media_recorder_handler_->initialize( |
| 292 this, registry_.test_stream(), mime_type, WebString(), 0, 0)); | 292 this, registry_.test_stream(), mime_type, WebString(), 0, 0)); |
| 293 EXPECT_TRUE(media_recorder_handler_->start(0)); | 293 EXPECT_TRUE(media_recorder_handler_->start(0)); |
| 294 | 294 |
| 295 InSequence s; | 295 InSequence s; |
| 296 const std::unique_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); | 296 const std::unique_ptr<media::AudioBus> audio_bus1 = NextAudioBus(); |
| 297 const std::unique_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); | 297 const std::unique_ptr<media::AudioBus> audio_bus2 = NextAudioBus(); |
| 298 | 298 |
| 299 media::AudioParameters params( | 299 media::AudioParameters params( |
| 300 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, | 300 media::AudioParameters::AUDIO_PCM_LINEAR, media::CHANNEL_LAYOUT_STEREO, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Starts up recording and forces a WebmMuxer's libwebm error. | 346 // Starts up recording and forces a WebmMuxer's libwebm error. |
| 347 TEST_P(MediaRecorderHandlerTest, WebmMuxerErrorWhileEncoding) { | 347 TEST_P(MediaRecorderHandlerTest, WebmMuxerErrorWhileEncoding) { |
| 348 // Video-only test: Audio would be very similar. | 348 // Video-only test: Audio would be very similar. |
| 349 if (GetParam().has_audio) | 349 if (GetParam().has_audio) |
| 350 return; | 350 return; |
| 351 | 351 |
| 352 AddTracks(); | 352 AddTracks(); |
| 353 | 353 |
| 354 const WebString mime_type(base::UTF8ToUTF16(GetParam().mime_type)); | 354 const WebString mime_type(WebString::fromASCII(GetParam().mime_type)); |
| 355 const WebString codecs(base::UTF8ToUTF16(GetParam().codecs)); | 355 const WebString codecs(WebString::fromASCII(GetParam().codecs)); |
| 356 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), | 356 EXPECT_TRUE(media_recorder_handler_->initialize(this, registry_.test_stream(), |
| 357 mime_type, codecs, 0, 0)); | 357 mime_type, codecs, 0, 0)); |
| 358 EXPECT_TRUE(media_recorder_handler_->start(0)); | 358 EXPECT_TRUE(media_recorder_handler_->start(0)); |
| 359 | 359 |
| 360 InSequence s; | 360 InSequence s; |
| 361 const scoped_refptr<media::VideoFrame> video_frame = | 361 const scoped_refptr<media::VideoFrame> video_frame = |
| 362 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); | 362 media::VideoFrame::CreateBlackFrame(gfx::Size(160, 80)); |
| 363 | 363 |
| 364 { | 364 { |
| 365 const size_t kEncodedSizeThreshold = 16; | 365 const size_t kEncodedSizeThreshold = 16; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 386 run_loop.Run(); | 386 run_loop.Run(); |
| 387 } | 387 } |
| 388 | 388 |
| 389 | 389 |
| 390 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 390 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
| 391 EXPECT_CALL(*this, writeData(nullptr, 0, true, _)).Times(1); | 391 EXPECT_CALL(*this, writeData(nullptr, 0, true, _)).Times(1); |
| 392 media_recorder_handler_.reset(); | 392 media_recorder_handler_.reset(); |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace content | 395 } // namespace content |
| OLD | NEW |