| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 AudioInputControllerTest() | 82 AudioInputControllerTest() |
| 83 : audio_thread_("AudioThread"), | 83 : audio_thread_("AudioThread"), |
| 84 suspend_event_(WaitableEvent::ResetPolicy::AUTOMATIC, | 84 suspend_event_(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 85 WaitableEvent::InitialState::NOT_SIGNALED) { | 85 WaitableEvent::InitialState::NOT_SIGNALED) { |
| 86 audio_thread_.StartAndWaitForTesting(); | 86 audio_thread_.StartAndWaitForTesting(); |
| 87 audio_manager_ = | 87 audio_manager_ = |
| 88 AudioManager::CreateForTesting(audio_thread_.task_runner()); | 88 AudioManager::CreateForTesting(audio_thread_.task_runner()); |
| 89 } | 89 } |
| 90 ~AudioInputControllerTest() override { | 90 ~AudioInputControllerTest() override { |
| 91 audio_task_runner()->PostTask( | 91 audio_task_runner()->PostTask( |
| 92 FROM_HERE, base::Bind(&AudioInputControllerTest::DeleteAudioManager, | 92 FROM_HERE, base::Bind(&AudioManager::Shutdown, |
| 93 base::Unretained(this))); | 93 base::Unretained(audio_manager_.get()))); |
| 94 audio_thread_.Stop(); | 94 audio_thread_.Stop(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner() const { | 97 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner() const { |
| 98 return audio_thread_.task_runner(); | 98 return audio_thread_.task_runner(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SuspendAudioThread() { | 101 void SuspendAudioThread() { |
| 102 audio_task_runner()->PostTask( | 102 audio_task_runner()->PostTask( |
| 103 FROM_HERE, base::Bind(&AudioInputControllerTest::WaitForResume, | 103 FROM_HERE, base::Bind(&AudioInputControllerTest::WaitForResume, |
| 104 base::Unretained(this))); | 104 base::Unretained(this))); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ResumeAudioThread() { suspend_event_.Signal(); } | 107 void ResumeAudioThread() { suspend_event_.Signal(); } |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 void DeleteAudioManager() { audio_manager_.reset(); } | |
| 111 void WaitForResume() { suspend_event_.Wait(); } | 110 void WaitForResume() { suspend_event_.Wait(); } |
| 112 | 111 |
| 113 protected: | 112 protected: |
| 114 base::Thread audio_thread_; | 113 base::Thread audio_thread_; |
| 115 base::MessageLoop message_loop_; | 114 base::MessageLoop message_loop_; |
| 116 ScopedAudioManagerPtr audio_manager_; | 115 std::unique_ptr<AudioManager> audio_manager_; |
| 117 WaitableEvent suspend_event_; | 116 WaitableEvent suspend_event_; |
| 118 | 117 |
| 119 private: | 118 private: |
| 120 DISALLOW_COPY_AND_ASSIGN(AudioInputControllerTest); | 119 DISALLOW_COPY_AND_ASSIGN(AudioInputControllerTest); |
| 121 }; | 120 }; |
| 122 | 121 |
| 123 // Test AudioInputController for create and close without recording audio. | 122 // Test AudioInputController for create and close without recording audio. |
| 124 TEST_F(AudioInputControllerTest, CreateAndClose) { | 123 TEST_F(AudioInputControllerTest, CreateAndClose) { |
| 125 base::RunLoop run_loop; | 124 base::RunLoop run_loop; |
| 126 | 125 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 controller->Record(); | 224 controller->Record(); |
| 226 | 225 |
| 227 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 226 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 228 base::RunLoop().Run(); | 227 base::RunLoop().Run(); |
| 229 | 228 |
| 230 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 229 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 231 base::RunLoop().Run(); | 230 base::RunLoop().Run(); |
| 232 } | 231 } |
| 233 | 232 |
| 234 } // namespace media | 233 } // namespace media |
| OLD | NEW |