OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 class HttpAuthHandlerMock : public HttpAuthHandler { | 22 class HttpAuthHandlerMock : public HttpAuthHandler { |
23 public: | 23 public: |
24 enum Resolve { | 24 enum Resolve { |
25 RESOLVE_INIT, | 25 RESOLVE_INIT, |
26 RESOLVE_SKIP, | 26 RESOLVE_SKIP, |
27 RESOLVE_SYNC, | 27 RESOLVE_SYNC, |
28 RESOLVE_ASYNC, | 28 RESOLVE_ASYNC, |
29 RESOLVE_TESTED, | 29 RESOLVE_TESTED, |
30 }; | 30 }; |
31 | 31 |
32 HttpAuthHandlerMock(); | |
33 | |
34 virtual ~HttpAuthHandlerMock(); | |
35 | |
36 void SetResolveExpectation(Resolve resolve); | |
37 | |
38 virtual bool NeedsCanonicalName(); | |
39 | |
40 virtual int ResolveCanonicalName(HostResolver* host_resolver, | |
41 CompletionCallback* callback); | |
42 | |
43 virtual bool NeedsIdentity() { return first_round_; } | |
44 | |
45 void SetGenerateExpectation(bool async, int rv); | |
46 | |
47 void set_connection_based(bool connection_based) { | |
48 connection_based_ = connection_based; | |
49 } | |
50 | |
51 const GURL& request_url() const { | |
52 return request_url_; | |
53 } | |
54 | |
55 HttpAuth::AuthorizationResult HandleAnotherChallenge( | |
56 HttpAuth::ChallengeTokenizer* challenge); | |
57 | |
58 // The Factory class simply returns the same handler each time | 32 // The Factory class simply returns the same handler each time |
59 // CreateAuthHandler is called. | 33 // CreateAuthHandler is called. |
60 class Factory : public HttpAuthHandlerFactory { | 34 class Factory : public HttpAuthHandlerFactory { |
61 public: | 35 public: |
62 Factory(); | 36 Factory(); |
63 virtual ~Factory(); | 37 virtual ~Factory(); |
64 | 38 |
65 void set_mock_handler(HttpAuthHandler* handler, HttpAuth::Target target); | 39 void set_mock_handler(HttpAuthHandler* handler, HttpAuth::Target target); |
66 | 40 |
67 void set_do_init_from_challenge(bool do_init_from_challenge) { | 41 void set_do_init_from_challenge(bool do_init_from_challenge) { |
68 do_init_from_challenge_ = do_init_from_challenge; | 42 do_init_from_challenge_ = do_init_from_challenge; |
69 } | 43 } |
70 | 44 |
| 45 // HttpAuthHandlerFactory: |
71 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, | 46 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, |
72 HttpAuth::Target target, | 47 HttpAuth::Target target, |
73 const GURL& origin, | 48 const GURL& origin, |
74 CreateReason reason, | 49 CreateReason reason, |
75 int nonce_count, | 50 int nonce_count, |
76 const BoundNetLog& net_log, | 51 const BoundNetLog& net_log, |
77 scoped_ptr<HttpAuthHandler>* handler); | 52 scoped_ptr<HttpAuthHandler>* handler); |
78 | 53 |
79 private: | 54 private: |
80 scoped_ptr<HttpAuthHandler> handlers_[HttpAuth::AUTH_NUM_TARGETS]; | 55 scoped_ptr<HttpAuthHandler> handlers_[HttpAuth::AUTH_NUM_TARGETS]; |
81 bool do_init_from_challenge_; | 56 bool do_init_from_challenge_; |
82 }; | 57 }; |
83 | 58 |
| 59 HttpAuthHandlerMock(); |
| 60 |
| 61 virtual ~HttpAuthHandlerMock(); |
| 62 |
| 63 void SetResolveExpectation(Resolve resolve); |
| 64 |
| 65 virtual bool NeedsCanonicalName(); |
| 66 |
| 67 virtual int ResolveCanonicalName(HostResolver* host_resolver, |
| 68 CompletionCallback* callback); |
| 69 |
| 70 |
| 71 void SetGenerateExpectation(bool async, int rv); |
| 72 |
| 73 void set_connection_based(bool connection_based) { |
| 74 connection_based_ = connection_based; |
| 75 } |
| 76 |
| 77 const GURL& request_url() const { |
| 78 return request_url_; |
| 79 } |
| 80 |
| 81 // HttpAuthHandler: |
| 82 virtual HttpAuth::AuthorizationResult HandleAnotherChallenge( |
| 83 HttpAuth::ChallengeTokenizer* challenge); |
| 84 virtual bool NeedsIdentity(); |
| 85 |
84 protected: | 86 protected: |
85 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); | 87 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); |
86 | 88 |
87 virtual int GenerateAuthTokenImpl(const string16* username, | 89 virtual int GenerateAuthTokenImpl(const string16* username, |
88 const string16* password, | 90 const string16* password, |
89 const HttpRequestInfo* request, | 91 const HttpRequestInfo* request, |
90 CompletionCallback* callback, | 92 CompletionCallback* callback, |
91 std::string* auth_token); | 93 std::string* auth_token); |
92 | 94 |
93 private: | 95 private: |
94 void OnResolveCanonicalName(); | 96 void OnResolveCanonicalName(); |
95 | 97 |
96 void OnGenerateAuthToken(); | 98 void OnGenerateAuthToken(); |
97 | 99 |
98 Resolve resolve_; | 100 Resolve resolve_; |
99 CompletionCallback* user_callback_; | 101 CompletionCallback* user_callback_; |
100 ScopedRunnableMethodFactory<HttpAuthHandlerMock> method_factory_; | 102 ScopedRunnableMethodFactory<HttpAuthHandlerMock> method_factory_; |
101 bool generate_async_; | 103 bool generate_async_; |
102 int generate_rv_; | 104 int generate_rv_; |
103 std::string* auth_token_; | 105 std::string* auth_token_; |
104 bool first_round_; | 106 bool first_round_; |
105 bool connection_based_; | 107 bool connection_based_; |
106 GURL request_url_; | 108 GURL request_url_; |
107 }; | 109 }; |
108 | 110 |
109 } // namespace net | 111 } // namespace net |
110 | 112 |
111 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ | 113 #endif // NET_HTTP_HTTP_AUTH_HANDLER_MOCK_H_ |
OLD | NEW |