| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 44 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 45 base::RunLoop().Run(); | 45 base::RunLoop().Run(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 class MockAudioInputControllerEventHandler | 48 class MockAudioInputControllerEventHandler |
| 49 : public AudioInputController::EventHandler { | 49 : public AudioInputController::EventHandler { |
| 50 public: | 50 public: |
| 51 MockAudioInputControllerEventHandler() {} | 51 MockAudioInputControllerEventHandler() {} |
| 52 | 52 |
| 53 MOCK_METHOD1(OnCreated, void(AudioInputController* controller)); | 53 MOCK_METHOD1(OnCreated, void(AudioInputController* controller)); |
| 54 MOCK_METHOD1(OnRecording, void(AudioInputController* controller)); | |
| 55 MOCK_METHOD2(OnError, void(AudioInputController* controller, | 54 MOCK_METHOD2(OnError, void(AudioInputController* controller, |
| 56 AudioInputController::ErrorCode error_code)); | 55 AudioInputController::ErrorCode error_code)); |
| 57 MOCK_METHOD2(OnData, | 56 MOCK_METHOD2(OnData, |
| 58 void(AudioInputController* controller, const AudioBus* data)); | 57 void(AudioInputController* controller, const AudioBus* data)); |
| 59 MOCK_METHOD2(OnLog, | 58 MOCK_METHOD2(OnLog, |
| 60 void(AudioInputController* controller, | 59 void(AudioInputController* controller, |
| 61 const std::string& message)); | 60 const std::string& message)); |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler); | 63 DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 112 |
| 114 // Test a normal call sequence of create, record and close. | 113 // Test a normal call sequence of create, record and close. |
| 115 TEST_F(AudioInputControllerTest, RecordAndClose) { | 114 TEST_F(AudioInputControllerTest, RecordAndClose) { |
| 116 MockAudioInputControllerEventHandler event_handler; | 115 MockAudioInputControllerEventHandler event_handler; |
| 117 int count = 0; | 116 int count = 0; |
| 118 | 117 |
| 119 // OnCreated() will be called once. | 118 // OnCreated() will be called once. |
| 120 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 119 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 121 .Times(Exactly(1)); | 120 .Times(Exactly(1)); |
| 122 | 121 |
| 123 // OnRecording() will be called only once. | |
| 124 EXPECT_CALL(event_handler, OnRecording(NotNull())) | |
| 125 .Times(Exactly(1)); | |
| 126 | |
| 127 // OnData() shall be called ten times. | 122 // OnData() shall be called ten times. |
| 128 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull())) | 123 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull())) |
| 129 .Times(AtLeast(10)) | 124 .Times(AtLeast(10)) |
| 130 .WillRepeatedly(CheckCountAndPostQuitTask( | 125 .WillRepeatedly(CheckCountAndPostQuitTask( |
| 131 &count, 10, message_loop_.task_runner())); | 126 &count, 10, message_loop_.task_runner())); |
| 132 | 127 |
| 133 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 128 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 134 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 129 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 135 | 130 |
| 136 // Creating the AudioInputController should render an OnCreated() call. | 131 // Creating the AudioInputController should render an OnCreated() call. |
| 137 scoped_refptr<AudioInputController> controller = AudioInputController::Create( | 132 scoped_refptr<AudioInputController> controller = AudioInputController::Create( |
| 138 audio_manager_.get(), &event_handler, params, | 133 audio_manager_.get(), &event_handler, params, |
| 139 AudioDeviceDescription::kDefaultDeviceId, NULL); | 134 AudioDeviceDescription::kDefaultDeviceId, NULL); |
| 140 ASSERT_TRUE(controller.get()); | 135 ASSERT_TRUE(controller.get()); |
| 141 | 136 |
| 142 // Start recording and trigger one OnRecording() call. | |
| 143 controller->Record(); | 137 controller->Record(); |
| 144 | 138 |
| 145 // Record and wait until ten OnData() callbacks are received. | 139 // Record and wait until ten OnData() callbacks are received. |
| 146 base::RunLoop().Run(); | 140 base::RunLoop().Run(); |
| 147 | 141 |
| 148 // Close the AudioInputController synchronously. | 142 // Close the AudioInputController synchronously. |
| 149 CloseAudioController(controller.get()); | 143 CloseAudioController(controller.get()); |
| 150 } | 144 } |
| 151 | 145 |
| 152 // Test that AudioInputController rejects insanely large packet sizes. | 146 // Test that AudioInputController rejects insanely large packet sizes. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 166 scoped_refptr<AudioInputController> controller = AudioInputController::Create( | 160 scoped_refptr<AudioInputController> controller = AudioInputController::Create( |
| 167 audio_manager_.get(), &event_handler, params, | 161 audio_manager_.get(), &event_handler, params, |
| 168 AudioDeviceDescription::kDefaultDeviceId, NULL); | 162 AudioDeviceDescription::kDefaultDeviceId, NULL); |
| 169 ASSERT_FALSE(controller.get()); | 163 ASSERT_FALSE(controller.get()); |
| 170 } | 164 } |
| 171 | 165 |
| 172 // Test calling AudioInputController::Close multiple times. | 166 // Test calling AudioInputController::Close multiple times. |
| 173 TEST_F(AudioInputControllerTest, CloseTwice) { | 167 TEST_F(AudioInputControllerTest, CloseTwice) { |
| 174 MockAudioInputControllerEventHandler event_handler; | 168 MockAudioInputControllerEventHandler event_handler; |
| 175 | 169 |
| 176 // OnRecording() will be called only once. | 170 // OnCreated() will be called only once. |
| 177 EXPECT_CALL(event_handler, OnCreated(NotNull())); | 171 EXPECT_CALL(event_handler, OnCreated(NotNull())); |
| 178 | 172 |
| 179 // OnRecording() will be called only once. | |
| 180 EXPECT_CALL(event_handler, OnRecording(NotNull())) | |
| 181 .Times(Exactly(1)); | |
| 182 | |
| 183 AudioParameters params(AudioParameters::AUDIO_FAKE, | 173 AudioParameters params(AudioParameters::AUDIO_FAKE, |
| 184 kChannelLayout, | 174 kChannelLayout, |
| 185 kSampleRate, | 175 kSampleRate, |
| 186 kBitsPerSample, | 176 kBitsPerSample, |
| 187 kSamplesPerPacket); | 177 kSamplesPerPacket); |
| 188 scoped_refptr<AudioInputController> controller = AudioInputController::Create( | 178 scoped_refptr<AudioInputController> controller = AudioInputController::Create( |
| 189 audio_manager_.get(), &event_handler, params, | 179 audio_manager_.get(), &event_handler, params, |
| 190 AudioDeviceDescription::kDefaultDeviceId, NULL); | 180 AudioDeviceDescription::kDefaultDeviceId, NULL); |
| 191 ASSERT_TRUE(controller.get()); | 181 ASSERT_TRUE(controller.get()); |
| 192 | 182 |
| 193 controller->Record(); | 183 controller->Record(); |
| 194 | 184 |
| 195 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 185 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 196 base::RunLoop().Run(); | 186 base::RunLoop().Run(); |
| 197 | 187 |
| 198 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); | 188 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 199 base::RunLoop().Run(); | 189 base::RunLoop().Run(); |
| 200 } | 190 } |
| 201 | 191 |
| 202 } // namespace media | 192 } // namespace media |
| OLD | NEW |