| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/http/http_auth_handler_mock.h" | 5 #include "net/http/http_auth_handler_mock.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/http/http_request_info.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace net { | 12 namespace net { |
| 12 | 13 |
| 13 HttpAuthHandlerMock::HttpAuthHandlerMock() | 14 HttpAuthHandlerMock::HttpAuthHandlerMock() |
| 14 : resolve_(RESOLVE_INIT), user_callback_(NULL), | 15 : resolve_(RESOLVE_INIT), user_callback_(NULL), |
| 15 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 16 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 16 generate_async_(false), generate_rv_(OK), | 17 generate_async_(false), generate_rv_(OK), |
| 17 auth_token_(NULL), | 18 auth_token_(NULL), |
| 18 first_round_(true), | 19 first_round_(true), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0; | 76 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0; |
| 76 return true; | 77 return true; |
| 77 } | 78 } |
| 78 | 79 |
| 79 int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, | 80 int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, |
| 80 const string16* password, | 81 const string16* password, |
| 81 const HttpRequestInfo* request, | 82 const HttpRequestInfo* request, |
| 82 CompletionCallback* callback, | 83 CompletionCallback* callback, |
| 83 std::string* auth_token) { | 84 std::string* auth_token) { |
| 84 first_round_ = false; | 85 first_round_ = false; |
| 86 request_url_ = request->url; |
| 85 if (generate_async_) { | 87 if (generate_async_) { |
| 86 EXPECT_TRUE(user_callback_ == NULL); | 88 EXPECT_TRUE(user_callback_ == NULL); |
| 87 EXPECT_TRUE(auth_token_ == NULL); | 89 EXPECT_TRUE(auth_token_ == NULL); |
| 88 user_callback_ = callback; | 90 user_callback_ = callback; |
| 89 auth_token_ = auth_token; | 91 auth_token_ = auth_token; |
| 90 MessageLoop::current()->PostTask( | 92 MessageLoop::current()->PostTask( |
| 91 FROM_HERE, method_factory_.NewRunnableMethod( | 93 FROM_HERE, method_factory_.NewRunnableMethod( |
| 92 &HttpAuthHandlerMock::OnGenerateAuthToken)); | 94 &HttpAuthHandlerMock::OnGenerateAuthToken)); |
| 93 return ERR_IO_PENDING; | 95 return ERR_IO_PENDING; |
| 94 } else { | 96 } else { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 111 EXPECT_TRUE(generate_async_); | 113 EXPECT_TRUE(generate_async_); |
| 112 EXPECT_TRUE(user_callback_ != NULL); | 114 EXPECT_TRUE(user_callback_ != NULL); |
| 113 if (generate_rv_ == OK) | 115 if (generate_rv_ == OK) |
| 114 *auth_token_ = "auth_token"; | 116 *auth_token_ = "auth_token"; |
| 115 auth_token_ = NULL; | 117 auth_token_ = NULL; |
| 116 CompletionCallback* callback = user_callback_; | 118 CompletionCallback* callback = user_callback_; |
| 117 user_callback_ = NULL; | 119 user_callback_ = NULL; |
| 118 callback->Run(generate_rv_); | 120 callback->Run(generate_rv_); |
| 119 } | 121 } |
| 120 | 122 |
| 123 HttpAuthHandlerMock::Factory::Factory() |
| 124 : do_init_from_challenge_(false) { |
| 125 // TODO(cbentzel): Default do_init_from_challenge_ to true. |
| 126 } |
| 127 |
| 128 HttpAuthHandlerMock::Factory::~Factory() { |
| 129 } |
| 130 |
| 121 void HttpAuthHandlerMock::Factory::set_mock_handler( | 131 void HttpAuthHandlerMock::Factory::set_mock_handler( |
| 122 HttpAuthHandler* handler, HttpAuth::Target target) { | 132 HttpAuthHandler* handler, HttpAuth::Target target) { |
| 123 EXPECT_TRUE(handlers_[target].get() == NULL); | 133 EXPECT_TRUE(handlers_[target].get() == NULL); |
| 124 handlers_[target].reset(handler); | 134 handlers_[target].reset(handler); |
| 125 } | 135 } |
| 126 | 136 |
| 127 int HttpAuthHandlerMock::Factory::CreateAuthHandler( | 137 int HttpAuthHandlerMock::Factory::CreateAuthHandler( |
| 128 HttpAuth::ChallengeTokenizer* challenge, | 138 HttpAuth::ChallengeTokenizer* challenge, |
| 129 HttpAuth::Target target, | 139 HttpAuth::Target target, |
| 130 const GURL& origin, | 140 const GURL& origin, |
| 131 CreateReason reason, | 141 CreateReason reason, |
| 132 int nonce_count, | 142 int nonce_count, |
| 133 const BoundNetLog& net_log, | 143 const BoundNetLog& net_log, |
| 134 scoped_ptr<HttpAuthHandler>* handler) { | 144 scoped_ptr<HttpAuthHandler>* handler) { |
| 135 if (!handlers_[target].get()) | 145 if (!handlers_[target].get()) |
| 136 return ERR_UNEXPECTED; | 146 return ERR_UNEXPECTED; |
| 137 handler->swap(handlers_[target]); | 147 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target].release()); |
| 148 if (do_init_from_challenge_ && |
| 149 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
| 150 return ERR_INVALID_RESPONSE; |
| 151 handler->swap(tmp_handler); |
| 138 return OK; | 152 return OK; |
| 139 } | 153 } |
| 140 | 154 |
| 141 } // namespace net | 155 } // namespace net |
| OLD | NEW |