Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: media/audio/audio_input_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass task runners into AudioManager::Create Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/platform_thread.h" 14 #include "base/threading/platform_thread.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "media/audio/audio_io.h" 16 #include "media/audio/audio_io.h"
17 #include "media/audio/audio_manager_base.h" 17 #include "media/audio/audio_manager_base.h"
18 #include "media/audio/audio_unittest_util.h" 18 #include "media/audio/audio_unittest_util.h"
19 #include "media/audio/fake_audio_log_factory.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace media { 22 namespace media {
22 23
23 // This class allows to find out if the callbacks are occurring as 24 // This class allows to find out if the callbacks are occurring as
24 // expected and if any error has been reported. 25 // expected and if any error has been reported.
25 class TestInputCallback : public AudioInputStream::AudioInputCallback { 26 class TestInputCallback : public AudioInputStream::AudioInputCallback {
26 public: 27 public:
27 explicit TestInputCallback() 28 explicit TestInputCallback()
28 : callback_count_(0), 29 : callback_count_(0),
(...skipping 15 matching lines...) Expand all
44 return had_error_; 45 return had_error_;
45 } 46 }
46 47
47 private: 48 private:
48 int callback_count_; 49 int callback_count_;
49 int had_error_; 50 int had_error_;
50 }; 51 };
51 52
52 class AudioInputTest : public testing::Test { 53 class AudioInputTest : public testing::Test {
53 public: 54 public:
54 AudioInputTest() : 55 AudioInputTest()
55 message_loop_(base::MessageLoop::TYPE_UI), 56 : message_loop_(base::MessageLoop::TYPE_UI),
56 audio_manager_(AudioManager::CreateForTesting()), 57 audio_manager_(AudioManager::Create(nullptr,
57 audio_input_stream_(NULL) { 58 nullptr,
58 // Wait for the AudioManager to finish any initialization on the audio loop. 59 nullptr,
59 base::RunLoop().RunUntilIdle(); 60 &fake_audio_log_factory_)),
61 audio_input_stream_(NULL) {
62 // Wait for the AudioManager to finish any initialization on the audio
63 // loop.
64 base::RunLoop().RunUntilIdle();
65 }
66
67 ~AudioInputTest() override {
68 AudioManager::Destroy(audio_manager_.release());
69 base::RunLoop().RunUntilIdle();
60 } 70 }
61 71
62 ~AudioInputTest() override { base::RunLoop().RunUntilIdle(); }
63
64 protected: 72 protected:
65 bool InputDevicesAvailable() { 73 bool InputDevicesAvailable() {
66 return audio_manager_->HasAudioInputDevices(); 74 return audio_manager_->HasAudioInputDevices();
67 } 75 }
68 76
69 void MakeAudioInputStreamOnAudioThread() { 77 void MakeAudioInputStreamOnAudioThread() {
70 RunOnAudioThread( 78 RunOnAudioThread(
71 base::Bind(&AudioInputTest::MakeAudioInputStream, 79 base::Bind(&AudioInputTest::MakeAudioInputStream,
72 base::Unretained(this))); 80 base::Unretained(this)));
73 } 81 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 167 }
160 168
161 void RunOnAudioThreadImpl(const base::Closure& closure, 169 void RunOnAudioThreadImpl(const base::Closure& closure,
162 base::WaitableEvent* event) { 170 base::WaitableEvent* event) {
163 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); 171 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
164 closure.Run(); 172 closure.Run();
165 event->Signal(); 173 event->Signal();
166 } 174 }
167 175
168 base::MessageLoop message_loop_; 176 base::MessageLoop message_loop_;
177 FakeAudioLogFactory fake_audio_log_factory_;
169 scoped_ptr<AudioManager> audio_manager_; 178 scoped_ptr<AudioManager> audio_manager_;
170 AudioInputStream* audio_input_stream_; 179 AudioInputStream* audio_input_stream_;
171 180
172 private: 181 private:
173 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); 182 DISALLOW_COPY_AND_ASSIGN(AudioInputTest);
174 }; 183 };
175 184
176 // Test create and close of an AudioInputStream without recording audio. 185 // Test create and close of an AudioInputStream without recording audio.
177 TEST_F(AudioInputTest, CreateAndClose) { 186 TEST_F(AudioInputTest, CreateAndClose) {
178 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 187 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 base::MessageLoop::QuitWhenIdleClosure(), 235 base::MessageLoop::QuitWhenIdleClosure(),
227 base::TimeDelta::FromMilliseconds(500)); 236 base::TimeDelta::FromMilliseconds(500));
228 message_loop_.Run(); 237 message_loop_.Run();
229 EXPECT_GE(test_callback.callback_count(), 2); 238 EXPECT_GE(test_callback.callback_count(), 2);
230 EXPECT_FALSE(test_callback.had_error()); 239 EXPECT_FALSE(test_callback.had_error());
231 240
232 StopAndCloseAudioInputStreamOnAudioThread(); 241 StopAndCloseAudioInputStreamOnAudioThread();
233 } 242 }
234 243
235 } // namespace media 244 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698