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

Side by Side Diff: media/audio/sounds/audio_stream_handler_unittest.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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
« no previous file with comments | « media/audio/pulse/pulse_util.cc ('k') | media/audio/sounds/sounds_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "media/audio/sounds/audio_stream_handler.h" 5 #include "media/audio/sounds/audio_stream_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/test/test_message_loop.h" 16 #include "base/test/test_message_loop.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "media/audio/audio_io.h" 18 #include "media/audio/audio_io.h"
19 #include "media/audio/audio_manager.h" 19 #include "media/audio/audio_manager.h"
20 #include "media/audio/simple_sources.h" 20 #include "media/audio/simple_sources.h"
21 #include "media/audio/sounds/test_data.h" 21 #include "media/audio/sounds/test_data.h"
22 #include "media/audio/test_audio_thread.h"
22 #include "media/base/channel_layout.h" 23 #include "media/base/channel_layout.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 namespace media { 26 namespace media {
26 27
27 class AudioStreamHandlerTest : public testing::Test { 28 class AudioStreamHandlerTest : public testing::Test {
28 public: 29 public:
29 AudioStreamHandlerTest() {} 30 AudioStreamHandlerTest() {}
30 ~AudioStreamHandlerTest() override {} 31 ~AudioStreamHandlerTest() override {}
31 32
32 void SetUp() override { 33 void SetUp() override {
33 audio_manager_ = 34 audio_manager_ =
34 AudioManager::CreateForTesting(base::ThreadTaskRunnerHandle::Get()); 35 AudioManager::CreateForTesting(base::MakeUnique<TestAudioThread>());
35 base::RunLoop().RunUntilIdle(); 36 base::RunLoop().RunUntilIdle();
36 37
37 base::StringPiece data(kTestAudioData, arraysize(kTestAudioData)); 38 base::StringPiece data(kTestAudioData, arraysize(kTestAudioData));
38 audio_stream_handler_.reset(new AudioStreamHandler(data)); 39 audio_stream_handler_.reset(new AudioStreamHandler(data));
39 } 40 }
40 41
41 void TearDown() override { 42 void TearDown() override {
42 audio_stream_handler_.reset(); 43 audio_stream_handler_.reset();
44 audio_manager_->Shutdown();
43 base::RunLoop().RunUntilIdle(); 45 base::RunLoop().RunUntilIdle();
44 } 46 }
45 47
46 AudioStreamHandler* audio_stream_handler() { 48 AudioStreamHandler* audio_stream_handler() {
47 return audio_stream_handler_.get(); 49 return audio_stream_handler_.get();
48 } 50 }
49 51
50 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { 52 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) {
51 AudioStreamHandler::SetObserverForTesting(observer); 53 AudioStreamHandler::SetObserverForTesting(observer);
52 } 54 }
53 55
54 void SetAudioSourceForTesting( 56 void SetAudioSourceForTesting(
55 AudioOutputStream::AudioSourceCallback* source) { 57 AudioOutputStream::AudioSourceCallback* source) {
56 AudioStreamHandler::SetAudioSourceForTesting(source); 58 AudioStreamHandler::SetAudioSourceForTesting(source);
57 } 59 }
58 60
59 private: 61 private:
60 base::TestMessageLoop message_loop_; 62 base::TestMessageLoop message_loop_;
61 ScopedAudioManagerPtr audio_manager_; 63 std::unique_ptr<AudioManager> audio_manager_;
62 std::unique_ptr<AudioStreamHandler> audio_stream_handler_; 64 std::unique_ptr<AudioStreamHandler> audio_stream_handler_;
63 }; 65 };
64 66
65 TEST_F(AudioStreamHandlerTest, Play) { 67 TEST_F(AudioStreamHandlerTest, Play) {
66 base::RunLoop run_loop; 68 base::RunLoop run_loop;
67 TestObserver observer(run_loop.QuitClosure()); 69 TestObserver observer(run_loop.QuitClosure());
68 70
69 SetObserverForTesting(&observer); 71 SetObserverForTesting(&observer);
70 72
71 ASSERT_TRUE(audio_stream_handler()->IsInitialized()); 73 ASSERT_TRUE(audio_stream_handler()->IsInitialized());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 AudioStreamHandler handler("RIFF1234WAVEjunkjunkjunkjunk"); 122 AudioStreamHandler handler("RIFF1234WAVEjunkjunkjunkjunk");
121 EXPECT_FALSE(handler.IsInitialized()); 123 EXPECT_FALSE(handler.IsInitialized());
122 EXPECT_FALSE(handler.Play()); 124 EXPECT_FALSE(handler.Play());
123 EXPECT_EQ(base::TimeDelta(), handler.duration()); 125 EXPECT_EQ(base::TimeDelta(), handler.duration());
124 126
125 // Call Stop() to ensure that there is no crash. 127 // Call Stop() to ensure that there is no crash.
126 handler.Stop(); 128 handler.Stop();
127 } 129 }
128 130
129 } // namespace media 131 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_util.cc ('k') | media/audio/sounds/sounds_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698