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/audio_system_impl_unittest.cc

Issue 2687853002: Switching VirtualKeyboardPrivate keyboard config call stack to receive HasInputDevices() responce a… (Closed)
Patch Set: Fix for compilation error on linux_chromium_chromeos Created 3 years, 10 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/audio_system_impl.h" 5 #include "media/audio/audio_system_impl.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 15 matching lines...) Expand all
26 audio_thread_.StartAndWaitForTesting(); 26 audio_thread_.StartAndWaitForTesting();
27 audio_manager_.reset( 27 audio_manager_.reset(
28 new media::MockAudioManager(audio_thread_.task_runner())); 28 new media::MockAudioManager(audio_thread_.task_runner()));
29 } else { 29 } else {
30 audio_manager_.reset(new media::MockAudioManager( 30 audio_manager_.reset(new media::MockAudioManager(
31 base::ThreadTaskRunnerHandle::Get().get())); 31 base::ThreadTaskRunnerHandle::Get().get()));
32 } 32 }
33 audio_manager_->SetInputStreamParameters( 33 audio_manager_->SetInputStreamParameters(
34 media::AudioParameters::UnavailableDeviceParams()); 34 media::AudioParameters::UnavailableDeviceParams());
35 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 35 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
36 EXPECT_EQ(AudioSystem::Get(), audio_system_.get());
36 } 37 }
37 38
38 ~AudioSystemImplTest() override { 39 ~AudioSystemImplTest() override {
39 // Deleting |audio_manager_| on its thread. 40 // Deleting |audio_manager_| on its thread.
41 audio_system_.reset();
42 EXPECT_EQ(AudioSystem::Get(), nullptr);
40 audio_manager_.reset(); 43 audio_manager_.reset();
41 audio_thread_.Stop(); 44 audio_thread_.Stop();
42 } 45 }
43 46
44 void OnAudioParams(const AudioParameters& expected, 47 void OnAudioParams(const AudioParameters& expected,
45 const AudioParameters& received) { 48 const AudioParameters& received) {
46 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); 49 EXPECT_TRUE(thread_checker_.CalledOnValidThread());
47 EXPECT_EQ(expected.AsHumanReadableString(), 50 EXPECT_EQ(expected.AsHumanReadableString(),
48 received.AsHumanReadableString()); 51 received.AsHumanReadableString());
49 AudioParametersReceived(); 52 AudioParametersReceived();
50 } 53 }
51 54
52 void WaitForCallback() { 55 void WaitForCallback() {
53 if (!use_audio_thread_) { 56 if (!use_audio_thread_) {
54 base::RunLoop().RunUntilIdle(); 57 base::RunLoop().RunUntilIdle();
55 return; 58 return;
56 } 59 }
57 media::WaitableMessageLoopEvent event; 60 media::WaitableMessageLoopEvent event;
58 audio_thread_.task_runner()->PostTaskAndReply( 61 audio_thread_.task_runner()->PostTaskAndReply(
59 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); 62 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
60 // Runs the loop and waits for the |audio_thread_| to call event's closure, 63 // Runs the loop and waits for the |audio_thread_| to call event's closure,
61 // which means AudioSystem reply containing device parameters is already 64 // which means AudioSystem reply containing device parameters is already
62 // queued on the main thread. 65 // queued on the main thread.
63 event.RunAndWait(); 66 event.RunAndWait();
64 base::RunLoop().RunUntilIdle(); 67 base::RunLoop().RunUntilIdle();
65 } 68 }
66 69
67 MOCK_METHOD0(AudioParametersReceived, void(void)); 70 MOCK_METHOD0(AudioParametersReceived, void(void));
71 MOCK_METHOD1(HasInputDevicesCallback, void(bool));
68 72
69 protected: 73 protected:
70 base::MessageLoop message_loop_; 74 base::MessageLoop message_loop_;
71 base::ThreadChecker thread_checker_; 75 base::ThreadChecker thread_checker_;
72 bool use_audio_thread_; 76 bool use_audio_thread_;
73 base::Thread audio_thread_; 77 base::Thread audio_thread_;
74 MockAudioManager::UniquePtr audio_manager_; 78 MockAudioManager::UniquePtr audio_manager_;
75 std::unique_ptr<media::AudioSystem> audio_system_; 79 std::unique_ptr<media::AudioSystem> audio_system_;
76 }; 80 };
77 81
78 TEST_P(AudioSystemImplTest, GetInputStreamParameters) { 82 TEST_P(AudioSystemImplTest, GetInputStreamParameters) {
79 EXPECT_CALL(*this, AudioParametersReceived()); 83 EXPECT_CALL(*this, AudioParametersReceived());
80 audio_system_->GetInputStreamParameters( 84 audio_system_->GetInputStreamParameters(
81 media::AudioDeviceDescription::kDefaultDeviceId, 85 media::AudioDeviceDescription::kDefaultDeviceId,
82 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this), 86 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
83 media::AudioParameters::UnavailableDeviceParams())); 87 media::AudioParameters::UnavailableDeviceParams()));
84 WaitForCallback(); 88 WaitForCallback();
85 } 89 }
86 90
87 TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) { 91 TEST_P(AudioSystemImplTest, GetInputStreamParametersNoDevice) {
88 audio_manager_->SetHasInputDevices(false); 92 audio_manager_->SetHasInputDevices(false);
89 EXPECT_CALL(*this, AudioParametersReceived()); 93 EXPECT_CALL(*this, AudioParametersReceived());
90 audio_system_->GetInputStreamParameters( 94 audio_system_->GetInputStreamParameters(
91 media::AudioDeviceDescription::kDefaultDeviceId, 95 media::AudioDeviceDescription::kDefaultDeviceId,
92 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this), 96 base::Bind(&AudioSystemImplTest::OnAudioParams, base::Unretained(this),
93 media::AudioParameters())); 97 media::AudioParameters()));
94 WaitForCallback(); 98 WaitForCallback();
95 } 99 }
96 100
101 TEST_P(AudioSystemImplTest, HasInputDevices) {
102 EXPECT_CALL(*this, HasInputDevicesCallback(true));
103 audio_system_->HasInputDevices(base::Bind(
104 &AudioSystemImplTest::HasInputDevicesCallback, base::Unretained(this)));
105 WaitForCallback();
106 }
107
108 TEST_P(AudioSystemImplTest, HasNoInputDevices) {
109 audio_manager_->SetHasInputDevices(false);
110 EXPECT_CALL(*this, HasInputDevicesCallback(false));
111 audio_system_->HasInputDevices(base::Bind(
112 &AudioSystemImplTest::HasInputDevicesCallback, base::Unretained(this)));
113 WaitForCallback();
114 }
115
97 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true)); 116 INSTANTIATE_TEST_CASE_P(, AudioSystemImplTest, testing::Values(false, true));
98 117
99 } // namespace media 118 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698