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