diff options
author | leandrogracia@chromium.org <leandrogracia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 13:29:35 +0000 |
---|---|---|
committer | leandrogracia@chromium.org <leandrogracia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-07 13:29:35 +0000 |
commit | d1ecb010a30afb74dfd33294771c9a1559f62141 (patch) | |
tree | 259e50648ff9445ff7c43f713c960a31f55e7b2b /content/browser/speech/speech_recognizer_unittest.cc | |
parent | b773cee71532fbce19c1b92f256a950979764c8c (diff) | |
download | chromium_src-d1ecb010a30afb74dfd33294771c9a1559f62141.zip chromium_src-d1ecb010a30afb74dfd33294771c9a1559f62141.tar.gz chromium_src-d1ecb010a30afb74dfd33294771c9a1559f62141.tar.bz2 |
Applying changes to the existing speech input code to support the extension API.
This includes extended error management by handling the status response code and the DidStartReceivingSpeech/DidStopReceivingSpeech events.
BUG=97388
TEST=none
Review URL: http://codereview.chromium.org/8137005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/speech_recognizer_unittest.cc')
-rw-r--r-- | content/browser/speech/speech_recognizer_unittest.cc | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc index 17e3e56..0be64eb 100644 --- a/content/browser/speech/speech_recognizer_unittest.cc +++ b/content/browser/speech/speech_recognizer_unittest.cc @@ -31,7 +31,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, recognition_complete_(false), result_received_(false), audio_received_(false), - error_(SpeechRecognizer::RECOGNIZER_NO_ERROR), + error_(kErrorNone), volume_(-1.0f) { int audio_packet_length_bytes = (SpeechRecognizer::kAudioSampleRate * @@ -43,43 +43,49 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, // SpeechRecognizer::Delegate methods. virtual void SetRecognitionResult(int caller_id, - bool error, - const SpeechInputResultArray& result) { + const SpeechInputResult& result) OVERRIDE { result_received_ = true; } - virtual void DidCompleteRecording(int caller_id) { + virtual void DidCompleteRecording(int caller_id) OVERRIDE { recording_complete_ = true; } - virtual void DidCompleteRecognition(int caller_id) { + virtual void DidCompleteRecognition(int caller_id) OVERRIDE { recognition_complete_ = true; } - virtual void DidCompleteEnvironmentEstimation(int caller_id) { + virtual void DidCompleteEnvironmentEstimation(int caller_id) OVERRIDE { } - virtual void DidStartReceivingAudio(int caller_id) { + virtual void DidStartReceivingAudio(int caller_id) OVERRIDE { audio_received_ = true; } + virtual void DidStartReceivingSpeech(int caller_id) OVERRIDE { + } + + virtual void DidStopReceivingSpeech(int caller_id) OVERRIDE { + } + virtual void OnRecognizerError(int caller_id, - SpeechRecognizer::ErrorCode error) { + SpeechInputError error) OVERRIDE { error_ = error; } - virtual void SetInputVolume(int caller_id, float volume, float noise_volume) { + virtual void SetInputVolume(int caller_id, float volume, + float noise_volume) OVERRIDE { volume_ = volume; noise_volume_ = noise_volume; } // testing::Test methods. - virtual void SetUp() { + virtual void SetUp() OVERRIDE { AudioInputController::set_factory_for_testing( &audio_input_controller_factory_); } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { AudioInputController::set_factory_for_testing(NULL); } @@ -106,7 +112,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, bool recognition_complete_; bool result_received_; bool audio_received_; - SpeechRecognizer::ErrorCode error_; + SpeechInputError error_; TestURLFetcherFactory url_fetcher_factory_; TestAudioInputControllerFactory audio_input_controller_factory_; std::vector<uint8> audio_packet_; @@ -122,7 +128,7 @@ TEST_F(SpeechRecognizerTest, StopNoData) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); EXPECT_FALSE(audio_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); } TEST_F(SpeechRecognizerTest, CancelNoData) { @@ -134,7 +140,7 @@ TEST_F(SpeechRecognizerTest, CancelNoData) { EXPECT_TRUE(recognition_complete_); EXPECT_FALSE(result_received_); EXPECT_FALSE(audio_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); } TEST_F(SpeechRecognizerTest, StopWithData) { @@ -164,7 +170,7 @@ TEST_F(SpeechRecognizerTest, StopWithData) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); // Issue the network callback to complete the process. TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); @@ -175,12 +181,13 @@ TEST_F(SpeechRecognizerTest, StopWithData) { status.set_status(net::URLRequestStatus::SUCCESS); fetcher->set_status(status); fetcher->set_response_code(200); - fetcher->SetResponseString("{\"hypotheses\":[{\"utterance\":\"123\"}]}"); + fetcher->SetResponseString( + "{\"status\":0,\"hypotheses\":[{\"utterance\":\"123\"}]}"); fetcher->delegate()->OnURLFetchComplete(fetcher); EXPECT_TRUE(recognition_complete_); EXPECT_TRUE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); } TEST_F(SpeechRecognizerTest, CancelWithData) { @@ -199,7 +206,7 @@ TEST_F(SpeechRecognizerTest, CancelWithData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); } TEST_F(SpeechRecognizerTest, ConnectionError) { @@ -220,7 +227,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); // Issue the network callback to complete the process. fetcher->set_url(fetcher->original_url()); @@ -234,7 +241,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, error_); + EXPECT_EQ(kErrorNetwork, error_); } TEST_F(SpeechRecognizerTest, ServerError) { @@ -255,7 +262,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); // Issue the network callback to complete the process. fetcher->set_url(fetcher->original_url()); @@ -268,7 +275,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, error_); + EXPECT_EQ(kErrorNetwork, error_); } TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { @@ -283,7 +290,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, error_); + EXPECT_EQ(kErrorAudio, error_); } TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { @@ -302,7 +309,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, error_); + EXPECT_EQ(kErrorAudio, error_); } TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { @@ -327,7 +334,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NO_SPEECH, error_); + EXPECT_EQ(kErrorNoSpeech, error_); } TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { @@ -358,7 +365,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { } MessageLoop::current()->RunAllPending(); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); @@ -401,7 +408,7 @@ TEST_F(SpeechRecognizerTest, SetInputVolumeCallback) { EXPECT_FLOAT_EQ(0.89926866f, volume_); EXPECT_FLOAT_EQ(0.75071919f, noise_volume_); - EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_EQ(kErrorNone, error_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); recognizer_->CancelRecognition(); |