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/url_request/test_url_fetcher_factory.h" | 11 #include "net/url_request/test_url_fetcher_factory.h" |
12 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
13 #include "net/url_request/url_request_status.h" | 13 #include "net/url_request/url_request_status.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 class GoogleOneShotRemoteEngineTest : public SpeechRecognitionEngineDelegate, | 18 class GoogleOneShotRemoteEngineTest : public SpeechRecognitionEngineDelegate, |
19 public testing::Test { | 19 public testing::Test { |
20 public: | 20 public: |
21 GoogleOneShotRemoteEngineTest() | 21 GoogleOneShotRemoteEngineTest() |
22 : error_(SPEECH_RECOGNITION_ERROR_NONE) {} | 22 : error_(SPEECH_RECOGNITION_ERROR_NONE) {} |
23 | 23 |
24 // Creates a speech recognition request and invokes its URL fetcher delegate | 24 // Creates a speech recognition request and invokes its URL fetcher delegate |
25 // with the given test data. | 25 // with the given test data. |
26 void CreateAndTestRequest(bool success, const std::string& http_response); | 26 void CreateAndTestRequest(bool success, const std::string& http_response); |
27 | 27 |
28 // SpeechRecognitionRequestDelegate methods. | 28 // SpeechRecognitionRequestDelegate methods. |
29 virtual void OnSpeechRecognitionEngineResults( | 29 virtual void OnSpeechRecognitionEngineResults( |
30 const SpeechRecognitionResults& results) OVERRIDE { | 30 const SpeechRecognitionResults& results) override { |
31 results_ = results; | 31 results_ = results; |
32 } | 32 } |
33 | 33 |
34 virtual void OnSpeechRecognitionEngineError( | 34 virtual void OnSpeechRecognitionEngineError( |
35 const SpeechRecognitionError& error) OVERRIDE { | 35 const SpeechRecognitionError& error) override { |
36 error_ = error.code; | 36 error_ = error.code; |
37 } | 37 } |
38 | 38 |
39 // Accessor for the only result item. | 39 // Accessor for the only result item. |
40 const SpeechRecognitionResult& result() const { | 40 const SpeechRecognitionResult& result() const { |
41 DCHECK_EQ(results_.size(), 1U); | 41 DCHECK_EQ(results_.size(), 1U); |
42 return results_[0]; | 42 return results_[0]; |
43 } | 43 } |
44 | 44 |
45 protected: | 45 protected: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 EXPECT_EQ(0U, result().hypotheses.size()); | 119 EXPECT_EQ(0U, result().hypotheses.size()); |
120 | 120 |
121 // Malformed JSON case. | 121 // Malformed JSON case. |
122 CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" | 122 CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" |
123 "[{\"unknownkey\":\"hello\"}]}"); | 123 "[{\"unknownkey\":\"hello\"}]}"); |
124 EXPECT_EQ(error_, SPEECH_RECOGNITION_ERROR_NETWORK); | 124 EXPECT_EQ(error_, SPEECH_RECOGNITION_ERROR_NETWORK); |
125 EXPECT_EQ(0U, result().hypotheses.size()); | 125 EXPECT_EQ(0U, result().hypotheses.size()); |
126 } | 126 } |
127 | 127 |
128 } // namespace content | 128 } // namespace content |
OLD | NEW |