| 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_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // The Factory class returns handlers in the order they were added via | 31 // The Factory class returns handlers in the order they were added via |
| 32 // AddMockHandler. | 32 // AddMockHandler. |
| 33 class Factory : public HttpAuthHandlerFactory { | 33 class Factory : public HttpAuthHandlerFactory { |
| 34 public: | 34 public: |
| 35 Factory(); | 35 Factory(); |
| 36 ~Factory() override; | 36 ~Factory() override; |
| 37 | 37 |
| 38 void AddMockHandler(HttpAuthHandler* handler, HttpAuth::Target target); | 38 void AddMockHandler(HttpAuthHandler* handler, HttpAuth::Target target); |
| 39 | 39 |
| 40 bool HaveAuthHandlers(HttpAuth::Target) const; |
| 41 |
| 40 void set_do_init_from_challenge(bool do_init_from_challenge) { | 42 void set_do_init_from_challenge(bool do_init_from_challenge) { |
| 41 do_init_from_challenge_ = do_init_from_challenge; | 43 do_init_from_challenge_ = do_init_from_challenge; |
| 42 } | 44 } |
| 43 | 45 |
| 44 // HttpAuthHandlerFactory: | 46 // HttpAuthHandlerFactory: |
| 45 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, | 47 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, |
| 46 HttpAuth::Target target, | 48 HttpAuth::Target target, |
| 47 const GURL& origin, | 49 const GURL& origin, |
| 48 CreateReason reason, | 50 CreateReason reason, |
| 49 int nonce_count, | 51 int nonce_count, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 void SetResolveExpectation(Resolve resolve); | 64 void SetResolveExpectation(Resolve resolve); |
| 63 | 65 |
| 64 virtual bool NeedsCanonicalName(); | 66 virtual bool NeedsCanonicalName(); |
| 65 | 67 |
| 66 virtual int ResolveCanonicalName(HostResolver* host_resolver, | 68 virtual int ResolveCanonicalName(HostResolver* host_resolver, |
| 67 const CompletionCallback& callback); | 69 const CompletionCallback& callback); |
| 68 | 70 |
| 69 | 71 |
| 70 void SetGenerateExpectation(bool async, int rv); | 72 void SetGenerateExpectation(bool async, int rv); |
| 71 | 73 |
| 72 void set_connection_based(bool connection_based) { | 74 void set_expect_multiple_challenges(bool expect_multiple_challenges) { |
| 73 connection_based_ = connection_based; | 75 expect_multiple_challenges_ = expect_multiple_challenges; |
| 74 } | 76 } |
| 75 | 77 |
| 76 void set_allows_default_credentials(bool allows_default_credentials) { | 78 void set_allows_default_credentials(bool allows_default_credentials) { |
| 77 allows_default_credentials_ = allows_default_credentials; | 79 allows_default_credentials_ = allows_default_credentials; |
| 78 } | 80 } |
| 79 | 81 |
| 82 bool expect_multiple_challenges() const { |
| 83 return expect_multiple_challenges_; |
| 84 } |
| 85 |
| 80 void set_allows_explicit_credentials(bool allows_explicit_credentials) { | 86 void set_allows_explicit_credentials(bool allows_explicit_credentials) { |
| 81 allows_explicit_credentials_ = allows_explicit_credentials; | 87 allows_explicit_credentials_ = allows_explicit_credentials; |
| 82 } | 88 } |
| 83 | 89 |
| 84 const GURL& request_url() const { | 90 const GURL& request_url() const { |
| 85 return request_url_; | 91 return request_url_; |
| 86 } | 92 } |
| 87 | 93 |
| 88 // HttpAuthHandler: | 94 // HttpAuthHandler: |
| 89 HttpAuth::AuthorizationResult HandleAnotherChallenge( | 95 HttpAuth::AuthorizationResult HandleAnotherChallenge( |
| 90 HttpAuthChallengeTokenizer* challenge) override; | 96 HttpAuthChallengeTokenizer* challenge) override; |
| 91 bool NeedsIdentity() override; | 97 bool NeedsIdentity() override; |
| 92 bool AllowsDefaultCredentials() override; | 98 bool AllowsDefaultCredentials() override; |
| 93 bool AllowsExplicitCredentials() override; | 99 bool AllowsExplicitCredentials() override; |
| 94 | 100 |
| 95 protected: | 101 protected: |
| 96 bool Init(HttpAuthChallengeTokenizer* challenge) override; | 102 bool Init(HttpAuthChallengeTokenizer* challenge) override; |
| 97 | 103 |
| 98 int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 104 int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 99 const HttpRequestInfo* request, | 105 const HttpRequestInfo* request, |
| 100 const CompletionCallback& callback, | 106 const CompletionCallback& callback, |
| 101 std::string* auth_token) override; | 107 std::string* auth_token) override; |
| 102 | 108 |
| 103 private: | 109 private: |
| 104 void OnResolveCanonicalName(); | 110 void OnResolveCanonicalName(); |
| 105 | 111 |
| 106 void OnGenerateAuthToken(); | 112 void OnGenerateAuthToken(); |
| 107 | 113 |
| 108 Resolve resolve_; | 114 Resolve resolve_ = RESOLVE_INIT; |
| 109 CompletionCallback callback_; | 115 CompletionCallback callback_; |
| 110 bool generate_async_; | 116 bool generate_async_ = false; |
| 111 int generate_rv_; | 117 int generate_rv_; |
| 112 std::string* auth_token_; | 118 std::string* auth_token_ = nullptr; |
| 113 bool first_round_; | 119 bool first_round_ = true; |
| 114 bool connection_based_; | 120 bool allows_default_credentials_ = false; |
| 115 bool allows_default_credentials_; | 121 bool allows_explicit_credentials_ = true; |
| 116 bool allows_explicit_credentials_; | 122 bool expect_multiple_challenges_ = false; |
| 117 GURL request_url_; | 123 GURL request_url_; |
| 118 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; | 124 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; |
| 119 }; | 125 }; |
| 120 | 126 |
| 121 } // namespace net | 127 } // namespace net |
| 122 | 128 |
| 123 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 129 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
| OLD | NEW |