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 "content/browser/speech/speech_recognition_engine.h" | 5 #include "content/browser/speech/speech_recognition_engine.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 TestURLFetcher* downstream_fetcher = GetDownstreamFetcher(); | 502 TestURLFetcher* downstream_fetcher = GetDownstreamFetcher(); |
503 | 503 |
504 ASSERT_TRUE(downstream_fetcher); | 504 ASSERT_TRUE(downstream_fetcher); |
505 downstream_fetcher->set_status(URLRequestStatus(/* default=SUCCESS */)); | 505 downstream_fetcher->set_status(URLRequestStatus(/* default=SUCCESS */)); |
506 downstream_fetcher->set_response_code(200); | 506 downstream_fetcher->set_response_code(200); |
507 | 507 |
508 std::string response_string = SerializeProtobufResponse(result); | 508 std::string response_string = SerializeProtobufResponse(result); |
509 response_buffer_.append(response_string); | 509 response_buffer_.append(response_string); |
510 downstream_fetcher->SetResponseString(response_buffer_); | 510 downstream_fetcher->SetResponseString(response_buffer_); |
511 downstream_fetcher->delegate()->OnURLFetchDownloadProgress( | 511 downstream_fetcher->delegate()->OnURLFetchDownloadProgress( |
512 downstream_fetcher, | 512 downstream_fetcher, response_buffer_.size(), |
513 response_buffer_.size(), | 513 -1 /* total response length not used */, response_buffer_.size()); |
514 -1 /* total response length not used */); | |
515 } | 514 } |
516 | 515 |
517 void SpeechRecognitionEngineTest::ProvideMockResultDownstream( | 516 void SpeechRecognitionEngineTest::ProvideMockResultDownstream( |
518 const SpeechRecognitionResult& result) { | 517 const SpeechRecognitionResult& result) { |
519 proto::SpeechRecognitionEvent proto_event; | 518 proto::SpeechRecognitionEvent proto_event; |
520 proto_event.set_status(proto::SpeechRecognitionEvent::STATUS_SUCCESS); | 519 proto_event.set_status(proto::SpeechRecognitionEvent::STATUS_SUCCESS); |
521 proto::SpeechRecognitionResult* proto_result = proto_event.add_result(); | 520 proto::SpeechRecognitionResult* proto_result = proto_event.add_result(); |
522 proto_result->set_final(!result.is_provisional); | 521 proto_result->set_final(!result.is_provisional); |
523 for (size_t i = 0; i < result.hypotheses.size(); ++i) { | 522 for (size_t i = 0; i < result.hypotheses.size(); ++i) { |
524 proto::SpeechRecognitionAlternative* proto_alternative = | 523 proto::SpeechRecognitionAlternative* proto_alternative = |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 597 |
599 // Prepend 4 byte prefix length indication to the protobuf message as | 598 // Prepend 4 byte prefix length indication to the protobuf message as |
600 // envisaged by the google streaming recognition webservice protocol. | 599 // envisaged by the google streaming recognition webservice protocol. |
601 uint32_t prefix = HostToNet32(checked_cast<uint32_t>(msg_string.size())); | 600 uint32_t prefix = HostToNet32(checked_cast<uint32_t>(msg_string.size())); |
602 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); | 601 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); |
603 | 602 |
604 return msg_string; | 603 return msg_string; |
605 } | 604 } |
606 | 605 |
607 } // namespace content | 606 } // namespace content |
OLD | NEW |