Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: content/browser/speech/speech_recognition_request_unittest.cc

Issue 8137005: Applying changes to the existing speech input code to support the extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review and unit test fixes. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/speech/speech_recognition_request_unittest.cc
diff --git a/content/browser/speech/speech_recognition_request_unittest.cc b/content/browser/speech/speech_recognition_request_unittest.cc
index a5d75c4caa9822cf5a71499f1e1ea7c90c0b8f81..36f5b35eb2f8ad135fad0f682f28a7cf213edbdf 100644
--- a/content/browser/speech/speech_recognition_request_unittest.cc
+++ b/content/browser/speech/speech_recognition_request_unittest.cc
@@ -22,7 +22,7 @@ class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate,
// SpeechRecognitionRequestDelegate methods.
virtual void SetRecognitionResult(bool error,
- const SpeechInputResultArray& result) {
+ const SpeechInputResult& result) {
error_ = error;
result_ = result;
}
@@ -31,7 +31,7 @@ class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate,
MessageLoop message_loop_;
TestURLFetcherFactory url_fetcher_factory_;
bool error_;
- SpeechInputResultArray result_;
+ SpeechInputResult result_;
};
void SpeechRecognitionRequestTest::CreateAndTestRequest(
@@ -58,37 +58,50 @@ void SpeechRecognitionRequestTest::CreateAndTestRequest(
TEST_F(SpeechRecognitionRequestTest, BasicTest) {
// Normal success case with one result.
CreateAndTestRequest(true,
- "{\"hypotheses\":[{\"utterance\":\"123456\",\"confidence\":0.9}]}");
+ "{\"status\":0,\"hypotheses\":"
+ "[{\"utterance\":\"123456\",\"confidence\":0.9}]}");
EXPECT_FALSE(error_);
- EXPECT_EQ(1U, result_.size());
- EXPECT_EQ(ASCIIToUTF16("123456"), result_[0].utterance);
- EXPECT_EQ(0.9, result_[0].confidence);
+ EXPECT_EQ(1U, result_.hypotheses.size());
+ EXPECT_EQ(ASCIIToUTF16("123456"), result_.hypotheses[0].utterance);
+ EXPECT_EQ(0.9, result_.hypotheses[0].confidence);
// Normal success case with multiple results.
CreateAndTestRequest(true,
- "{\"hypotheses\":[{\"utterance\":\"hello\",\"confidence\":0.9},"
+ "{\"status\":0,\"hypotheses\":["
+ "{\"utterance\":\"hello\",\"confidence\":0.9},"
"{\"utterance\":\"123456\",\"confidence\":0.5}]}");
EXPECT_FALSE(error_);
- EXPECT_EQ(2u, result_.size());
- EXPECT_EQ(ASCIIToUTF16("hello"), result_[0].utterance);
- EXPECT_EQ(0.9, result_[0].confidence);
- EXPECT_EQ(ASCIIToUTF16("123456"), result_[1].utterance);
- EXPECT_EQ(0.5, result_[1].confidence);
+ EXPECT_EQ(2u, result_.hypotheses.size());
+ EXPECT_EQ(ASCIIToUTF16("hello"), result_.hypotheses[0].utterance);
+ EXPECT_EQ(0.9, result_.hypotheses[0].confidence);
+ EXPECT_EQ(ASCIIToUTF16("123456"), result_.hypotheses[1].utterance);
+ EXPECT_EQ(0.5, result_.hypotheses[1].confidence);
// Zero results.
- CreateAndTestRequest(true, "{\"hypotheses\":[]}");
+ CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":[]}");
EXPECT_FALSE(error_);
- EXPECT_EQ(0U, result_.size());
+ EXPECT_EQ(0U, result_.hypotheses.size());
// Http failure case.
CreateAndTestRequest(false, "");
EXPECT_TRUE(error_);
- EXPECT_EQ(0U, result_.size());
+ EXPECT_EQ(0U, result_.hypotheses.size());
+
+ // Invalid status case.
+ CreateAndTestRequest(true, "{\"status\":\"invalid\",\"hypotheses\":[]}");
+ EXPECT_TRUE(error_);
+ EXPECT_EQ(0U, result_.hypotheses.size());
+
+ // Server-side error case.
+ CreateAndTestRequest(true, "{\"status\":1,\"hypotheses\":[]}");
+ EXPECT_TRUE(error_);
+ EXPECT_EQ(0U, result_.hypotheses.size());
// Malformed JSON case.
- CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}");
+ CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":"
+ "[{\"unknownkey\":\"hello\"}]}");
EXPECT_TRUE(error_);
- EXPECT_EQ(0U, result_.size());
+ EXPECT_EQ(0U, result_.hypotheses.size());
}
} // namespace speech_input

Powered by Google App Engine
This is Rietveld 408576698