OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/url_request/url_request_context_builder.h" | 5 #include "net/url_request/url_request_context_builder.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 MockHttpAuthHandlerFactory(std::string supported_scheme, int return_code) | 34 MockHttpAuthHandlerFactory(std::string supported_scheme, int return_code) |
35 : return_code_(return_code), supported_scheme_(supported_scheme) {} | 35 : return_code_(return_code), supported_scheme_(supported_scheme) {} |
36 ~MockHttpAuthHandlerFactory() override {} | 36 ~MockHttpAuthHandlerFactory() override {} |
37 | 37 |
38 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, | 38 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, |
39 HttpAuth::Target target, | 39 HttpAuth::Target target, |
40 const SSLInfo& ssl_info, | 40 const SSLInfo& ssl_info, |
41 const GURL& origin, | 41 const GURL& origin, |
42 CreateReason reason, | 42 CreateReason reason, |
43 int nonce_count, | 43 int nonce_count, |
44 const BoundNetLog& net_log, | 44 const NetLogWithSource& net_log, |
45 std::unique_ptr<HttpAuthHandler>* handler) override { | 45 std::unique_ptr<HttpAuthHandler>* handler) override { |
46 handler->reset(); | 46 handler->reset(); |
47 | 47 |
48 return challenge->scheme() == supported_scheme_ | 48 return challenge->scheme() == supported_scheme_ |
49 ? return_code_ | 49 ? return_code_ |
50 : ERR_UNSUPPORTED_AUTH_SCHEME; | 50 : ERR_UNSUPPORTED_AUTH_SCHEME; |
51 } | 51 } |
52 | 52 |
53 private: | 53 private: |
54 int return_code_; | 54 int return_code_; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 TEST_F(URLRequestContextBuilderTest, DefaultHttpAuthHandlerFactory) { | 102 TEST_F(URLRequestContextBuilderTest, DefaultHttpAuthHandlerFactory) { |
103 GURL gurl("www.google.com"); | 103 GURL gurl("www.google.com"); |
104 std::unique_ptr<HttpAuthHandler> handler; | 104 std::unique_ptr<HttpAuthHandler> handler; |
105 std::unique_ptr<URLRequestContext> context(builder_.Build()); | 105 std::unique_ptr<URLRequestContext> context(builder_.Build()); |
106 SSLInfo null_ssl_info; | 106 SSLInfo null_ssl_info; |
107 | 107 |
108 // Verify that the default basic handler is present | 108 // Verify that the default basic handler is present |
109 EXPECT_EQ(OK, | 109 EXPECT_EQ(OK, |
110 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 110 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
111 "basic", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, | 111 "basic", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, |
112 BoundNetLog(), &handler)); | 112 NetLogWithSource(), &handler)); |
113 } | 113 } |
114 | 114 |
115 TEST_F(URLRequestContextBuilderTest, CustomHttpAuthHandlerFactory) { | 115 TEST_F(URLRequestContextBuilderTest, CustomHttpAuthHandlerFactory) { |
116 GURL gurl("www.google.com"); | 116 GURL gurl("www.google.com"); |
117 const int kBasicReturnCode = OK; | 117 const int kBasicReturnCode = OK; |
118 std::unique_ptr<HttpAuthHandler> handler; | 118 std::unique_ptr<HttpAuthHandler> handler; |
119 builder_.SetHttpAuthHandlerFactory( | 119 builder_.SetHttpAuthHandlerFactory( |
120 base::MakeUnique<MockHttpAuthHandlerFactory>("ExtraScheme", | 120 base::MakeUnique<MockHttpAuthHandlerFactory>("ExtraScheme", |
121 kBasicReturnCode)); | 121 kBasicReturnCode)); |
122 std::unique_ptr<URLRequestContext> context(builder_.Build()); | 122 std::unique_ptr<URLRequestContext> context(builder_.Build()); |
123 SSLInfo null_ssl_info; | 123 SSLInfo null_ssl_info; |
124 // Verify that a handler is returned for a custom scheme. | 124 // Verify that a handler is returned for a custom scheme. |
125 EXPECT_EQ(kBasicReturnCode, | 125 EXPECT_EQ(kBasicReturnCode, |
126 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 126 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
127 "ExtraScheme", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, | 127 "ExtraScheme", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, |
128 BoundNetLog(), &handler)); | 128 NetLogWithSource(), &handler)); |
129 | 129 |
130 // Verify that the default basic handler isn't present | 130 // Verify that the default basic handler isn't present |
131 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, | 131 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, |
132 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 132 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
133 "basic", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, | 133 "basic", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, |
134 BoundNetLog(), &handler)); | 134 NetLogWithSource(), &handler)); |
135 | 135 |
136 // Verify that a handler isn't returned for a bogus scheme. | 136 // Verify that a handler isn't returned for a bogus scheme. |
137 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, | 137 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, |
138 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 138 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
139 "Bogus", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, | 139 "Bogus", HttpAuth::AUTH_SERVER, null_ssl_info, gurl, |
140 BoundNetLog(), &handler)); | 140 NetLogWithSource(), &handler)); |
141 } | 141 } |
142 | 142 |
143 } // namespace | 143 } // namespace |
144 | 144 |
145 } // namespace net | 145 } // namespace net |
OLD | NEW |