summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_input_controller_unittest.cc
diff options
context:
space:
mode:
authorallanwoj@chromium.org <allanwoj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 16:02:58 +0000
committerallanwoj@chromium.org <allanwoj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 16:02:58 +0000
commit823a51b179f3bb00f3833f6ab438064ee0b64572 (patch)
tree4ab7b8e9d8384b60d6fe89ba7c32dd4d5c90da01 /media/audio/audio_input_controller_unittest.cc
parent24e7135c10bc62da05ab6c243eb433dcff45a9d2 (diff)
downloadchromium_src-823a51b179f3bb00f3833f6ab438064ee0b64572.zip
chromium_src-823a51b179f3bb00f3833f6ab438064ee0b64572.tar.gz
chromium_src-823a51b179f3bb00f3833f6ab438064ee0b64572.tar.bz2
Fix bug when unplugging an audio input device whilst using speech input on Windows.
Added a three second timeout for not receiving an OnData callback in AudioInputController and a one second timeout for not receiving any callback in PCMWaveInAudioInputStream. Also added a unit test fixture for it. BUG=79936 TEST=Unplug microphone while using speech input, browser should no longer hang. Review URL: http://codereview.chromium.org/7129057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_input_controller_unittest.cc')
-rw-r--r--media/audio/audio_input_controller_unittest.cc49
1 files changed, 48 insertions, 1 deletions
diff --git a/media/audio/audio_input_controller_unittest.cc b/media/audio/audio_input_controller_unittest.cc
index 6a62871..d7ce4db 100644
--- a/media/audio/audio_input_controller_unittest.cc
+++ b/media/audio/audio_input_controller_unittest.cc
@@ -92,13 +92,60 @@ TEST(AudioInputControllerTest, RecordAndClose) {
event.Wait();
event.Reset();
- // Play and then wait for the event to be signaled.
+ // Record and then wait for the event to be signaled.
controller->Record();
event.Wait();
controller->Close();
}
+// Test that the AudioInputController reports an error when the input stream
+// stops without an OnClose callback.
+TEST(AudioInputControllerTest, RecordAndError) {
+ MockAudioInputControllerEventHandler event_handler;
+ base::WaitableEvent event(false, false);
+ int count = 0;
+
+ // If OnCreated is called then signal the event.
+ EXPECT_CALL(event_handler, OnCreated(NotNull()))
+ .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
+
+ // OnRecording() will be called only once.
+ EXPECT_CALL(event_handler, OnRecording(NotNull()))
+ .Times(Exactly(1));
+
+ // If OnData is called enough then signal the event.
+ EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _))
+ .Times(AtLeast(10))
+ .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event));
+
+ // OnError will be called after the data stream stops.
+ EXPECT_CALL(event_handler, OnError(NotNull(), 0))
+ .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
+
+ AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout,
+ kSampleRate, kBitsPerSample, kSamplesPerPacket);
+ scoped_refptr<AudioInputController> controller =
+ AudioInputController::Create(&event_handler, params);
+ ASSERT_TRUE(controller.get());
+
+ // Wait for OnCreated() to be called.
+ event.Wait();
+ event.Reset();
+
+ // Record and then wait for the event to be signaled.
+ controller->Record();
+ event.Wait();
+ event.Reset();
+
+ // Wait for the stream to be stopped.
+ AudioInputStream* stream = controller->stream();
+ stream->Stop();
+ event.Wait();
+
+ controller->Close();
+}
+
// Test that AudioInputController rejects insanely large packet sizes.
TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) {
// Create an audio device with a very large packet size.