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

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: speculative hack to fix test timeouts Created 4 years, 8 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"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 int had_error() const { 43 int had_error() const {
44 return had_error_; 44 return had_error_;
45 } 45 }
46 46
47 private: 47 private:
48 int callback_count_; 48 int callback_count_;
49 int had_error_; 49 int had_error_;
50 }; 50 };
51 51
52 class AudioInputTest : public testing::Test { 52 class AudioInputTest : public testing::Test {
53 public: 53 public:
54 AudioInputTest() : 54 AudioInputTest()
55 message_loop_(base::MessageLoop::TYPE_UI), 55 : message_loop_(base::MessageLoop::TYPE_UI),
56 audio_manager_(AudioManager::CreateForTesting()), 56 audio_manager_(
57 audio_input_stream_(NULL) { 57 AudioManager::CreateForTesting(message_loop_.task_runner())),
58 // Wait for the AudioManager to finish any initialization on the audio loop. 58 audio_input_stream_(NULL) {
59 // Wait for the AudioManager to finish any initialization on the audio
60 // loop.
59 base::RunLoop().RunUntilIdle(); 61 base::RunLoop().RunUntilIdle();
60 } 62 }
61 63
62 ~AudioInputTest() override { base::RunLoop().RunUntilIdle(); } 64 ~AudioInputTest() override { base::RunLoop().RunUntilIdle(); }
63 65
64 protected: 66 protected:
65 bool InputDevicesAvailable() { 67 bool InputDevicesAvailable() {
66 return audio_manager_->HasAudioInputDevices(); 68 return audio_manager_->HasAudioInputDevices();
67 } 69 }
68 70
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 161 }
160 162
161 void RunOnAudioThreadImpl(const base::Closure& closure, 163 void RunOnAudioThreadImpl(const base::Closure& closure,
162 base::WaitableEvent* event) { 164 base::WaitableEvent* event) {
163 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); 165 DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
164 closure.Run(); 166 closure.Run();
165 event->Signal(); 167 event->Signal();
166 } 168 }
167 169
168 base::MessageLoop message_loop_; 170 base::MessageLoop message_loop_;
169 scoped_ptr<AudioManager> audio_manager_; 171 ScopedAudioManagerPtr audio_manager_;
170 AudioInputStream* audio_input_stream_; 172 AudioInputStream* audio_input_stream_;
171 173
172 private: 174 private:
173 DISALLOW_COPY_AND_ASSIGN(AudioInputTest); 175 DISALLOW_COPY_AND_ASSIGN(AudioInputTest);
174 }; 176 };
175 177
176 // Test create and close of an AudioInputStream without recording audio. 178 // Test create and close of an AudioInputStream without recording audio.
177 TEST_F(AudioInputTest, CreateAndClose) { 179 TEST_F(AudioInputTest, CreateAndClose) {
178 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 180 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
179 MakeAudioInputStreamOnAudioThread(); 181 MakeAudioInputStreamOnAudioThread();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 base::MessageLoop::QuitWhenIdleClosure(), 228 base::MessageLoop::QuitWhenIdleClosure(),
227 base::TimeDelta::FromMilliseconds(500)); 229 base::TimeDelta::FromMilliseconds(500));
228 message_loop_.Run(); 230 message_loop_.Run();
229 EXPECT_GE(test_callback.callback_count(), 2); 231 EXPECT_GE(test_callback.callback_count(), 2);
230 EXPECT_FALSE(test_callback.had_error()); 232 EXPECT_FALSE(test_callback.had_error());
231 233
232 StopAndCloseAudioInputStreamOnAudioThread(); 234 StopAndCloseAudioInputStreamOnAudioThread();
233 } 235 }
234 236
235 } // namespace media 237 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698