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