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

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

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from patch 48 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
« no previous file with comments | « media/audio/pulse/audio_manager_pulse.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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/test/test_message_loop.h"
12 #include "base/thread_task_runner_handle.h"
12 #include "media/audio/audio_io.h" 13 #include "media/audio/audio_io.h"
13 #include "media/audio/audio_manager.h" 14 #include "media/audio/audio_manager.h"
14 #include "media/audio/simple_sources.h" 15 #include "media/audio/simple_sources.h"
15 #include "media/audio/sounds/audio_stream_handler.h" 16 #include "media/audio/sounds/audio_stream_handler.h"
16 #include "media/audio/sounds/test_data.h" 17 #include "media/audio/sounds/test_data.h"
17 #include "media/base/channel_layout.h" 18 #include "media/base/channel_layout.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace media { 21 namespace media {
21 22
22 class AudioStreamHandlerTest : public testing::Test { 23 class AudioStreamHandlerTest : public testing::Test {
23 public: 24 public:
24 AudioStreamHandlerTest() {} 25 AudioStreamHandlerTest() {}
25 ~AudioStreamHandlerTest() override {} 26 ~AudioStreamHandlerTest() override {}
26 27
27 void SetUp() override { 28 void SetUp() override {
28 audio_manager_.reset(AudioManager::CreateForTesting()); 29 audio_manager_ =
30 AudioManager::CreateForTesting(base::ThreadTaskRunnerHandle::Get());
31 base::RunLoop().RunUntilIdle();
29 32
30 base::StringPiece data(kTestAudioData, arraysize(kTestAudioData)); 33 base::StringPiece data(kTestAudioData, arraysize(kTestAudioData));
31 audio_stream_handler_.reset(new AudioStreamHandler(data)); 34 audio_stream_handler_.reset(new AudioStreamHandler(data));
32 } 35 }
33 36
34 void TearDown() override { 37 void TearDown() override {
35 audio_stream_handler_.reset(); 38 audio_stream_handler_.reset();
36 audio_manager_.reset(); 39 base::RunLoop().RunUntilIdle();
37 } 40 }
38 41
39 AudioStreamHandler* audio_stream_handler() { 42 AudioStreamHandler* audio_stream_handler() {
40 return audio_stream_handler_.get(); 43 return audio_stream_handler_.get();
41 } 44 }
42 45
43 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) { 46 void SetObserverForTesting(AudioStreamHandler::TestObserver* observer) {
44 AudioStreamHandler::SetObserverForTesting(observer); 47 AudioStreamHandler::SetObserverForTesting(observer);
45 } 48 }
46 49
47 void SetAudioSourceForTesting( 50 void SetAudioSourceForTesting(
48 AudioOutputStream::AudioSourceCallback* source) { 51 AudioOutputStream::AudioSourceCallback* source) {
49 AudioStreamHandler::SetAudioSourceForTesting(source); 52 AudioStreamHandler::SetAudioSourceForTesting(source);
50 } 53 }
51 54
52 private: 55 private:
53 scoped_ptr<AudioManager> audio_manager_; 56 base::TestMessageLoop message_loop_;
57 ScopedAudioManagerPtr audio_manager_;
54 scoped_ptr<AudioStreamHandler> audio_stream_handler_; 58 scoped_ptr<AudioStreamHandler> audio_stream_handler_;
55
56 base::MessageLoop message_loop_;
57 }; 59 };
58 60
59 TEST_F(AudioStreamHandlerTest, Play) { 61 TEST_F(AudioStreamHandlerTest, Play) {
60 base::RunLoop run_loop; 62 base::RunLoop run_loop;
61 TestObserver observer(run_loop.QuitClosure()); 63 TestObserver observer(run_loop.QuitClosure());
62 64
63 SetObserverForTesting(&observer); 65 SetObserverForTesting(&observer);
64 66
65 ASSERT_TRUE(audio_stream_handler()->IsInitialized()); 67 ASSERT_TRUE(audio_stream_handler()->IsInitialized());
66 EXPECT_EQ(base::TimeDelta::FromMicroseconds(20u), 68 EXPECT_EQ(base::TimeDelta::FromMicroseconds(20u),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 AudioStreamHandler handler("RIFF1234WAVEjunkjunkjunkjunk"); 118 AudioStreamHandler handler("RIFF1234WAVEjunkjunkjunkjunk");
117 EXPECT_FALSE(handler.IsInitialized()); 119 EXPECT_FALSE(handler.IsInitialized());
118 EXPECT_FALSE(handler.Play()); 120 EXPECT_FALSE(handler.Play());
119 EXPECT_EQ(base::TimeDelta(), handler.duration()); 121 EXPECT_EQ(base::TimeDelta(), handler.duration());
120 122
121 // Call Stop() to ensure that there is no crash. 123 // Call Stop() to ensure that there is no crash.
122 handler.Stop(); 124 handler.Stop();
123 } 125 }
124 126
125 } // namespace media 127 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/audio_manager_pulse.cc ('k') | media/audio/sounds/sounds_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698