| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/test/mock_google_streaming_server.h" | 5 #include "content/test/mock_google_streaming_server.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 9 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/sys_byteorder.h" | 15 #include "base/sys_byteorder.h" |
| 13 #include "base/values.h" | 16 #include "base/values.h" |
| 14 #include "content/browser/speech/google_streaming_remote_engine.h" | 17 #include "content/browser/speech/google_streaming_remote_engine.h" |
| 15 #include "content/browser/speech/proto/google_streaming_api.pb.h" | 18 #include "content/browser/speech/proto/google_streaming_api.pb.h" |
| 16 #include "content/browser/speech/speech_recognition_manager_impl.h" | 19 #include "content/browser/speech/speech_recognition_manager_impl.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i]; | 98 const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i]; |
| 96 proto_alternative->set_confidence(hypothesis.confidence); | 99 proto_alternative->set_confidence(hypothesis.confidence); |
| 97 proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance)); | 100 proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance)); |
| 98 } | 101 } |
| 99 | 102 |
| 100 std::string msg_string; | 103 std::string msg_string; |
| 101 proto_event.SerializeToString(&msg_string); | 104 proto_event.SerializeToString(&msg_string); |
| 102 | 105 |
| 103 // Prepend 4 byte prefix length indication to the protobuf message as | 106 // Prepend 4 byte prefix length indication to the protobuf message as |
| 104 // envisaged by the google streaming recognition webservice protocol. | 107 // envisaged by the google streaming recognition webservice protocol. |
| 105 uint32 prefix = HostToNet32(checked_cast<uint32>(msg_string.size())); | 108 uint32_t prefix = HostToNet32(checked_cast<uint32_t>(msg_string.size())); |
| 106 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); | 109 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); |
| 107 | 110 |
| 108 SimulateServerResponse(true, msg_string); | 111 SimulateServerResponse(true, msg_string); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void MockGoogleStreamingServer::SimulateServerFailure() { | 114 void MockGoogleStreamingServer::SimulateServerFailure() { |
| 112 SimulateServerResponse(false, ""); | 115 SimulateServerResponse(false, ""); |
| 113 } | 116 } |
| 114 | 117 |
| 115 void MockGoogleStreamingServer::SimulateMalformedResponse() { | 118 void MockGoogleStreamingServer::SimulateMalformedResponse() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 138 } | 141 } |
| 139 | 142 |
| 140 // Can return NULL if the SpeechRecognizer has not requested the connection yet. | 143 // Can return NULL if the SpeechRecognizer has not requested the connection yet. |
| 141 net::TestURLFetcher* MockGoogleStreamingServer::GetURLFetcher( | 144 net::TestURLFetcher* MockGoogleStreamingServer::GetURLFetcher( |
| 142 bool downstream) const { | 145 bool downstream) const { |
| 143 return url_fetcher_factory_.GetFetcherByID( | 146 return url_fetcher_factory_.GetFetcherByID( |
| 144 downstream ? kDownstreamUrlFetcherId : kUpstreamUrlFetcherId); | 147 downstream ? kDownstreamUrlFetcherId : kUpstreamUrlFetcherId); |
| 145 } | 148 } |
| 146 | 149 |
| 147 } // namespace content | 150 } // namespace content |
| OLD | NEW |