| 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 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h" | 5 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/common/net/url_fetcher.h" | 10 #include "chrome/common/net/url_fetcher.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "net/url_request/url_request_status.h" | 12 #include "net/url_request/url_request_status.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::Invoke; | 18 using ::testing::Invoke; |
| 19 | 19 |
| 20 MockAuthResponseHandler::MockAuthResponseHandler(const GURL& url, | 20 MockAuthResponseHandler::MockAuthResponseHandler( |
| 21 const URLRequestStatus& status, | 21 const GURL& url, |
| 22 const int code, | 22 const net::URLRequestStatus& status, |
| 23 const std::string& data) | 23 const int code, |
| 24 const std::string& data) |
| 24 : remote_(url), | 25 : remote_(url), |
| 25 status_(status), | 26 status_(status), |
| 26 http_response_code_(code), | 27 http_response_code_(code), |
| 27 data_(data) { | 28 data_(data) { |
| 28 // Take the args sent to Handle() and pass them to MockNetwork(), which will | 29 // Take the args sent to Handle() and pass them to MockNetwork(), which will |
| 29 // use the data passed to the constructor here to fill out the call to | 30 // use the data passed to the constructor here to fill out the call to |
| 30 // OnURLFetchComplete(). | 31 // OnURLFetchComplete(). |
| 31 ON_CALL(*this, Handle(_,_)) | 32 ON_CALL(*this, Handle(_,_)) |
| 32 .WillByDefault(Invoke(this, &MockAuthResponseHandler::MockNetwork)); | 33 .WillByDefault(Invoke(this, &MockAuthResponseHandler::MockNetwork)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void MockAuthResponseHandler::CompleteFetch(URLFetcher::Delegate* delegate, | 36 void MockAuthResponseHandler::CompleteFetch(URLFetcher::Delegate* delegate, |
| 36 const GURL remote, | 37 const GURL remote, |
| 37 const URLRequestStatus status, | 38 const net::URLRequestStatus status, |
| 38 const int http_response_code, | 39 const int http_response_code, |
| 39 const std::string data) { | 40 const std::string data) { |
| 40 delegate->OnURLFetchComplete(NULL, | 41 delegate->OnURLFetchComplete(NULL, |
| 41 remote, | 42 remote, |
| 42 status, | 43 status, |
| 43 http_response_code, | 44 http_response_code, |
| 44 ResponseCookies(), | 45 ResponseCookies(), |
| 45 data); | 46 data); |
| 46 } | 47 } |
| 47 | 48 |
| 48 URLFetcher* MockAuthResponseHandler::MockNetwork( | 49 URLFetcher* MockAuthResponseHandler::MockNetwork( |
| 49 std::string data, | 50 std::string data, |
| 50 URLFetcher::Delegate* delegate) { | 51 URLFetcher::Delegate* delegate) { |
| 51 MessageLoop::current()->PostTask( | 52 MessageLoop::current()->PostTask( |
| 52 FROM_HERE, | 53 FROM_HERE, |
| 53 NewRunnableFunction(MockAuthResponseHandler::CompleteFetch, | 54 NewRunnableFunction(MockAuthResponseHandler::CompleteFetch, |
| 54 delegate, | 55 delegate, |
| 55 remote_, | 56 remote_, |
| 56 status_, | 57 status_, |
| 57 http_response_code_, | 58 http_response_code_, |
| 58 data_)); | 59 data_)); |
| 59 return new URLFetcher(GURL(), URLFetcher::GET, delegate); | 60 return new URLFetcher(GURL(), URLFetcher::GET, delegate); |
| 60 } | 61 } |
| 61 | 62 |
| 62 } // namespace chromeos | 63 } // namespace chromeos |
| OLD | NEW |