OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "media/audio/audio_device_description.h" | 11 #include "media/audio/audio_device_description.h" |
12 #include "media/audio/audio_input_controller.h" | 12 #include "media/audio/audio_input_controller.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using ::testing::_; | 16 using ::testing::_; |
17 using ::testing::AtLeast; | 17 using ::testing::AtLeast; |
18 using ::testing::Exactly; | 18 using ::testing::Exactly; |
19 using ::testing::InvokeWithoutArgs; | 19 using ::testing::InvokeWithoutArgs; |
20 using ::testing::NotNull; | 20 using ::testing::NotNull; |
21 | 21 |
22 namespace media { | 22 namespace media { |
23 | 23 |
24 static const int kSampleRate = AudioParameters::kAudioCDSampleRate; | 24 static const int kSampleRate = AudioParameters::kAudioCDSampleRate; |
25 static const int kBitsPerSample = 16; | 25 static const int kBitsPerSample = 16; |
26 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 26 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
27 static const int kSamplesPerPacket = kSampleRate / 10; | 27 static const int kSamplesPerPacket = kSampleRate / 10; |
28 | 28 |
29 // Posts base::MessageLoop::QuitWhenIdleClosure() on specified message loop. | 29 ACTION_P(QuitRunLoop, run_loop) { |
30 ACTION_P(QuitMessageLoop, loop_or_proxy) { | 30 run_loop->QuitWhenIdle(); |
31 loop_or_proxy->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
32 } | 31 } |
33 | 32 |
34 // Posts base::MessageLoop::QuitWhenIdleClosure() on specified message loop | 33 // Posts base::MessageLoop::QuitWhenIdleClosure() on specified message loop |
35 // after a certain number of calls given by |limit|. | 34 // after a certain number of calls given by |limit|. |
36 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop_or_proxy) { | 35 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop_or_proxy) { |
37 if (++*count >= limit) { | 36 if (++*count >= limit) { |
38 loop_or_proxy->PostTask(FROM_HERE, | 37 loop_or_proxy->PostTask(FROM_HERE, |
39 base::MessageLoop::QuitWhenIdleClosure()); | 38 base::MessageLoop::QuitWhenIdleClosure()); |
40 } | 39 } |
41 } | 40 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 protected: | 81 protected: |
83 base::MessageLoop message_loop_; | 82 base::MessageLoop message_loop_; |
84 ScopedAudioManagerPtr audio_manager_; | 83 ScopedAudioManagerPtr audio_manager_; |
85 | 84 |
86 private: | 85 private: |
87 DISALLOW_COPY_AND_ASSIGN(AudioInputControllerTest); | 86 DISALLOW_COPY_AND_ASSIGN(AudioInputControllerTest); |
88 }; | 87 }; |
89 | 88 |
90 // Test AudioInputController for create and close without recording audio. | 89 // Test AudioInputController for create and close without recording audio. |
91 TEST_F(AudioInputControllerTest, CreateAndClose) { | 90 TEST_F(AudioInputControllerTest, CreateAndClose) { |
| 91 base::RunLoop run_loop; |
| 92 |
92 MockAudioInputControllerEventHandler event_handler; | 93 MockAudioInputControllerEventHandler event_handler; |
93 | 94 |
94 // OnCreated() will be posted once. | 95 // OnCreated() will be posted once. |
95 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 96 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
96 .WillOnce(QuitMessageLoop(&message_loop_)); | 97 .WillOnce(QuitRunLoop(&run_loop)); |
97 | 98 |
98 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 99 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
99 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 100 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
100 | 101 |
101 scoped_refptr<AudioInputController> controller = AudioInputController::Create( | 102 scoped_refptr<AudioInputController> controller = AudioInputController::Create( |
102 audio_manager_.get(), &event_handler, params, | 103 audio_manager_.get(), &event_handler, params, |
103 AudioDeviceDescription::kDefaultDeviceId, NULL); | 104 AudioDeviceDescription::kDefaultDeviceId, NULL); |
104 ASSERT_TRUE(controller.get()); | 105 ASSERT_TRUE(controller.get()); |
105 | 106 |
106 // Wait for OnCreated() to fire. | 107 // Wait for OnCreated() to fire. |
107 base::RunLoop().Run(); | 108 run_loop.Run(); |
108 | 109 |
109 // Close the AudioInputController synchronously. | 110 // Close the AudioInputController synchronously. |
110 CloseAudioController(controller.get()); | 111 CloseAudioController(controller.get()); |
111 } | 112 } |
112 | 113 |
113 // Test a normal call sequence of create, record and close. | 114 // Test a normal call sequence of create, record and close. |
114 TEST_F(AudioInputControllerTest, RecordAndClose) { | 115 TEST_F(AudioInputControllerTest, RecordAndClose) { |
115 MockAudioInputControllerEventHandler event_handler; | 116 MockAudioInputControllerEventHandler event_handler; |
116 int count = 0; | 117 int count = 0; |
117 | 118 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 controller->Record(); | 193 controller->Record(); |
193 | 194 |
194 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 195 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
195 base::RunLoop().Run(); | 196 base::RunLoop().Run(); |
196 | 197 |
197 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 198 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
198 base::RunLoop().Run(); | 199 base::RunLoop().Run(); |
199 } | 200 } |
200 | 201 |
201 } // namespace media | 202 } // namespace media |
OLD | NEW |