| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
| 10 #include "media/audio/audio_input_controller.h" | 10 #include "media/audio/audio_input_controller.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 virtual ~AudioInputControllerTest() {} | 65 virtual ~AudioInputControllerTest() {} |
| 66 | 66 |
| 67 protected: | 67 protected: |
| 68 MessageLoop message_loop_; | 68 MessageLoop message_loop_; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(AudioInputControllerTest); | 71 DISALLOW_COPY_AND_ASSIGN(AudioInputControllerTest); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Test AudioInputController for create and close without recording audio. | 74 // Test AudioInputController for create and close without recording audio. |
| 75 // TODO(leozwang): Because java calls were introduced in audio_manager_base, | 75 TEST_F(AudioInputControllerTest, CreateAndClose) { |
| 76 // unit test has to register jni first, else it will crash. | |
| 77 #if defined(OS_ANDROID) | |
| 78 #define MAYBE_CreateAndClose DISABLED_CreateAndClose | |
| 79 #else | |
| 80 #define MAYBE_CreateAndClose CreateAndClose | |
| 81 #endif | |
| 82 TEST_F(AudioInputControllerTest, MAYBE_CreateAndClose) { | |
| 83 MockAudioInputControllerEventHandler event_handler; | 76 MockAudioInputControllerEventHandler event_handler; |
| 84 | 77 |
| 85 // OnCreated() will be posted once. | 78 // OnCreated() will be posted once. |
| 86 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 79 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 87 .WillOnce(QuitMessageLoop(&message_loop_)); | 80 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 88 | 81 |
| 89 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 82 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 90 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 83 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 91 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 84 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 92 scoped_refptr<AudioInputController> controller = | 85 scoped_refptr<AudioInputController> controller = |
| 93 AudioInputController::Create(audio_manager.get(), &event_handler, params); | 86 AudioInputController::Create(audio_manager.get(), &event_handler, params); |
| 94 ASSERT_TRUE(controller.get()); | 87 ASSERT_TRUE(controller.get()); |
| 95 | 88 |
| 96 // Wait for OnCreated() to fire. | 89 // Wait for OnCreated() to fire. |
| 97 message_loop_.Run(); | 90 message_loop_.Run(); |
| 98 | 91 |
| 99 // Close the AudioInputController synchronously. | 92 // Close the AudioInputController synchronously. |
| 100 CloseAudioController(controller); | 93 CloseAudioController(controller); |
| 101 } | 94 } |
| 102 | 95 |
| 103 // Test a normal call sequence of create, record and close. | 96 // Test a normal call sequence of create, record and close. |
| 104 // TODO(leozwang): Because java calls were introduced in audio_manager_base, | 97 TEST_F(AudioInputControllerTest, RecordAndClose) { |
| 105 // unit test has to register jni first, else it will crash. | |
| 106 #if defined(OS_ANDROID) | |
| 107 #define MAYBE_RecordAndClose DISABLED_RecordAndClose | |
| 108 #else | |
| 109 #define MAYBE_RecordAndClose RecordAndClose | |
| 110 #endif | |
| 111 TEST_F(AudioInputControllerTest, MAYBE_RecordAndClose) { | |
| 112 MockAudioInputControllerEventHandler event_handler; | 98 MockAudioInputControllerEventHandler event_handler; |
| 113 int count = 0; | 99 int count = 0; |
| 114 | 100 |
| 115 // OnCreated() will be called once. | 101 // OnCreated() will be called once. |
| 116 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 102 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 117 .Times(Exactly(1)); | 103 .Times(Exactly(1)); |
| 118 | 104 |
| 119 // OnRecording() will be called only once. | 105 // OnRecording() will be called only once. |
| 120 EXPECT_CALL(event_handler, OnRecording(NotNull())) | 106 EXPECT_CALL(event_handler, OnRecording(NotNull())) |
| 121 .Times(Exactly(1)); | 107 .Times(Exactly(1)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 141 // Record and wait until ten OnData() callbacks are received. | 127 // Record and wait until ten OnData() callbacks are received. |
| 142 message_loop_.Run(); | 128 message_loop_.Run(); |
| 143 | 129 |
| 144 // Close the AudioInputController synchronously. | 130 // Close the AudioInputController synchronously. |
| 145 CloseAudioController(controller); | 131 CloseAudioController(controller); |
| 146 } | 132 } |
| 147 | 133 |
| 148 // Test that the AudioInputController reports an error when the input stream | 134 // Test that the AudioInputController reports an error when the input stream |
| 149 // stops without an OnClose() callback. This can happen when the underlying | 135 // stops without an OnClose() callback. This can happen when the underlying |
| 150 // audio layer stops feeding data as a result of a removed microphone device. | 136 // audio layer stops feeding data as a result of a removed microphone device. |
| 151 // TODO(leozwang): Because java calls were introduced in audio_manager_base, | 137 TEST_F(AudioInputControllerTest, RecordAndError) { |
| 152 // unit test has to register jni first to make unit test run. | |
| 153 #if defined(OS_ANDROID) | |
| 154 #define MAYBE_RecordAndError DISABLED_RecordAndError | |
| 155 #else | |
| 156 #define MAYBE_RecordAndError RecordAndError | |
| 157 #endif | |
| 158 TEST_F(AudioInputControllerTest, MAYBE_RecordAndError) { | |
| 159 MockAudioInputControllerEventHandler event_handler; | 138 MockAudioInputControllerEventHandler event_handler; |
| 160 int count = 0; | 139 int count = 0; |
| 161 | 140 |
| 162 // OnCreated() will be called once. | 141 // OnCreated() will be called once. |
| 163 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 142 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 164 .Times(Exactly(1)); | 143 .Times(Exactly(1)); |
| 165 | 144 |
| 166 // OnRecording() will be called only once. | 145 // OnRecording() will be called only once. |
| 167 EXPECT_CALL(event_handler, OnRecording(NotNull())) | 146 EXPECT_CALL(event_handler, OnRecording(NotNull())) |
| 168 .Times(Exactly(1)); | 147 .Times(Exactly(1)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 193 |
| 215 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 194 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 216 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 195 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 217 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); | 196 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); |
| 218 scoped_refptr<AudioInputController> controller = | 197 scoped_refptr<AudioInputController> controller = |
| 219 AudioInputController::Create(audio_manager.get(), &event_handler, params); | 198 AudioInputController::Create(audio_manager.get(), &event_handler, params); |
| 220 ASSERT_FALSE(controller); | 199 ASSERT_FALSE(controller); |
| 221 } | 200 } |
| 222 | 201 |
| 223 // Test calling AudioInputController::Close multiple times. | 202 // Test calling AudioInputController::Close multiple times. |
| 224 #if defined(OS_ANDROID) | 203 TEST_F(AudioInputControllerTest, CloseTwice) { |
| 225 #define MAYBE_CloseTwice DISABLED_CloseTwice | |
| 226 #else | |
| 227 #define MAYBE_CloseTwice CloseTwice | |
| 228 #endif | |
| 229 TEST_F(AudioInputControllerTest, MAYBE_CloseTwice) { | |
| 230 MockAudioInputControllerEventHandler event_handler; | 204 MockAudioInputControllerEventHandler event_handler; |
| 231 | 205 |
| 232 // OnRecording() will be called only once. | 206 // OnRecording() will be called only once. |
| 233 EXPECT_CALL(event_handler, OnCreated(NotNull())); | 207 EXPECT_CALL(event_handler, OnCreated(NotNull())); |
| 234 | 208 |
| 235 // OnRecording() will be called only once. | 209 // OnRecording() will be called only once. |
| 236 EXPECT_CALL(event_handler, OnRecording(NotNull())) | 210 EXPECT_CALL(event_handler, OnRecording(NotNull())) |
| 237 .Times(Exactly(1)); | 211 .Times(Exactly(1)); |
| 238 | 212 |
| 239 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 213 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 240 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 214 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 241 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 215 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 242 scoped_refptr<AudioInputController> controller = | 216 scoped_refptr<AudioInputController> controller = |
| 243 AudioInputController::Create(audio_manager.get(), &event_handler, params); | 217 AudioInputController::Create(audio_manager.get(), &event_handler, params); |
| 244 ASSERT_TRUE(controller.get()); | 218 ASSERT_TRUE(controller.get()); |
| 245 | 219 |
| 246 controller->Record(); | 220 controller->Record(); |
| 247 | 221 |
| 248 controller->Close(MessageLoop::QuitClosure()); | 222 controller->Close(MessageLoop::QuitClosure()); |
| 249 MessageLoop::current()->Run(); | 223 MessageLoop::current()->Run(); |
| 250 | 224 |
| 251 controller->Close(MessageLoop::QuitClosure()); | 225 controller->Close(MessageLoop::QuitClosure()); |
| 252 MessageLoop::current()->Run(); | 226 MessageLoop::current()->Run(); |
| 253 } | 227 } |
| 254 | 228 |
| 255 } // namespace media | 229 } // namespace media |
| OLD | NEW |