| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/speech/speech_recognition_request.h" | 6 #include "chrome/browser/speech/speech_recognition_request.h" |
| 7 #include "chrome/common/net/url_request_context_getter.h" | 7 #include "chrome/common/net/url_request_context_getter.h" |
| 8 #include "chrome/common/net/test_url_fetcher_factory.h" | 8 #include "chrome/common/net/test_url_fetcher_factory.h" |
| 9 #include "net/url_request/url_request_status.h" | 9 #include "net/url_request/url_request_status.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 SpeechInputResultArray result_; | 43 SpeechInputResultArray result_; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 void SpeechRecognitionRequestTest::CreateAndTestRequest( | 46 void SpeechRecognitionRequestTest::CreateAndTestRequest( |
| 47 bool success, const std::string& http_response) { | 47 bool success, const std::string& http_response) { |
| 48 SpeechRecognitionRequest request(NULL, this); | 48 SpeechRecognitionRequest request(NULL, this); |
| 49 request.Send(std::string(), std::string(), std::string(), std::string(), | 49 request.Send(std::string(), std::string(), std::string(), std::string(), |
| 50 std::string()); | 50 std::string()); |
| 51 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 51 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 52 ASSERT_TRUE(fetcher); | 52 ASSERT_TRUE(fetcher); |
| 53 URLRequestStatus status; | 53 net::URLRequestStatus status; |
| 54 status.set_status(success ? URLRequestStatus::SUCCESS : | 54 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
| 55 URLRequestStatus::FAILED); | 55 net::URLRequestStatus::FAILED); |
| 56 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), | 56 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), |
| 57 status, success ? 200 : 500, | 57 status, success ? 200 : 500, |
| 58 ResponseCookies(), | 58 ResponseCookies(), |
| 59 http_response); | 59 http_response); |
| 60 // Parsed response will be available in result_. | 60 // Parsed response will be available in result_. |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(SpeechRecognitionRequestTest, BasicTest) { | 63 TEST_F(SpeechRecognitionRequestTest, BasicTest) { |
| 64 // Normal success case with one result. | 64 // Normal success case with one result. |
| 65 CreateAndTestRequest(true, | 65 CreateAndTestRequest(true, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 EXPECT_TRUE(error_); | 85 EXPECT_TRUE(error_); |
| 86 EXPECT_EQ(0U, result_.size()); | 86 EXPECT_EQ(0U, result_.size()); |
| 87 | 87 |
| 88 // Malformed JSON case. | 88 // Malformed JSON case. |
| 89 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); | 89 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); |
| 90 EXPECT_TRUE(error_); | 90 EXPECT_TRUE(error_); |
| 91 EXPECT_EQ(0U, result_.size()); | 91 EXPECT_EQ(0U, result_.size()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace speech_input | 94 } // namespace speech_input |
| OLD | NEW |