Index: content/browser/speech/google_one_shot_remote_engine_unittest.cc |
diff --git a/content/browser/speech/speech_recognition_request_unittest.cc b/content/browser/speech/google_one_shot_remote_engine_unittest.cc |
similarity index 72% |
rename from content/browser/speech/speech_recognition_request_unittest.cc |
rename to content/browser/speech/google_one_shot_remote_engine_unittest.cc |
index 822e2540b98bd85e88eb84a73e7bf3e528d51eec..fab2b5f5f1a20f86380724c2ae061886091b7fa7 100644 |
--- a/content/browser/speech/speech_recognition_request_unittest.cc |
+++ b/content/browser/speech/google_one_shot_remote_engine_unittest.cc |
@@ -5,7 +5,8 @@ |
#include "base/message_loop.h" |
#include "base/utf_string_conversions.h" |
#include "content/browser/speech/audio_buffer.h" |
-#include "content/browser/speech/speech_recognition_request.h" |
+#include "content/browser/speech/google_one_shot_remote_engine.h" |
+#include "content/public/common/speech_recognition_error.h" |
#include "content/public/common/speech_recognition_result.h" |
#include "content/test/test_url_fetcher_factory.h" |
#include "net/url_request/url_request_context_getter.h" |
@@ -14,37 +15,46 @@ |
namespace speech { |
-class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, |
- public testing::Test { |
+class GoogleOneShotRemoteEngineTest |
+ : public SpeechRecognitionEngineDelegate, |
+ public testing::Test { |
public: |
- SpeechRecognitionRequestTest() { } |
+ GoogleOneShotRemoteEngineTest() |
+ : error_(content::SPEECH_RECOGNITION_ERROR_NONE) {} |
// Creates a speech recognition request and invokes it's URL fetcher delegate |
// with the given test data. |
void CreateAndTestRequest(bool success, const std::string& http_response); |
// SpeechRecognitionRequestDelegate methods. |
- virtual void SetRecognitionResult( |
+ virtual void OnSpeechRecognitionEngineResult( |
const content::SpeechRecognitionResult& result) OVERRIDE { |
result_ = result; |
} |
+ virtual void OnSpeechRecognitionEngineError( |
+ const content::SpeechRecognitionError& error) OVERRIDE { |
+ error_ = error.code; |
+ } |
+ |
protected: |
MessageLoop message_loop_; |
TestURLFetcherFactory url_fetcher_factory_; |
+ content::SpeechRecognitionErrorCode error_; |
content::SpeechRecognitionResult result_; |
}; |
-void SpeechRecognitionRequestTest::CreateAndTestRequest( |
+void GoogleOneShotRemoteEngineTest::CreateAndTestRequest( |
bool success, const std::string& http_response) { |
- SpeechRecognitionRequest request(NULL, this); |
- request.Start(std::string(), std::string(), false, std::string(), |
- std::string(), std::string()); |
+ GoogleOneShotRemoteEngine client(NULL); |
unsigned char dummy_audio_buffer_data[2] = {'\0', '\0'}; |
AudioChunk dummy_audio_chunk(&dummy_audio_buffer_data[0], |
sizeof(dummy_audio_buffer_data), |
2 /* bytes per sample */); |
- request.UploadAudioChunk(dummy_audio_chunk, true); |
+ client.set_delegate(this); |
+ client.StartRecognition(); |
+ client.TakeAudioChunk(dummy_audio_chunk); |
+ client.AudioChunksEnded(); |
TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
ASSERT_TRUE(fetcher); |
@@ -60,12 +70,12 @@ void SpeechRecognitionRequestTest::CreateAndTestRequest( |
// Parsed response will be available in result_. |
} |
-TEST_F(SpeechRecognitionRequestTest, BasicTest) { |
+TEST_F(GoogleOneShotRemoteEngineTest, BasicTest) { |
// Normal success case with one result. |
CreateAndTestRequest(true, |
"{\"status\":0,\"hypotheses\":" |
"[{\"utterance\":\"123456\",\"confidence\":0.9}]}"); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NONE); |
EXPECT_EQ(1U, result_.hypotheses.size()); |
EXPECT_EQ(ASCIIToUTF16("123456"), result_.hypotheses[0].utterance); |
EXPECT_EQ(0.9, result_.hypotheses[0].confidence); |
@@ -75,7 +85,7 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { |
"{\"status\":0,\"hypotheses\":[" |
"{\"utterance\":\"hello\",\"confidence\":0.9}," |
"{\"utterance\":\"123456\",\"confidence\":0.5}]}"); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NONE); |
EXPECT_EQ(2u, result_.hypotheses.size()); |
EXPECT_EQ(ASCIIToUTF16("hello"), result_.hypotheses[0].utterance); |
EXPECT_EQ(0.9, result_.hypotheses[0].confidence); |
@@ -84,28 +94,28 @@ TEST_F(SpeechRecognitionRequestTest, BasicTest) { |
// Zero results. |
CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":[]}"); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NONE); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NONE); |
EXPECT_EQ(0U, result_.hypotheses.size()); |
// Http failure case. |
CreateAndTestRequest(false, ""); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
EXPECT_EQ(0U, result_.hypotheses.size()); |
// Invalid status case. |
CreateAndTestRequest(true, "{\"status\":\"invalid\",\"hypotheses\":[]}"); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
EXPECT_EQ(0U, result_.hypotheses.size()); |
// Server-side error case. |
CreateAndTestRequest(true, "{\"status\":1,\"hypotheses\":[]}"); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
EXPECT_EQ(0U, result_.hypotheses.size()); |
// Malformed JSON case. |
CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" |
"[{\"unknownkey\":\"hello\"}]}"); |
- EXPECT_EQ(result_.error, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
+ EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NETWORK); |
EXPECT_EQ(0U, result_.hypotheses.size()); |
} |