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