| 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 "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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 break; | 64 break; |
| 65 } | 65 } |
| 66 return rv; | 66 return rv; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) { | 69 void HttpAuthHandlerMock::SetGenerateExpectation(bool async, int rv) { |
| 70 generate_async_ = async; | 70 generate_async_ = async; |
| 71 generate_rv_ = rv; | 71 generate_rv_ = rv; |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool HttpAuthHandlerMock::Init(HttpAuth::ChallengeTokenizer* challenge) { | |
| 75 auth_scheme_ = HttpAuth::AUTH_SCHEME_MOCK; | |
| 76 score_ = 1; | |
| 77 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0; | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge( | 74 HttpAuth::AuthorizationResult HttpAuthHandlerMock::HandleAnotherChallenge( |
| 82 HttpAuth::ChallengeTokenizer* challenge) { | 75 HttpAuth::ChallengeTokenizer* challenge) { |
| 83 if (!is_connection_based()) | 76 if (!is_connection_based()) |
| 84 return HttpAuth::AUTHORIZATION_RESULT_REJECT; | 77 return HttpAuth::AUTHORIZATION_RESULT_REJECT; |
| 85 if (!LowerCaseEqualsASCII(challenge->scheme(), "mock")) | 78 if (!LowerCaseEqualsASCII(challenge->scheme(), "mock")) |
| 86 return HttpAuth::AUTHORIZATION_RESULT_INVALID; | 79 return HttpAuth::AUTHORIZATION_RESULT_INVALID; |
| 87 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; | 80 return HttpAuth::AUTHORIZATION_RESULT_ACCEPT; |
| 88 } | 81 } |
| 89 | 82 |
| 83 bool HttpAuthHandlerMock::NeedsIdentity() { |
| 84 return first_round_; |
| 85 } |
| 86 |
| 87 bool HttpAuthHandlerMock::Init(HttpAuth::ChallengeTokenizer* challenge) { |
| 88 auth_scheme_ = HttpAuth::AUTH_SCHEME_MOCK; |
| 89 score_ = 1; |
| 90 properties_ = connection_based_ ? IS_CONNECTION_BASED : 0; |
| 91 return true; |
| 92 } |
| 93 |
| 90 int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, | 94 int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, |
| 91 const string16* password, | 95 const string16* password, |
| 92 const HttpRequestInfo* request, | 96 const HttpRequestInfo* request, |
| 93 CompletionCallback* callback, | 97 CompletionCallback* callback, |
| 94 std::string* auth_token) { | 98 std::string* auth_token) { |
| 95 first_round_ = false; | 99 first_round_ = false; |
| 96 request_url_ = request->url; | 100 request_url_ = request->url; |
| 97 if (generate_async_) { | 101 if (generate_async_) { |
| 98 EXPECT_TRUE(user_callback_ == NULL); | 102 EXPECT_TRUE(user_callback_ == NULL); |
| 99 EXPECT_TRUE(auth_token_ == NULL); | 103 EXPECT_TRUE(auth_token_ == NULL); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return ERR_UNEXPECTED; | 160 return ERR_UNEXPECTED; |
| 157 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target].release()); | 161 scoped_ptr<HttpAuthHandler> tmp_handler(handlers_[target].release()); |
| 158 if (do_init_from_challenge_ && | 162 if (do_init_from_challenge_ && |
| 159 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 163 !tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
| 160 return ERR_INVALID_RESPONSE; | 164 return ERR_INVALID_RESPONSE; |
| 161 handler->swap(tmp_handler); | 165 handler->swap(tmp_handler); |
| 162 return OK; | 166 return OK; |
| 163 } | 167 } |
| 164 | 168 |
| 165 } // namespace net | 169 } // namespace net |
| OLD | NEW |