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 15 matching lines...) Expand all Loading... |
26 RESOLVE_SYNC, | 26 RESOLVE_SYNC, |
27 RESOLVE_ASYNC, | 27 RESOLVE_ASYNC, |
28 RESOLVE_TESTED, | 28 RESOLVE_TESTED, |
29 }; | 29 }; |
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 virtual ~Factory(); | 36 ~Factory() override; |
37 | 37 |
38 void AddMockHandler(HttpAuthHandler* handler, HttpAuth::Target target); | 38 void AddMockHandler(HttpAuthHandler* handler, HttpAuth::Target target); |
39 | 39 |
40 void set_do_init_from_challenge(bool do_init_from_challenge) { | 40 void set_do_init_from_challenge(bool do_init_from_challenge) { |
41 do_init_from_challenge_ = do_init_from_challenge; | 41 do_init_from_challenge_ = do_init_from_challenge; |
42 } | 42 } |
43 | 43 |
44 // HttpAuthHandlerFactory: | 44 // HttpAuthHandlerFactory: |
45 virtual int CreateAuthHandler( | 45 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, |
46 HttpAuthChallengeTokenizer* challenge, | 46 HttpAuth::Target target, |
47 HttpAuth::Target target, | 47 const GURL& origin, |
48 const GURL& origin, | 48 CreateReason reason, |
49 CreateReason reason, | 49 int nonce_count, |
50 int nonce_count, | 50 const BoundNetLog& net_log, |
51 const BoundNetLog& net_log, | 51 scoped_ptr<HttpAuthHandler>* handler) override; |
52 scoped_ptr<HttpAuthHandler>* handler) override; | |
53 | 52 |
54 private: | 53 private: |
55 ScopedVector<HttpAuthHandler> handlers_[HttpAuth::AUTH_NUM_TARGETS]; | 54 ScopedVector<HttpAuthHandler> handlers_[HttpAuth::AUTH_NUM_TARGETS]; |
56 bool do_init_from_challenge_; | 55 bool do_init_from_challenge_; |
57 }; | 56 }; |
58 | 57 |
59 HttpAuthHandlerMock(); | 58 HttpAuthHandlerMock(); |
60 | 59 |
61 virtual ~HttpAuthHandlerMock(); | 60 ~HttpAuthHandlerMock() override; |
62 | 61 |
63 void SetResolveExpectation(Resolve resolve); | 62 void SetResolveExpectation(Resolve resolve); |
64 | 63 |
65 virtual bool NeedsCanonicalName(); | 64 virtual bool NeedsCanonicalName(); |
66 | 65 |
67 virtual int ResolveCanonicalName(HostResolver* host_resolver, | 66 virtual int ResolveCanonicalName(HostResolver* host_resolver, |
68 const CompletionCallback& callback); | 67 const CompletionCallback& callback); |
69 | 68 |
70 | 69 |
71 void SetGenerateExpectation(bool async, int rv); | 70 void SetGenerateExpectation(bool async, int rv); |
72 | 71 |
73 void set_connection_based(bool connection_based) { | 72 void set_connection_based(bool connection_based) { |
74 connection_based_ = connection_based; | 73 connection_based_ = connection_based; |
75 } | 74 } |
76 | 75 |
77 void set_allows_default_credentials(bool allows_default_credentials) { | 76 void set_allows_default_credentials(bool allows_default_credentials) { |
78 allows_default_credentials_ = allows_default_credentials; | 77 allows_default_credentials_ = allows_default_credentials; |
79 } | 78 } |
80 | 79 |
81 void set_allows_explicit_credentials(bool allows_explicit_credentials) { | 80 void set_allows_explicit_credentials(bool allows_explicit_credentials) { |
82 allows_explicit_credentials_ = allows_explicit_credentials; | 81 allows_explicit_credentials_ = allows_explicit_credentials; |
83 } | 82 } |
84 | 83 |
85 const GURL& request_url() const { | 84 const GURL& request_url() const { |
86 return request_url_; | 85 return request_url_; |
87 } | 86 } |
88 | 87 |
89 // HttpAuthHandler: | 88 // HttpAuthHandler: |
90 virtual HttpAuth::AuthorizationResult HandleAnotherChallenge( | 89 HttpAuth::AuthorizationResult HandleAnotherChallenge( |
91 HttpAuthChallengeTokenizer* challenge) override; | 90 HttpAuthChallengeTokenizer* challenge) override; |
92 virtual bool NeedsIdentity() override; | 91 bool NeedsIdentity() override; |
93 virtual bool AllowsDefaultCredentials() override; | 92 bool AllowsDefaultCredentials() override; |
94 virtual bool AllowsExplicitCredentials() override; | 93 bool AllowsExplicitCredentials() override; |
95 | 94 |
96 protected: | 95 protected: |
97 virtual bool Init(HttpAuthChallengeTokenizer* challenge) override; | 96 bool Init(HttpAuthChallengeTokenizer* challenge) override; |
98 | 97 |
99 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, | 98 int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
100 const HttpRequestInfo* request, | 99 const HttpRequestInfo* request, |
101 const CompletionCallback& callback, | 100 const CompletionCallback& callback, |
102 std::string* auth_token) override; | 101 std::string* auth_token) override; |
103 | 102 |
104 private: | 103 private: |
105 void OnResolveCanonicalName(); | 104 void OnResolveCanonicalName(); |
106 | 105 |
107 void OnGenerateAuthToken(); | 106 void OnGenerateAuthToken(); |
108 | 107 |
109 Resolve resolve_; | 108 Resolve resolve_; |
110 CompletionCallback callback_; | 109 CompletionCallback callback_; |
111 bool generate_async_; | 110 bool generate_async_; |
112 int generate_rv_; | 111 int generate_rv_; |
113 std::string* auth_token_; | 112 std::string* auth_token_; |
114 bool first_round_; | 113 bool first_round_; |
115 bool connection_based_; | 114 bool connection_based_; |
116 bool allows_default_credentials_; | 115 bool allows_default_credentials_; |
117 bool allows_explicit_credentials_; | 116 bool allows_explicit_credentials_; |
118 GURL request_url_; | 117 GURL request_url_; |
119 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; | 118 base::WeakPtrFactory<HttpAuthHandlerMock> weak_factory_; |
120 }; | 119 }; |
121 | 120 |
122 } // namespace net | 121 } // namespace net |
123 | 122 |
124 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 123 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
OLD | NEW |