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/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/strings/string_piece.h" | 13 #include "base/strings/string_piece.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 "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class SoundsManagerTest : public testing::Test { | 23 class SoundsManagerTest : public testing::Test { |
24 public: | 24 public: |
25 SoundsManagerTest() {} | 25 SoundsManagerTest() {} |
26 ~SoundsManagerTest() override {} | 26 ~SoundsManagerTest() override {} |
27 | 27 |
28 void SetUp() override { | 28 void SetUp() override { |
29 audio_manager_.reset(AudioManager::CreateForTesting()); | 29 audio_manager_ = |
| 30 AudioManager::CreateForTesting(message_loop_.task_runner()); |
30 SoundsManager::Create(); | 31 SoundsManager::Create(); |
31 } | 32 } |
32 | 33 |
33 void TearDown() override { | 34 void TearDown() override { |
34 SoundsManager::Shutdown(); | 35 SoundsManager::Shutdown(); |
| 36 // AudioStreamHandler destructor posts stop and delete task to audio thread. |
| 37 // Flush audio thread to ensure that those tasks are run before attempting |
| 38 // to destroy AudioManager. |
| 39 base::RunLoop().RunUntilIdle(); |
| 40 |
35 audio_manager_.reset(); | 41 audio_manager_.reset(); |
36 } | 42 } |
37 | 43 |
38 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { | 44 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { |
39 AudioStreamHandler::SetObserverForTesting(observer); | 45 AudioStreamHandler::SetObserverForTesting(observer); |
40 } | 46 } |
41 | 47 |
42 void SetAudioSourceForTesting( | 48 void SetAudioSourceForTesting( |
43 AudioOutputStream::AudioSourceCallback* source) { | 49 AudioOutputStream::AudioSourceCallback* source) { |
44 AudioStreamHandler::SetAudioSourceForTesting(source); | 50 AudioStreamHandler::SetAudioSourceForTesting(source); |
45 } | 51 } |
46 | 52 |
47 private: | 53 private: |
48 scoped_ptr<AudioManager> audio_manager_; | 54 ScopedAudioManagerPtr audio_manager_; |
49 | 55 |
50 base::MessageLoop message_loop_; | 56 base::MessageLoop message_loop_; |
51 }; | 57 }; |
52 | 58 |
53 TEST_F(SoundsManagerTest, Play) { | 59 TEST_F(SoundsManagerTest, Play) { |
54 ASSERT_TRUE(SoundsManager::Get()); | 60 ASSERT_TRUE(SoundsManager::Get()); |
55 | 61 |
56 base::RunLoop run_loop; | 62 base::RunLoop run_loop; |
57 TestObserver observer(run_loop.QuitClosure()); | 63 TestObserver observer(run_loop.QuitClosure()); |
58 | 64 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 SetObserverForTesting(NULL); | 112 SetObserverForTesting(NULL); |
107 } | 113 } |
108 | 114 |
109 TEST_F(SoundsManagerTest, Uninitialized) { | 115 TEST_F(SoundsManagerTest, Uninitialized) { |
110 ASSERT_TRUE(SoundsManager::Get()); | 116 ASSERT_TRUE(SoundsManager::Get()); |
111 ASSERT_FALSE(SoundsManager::Get()->Play(kTestAudioKey)); | 117 ASSERT_FALSE(SoundsManager::Get()->Play(kTestAudioKey)); |
112 ASSERT_FALSE(SoundsManager::Get()->Stop(kTestAudioKey)); | 118 ASSERT_FALSE(SoundsManager::Get()->Stop(kTestAudioKey)); |
113 } | 119 } |
114 | 120 |
115 } // namespace media | 121 } // namespace media |
OLD | NEW |