OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/speech/audio_buffer.h" | 7 #include "content/browser/speech/audio_buffer.h" |
8 #include "content/browser/speech/google_one_shot_remote_engine.h" | 8 #include "content/browser/speech/google_one_shot_remote_engine.h" |
9 #include "content/public/common/speech_recognition_error.h" | 9 #include "content/public/common/speech_recognition_error.h" |
10 #include "content/public/common/speech_recognition_result.h" | 10 #include "content/public/common/speech_recognition_result.h" |
| 11 #include "net/base/net_errors.h" |
11 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
12 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
13 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class GoogleOneShotRemoteEngineTest : public SpeechRecognitionEngineDelegate, | 19 class GoogleOneShotRemoteEngineTest : public SpeechRecognitionEngineDelegate, |
19 public testing::Test { | 20 public testing::Test { |
20 public: | 21 public: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 sizeof(dummy_audio_buffer_data), | 59 sizeof(dummy_audio_buffer_data), |
59 2 /* bytes per sample */)); | 60 2 /* bytes per sample */)); |
60 client.set_delegate(this); | 61 client.set_delegate(this); |
61 client.StartRecognition(); | 62 client.StartRecognition(); |
62 client.TakeAudioChunk(*dummy_audio_chunk.get()); | 63 client.TakeAudioChunk(*dummy_audio_chunk.get()); |
63 client.AudioChunksEnded(); | 64 client.AudioChunksEnded(); |
64 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 65 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
65 ASSERT_TRUE(fetcher); | 66 ASSERT_TRUE(fetcher); |
66 | 67 |
67 fetcher->set_url(fetcher->GetOriginalURL()); | 68 fetcher->set_url(fetcher->GetOriginalURL()); |
68 net::URLRequestStatus status; | 69 fetcher->set_status( |
69 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 70 net::URLRequestStatus::FromError(success ? net::OK : net::ERR_FAILED)); |
70 net::URLRequestStatus::FAILED); | |
71 fetcher->set_status(status); | |
72 fetcher->set_response_code(success ? 200 : 500); | 71 fetcher->set_response_code(success ? 200 : 500); |
73 fetcher->SetResponseString(http_response); | 72 fetcher->SetResponseString(http_response); |
74 | 73 |
75 fetcher->delegate()->OnURLFetchComplete(fetcher); | 74 fetcher->delegate()->OnURLFetchComplete(fetcher); |
76 // Parsed response will be available in result(). | 75 // Parsed response will be available in result(). |
77 } | 76 } |
78 | 77 |
79 TEST_F(GoogleOneShotRemoteEngineTest, BasicTest) { | 78 TEST_F(GoogleOneShotRemoteEngineTest, BasicTest) { |
80 // Normal success case with one result. | 79 // Normal success case with one result. |
81 CreateAndTestRequest(true, | 80 CreateAndTestRequest(true, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 EXPECT_EQ(0U, result().hypotheses.size()); | 118 EXPECT_EQ(0U, result().hypotheses.size()); |
120 | 119 |
121 // Malformed JSON case. | 120 // Malformed JSON case. |
122 CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" | 121 CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" |
123 "[{\"unknownkey\":\"hello\"}]}"); | 122 "[{\"unknownkey\":\"hello\"}]}"); |
124 EXPECT_EQ(error_, SPEECH_RECOGNITION_ERROR_NETWORK); | 123 EXPECT_EQ(error_, SPEECH_RECOGNITION_ERROR_NETWORK); |
125 EXPECT_EQ(0U, result().hypotheses.size()); | 124 EXPECT_EQ(0U, result().hypotheses.size()); |
126 } | 125 } |
127 | 126 |
128 } // namespace content | 127 } // namespace content |
OLD | NEW |