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 <queue> | 5 #include <queue> |
6 | 6 |
7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/sys_byteorder.h" | 12 #include "base/sys_byteorder.h" |
13 #include "content/browser/speech/audio_buffer.h" | 13 #include "content/browser/speech/audio_buffer.h" |
14 #include "content/browser/speech/google_streaming_remote_engine.h" | 14 #include "content/browser/speech/google_streaming_remote_engine.h" |
15 #include "content/browser/speech/proto/google_streaming_api.pb.h" | 15 #include "content/browser/speech/proto/google_streaming_api.pb.h" |
16 #include "content/public/common/speech_recognition_error.h" | 16 #include "content/public/common/speech_recognition_error.h" |
17 #include "content/public/common/speech_recognition_result.h" | 17 #include "content/public/common/speech_recognition_result.h" |
| 18 #include "net/base/net_errors.h" |
18 #include "net/url_request/test_url_fetcher_factory.h" | 19 #include "net/url_request/test_url_fetcher_factory.h" |
19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
20 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using base::HostToNet32; | 24 using base::HostToNet32; |
24 using base::checked_cast; | 25 using base::checked_cast; |
25 using net::URLRequestStatus; | 26 using net::URLRequestStatus; |
26 using net::TestURLFetcher; | 27 using net::TestURLFetcher; |
27 using net::TestURLFetcherFactory; | 28 using net::TestURLFetcherFactory; |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance)); | 493 proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance)); |
493 } | 494 } |
494 ProvideMockProtoResultDownstream(proto_event); | 495 ProvideMockProtoResultDownstream(proto_event); |
495 } | 496 } |
496 | 497 |
497 void GoogleStreamingRemoteEngineTest::CloseMockDownstream( | 498 void GoogleStreamingRemoteEngineTest::CloseMockDownstream( |
498 DownstreamError error) { | 499 DownstreamError error) { |
499 TestURLFetcher* downstream_fetcher = GetDownstreamFetcher(); | 500 TestURLFetcher* downstream_fetcher = GetDownstreamFetcher(); |
500 ASSERT_TRUE(downstream_fetcher); | 501 ASSERT_TRUE(downstream_fetcher); |
501 | 502 |
502 const URLRequestStatus::Status fetcher_status = | 503 const net::Error net_error = |
503 (error == DOWNSTREAM_ERROR_NETWORK) ? URLRequestStatus::FAILED : | 504 (error == DOWNSTREAM_ERROR_NETWORK) ? net::ERR_FAILED : net::OK; |
504 URLRequestStatus::SUCCESS; | 505 downstream_fetcher->set_status(URLRequestStatus::FromError(net_error)); |
505 downstream_fetcher->set_status(URLRequestStatus(fetcher_status, 0)); | |
506 downstream_fetcher->set_response_code( | 506 downstream_fetcher->set_response_code( |
507 (error == DOWNSTREAM_ERROR_HTTP500) ? 500 : 200); | 507 (error == DOWNSTREAM_ERROR_HTTP500) ? 500 : 200); |
508 | 508 |
509 if (error == DOWNSTREAM_ERROR_WEBSERVICE_NO_MATCH) { | 509 if (error == DOWNSTREAM_ERROR_WEBSERVICE_NO_MATCH) { |
510 // Send empty response. | 510 // Send empty response. |
511 proto::SpeechRecognitionEvent response; | 511 proto::SpeechRecognitionEvent response; |
512 response_buffer_.append(SerializeProtobufResponse(response)); | 512 response_buffer_.append(SerializeProtobufResponse(response)); |
513 } | 513 } |
514 downstream_fetcher->SetResponseString(response_buffer_); | 514 downstream_fetcher->SetResponseString(response_buffer_); |
515 downstream_fetcher->delegate()->OnURLFetchComplete(downstream_fetcher); | 515 downstream_fetcher->delegate()->OnURLFetchComplete(downstream_fetcher); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 | 563 |
564 // Prepend 4 byte prefix length indication to the protobuf message as | 564 // Prepend 4 byte prefix length indication to the protobuf message as |
565 // envisaged by the google streaming recognition webservice protocol. | 565 // envisaged by the google streaming recognition webservice protocol. |
566 uint32 prefix = HostToNet32(checked_cast<uint32>(msg_string.size())); | 566 uint32 prefix = HostToNet32(checked_cast<uint32>(msg_string.size())); |
567 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); | 567 msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); |
568 | 568 |
569 return msg_string; | 569 return msg_string; |
570 } | 570 } |
571 | 571 |
572 } // namespace content | 572 } // namespace content |
OLD | NEW |