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