| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 public: | 26 public: |
| 27 // 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 |
| 28 // AddMockHandler. | 28 // AddMockHandler. |
| 29 class Factory : public HttpAuthHandlerFactory { | 29 class Factory : public HttpAuthHandlerFactory { |
| 30 public: | 30 public: |
| 31 Factory(); | 31 Factory(); |
| 32 ~Factory() override; | 32 ~Factory() override; |
| 33 | 33 |
| 34 void AddMockHandler(scoped_ptr<HttpAuthHandler> handler, | 34 void AddMockHandler(scoped_ptr<HttpAuthHandler> handler, |
| 35 HttpAuthHandlerCreateReason reason); | 35 HttpAuthHandlerCreateReason reason); |
| 36 | |
| 37 bool HaveAuthHandlers() const; | 36 bool HaveAuthHandlers() const; |
| 38 | 37 |
| 39 // HttpAuthHandlerFactory: | 38 // HttpAuthHandlerFactory: |
| 40 scoped_ptr<HttpAuthHandler> CreateAuthHandlerForScheme( | 39 scoped_ptr<HttpAuthHandler> CreateAuthHandlerForScheme( |
| 41 const std::string& scheme) override; | 40 const std::string& scheme) override; |
| 42 scoped_ptr<HttpAuthHandler> CreateAndInitPreemptiveAuthHandler( | 41 scoped_ptr<HttpAuthHandler> CreateAndInitPreemptiveAuthHandler( |
| 43 HttpAuthCache::Entry* cache_entry, | 42 HttpAuthCache::Entry* cache_entry, |
| 44 const HttpAuthChallengeTokenizer& tokenizer, | |
| 45 HttpAuth::Target target, | 43 HttpAuth::Target target, |
| 46 const BoundNetLog& net_log) override; | 44 const BoundNetLog& net_log) override; |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 scoped_ptr<HttpAuthHandler> GetNextAuthHandler( | 47 scoped_ptr<HttpAuthHandler> GetNextAuthHandler( |
| 50 ScopedVector<HttpAuthHandler>* handler_list); | 48 ScopedVector<HttpAuthHandler>* handler_list); |
| 51 ScopedVector<HttpAuthHandler> challenge_handlers_; | 49 ScopedVector<HttpAuthHandler> challenge_handlers_; |
| 52 ScopedVector<HttpAuthHandler> preemptive_handlers_; | 50 ScopedVector<HttpAuthHandler> preemptive_handlers_; |
| 53 }; | 51 }; |
| 54 | 52 |
| 55 HttpAuthHandlerMock(); | 53 HttpAuthHandlerMock(); |
| 56 | 54 |
| 57 ~HttpAuthHandlerMock() override; | 55 ~HttpAuthHandlerMock() override; |
| 58 | 56 |
| 57 void SetInitExpectation(bool async, int rv); |
| 59 void SetGenerateExpectation(bool async, int rv); | 58 void SetGenerateExpectation(bool async, int rv); |
| 60 | 59 |
| 61 void set_expected_auth_scheme(const std::string& scheme) { | 60 void set_expected_auth_scheme(const std::string& scheme) { |
| 62 auth_scheme_ = scheme; | 61 auth_scheme_ = scheme; |
| 63 } | 62 } |
| 64 | 63 |
| 65 void set_expected_auth_target(HttpAuth::Target target) { | 64 void set_expected_auth_target(HttpAuth::Target target) { |
| 66 expected_auth_target_ = target; | 65 expected_auth_target_ = target; |
| 67 } | 66 } |
| 68 | 67 |
| 69 void set_expect_multiple_challenges(bool expect_multiple_challenges) { | 68 void set_expect_multiple_challenges(bool expect_multiple_challenges) { |
| 70 expect_multiple_challenges_ = expect_multiple_challenges; | 69 expect_multiple_challenges_ = expect_multiple_challenges; |
| 71 } | 70 } |
| 72 | 71 |
| 73 void set_allows_default_credentials(bool allows_default_credentials) { | 72 void set_allows_default_credentials(bool allows_default_credentials) { |
| 74 allows_default_credentials_ = allows_default_credentials; | 73 allows_default_credentials_ = allows_default_credentials; |
| 75 } | 74 } |
| 76 | 75 |
| 77 void set_allows_explicit_credentials(bool allows_explicit_credentials) { | 76 void set_allows_explicit_credentials(bool allows_explicit_credentials) { |
| 78 allows_explicit_credentials_ = allows_explicit_credentials; | 77 allows_explicit_credentials_ = allows_explicit_credentials; |
| 79 } | 78 } |
| 80 | 79 |
| 81 void set_auth_token(const std::string& auth_token) { | |
| 82 auth_token_ = auth_token; | |
| 83 } | |
| 84 | |
| 85 const GURL& request_url() const { | 80 const GURL& request_url() const { |
| 86 return request_url_; | 81 return request_url_; |
| 87 } | 82 } |
| 88 | 83 |
| 89 // HttpAuthHandler: | 84 // HttpAuthHandler: |
| 90 HttpAuth::AuthorizationResult HandleAnotherChallenge( | 85 HttpAuth::AuthorizationResult HandleAnotherChallenge( |
| 91 const HttpAuthChallengeTokenizer& challenge) override; | 86 const HttpAuthChallengeTokenizer& challenge) override; |
| 92 bool NeedsIdentity() override; | 87 bool NeedsIdentity() override; |
| 93 bool AllowsDefaultCredentials() override; | 88 bool AllowsDefaultCredentials() override; |
| 94 bool AllowsExplicitCredentials() override; | 89 bool AllowsExplicitCredentials() override; |
| 95 | 90 |
| 96 protected: | 91 protected: |
| 97 int Init(const HttpAuthChallengeTokenizer& challenge) override; | 92 // HttpAuthHandler |
| 98 | 93 int InitializeFromChallengeInternal( |
| 94 const HttpAuthChallengeTokenizer& challenge, |
| 95 const HttpResponseInfo& response_with_challenge, |
| 96 const CompletionCallback& callback) override; |
| 97 int InitializeFromCacheEntryInternal( |
| 98 HttpAuthCache::Entry* cache_entry) override; |
| 99 int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 99 int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 100 const HttpRequestInfo& request, | 100 const HttpRequestInfo& request, |
| 101 const CompletionCallback& callback, | 101 const CompletionCallback& callback, |
| 102 std::string* auth_token) override; | 102 std::string* auth_token) override; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 void OnGenerateAuthToken(); | 105 void OnInitializeComplete(); |
| 106 void OnGenerateAuthTokenComplete(); |
| 106 | 107 |
| 107 CompletionCallback callback_; | 108 CompletionCallback callback_; |
| 109 bool init_async_ = false; |
| 110 int init_rv_ = 0; |
| 108 bool generate_async_ = false; | 111 bool generate_async_ = false; |
| 109 int generate_rv_ = 0; | 112 int generate_rv_ = 0; |
| 110 std::string auth_token_; | 113 std::string auth_token_; |
| 111 std::string* generate_auth_token_buffer_ = nullptr; | 114 std::string* generate_auth_token_buffer_ = nullptr; |
| 112 bool first_round_ = true; | 115 bool first_round_ = true; |
| 113 bool allows_default_credentials_ = false; | 116 bool allows_default_credentials_ = false; |
| 114 bool allows_explicit_credentials_ = true; | 117 bool allows_explicit_credentials_ = true; |
| 115 bool expect_multiple_challenges_ = false; | 118 bool expect_multiple_challenges_ = false; |
| 119 bool initialized_ = false; |
| 120 bool initialization_succeeded = false; |
| 116 HttpAuth::Target expected_auth_target_ = HttpAuth::AUTH_SERVER; | 121 HttpAuth::Target expected_auth_target_ = HttpAuth::AUTH_SERVER; |
| 117 GURL request_url_; | 122 GURL request_url_; |
| 118 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; | 123 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; |
| 119 }; | 124 }; |
| 120 | 125 |
| 121 } // namespace net | 126 } // namespace net |
| 122 | 127 |
| 123 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 128 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
| OLD | NEW |