OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
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/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/test/test_message_loop.h" | 12 #include "base/test/test_message_loop.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
15 #include "media/audio/simple_sources.h" | 15 #include "media/audio/simple_sources.h" |
16 #include "media/audio/sounds/audio_stream_handler.h" | 16 #include "media/audio/sounds/audio_stream_handler.h" |
17 #include "media/audio/sounds/sounds_manager.h" | 17 #include "media/audio/sounds/sounds_manager.h" |
18 #include "media/audio/sounds/test_data.h" | 18 #include "media/audio/sounds/test_data.h" |
| 19 #include "media/audio/test_audio_thread.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 class SoundsManagerTest : public testing::Test { | 24 class SoundsManagerTest : public testing::Test { |
24 public: | 25 public: |
25 SoundsManagerTest() {} | 26 SoundsManagerTest() {} |
26 ~SoundsManagerTest() override {} | 27 ~SoundsManagerTest() override {} |
27 | 28 |
28 void SetUp() override { | 29 void SetUp() override { |
29 audio_manager_ = | 30 audio_manager_ = |
30 AudioManager::CreateForTesting(base::ThreadTaskRunnerHandle::Get()); | 31 AudioManager::CreateForTesting(base::MakeUnique<TestAudioThread>()); |
31 SoundsManager::Create(); | 32 SoundsManager::Create(); |
32 base::RunLoop().RunUntilIdle(); | 33 base::RunLoop().RunUntilIdle(); |
33 } | 34 } |
34 | 35 |
35 void TearDown() override { | 36 void TearDown() override { |
36 SoundsManager::Shutdown(); | 37 SoundsManager::Shutdown(); |
| 38 audio_manager_->Shutdown(); |
37 base::RunLoop().RunUntilIdle(); | 39 base::RunLoop().RunUntilIdle(); |
38 } | 40 } |
39 | 41 |
40 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { | 42 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { |
41 AudioStreamHandler::SetObserverForTesting(observer); | 43 AudioStreamHandler::SetObserverForTesting(observer); |
42 } | 44 } |
43 | 45 |
44 void SetAudioSourceForTesting( | 46 void SetAudioSourceForTesting( |
45 AudioOutputStream::AudioSourceCallback* source) { | 47 AudioOutputStream::AudioSourceCallback* source) { |
46 AudioStreamHandler::SetAudioSourceForTesting(source); | 48 AudioStreamHandler::SetAudioSourceForTesting(source); |
47 } | 49 } |
48 | 50 |
49 private: | 51 private: |
50 base::TestMessageLoop message_loop_; | 52 base::TestMessageLoop message_loop_; |
51 ScopedAudioManagerPtr audio_manager_; | 53 std::unique_ptr<AudioManager> audio_manager_; |
52 }; | 54 }; |
53 | 55 |
54 TEST_F(SoundsManagerTest, Play) { | 56 TEST_F(SoundsManagerTest, Play) { |
55 ASSERT_TRUE(SoundsManager::Get()); | 57 ASSERT_TRUE(SoundsManager::Get()); |
56 | 58 |
57 base::RunLoop run_loop; | 59 base::RunLoop run_loop; |
58 TestObserver observer(run_loop.QuitClosure()); | 60 TestObserver observer(run_loop.QuitClosure()); |
59 | 61 |
60 SetObserverForTesting(&observer); | 62 SetObserverForTesting(&observer); |
61 | 63 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 SetObserverForTesting(NULL); | 109 SetObserverForTesting(NULL); |
108 } | 110 } |
109 | 111 |
110 TEST_F(SoundsManagerTest, Uninitialized) { | 112 TEST_F(SoundsManagerTest, Uninitialized) { |
111 ASSERT_TRUE(SoundsManager::Get()); | 113 ASSERT_TRUE(SoundsManager::Get()); |
112 ASSERT_FALSE(SoundsManager::Get()->Play(kTestAudioKey)); | 114 ASSERT_FALSE(SoundsManager::Get()->Play(kTestAudioKey)); |
113 ASSERT_FALSE(SoundsManager::Get()->Stop(kTestAudioKey)); | 115 ASSERT_FALSE(SoundsManager::Get()->Stop(kTestAudioKey)); |
114 } | 116 } |
115 | 117 |
116 } // namespace media | 118 } // namespace media |
OLD | NEW |