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

Side by Side Diff: media/audio/alsa/alsa_output_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implemented ScopedAudioManagerPtr 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/thread_task_runner_handle.h"
9 #include "media/audio/alsa/alsa_output.h" 10 #include "media/audio/alsa/alsa_output.h"
10 #include "media/audio/alsa/alsa_wrapper.h" 11 #include "media/audio/alsa/alsa_wrapper.h"
11 #include "media/audio/alsa/audio_manager_alsa.h" 12 #include "media/audio/alsa/audio_manager_alsa.h"
12 #include "media/audio/fake_audio_log_factory.h" 13 #include "media/audio/fake_audio_log_factory.h"
13 #include "media/audio/mock_audio_source_callback.h" 14 #include "media/audio/mock_audio_source_callback.h"
14 #include "media/base/data_buffer.h" 15 #include "media/base/data_buffer.h"
15 #include "media/base/seekable_buffer.h" 16 #include "media/base/seekable_buffer.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 MOCK_METHOD1(PcmName, const char*(snd_pcm_t* handle)); 66 MOCK_METHOD1(PcmName, const char*(snd_pcm_t* handle));
66 MOCK_METHOD1(PcmAvailUpdate, snd_pcm_sframes_t(snd_pcm_t* handle)); 67 MOCK_METHOD1(PcmAvailUpdate, snd_pcm_sframes_t(snd_pcm_t* handle));
67 MOCK_METHOD1(PcmState, snd_pcm_state_t(snd_pcm_t* handle)); 68 MOCK_METHOD1(PcmState, snd_pcm_state_t(snd_pcm_t* handle));
68 MOCK_METHOD1(PcmStart, int(snd_pcm_t* handle)); 69 MOCK_METHOD1(PcmStart, int(snd_pcm_t* handle));
69 70
70 MOCK_METHOD1(StrError, const char*(int errnum)); 71 MOCK_METHOD1(StrError, const char*(int errnum));
71 }; 72 };
72 73
73 class MockAudioManagerAlsa : public AudioManagerAlsa { 74 class MockAudioManagerAlsa : public AudioManagerAlsa {
74 public: 75 public:
75 MockAudioManagerAlsa() : AudioManagerAlsa(&fake_audio_log_factory_) {} 76 MockAudioManagerAlsa()
77 : AudioManagerAlsa(base::ThreadTaskRunnerHandle::Get(),
78 base::ThreadTaskRunnerHandle::Get(),
79 &fake_audio_log_factory_) {}
76 MOCK_METHOD0(Init, void()); 80 MOCK_METHOD0(Init, void());
77 MOCK_METHOD0(HasAudioOutputDevices, bool()); 81 MOCK_METHOD0(HasAudioOutputDevices, bool());
78 MOCK_METHOD0(HasAudioInputDevices, bool()); 82 MOCK_METHOD0(HasAudioInputDevices, bool());
79 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( 83 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*(
80 const AudioParameters& params)); 84 const AudioParameters& params));
81 MOCK_METHOD2(MakeLowLatencyOutputStream, AudioOutputStream*( 85 MOCK_METHOD2(MakeLowLatencyOutputStream, AudioOutputStream*(
82 const AudioParameters& params, 86 const AudioParameters& params,
83 const std::string& device_id)); 87 const std::string& device_id));
84 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( 88 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*(
85 const AudioParameters& params, const std::string& device_id)); 89 const AudioParameters& params, const std::string& device_id));
86 90
87 // We need to override this function in order to skip the checking the number 91 // We need to override this function in order to skip the checking the number
88 // of active output streams. It is because the number of active streams 92 // of active output streams. It is because the number of active streams
89 // is managed inside MakeAudioOutputStream, and we don't use 93 // is managed inside MakeAudioOutputStream, and we don't use
90 // MakeAudioOutputStream to create the stream in the tests. 94 // MakeAudioOutputStream to create the stream in the tests.
91 void ReleaseOutputStream(AudioOutputStream* stream) override { 95 void ReleaseOutputStream(AudioOutputStream* stream) override {
92 DCHECK(stream); 96 DCHECK(stream);
93 delete stream; 97 delete stream;
94 } 98 }
95 99
96 // We don't mock this method since all tests will do the same thing
97 // and use the current task runner.
98 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override {
99 return base::MessageLoop::current()->task_runner();
100 }
101
102 private: 100 private:
103 FakeAudioLogFactory fake_audio_log_factory_; 101 FakeAudioLogFactory fake_audio_log_factory_;
104 }; 102 };
105 103
106 class AlsaPcmOutputStreamTest : public testing::Test { 104 class AlsaPcmOutputStreamTest : public testing::Test {
107 protected: 105 protected:
108 AlsaPcmOutputStreamTest() { 106 AlsaPcmOutputStreamTest() {
109 mock_manager_.reset(new StrictMock<MockAudioManagerAlsa>()); 107 mock_manager_.reset(new StrictMock<MockAudioManagerAlsa>());
110 } 108 }
111 109
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 851
854 // TODO(ajwong): Find a way to test whether or not another task has been 852 // TODO(ajwong): Find a way to test whether or not another task has been
855 // posted so we can verify that the Alsa code will indeed break the task 853 // posted so we can verify that the Alsa code will indeed break the task
856 // posting loop. 854 // posting loop.
857 855
858 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed); 856 test_stream->TransitionTo(AlsaPcmOutputStream::kIsClosed);
859 test_stream->Close(); 857 test_stream->Close();
860 } 858 }
861 859
862 } // namespace media 860 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698