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

Side by Side Diff: media/audio/audio_output_proxy_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/thread_task_runner_handle.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
13 #include "media/audio/audio_manager_base.h" 14 #include "media/audio/audio_manager_base.h"
14 #include "media/audio/audio_output_dispatcher_impl.h" 15 #include "media/audio/audio_output_dispatcher_impl.h"
15 #include "media/audio/audio_output_proxy.h" 16 #include "media/audio/audio_output_proxy.h"
16 #include "media/audio/audio_output_resampler.h" 17 #include "media/audio/audio_output_resampler.h"
17 #include "media/audio/fake_audio_log_factory.h" 18 #include "media/audio/fake_audio_log_factory.h"
18 #include "media/audio/fake_audio_output_stream.h" 19 #include "media/audio/fake_audio_output_stream.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 private: 82 private:
82 bool start_called_; 83 bool start_called_;
83 bool stop_called_; 84 bool stop_called_;
84 AudioParameters params_; 85 AudioParameters params_;
85 scoped_ptr<AudioOutputStream> fake_output_stream_; 86 scoped_ptr<AudioOutputStream> fake_output_stream_;
86 }; 87 };
87 88
88 class MockAudioManager : public AudioManagerBase { 89 class MockAudioManager : public AudioManagerBase {
89 public: 90 public:
90 MockAudioManager() : AudioManagerBase(&fake_audio_log_factory_) {} 91 MockAudioManager()
92 : AudioManagerBase(base::ThreadTaskRunnerHandle::Get(),
93 base::ThreadTaskRunnerHandle::Get(),
94 &fake_audio_log_factory_) {}
91 virtual ~MockAudioManager() { 95 virtual ~MockAudioManager() {
92 Shutdown(); 96 Shutdown();
93 } 97 }
94 98
95 MOCK_METHOD0(HasAudioOutputDevices, bool()); 99 MOCK_METHOD0(HasAudioOutputDevices, bool());
96 MOCK_METHOD0(HasAudioInputDevices, bool()); 100 MOCK_METHOD0(HasAudioInputDevices, bool());
97 MOCK_METHOD0(GetAudioInputDeviceModel, base::string16()); 101 MOCK_METHOD0(GetAudioInputDeviceModel, base::string16());
98 MOCK_METHOD2(MakeAudioOutputStream, AudioOutputStream*( 102 MOCK_METHOD2(MakeAudioOutputStream, AudioOutputStream*(
99 const AudioParameters& params, 103 const AudioParameters& params,
100 const std::string& device_id)); 104 const std::string& device_id));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); 140 MOCK_METHOD1(OnError, void(AudioOutputStream* stream));
137 }; 141 };
138 142
139 } // namespace 143 } // namespace
140 144
141 namespace media { 145 namespace media {
142 146
143 class AudioOutputProxyTest : public testing::Test { 147 class AudioOutputProxyTest : public testing::Test {
144 protected: 148 protected:
145 void SetUp() override { 149 void SetUp() override {
146 EXPECT_CALL(manager_, GetTaskRunner())
147 .WillRepeatedly(Return(message_loop_.task_runner()));
148 EXPECT_CALL(manager_, GetWorkerTaskRunner())
149 .WillRepeatedly(Return(message_loop_.task_runner()));
150 // Use a low sample rate and large buffer size when testing otherwise the 150 // Use a low sample rate and large buffer size when testing otherwise the
151 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., 151 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e.,
152 // RunUntilIdle() will never terminate. 152 // RunUntilIdle() will never terminate.
153 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 153 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
154 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); 154 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048);
155 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); 155 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
156 } 156 }
157 157
158 void TearDown() override { 158 void TearDown() override {
159 // This is necessary to free all proxy objects that have been 159 // This is necessary to free all proxy objects that have been
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 _)).WillOnce(Return(&real_stream)); 726 _)).WillOnce(Return(&real_stream));
727 727
728 // Stream1 should be able to successfully open and start. 728 // Stream1 should be able to successfully open and start.
729 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); 729 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true));
730 proxy = new AudioOutputProxy(resampler_.get()); 730 proxy = new AudioOutputProxy(resampler_.get());
731 EXPECT_TRUE(proxy->Open()); 731 EXPECT_TRUE(proxy->Open());
732 CloseAndWaitForCloseTimer(proxy, &real_stream); 732 CloseAndWaitForCloseTimer(proxy, &real_stream);
733 } 733 }
734 734
735 } // namespace media 735 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698