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 "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 "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/http/http_request_info.h" | 10 #include "net/http/http_request_info.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 | 136 |
137 HttpAuthHandlerMock::Factory::Factory() | 137 HttpAuthHandlerMock::Factory::Factory() |
138 : do_init_from_challenge_(false) { | 138 : do_init_from_challenge_(false) { |
139 // TODO(cbentzel): Default do_init_from_challenge_ to true. | 139 // TODO(cbentzel): Default do_init_from_challenge_ to true. |
140 } | 140 } |
141 | 141 |
142 HttpAuthHandlerMock::Factory::~Factory() { | 142 HttpAuthHandlerMock::Factory::~Factory() { |
143 } | 143 } |
144 | 144 |
145 void HttpAuthHandlerMock::Factory::set_mock_handler( | 145 void HttpAuthHandlerMock::Factory::AddMockHandler( |
146 HttpAuthHandler* handler, HttpAuth::Target target) { | 146 HttpAuthHandler* handler, HttpAuth::Target target) { |
147 EXPECT_TRUE(handlers_[target].get() == NULL); | 147 handlers_[target].push_back(handler); |
148 handlers_[target].reset(handler); | |
149 } | 148 } |
150 | 149 |
151 int HttpAuthHandlerMock::Factory::CreateAuthHandler( | 150 int HttpAuthHandlerMock::Factory::CreateAuthHandler( |
152 HttpAuth::ChallengeTokenizer* challenge, | 151 HttpAuth::ChallengeTokenizer* challenge, |
153 HttpAuth::Target target, | 152 HttpAuth::Target target, |
154 const GURL& origin, | 153 const GURL& origin, |
155 CreateReason reason, | 154 CreateReason reason, |
156 int nonce_count, | 155 int nonce_count, |
157 const BoundNetLog& net_log, | 156 const BoundNetLog& net_log, |
158 scoped_ptr<HttpAuthHandler>* handler) { | 157 scoped_ptr<HttpAuthHandler>* handler) { |
159 if (!handlers_[target].get()) | 158 if (handlers_[target].empty()) |
160 return ERR_UNEXPECTED; | 159 return ERR_UNEXPECTED; |
161 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target].release()); | 160 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target][0]); |
| 161 std::vector<HttpAuthHandler*>& handlers = handlers_[target].get(); |
| 162 handlers.erase(handlers.begin()); |
162 if (do_init_from_challenge_ && | 163 if (do_init_from_challenge_ && |
163 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 164 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
164 return ERR_INVALID_RESPONSE; | 165 return ERR_INVALID_RESPONSE; |
165 handler->swap(tmp_handler); | 166 handler->swap(tmp_handler); |
166 return OK; | 167 return OK; |
167 } | 168 } |
168 | 169 |
169 } // namespace net | 170 } // namespace net |
OLD | NEW |