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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/scoped_task_environment.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
14 #include "content/renderer/media/mock_media_stream_registry.h" | 15 #include "content/renderer/media/mock_media_stream_registry.h" |
15 #include "content/renderer/media_recorder/media_recorder_handler.h" | 16 #include "content/renderer/media_recorder/media_recorder_handler.h" |
16 #include "media/audio/simple_sources.h" | 17 #include "media/audio/simple_sources.h" |
17 #include "media/base/audio_bus.h" | 18 #include "media/base/audio_bus.h" |
18 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h" | 22 #include "third_party/WebKit/public/platform/WebMediaRecorderHandlerClient.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 {true, false, "video/webm", "vp9", true}, | 66 {true, false, "video/webm", "vp9", true}, |
66 #if BUILDFLAG(RTC_USE_H264) | 67 #if BUILDFLAG(RTC_USE_H264) |
67 {true, false, "video/webm", "h264", false}, | 68 {true, false, "video/webm", "h264", false}, |
68 #endif | 69 #endif |
69 {false, true, "video/webm", "vp8", true}}; | 70 {false, true, "video/webm", "vp8", true}}; |
70 | 71 |
71 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, | 72 class MediaRecorderHandlerTest : public TestWithParam<MediaRecorderTestParams>, |
72 public blink::WebMediaRecorderHandlerClient { | 73 public blink::WebMediaRecorderHandlerClient { |
73 public: | 74 public: |
74 MediaRecorderHandlerTest() | 75 MediaRecorderHandlerTest() |
75 : media_recorder_handler_(new MediaRecorderHandler()), | 76 : scoped_task_environment_( |
| 77 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 78 media_recorder_handler_(new MediaRecorderHandler()), |
76 audio_source_(kTestAudioChannels, | 79 audio_source_(kTestAudioChannels, |
77 440 /* freq */, | 80 440 /* freq */, |
78 kTestAudioSampleRate) { | 81 kTestAudioSampleRate) { |
79 EXPECT_FALSE(media_recorder_handler_->recording_); | 82 EXPECT_FALSE(media_recorder_handler_->recording_); |
80 | 83 |
81 registry_.Init(kTestStreamUrl); | 84 registry_.Init(kTestStreamUrl); |
82 } | 85 } |
83 | 86 |
84 ~MediaRecorderHandlerTest() { | 87 ~MediaRecorderHandlerTest() { |
85 registry_.reset(); | 88 registry_.reset(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 std::unique_ptr<media::AudioBus> bus(media::AudioBus::Create( | 128 std::unique_ptr<media::AudioBus> bus(media::AudioBus::Create( |
126 kTestAudioChannels, | 129 kTestAudioChannels, |
127 kTestAudioSampleRate * kTestAudioBufferDurationMs / 1000)); | 130 kTestAudioSampleRate * kTestAudioBufferDurationMs / 1000)); |
128 audio_source_.OnMoreData(base::TimeDelta(), base::TimeTicks::Now(), 0, | 131 audio_source_.OnMoreData(base::TimeDelta(), base::TimeTicks::Now(), 0, |
129 bus.get()); | 132 bus.get()); |
130 return bus; | 133 return bus; |
131 } | 134 } |
132 | 135 |
133 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks | 136 // A ChildProcess and a MessageLoopForUI are both needed to fool the Tracks |
134 // and Sources in |registry_| into believing they are on the right threads. | 137 // and Sources in |registry_| into believing they are on the right threads. |
135 const base::MessageLoopForUI message_loop_; | 138 const base::test::ScopedTaskEnvironment scoped_task_environment_; |
136 const ChildProcess child_process_; | 139 const ChildProcess child_process_; |
137 MockMediaStreamRegistry registry_; | 140 MockMediaStreamRegistry registry_; |
138 | 141 |
139 // The Class under test. Needs to be scoped_ptr to force its destruction. | 142 // The Class under test. Needs to be scoped_ptr to force its destruction. |
140 std::unique_ptr<MediaRecorderHandler> media_recorder_handler_; | 143 std::unique_ptr<MediaRecorderHandler> media_recorder_handler_; |
141 | 144 |
142 // For generating test AudioBuses | 145 // For generating test AudioBuses |
143 media::SineWaveAudioSource audio_source_; | 146 media::SineWaveAudioSource audio_source_; |
144 | 147 |
145 private: | 148 private: |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 run_loop.Run(); | 418 run_loop.Run(); |
416 } | 419 } |
417 | 420 |
418 | 421 |
419 // Expect a last call on destruction, with size 0 and |lastInSlice| true. | 422 // Expect a last call on destruction, with size 0 and |lastInSlice| true. |
420 EXPECT_CALL(*this, WriteData(nullptr, 0, true, _)).Times(1); | 423 EXPECT_CALL(*this, WriteData(nullptr, 0, true, _)).Times(1); |
421 media_recorder_handler_.reset(); | 424 media_recorder_handler_.reset(); |
422 } | 425 } |
423 | 426 |
424 } // namespace content | 427 } // namespace content |
OLD | NEW |