OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 protected: | 39 protected: |
40 TestURLFetcherFactory url_fetcher_factory_; | 40 TestURLFetcherFactory url_fetcher_factory_; |
41 bool error_; | 41 bool error_; |
42 SpeechInputResultArray result_; | 42 SpeechInputResultArray result_; |
43 }; | 43 }; |
44 | 44 |
45 void SpeechRecognitionRequestTest::CreateAndTestRequest( | 45 void SpeechRecognitionRequestTest::CreateAndTestRequest( |
46 bool success, const std::string& http_response) { | 46 bool success, const std::string& http_response) { |
47 SpeechRecognitionRequest request(NULL, this); | 47 SpeechRecognitionRequest request(NULL, this); |
48 request.Send(std::string(), std::string(), std::string()); | 48 request.Send(std::string(), std::string(), std::string(), std::string()); |
49 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 49 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
50 ASSERT_TRUE(fetcher); | 50 ASSERT_TRUE(fetcher); |
51 URLRequestStatus status; | 51 URLRequestStatus status; |
52 status.set_status(success ? URLRequestStatus::SUCCESS : | 52 status.set_status(success ? URLRequestStatus::SUCCESS : |
53 URLRequestStatus::FAILED); | 53 URLRequestStatus::FAILED); |
54 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), | 54 fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(), |
55 status, success ? 200 : 500, | 55 status, success ? 200 : 500, |
56 ResponseCookies(), | 56 ResponseCookies(), |
57 http_response); | 57 http_response); |
58 // Parsed response will be available in result_. | 58 // Parsed response will be available in result_. |
(...skipping 24 matching lines...) Expand all Loading... |
83 EXPECT_TRUE(error_); | 83 EXPECT_TRUE(error_); |
84 EXPECT_EQ(0U, result_.size()); | 84 EXPECT_EQ(0U, result_.size()); |
85 | 85 |
86 // Malformed JSON case. | 86 // Malformed JSON case. |
87 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); | 87 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); |
88 EXPECT_TRUE(error_); | 88 EXPECT_TRUE(error_); |
89 EXPECT_EQ(0U, result_.size()); | 89 EXPECT_EQ(0U, result_.size()); |
90 } | 90 } |
91 | 91 |
92 } // namespace speech_input | 92 } // namespace speech_input |
OLD | NEW |