| Index: chrome/test/speech/mock_google_one_shot_server.h
|
| diff --git a/chrome/test/speech/mock_google_one_shot_server.h b/chrome/test/speech/mock_google_one_shot_server.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..22db681c43ec08c85e1d310bd676ed7f456307af
|
| --- /dev/null
|
| +++ b/chrome/test/speech/mock_google_one_shot_server.h
|
| @@ -0,0 +1,68 @@
|
| +// 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 CHROME_TEST_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_
|
| +#define CHROME_TEST_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_
|
| +
|
| +#include "base/compiler_specific.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:
|
| + class Delegate {
|
| + public:
|
| + virtual void OnClientConnected() = 0;
|
| + virtual void OnClientAudioUpload() = 0;
|
| + virtual void OnClientAudioUploadComplete() = 0;
|
| + virtual void OnClientDisconnected() = 0;
|
| + };
|
| +
|
| + explicit MockGoogleOneShotServer(Delegate* 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;
|
| +
|
| + Delegate* 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);
|
| +};
|
| +
|
| +typedef MockGoogleOneShotServer::Delegate MockGoogleOneShotServerDelegate;
|
| +
|
| +} // namespace speech
|
| +
|
| +#endif // CHROME_TEST_SPEECH_MOCK_GOOGLE_ONE_SHOT_SERVER_H_
|
|
|