| 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 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
| 6 #define NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 6 #define NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "net/http/http_auth.h" | 13 #include "net/http/http_auth.h" |
| 14 #include "net/http/http_auth_handler.h" | 14 #include "net/http/http_auth_handler.h" |
| 15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 class HostResolver; | 20 class HostResolver; |
| 21 | 21 |
| 22 enum class HttpAuthHandlerCreateReason { PREEMPTIVE, CHALLENGE }; |
| 23 |
| 22 // MockAuthHandler is used in tests to reliably trigger edge cases. | 24 // MockAuthHandler is used in tests to reliably trigger edge cases. |
| 23 class HttpAuthHandlerMock : public HttpAuthHandler { | 25 class HttpAuthHandlerMock : public HttpAuthHandler { |
| 24 public: | 26 public: |
| 25 // The Factory class returns handlers in the order they were added via | 27 // The Factory class returns handlers in the order they were added via |
| 26 // AddMockHandler. | 28 // AddMockHandler. |
| 27 class Factory : public HttpAuthHandlerFactory { | 29 class Factory : public HttpAuthHandlerFactory { |
| 28 public: | 30 public: |
| 29 Factory(); | 31 Factory(); |
| 30 ~Factory() override; | 32 ~Factory() override; |
| 31 | 33 |
| 32 void AddMockHandler(scoped_ptr<HttpAuthHandler> handler, | 34 void AddMockHandler(scoped_ptr<HttpAuthHandler> handler, |
| 33 CreateReason reason, | 35 HttpAuthHandlerCreateReason reason); |
| 34 HttpAuth::Target target); | |
| 35 | 36 |
| 36 bool HaveAuthHandlers(HttpAuth::Target) const; | 37 bool HaveAuthHandlers() const; |
| 37 | 38 |
| 38 // HttpAuthHandlerFactory: | 39 // HttpAuthHandlerFactory: |
| 39 int CreateAuthHandler(const HttpAuthChallengeTokenizer& challenge, | 40 scoped_ptr<HttpAuthHandler> CreateAuthHandlerForScheme( |
| 40 HttpAuth::Target target, | 41 const std::string& scheme) override; |
| 41 const GURL& origin, | 42 scoped_ptr<HttpAuthHandler> CreateAndInitPreemptiveAuthHandler( |
| 42 CreateReason reason, | 43 HttpAuthCache::Entry* cache_entry, |
| 43 int nonce_count, | 44 const HttpAuthChallengeTokenizer& tokenizer, |
| 44 const BoundNetLog& net_log, | 45 HttpAuth::Target target, |
| 45 scoped_ptr<HttpAuthHandler>* handler) override; | 46 const BoundNetLog& net_log) override; |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 ScopedVector<HttpAuthHandler> | 49 scoped_ptr<HttpAuthHandler> GetNextAuthHandler( |
| 49 challenge_handlers_[HttpAuth::AUTH_NUM_TARGETS]; | 50 ScopedVector<HttpAuthHandler>* handler_list); |
| 50 ScopedVector<HttpAuthHandler> | 51 ScopedVector<HttpAuthHandler> challenge_handlers_; |
| 51 preemptive_handlers_[HttpAuth::AUTH_NUM_TARGETS]; | 52 ScopedVector<HttpAuthHandler> preemptive_handlers_; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 HttpAuthHandlerMock(); | 55 HttpAuthHandlerMock(); |
| 55 | 56 |
| 56 ~HttpAuthHandlerMock() override; | 57 ~HttpAuthHandlerMock() override; |
| 57 | 58 |
| 58 void SetGenerateExpectation(bool async, int rv); | 59 void SetGenerateExpectation(bool async, int rv); |
| 59 | 60 |
| 60 void set_expected_auth_scheme(const std::string& scheme) { | 61 void set_expected_auth_scheme(const std::string& scheme) { |
| 61 expected_auth_scheme_ = scheme; | 62 auth_scheme_ = scheme; |
| 63 } |
| 64 |
| 65 void set_expected_auth_target(HttpAuth::Target target) { |
| 66 expected_auth_target_ = target; |
| 62 } | 67 } |
| 63 | 68 |
| 64 void set_expect_multiple_challenges(bool expect_multiple_challenges) { | 69 void set_expect_multiple_challenges(bool expect_multiple_challenges) { |
| 65 expect_multiple_challenges_ = expect_multiple_challenges; | 70 expect_multiple_challenges_ = expect_multiple_challenges; |
| 66 } | 71 } |
| 67 | 72 |
| 68 void set_allows_default_credentials(bool allows_default_credentials) { | 73 void set_allows_default_credentials(bool allows_default_credentials) { |
| 69 allows_default_credentials_ = allows_default_credentials; | 74 allows_default_credentials_ = allows_default_credentials; |
| 70 } | 75 } |
| 71 | 76 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 93 | 98 |
| 94 int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 99 int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 95 const HttpRequestInfo& request, | 100 const HttpRequestInfo& request, |
| 96 const CompletionCallback& callback, | 101 const CompletionCallback& callback, |
| 97 std::string* auth_token) override; | 102 std::string* auth_token) override; |
| 98 | 103 |
| 99 private: | 104 private: |
| 100 void OnGenerateAuthToken(); | 105 void OnGenerateAuthToken(); |
| 101 | 106 |
| 102 CompletionCallback callback_; | 107 CompletionCallback callback_; |
| 103 std::string expected_auth_scheme_; | |
| 104 bool generate_async_ = false; | 108 bool generate_async_ = false; |
| 105 int generate_rv_ = 0; | 109 int generate_rv_ = 0; |
| 106 std::string auth_token_; | 110 std::string auth_token_; |
| 107 std::string* generate_auth_token_buffer_ = nullptr; | 111 std::string* generate_auth_token_buffer_ = nullptr; |
| 108 bool first_round_ = true; | 112 bool first_round_ = true; |
| 109 bool allows_default_credentials_ = false; | 113 bool allows_default_credentials_ = false; |
| 110 bool allows_explicit_credentials_ = true; | 114 bool allows_explicit_credentials_ = true; |
| 111 bool expect_multiple_challenges_ = false; | 115 bool expect_multiple_challenges_ = false; |
| 116 HttpAuth::Target expected_auth_target_ = HttpAuth::AUTH_SERVER; |
| 112 GURL request_url_; | 117 GURL request_url_; |
| 113 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; | 118 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; |
| 114 }; | 119 }; |
| 115 | 120 |
| 116 } // namespace net | 121 } // namespace net |
| 117 | 122 |
| 118 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 123 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
| OLD | NEW |