Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: net/http/http_auth_controller_unittest.cc

Issue 8990001: base::Bind: Convert most of net/http. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "net/http/http_auth_controller.h" 5 #include "net/http/http_auth_controller.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "net/base/net_log.h" 9 #include "net/base/net_log.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 scoped_refptr<HttpAuthController> controller( 70 scoped_refptr<HttpAuthController> controller(
71 new HttpAuthController(HttpAuth::AUTH_PROXY, 71 new HttpAuthController(HttpAuth::AUTH_PROXY,
72 GURL("http://example.com"), 72 GURL("http://example.com"),
73 &dummy_auth_cache, &auth_handler_factory)); 73 &dummy_auth_cache, &auth_handler_factory));
74 ASSERT_EQ(OK, 74 ASSERT_EQ(OK,
75 controller->HandleAuthChallenge(headers, false, false, dummy_log)); 75 controller->HandleAuthChallenge(headers, false, false, dummy_log));
76 ASSERT_TRUE(controller->HaveAuthHandler()); 76 ASSERT_TRUE(controller->HaveAuthHandler());
77 controller->ResetAuth(AuthCredentials()); 77 controller->ResetAuth(AuthCredentials());
78 EXPECT_TRUE(controller->HaveAuth()); 78 EXPECT_TRUE(controller->HaveAuth());
79 79
80 TestOldCompletionCallback callback; 80 TestCompletionCallback callback;
81 EXPECT_EQ((run_mode == RUN_HANDLER_ASYNC)? ERR_IO_PENDING: 81 EXPECT_EQ((run_mode == RUN_HANDLER_ASYNC)? ERR_IO_PENDING:
82 expected_controller_rv, 82 expected_controller_rv,
83 controller->MaybeGenerateAuthToken(&request, &callback, 83 controller->MaybeGenerateAuthToken(&request, callback.callback(),
84 dummy_log)); 84 dummy_log));
85 if (run_mode == RUN_HANDLER_ASYNC) 85 if (run_mode == RUN_HANDLER_ASYNC)
86 EXPECT_EQ(expected_controller_rv, callback.WaitForResult()); 86 EXPECT_EQ(expected_controller_rv, callback.WaitForResult());
87 EXPECT_EQ((scheme_state == SCHEME_IS_DISABLED), 87 EXPECT_EQ((scheme_state == SCHEME_IS_DISABLED),
88 controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK)); 88 controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK));
89 } 89 }
90 90
91 } // namespace 91 } // namespace
92 92
93 // If an HttpAuthHandler returns an error code that indicates a 93 // If an HttpAuthHandler returns an error code that indicates a
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC; 137 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC;
138 --score_; // Reduce score, so we rank below Mock. 138 --score_; // Reduce score, so we rank below Mock.
139 set_allows_explicit_credentials(true); 139 set_allows_explicit_credentials(true);
140 } 140 }
141 EXPECT_EQ(expected_scheme_, auth_scheme_); 141 EXPECT_EQ(expected_scheme_, auth_scheme_);
142 return true; 142 return true;
143 } 143 }
144 144
145 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials, 145 virtual int GenerateAuthTokenImpl(const AuthCredentials* credentials,
146 const HttpRequestInfo* request, 146 const HttpRequestInfo* request,
147 OldCompletionCallback* callback, 147 const CompletionCallback& callback,
148 std::string* auth_token) OVERRIDE { 148 std::string* auth_token) OVERRIDE {
149 int result = 149 int result =
150 HttpAuthHandlerMock::GenerateAuthTokenImpl(credentials, 150 HttpAuthHandlerMock::GenerateAuthTokenImpl(credentials,
151 request, callback, 151 request, callback,
152 auth_token); 152 auth_token);
153 EXPECT_TRUE(result != OK || 153 EXPECT_TRUE(result != OK ||
154 !AllowsExplicitCredentials() || 154 !AllowsExplicitCredentials() ||
155 !credentials->Empty()); 155 !credentials->Empty());
156 return result; 156 return result;
157 } 157 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 new HttpAuthController(HttpAuth::AUTH_SERVER, 208 new HttpAuthController(HttpAuth::AUTH_SERVER,
209 GURL("http://example.com"), 209 GURL("http://example.com"),
210 &dummy_auth_cache, &auth_handler_factory)); 210 &dummy_auth_cache, &auth_handler_factory));
211 ASSERT_EQ(OK, 211 ASSERT_EQ(OK,
212 controller->HandleAuthChallenge(headers, false, false, dummy_log)); 212 controller->HandleAuthChallenge(headers, false, false, dummy_log));
213 ASSERT_TRUE(controller->HaveAuthHandler()); 213 ASSERT_TRUE(controller->HaveAuthHandler());
214 controller->ResetAuth(AuthCredentials()); 214 controller->ResetAuth(AuthCredentials());
215 EXPECT_TRUE(controller->HaveAuth()); 215 EXPECT_TRUE(controller->HaveAuth());
216 216
217 // Should only succeed if we are using the AUTH_SCHEME_MOCK MockHandler. 217 // Should only succeed if we are using the AUTH_SCHEME_MOCK MockHandler.
218 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log)); 218 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(
219 &request, CompletionCallback(), dummy_log));
219 controller->AddAuthorizationHeader(&request_headers); 220 controller->AddAuthorizationHeader(&request_headers);
220 221
221 // Once a token is generated, simulate the receipt of a server response 222 // Once a token is generated, simulate the receipt of a server response
222 // indicating that the authentication attempt was rejected. 223 // indicating that the authentication attempt was rejected.
223 ASSERT_EQ(OK, 224 ASSERT_EQ(OK,
224 controller->HandleAuthChallenge(headers, false, false, dummy_log)); 225 controller->HandleAuthChallenge(headers, false, false, dummy_log));
225 ASSERT_TRUE(controller->HaveAuthHandler()); 226 ASSERT_TRUE(controller->HaveAuthHandler());
226 controller->ResetAuth(AuthCredentials(ASCIIToUTF16("Hello"), string16())); 227 controller->ResetAuth(AuthCredentials(ASCIIToUTF16("Hello"), string16()));
227 EXPECT_TRUE(controller->HaveAuth()); 228 EXPECT_TRUE(controller->HaveAuth());
228 EXPECT_TRUE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK)); 229 EXPECT_TRUE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_MOCK));
229 EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC)); 230 EXPECT_FALSE(controller->IsAuthSchemeDisabled(HttpAuth::AUTH_SCHEME_BASIC));
230 231
231 // Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler. 232 // Should only succeed if we are using the AUTH_SCHEME_BASIC MockHandler.
232 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(&request, NULL, dummy_log)); 233 EXPECT_EQ(OK, controller->MaybeGenerateAuthToken(
234 &request, CompletionCallback(), dummy_log));
233 } 235 }
234 236
235 } // namespace net 237 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698