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

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

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