| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "content/browser/speech/mock_google_speech_recognition_server_delegate.
h" |
| 11 #include "content/public/common/speech_recognition_result.h" |
| 12 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 |
| 14 namespace content { |
| 15 struct SpeechRecognitionResult; |
| 16 } |
| 17 |
| 18 namespace speech { |
| 19 // Provides a mock implementation of the Google remote one-shot speech |
| 20 // recognition webservice, exploiting the TestURLFetcher to extract request |
| 21 // parameters and provide forged JSON responses back to the client. |
| 22 // It is intended for closing the server-side loop in speech tests that involve |
| 23 // the GoogleOneShotRemoteEngine client. |
| 24 class MockGoogleOneShotServer : public net::TestURLFetcherDelegateForTests { |
| 25 public: |
| 26 MockGoogleOneShotServer(MockGoogleSpeechRecognitionServerDelegate* delegate); |
| 27 virtual ~MockGoogleOneShotServer(); |
| 28 |
| 29 void SimulateResult(const content::SpeechRecognitionResult& result); |
| 30 void SimulateServerFailure(); |
| 31 void SimulateMalformedResponse(); |
| 32 |
| 33 // net::TestURLFetcherDelegateForTests implementation. |
| 34 virtual void OnRequestStart(int fetcher_id) OVERRIDE; |
| 35 virtual void OnChunkUpload(int fetcher_id) OVERRIDE; |
| 36 virtual void OnRequestEnd(int fetcher_id) OVERRIDE; |
| 37 |
| 38 // Retrieves the language parmeter for the request (e.g., lang=en-US). |
| 39 const std::string& GetRequestLanguage() const; |
| 40 |
| 41 // Retrieves the grammar parmeter for the request (e.g., lm=http://url/g.xml). |
| 42 const std::string& GetRequestGrammar() const; |
| 43 |
| 44 private: |
| 45 void SimulateServerResponse(bool success, const std::string& http_response); |
| 46 net::TestURLFetcher* GetURLFetcher() const; |
| 47 |
| 48 MockGoogleSpeechRecognitionServerDelegate* delegate_; |
| 49 net::TestURLFetcherFactory url_fetcher_factory_; |
| 50 |
| 51 // Request arguments extracted by the HTTP query string. |
| 52 std::string request_language; |
| 53 std::string request_grammar; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(MockGoogleOneShotServer); |
| 56 }; |
| 57 |
| 58 } // namespace speech |
| 59 |
| 60 #endif // CONTENT_BROWSER_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_ |
| OLD | NEW |