• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_BROWSER_CHROMEOS_LOGIN_MOCK_AUTH_RESPONSE_HANDLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTH_RESPONSE_HANDLER_H_
7 #pragma once
8 
9 #include "chrome/browser/chromeos/login/auth_response_handler.h"
10 
11 #include <string>
12 
13 #include "googleurl/src/gurl.h"
14 #include "net/url_request/url_request_status.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 
17 class URLFetcher;
18 
19 namespace chromeos {
20 
21 // In real AuthResponseHandler subclasses, Handle(data, delegate)
22 // initiates an HTTP fetch.  To mock this, we would like to set up
23 // appropriate state and then call the OnURLFetchComplete method of
24 // |delegate| directly.  Rather than using some kind of global state, we
25 // allow a MockAuthResponseHandler to be instantiated with the state we
26 // want to send to OnURLFetchComplete, and then have Handle() Invoke a helper
27 // method that will do this work.
28 class MockAuthResponseHandler : public AuthResponseHandler {
29  public:
30   MockAuthResponseHandler(const GURL& url,
31                           const net::URLRequestStatus& status,
32                           const int code,
33                           const std::string& data);
~MockAuthResponseHandler()34   virtual ~MockAuthResponseHandler() {}
35 
36   MOCK_METHOD1(CanHandle, bool(const GURL& url));
37   MOCK_METHOD2(Handle, URLFetcher*(const std::string& to_process,
38                                    URLFetcher::Delegate* catcher));
39 
40   URLFetcher* MockNetwork(std::string data, URLFetcher::Delegate* delegate);
41 
42  private:
43   const GURL remote_;
44   const net::URLRequestStatus status_;
45   const int http_response_code_;
46   const std::string data_;
47 
48   static void CompleteFetch(URLFetcher::Delegate* delegate,
49                             const GURL remote,
50                             const net::URLRequestStatus status,
51                             const int http_response_code,
52                             const std::string data);
53 
54   DISALLOW_COPY_AND_ASSIGN(MockAuthResponseHandler);
55 };
56 
57 }  // namespace chromeos
58 
59 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTH_RESPONSE_HANDLER_H_
60