| OLD | NEW |
| 1 // Copyright (c) 2010 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 class URLFetcher; | 17 class URLFetcher; |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 // In real AuthResponseHandler subclasses, Handle(data, delegate) | 21 // In real AuthResponseHandler subclasses, Handle(data, delegate) |
| 22 // initiates an HTTP fetch. To mock this, we would like to set up | 22 // initiates an HTTP fetch. To mock this, we would like to set up |
| 23 // appropriate state and then call the OnURLFetchComplete method of | 23 // appropriate state and then call the OnURLFetchComplete method of |
| 24 // |delegate| directly. Rather than using some kind of global state, we | 24 // |delegate| directly. Rather than using some kind of global state, we |
| 25 // allow a MockAuthResponseHandler to be instantiated with the 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 | 26 // want to send to OnURLFetchComplete, and then have Handle() Invoke a helper |
| 27 // method that will do this work. | 27 // method that will do this work. |
| 28 class MockAuthResponseHandler : public AuthResponseHandler { | 28 class MockAuthResponseHandler : public AuthResponseHandler { |
| 29 public: | 29 public: |
| 30 MockAuthResponseHandler(const GURL& url, | 30 MockAuthResponseHandler(const GURL& url, |
| 31 const URLRequestStatus& status, | 31 const net::URLRequestStatus& status, |
| 32 const int code, | 32 const int code, |
| 33 const std::string& data); | 33 const std::string& data); |
| 34 virtual ~MockAuthResponseHandler() {} | 34 virtual ~MockAuthResponseHandler() {} |
| 35 | 35 |
| 36 MOCK_METHOD1(CanHandle, bool(const GURL& url)); | 36 MOCK_METHOD1(CanHandle, bool(const GURL& url)); |
| 37 MOCK_METHOD2(Handle, URLFetcher*(const std::string& to_process, | 37 MOCK_METHOD2(Handle, URLFetcher*(const std::string& to_process, |
| 38 URLFetcher::Delegate* catcher)); | 38 URLFetcher::Delegate* catcher)); |
| 39 | 39 |
| 40 URLFetcher* MockNetwork(std::string data, URLFetcher::Delegate* delegate); | 40 URLFetcher* MockNetwork(std::string data, URLFetcher::Delegate* delegate); |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 const GURL remote_; | 43 const GURL remote_; |
| 44 const URLRequestStatus status_; | 44 const net::URLRequestStatus status_; |
| 45 const int http_response_code_; | 45 const int http_response_code_; |
| 46 const std::string data_; | 46 const std::string data_; |
| 47 | 47 |
| 48 static void CompleteFetch(URLFetcher::Delegate* delegate, | 48 static void CompleteFetch(URLFetcher::Delegate* delegate, |
| 49 const GURL remote, | 49 const GURL remote, |
| 50 const URLRequestStatus status, | 50 const net::URLRequestStatus status, |
| 51 const int http_response_code, | 51 const int http_response_code, |
| 52 const std::string data); | 52 const std::string data); |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(MockAuthResponseHandler); | 54 DISALLOW_COPY_AND_ASSIGN(MockAuthResponseHandler); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace chromeos | 57 } // namespace chromeos |
| 58 | 58 |
| 59 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTH_RESPONSE_HANDLER_H_ | 59 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTH_RESPONSE_HANDLER_H_ |
| OLD | NEW |