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 <memory> | 8 #include <memory> |
| 9 #include <ostream> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "net/http/http_auth_handler.h" | 14 #include "net/http/http_auth_handler.h" |
14 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 class HostResolver; | 20 class HostResolver; |
20 | 21 |
21 // MockAuthHandler is used in tests to reliably trigger edge cases. | 22 // MockAuthHandler is used in tests to reliably trigger edge cases. |
22 class HttpAuthHandlerMock : public HttpAuthHandler { | 23 class HttpAuthHandlerMock : public HttpAuthHandler { |
23 public: | 24 public: |
| 25 enum class State { |
| 26 WAIT_FOR_INIT, |
| 27 WAIT_FOR_CHALLENGE, |
| 28 WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 29 TOKEN_PENDING, |
| 30 DONE |
| 31 }; |
| 32 |
24 enum Resolve { | 33 enum Resolve { |
25 RESOLVE_INIT, | 34 RESOLVE_INIT, |
26 RESOLVE_SKIP, | 35 RESOLVE_SKIP, |
27 RESOLVE_SYNC, | 36 RESOLVE_SYNC, |
28 RESOLVE_ASYNC, | 37 RESOLVE_ASYNC, |
29 RESOLVE_TESTED, | 38 RESOLVE_TESTED, |
30 }; | 39 }; |
31 | 40 |
32 // The Factory class returns handlers in the order they were added via | 41 // The Factory class returns handlers in the order they were added via |
33 // AddMockHandler. | 42 // AddMockHandler. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 90 } |
82 | 91 |
83 void set_allows_explicit_credentials(bool allows_explicit_credentials) { | 92 void set_allows_explicit_credentials(bool allows_explicit_credentials) { |
84 allows_explicit_credentials_ = allows_explicit_credentials; | 93 allows_explicit_credentials_ = allows_explicit_credentials; |
85 } | 94 } |
86 | 95 |
87 const GURL& request_url() const { | 96 const GURL& request_url() const { |
88 return request_url_; | 97 return request_url_; |
89 } | 98 } |
90 | 99 |
| 100 State state() const { return state_; } |
| 101 |
91 // HttpAuthHandler: | 102 // HttpAuthHandler: |
92 HttpAuth::AuthorizationResult HandleAnotherChallenge( | 103 HttpAuth::AuthorizationResult HandleAnotherChallenge( |
93 HttpAuthChallengeTokenizer* challenge) override; | 104 HttpAuthChallengeTokenizer* challenge) override; |
94 bool NeedsIdentity() override; | 105 bool NeedsIdentity() override; |
95 bool AllowsDefaultCredentials() override; | 106 bool AllowsDefaultCredentials() override; |
96 bool AllowsExplicitCredentials() override; | 107 bool AllowsExplicitCredentials() override; |
97 | 108 |
98 protected: | 109 protected: |
99 bool Init(HttpAuthChallengeTokenizer* challenge, | 110 bool Init(HttpAuthChallengeTokenizer* challenge, |
100 const SSLInfo& ssl_info) override; | 111 const SSLInfo& ssl_info) override; |
101 | 112 |
102 int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 113 int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
103 const HttpRequestInfo* request, | 114 const HttpRequestInfo* request, |
104 const CompletionCallback& callback, | 115 const CompletionCallback& callback, |
105 std::string* auth_token) override; | 116 std::string* auth_token) override; |
106 | 117 |
107 private: | 118 private: |
108 void OnResolveCanonicalName(); | 119 void OnResolveCanonicalName(); |
109 | 120 |
110 void OnGenerateAuthToken(); | 121 void OnGenerateAuthToken(); |
111 | 122 |
| 123 State state_; |
112 Resolve resolve_; | 124 Resolve resolve_; |
113 CompletionCallback callback_; | 125 CompletionCallback callback_; |
114 bool generate_async_; | 126 bool generate_async_; |
115 int generate_rv_; | 127 int generate_rv_; |
116 std::string* auth_token_; | 128 std::string* auth_token_; |
117 bool first_round_; | 129 bool first_round_; |
118 bool connection_based_; | 130 bool connection_based_; |
119 bool allows_default_credentials_; | 131 bool allows_default_credentials_; |
120 bool allows_explicit_credentials_; | 132 bool allows_explicit_credentials_; |
121 GURL request_url_; | 133 GURL request_url_; |
122 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; | 134 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; |
123 }; | 135 }; |
124 | 136 |
| 137 void PrintTo(const HttpAuthHandlerMock::State& state, ::std::ostream* os); |
| 138 |
125 } // namespace net | 139 } // namespace net |
126 | 140 |
127 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 141 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
OLD | NEW |