diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-07 17:24:13 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-07 17:24:13 +0000 |
commit | 441c6c3210063f995d3541b45e01e3aaaea80c59 (patch) | |
tree | 1534273cebadd6fbf44f60ab31dcbbf70c1280e8 /content | |
parent | 2db531074be20594b38f882448fa918996cd2abc (diff) | |
download | chromium_src-441c6c3210063f995d3541b45e01e3aaaea80c59.zip chromium_src-441c6c3210063f995d3541b45e01e3aaaea80c59.tar.gz chromium_src-441c6c3210063f995d3541b45e01e3aaaea80c59.tar.bz2 |
Better error messages for speech input errors.
Show a connection-failed type error message when receiving connection errors with speech service.
Also updated the no-results error message with latest text and added 2 new unit tests.
BUG=61677
TEST=unit_tests --gtest_filter=SpeechRecognizerTest.*
Review URL: http://codereview.chromium.org/6628049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/speech/speech_recognizer.cc | 5 | ||||
-rw-r--r-- | content/browser/speech/speech_recognizer.h | 1 | ||||
-rw-r--r-- | content/browser/speech/speech_recognizer_unittest.cc | 63 |
3 files changed, 65 insertions, 4 deletions
diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc index 3b7b89e..3b9201a 100644 --- a/content/browser/speech/speech_recognizer.cc +++ b/content/browser/speech/speech_recognizer.cc @@ -278,8 +278,9 @@ void SpeechRecognizer::HandleOnData(string* data) { void SpeechRecognizer::SetRecognitionResult( bool error, const SpeechInputResultArray& result) { - if (result.empty()) { - InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NO_RESULTS); + if (error || result.empty()) { + InformErrorAndCancelRecognition(error ? RECOGNIZER_ERROR_NETWORK : + RECOGNIZER_ERROR_NO_RESULTS); return; } diff --git a/content/browser/speech/speech_recognizer.h b/content/browser/speech/speech_recognizer.h index d8c6d9a..faf4ace 100644 --- a/content/browser/speech/speech_recognizer.h +++ b/content/browser/speech/speech_recognizer.h @@ -30,6 +30,7 @@ class SpeechRecognizer RECOGNIZER_ERROR_CAPTURE, RECOGNIZER_ERROR_NO_SPEECH, RECOGNIZER_ERROR_NO_RESULTS, + RECOGNIZER_ERROR_NETWORK, }; // Implemented by the caller to receive recognition events. diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc index c7c7e91..f3c9cee 100644 --- a/content/browser/speech/speech_recognizer_unittest.cc +++ b/content/browser/speech/speech_recognizer_unittest.cc @@ -8,6 +8,7 @@ #include "content/browser/browser_thread.h" #include "content/browser/speech/speech_recognizer.h" #include "media/audio/test_audio_input_controller_factory.h" +#include "net/base/net_errors.h" #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" @@ -136,8 +137,6 @@ TEST_F(SpeechRecognizerTest, StopWithData) { TestAudioInputController* controller = audio_input_controller_factory_.controller(); ASSERT_TRUE(controller); - controller = audio_input_controller_factory_.controller(); - ASSERT_TRUE(controller); // Try sending 5 chunks of mock audio data and verify that each of them // resulted immediately in a packet sent out via the network. This verifies @@ -190,6 +189,66 @@ TEST_F(SpeechRecognizerTest, CancelWithData) { EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); } +TEST_F(SpeechRecognizerTest, ConnectionError) { + // Start recording, give some data and then stop. Issue the network callback + // with a connection error and verify that the recognizer bubbles the error up + EXPECT_TRUE(recognizer_->StartRecording()); + TestAudioInputController* controller = + audio_input_controller_factory_.controller(); + ASSERT_TRUE(controller); + controller->event_handler()->OnData(controller, &audio_packet_[0], + audio_packet_.size()); + MessageLoop::current()->RunAllPending(); + TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); + ASSERT_TRUE(fetcher); + + recognizer_->StopRecording(); + EXPECT_TRUE(recording_complete_); + EXPECT_FALSE(recognition_complete_); + EXPECT_FALSE(result_received_); + EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + + // Issue the network callback to complete the process. + net::URLRequestStatus status; + status.set_status(net::URLRequestStatus::FAILED); + status.set_os_error(net::ERR_CONNECTION_REFUSED); + fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), + status, 0, ResponseCookies(), ""); + EXPECT_FALSE(recognition_complete_); + EXPECT_FALSE(result_received_); + EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, error_); +} + +TEST_F(SpeechRecognizerTest, ServerError) { + // Start recording, give some data and then stop. Issue the network callback + // with a 500 error and verify that the recognizer bubbles the error up + EXPECT_TRUE(recognizer_->StartRecording()); + TestAudioInputController* controller = + audio_input_controller_factory_.controller(); + ASSERT_TRUE(controller); + controller->event_handler()->OnData(controller, &audio_packet_[0], + audio_packet_.size()); + MessageLoop::current()->RunAllPending(); + TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); + ASSERT_TRUE(fetcher); + + recognizer_->StopRecording(); + EXPECT_TRUE(recording_complete_); + EXPECT_FALSE(recognition_complete_); + EXPECT_FALSE(result_received_); + EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + + // Issue the network callback to complete the process. + net::URLRequestStatus status; + status.set_status(net::URLRequestStatus::SUCCESS); + fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), + status, 500, ResponseCookies(), + "Internal Server Error"); + EXPECT_FALSE(recognition_complete_); + EXPECT_FALSE(result_received_); + EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, error_); +} + TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { // Check if things tear down properly if AudioInputController threw an error. EXPECT_TRUE(recognizer_->StartRecording()); |