| OLD | NEW |
| 1 // Copyright (c) 2011 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 "content/browser/speech/speech_recognition_request.h" | 6 #include "content/browser/speech/speech_recognition_request.h" |
| 7 #include "content/common/test_url_fetcher_factory.h" | 7 #include "content/common/test_url_fetcher_factory.h" |
| 8 #include "net/url_request/url_request_context_getter.h" | 8 #include "net/url_request/url_request_context_getter.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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 protected: | 39 protected: |
| 40 MessageLoop message_loop_; | 40 MessageLoop message_loop_; |
| 41 TestURLFetcherFactory url_fetcher_factory_; | 41 TestURLFetcherFactory url_fetcher_factory_; |
| 42 bool error_; | 42 bool error_; |
| 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.Start(std::string(), std::string(), std::string(), std::string(), | 49 request.Start(std::string(), std::string(), false, std::string(), |
| 50 std::string()); | 50 std::string(), std::string()); |
| 51 request.UploadAudioChunk(std::string(" "), true); | 51 request.UploadAudioChunk(std::string(" "), true); |
| 52 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 52 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 53 ASSERT_TRUE(fetcher); | 53 ASSERT_TRUE(fetcher); |
| 54 net::URLRequestStatus status; | 54 net::URLRequestStatus status; |
| 55 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 55 status.set_status(success ? net::URLRequestStatus::SUCCESS : |
| 56 net::URLRequestStatus::FAILED); | 56 net::URLRequestStatus::FAILED); |
| 57 fetcher->delegate()->OnURLFetchComplete( | 57 fetcher->delegate()->OnURLFetchComplete( |
| 58 fetcher, fetcher->original_url(), status, success ? 200 : 500, | 58 fetcher, fetcher->original_url(), status, success ? 200 : 500, |
| 59 net::ResponseCookies(), http_response); | 59 net::ResponseCookies(), http_response); |
| 60 // Parsed response will be available in result_. | 60 // Parsed response will be available in result_. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 90 EXPECT_TRUE(error_); | 90 EXPECT_TRUE(error_); |
| 91 EXPECT_EQ(0U, result_.size()); | 91 EXPECT_EQ(0U, result_.size()); |
| 92 | 92 |
| 93 // Malformed JSON case. | 93 // Malformed JSON case. |
| 94 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); | 94 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); |
| 95 EXPECT_TRUE(error_); | 95 EXPECT_TRUE(error_); |
| 96 EXPECT_EQ(0U, result_.size()); | 96 EXPECT_EQ(0U, result_.size()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace speech_input | 99 } // namespace speech_input |
| OLD | NEW |