GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / test / mock_google_streaming_server.h
blobd2ea81b42e4ef3af4081f95c6acd1615ff137617
1 // Copyright 2013 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.
5 #ifndef CONTENT_TEST_MOCK_GOOGLE_STREAMING_SERVER_H_
6 #define CONTENT_TEST_MOCK_GOOGLE_STREAMING_SERVER_H_
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"
12 namespace content {
14 struct SpeechRecognitionResult;
16 // Provides a mock implementation of the Google remote streaming speech
17 // recognition webservice, exploiting the TestURLFetcher to extract request
18 // parameters and provide forged JSON responses back to the client.
19 // It is intended for closing the server-side loop in speech tests that involve
20 // the GoogleStreamingRemoteEngine client.
21 class MockGoogleStreamingServer : public net::TestURLFetcherDelegateForTests {
22 public:
23 class Delegate {
24 public:
25 virtual void OnClientConnected() = 0;
26 virtual void OnClientAudioUpload() = 0;
27 virtual void OnClientAudioUploadComplete() = 0;
28 virtual void OnClientDisconnected() = 0;
31 explicit MockGoogleStreamingServer(Delegate* delegate);
32 virtual ~MockGoogleStreamingServer();
34 // net::TestURLFetcherDelegateForTests implementation.
35 void OnRequestStart(int fetcher_id) override;
36 void OnChunkUpload(int fetcher_id) override;
37 void OnRequestEnd(int fetcher_id) override;
39 void SimulateResult(const content::SpeechRecognitionResult& result);
40 void SimulateServerFailure();
41 void SimulateMalformedResponse();
43 // Retrieves the language parmeter for the request (e.g., lang=en-US).
44 const std::string& GetRequestLanguage() const;
46 // Retrieves the grammar parmeter for the request (e.g., lm=http://url/g.xml).
47 const std::string& GetRequestGrammar() const;
49 private:
50 void SimulateServerResponse(bool success, const std::string& http_response);
51 net::TestURLFetcher* GetURLFetcher(bool downstream) const;
53 Delegate* delegate_;
54 int kDownstreamUrlFetcherId;
55 int kUpstreamUrlFetcherId;
56 net::TestURLFetcherFactory url_fetcher_factory_;
58 // Request arguments extracted by the HTTP query string.
59 std::string request_language;
60 std::string request_grammar;
62 DISALLOW_COPY_AND_ASSIGN(MockGoogleStreamingServer);
65 } // namespace content
67 #endif // CONTENT_TEST_MOCK_GOOGLE_STREAMING_SERVER_H_