| Index: content/browser/speech/mock_google_one_shot_server.h
|
| diff --git a/content/browser/speech/mock_google_one_shot_server.h b/content/browser/speech/mock_google_one_shot_server.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ed4262e878f3a14e4d2dd85ad399591d7da25040
|
| --- /dev/null
|
| +++ b/content/browser/speech/mock_google_one_shot_server.h
|
| @@ -0,0 +1,60 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CONTENT_BROWSER_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_
|
| +#define CONTENT_BROWSER_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_
|
| +#pragma once
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "content/browser/speech/mock_google_speech_recognition_server_delegate.h"
|
| +#include "content/public/common/speech_recognition_result.h"
|
| +#include "net/url_request/test_url_fetcher_factory.h"
|
| +
|
| +namespace content {
|
| +struct SpeechRecognitionResult;
|
| +}
|
| +
|
| +namespace speech {
|
| +// Provides a mock implementation of the Google remote one-shot speech
|
| +// recognition webservice, exploiting the TestURLFetcher to extract request
|
| +// parameters and provide forged JSON responses back to the client.
|
| +// It is intended for closing the server-side loop in speech tests that involve
|
| +// the GoogleOneShotRemoteEngine client.
|
| +class MockGoogleOneShotServer : public net::TestURLFetcherDelegateForTests {
|
| + public:
|
| + MockGoogleOneShotServer(MockGoogleSpeechRecognitionServerDelegate* delegate);
|
| + virtual ~MockGoogleOneShotServer();
|
| +
|
| + void SimulateResult(const content::SpeechRecognitionResult& result);
|
| + void SimulateServerFailure();
|
| + void SimulateMalformedResponse();
|
| +
|
| + // net::TestURLFetcherDelegateForTests implementation.
|
| + virtual void OnRequestStart(int fetcher_id) OVERRIDE;
|
| + virtual void OnChunkUpload(int fetcher_id) OVERRIDE;
|
| + virtual void OnRequestEnd(int fetcher_id) OVERRIDE;
|
| +
|
| + // Retrieves the language parmeter for the request (e.g., lang=en-US).
|
| + const std::string& GetRequestLanguage() const;
|
| +
|
| + // Retrieves the grammar parmeter for the request (e.g., lm=http://url/g.xml).
|
| + const std::string& GetRequestGrammar() const;
|
| +
|
| + private:
|
| + void SimulateServerResponse(bool success, const std::string& http_response);
|
| + net::TestURLFetcher* GetURLFetcher() const;
|
| +
|
| + MockGoogleSpeechRecognitionServerDelegate* delegate_;
|
| + net::TestURLFetcherFactory url_fetcher_factory_;
|
| +
|
| + // Request arguments extracted by the HTTP query string.
|
| + std::string request_language;
|
| + std::string request_grammar;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MockGoogleOneShotServer);
|
| +};
|
| +
|
| +} // namespace speech
|
| +
|
| +#endif // CONTENT_BROWSER_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_
|
|
|