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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 months 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
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_handler_basic.h" 5 #include "net/http/http_auth_handler_basic.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
14 #include "net/http/http_auth_challenge_tokenizer.h" 14 #include "net/http/http_auth_challenge_tokenizer.h"
15 #include "net/http/http_request_info.h" 15 #include "net/http/http_request_info.h"
16 #include "net/ssl/ssl_info.h" 16 #include "net/ssl/ssl_info.h"
17 #include "net/test/gtest_util.h"
18 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
21 using net::test::IsOk;
22
19 namespace net { 23 namespace net {
20 24
21 TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { 25 TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) {
22 static const struct { 26 static const struct {
23 const char* username; 27 const char* username;
24 const char* password; 28 const char* password;
25 const char* expected_credentials; 29 const char* expected_credentials;
26 } tests[] = { 30 } tests[] = {
27 { "foo", "bar", "Basic Zm9vOmJhcg==" }, 31 { "foo", "bar", "Basic Zm9vOmJhcg==" },
28 // Empty username 32 // Empty username
(...skipping 12 matching lines...) Expand all
41 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( 45 EXPECT_EQ(OK, factory.CreateAuthHandlerFromString(
42 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, 46 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin,
43 BoundNetLog(), &basic)); 47 BoundNetLog(), &basic));
44 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), 48 AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username),
45 base::ASCIIToUTF16(tests[i].password)); 49 base::ASCIIToUTF16(tests[i].password));
46 HttpRequestInfo request_info; 50 HttpRequestInfo request_info;
47 std::string auth_token; 51 std::string auth_token;
48 TestCompletionCallback callback; 52 TestCompletionCallback callback;
49 int rv = basic->GenerateAuthToken(&credentials, &request_info, 53 int rv = basic->GenerateAuthToken(&credentials, &request_info,
50 callback.callback(), &auth_token); 54 callback.callback(), &auth_token);
51 EXPECT_EQ(OK, rv); 55 EXPECT_THAT(rv, IsOk());
52 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str()); 56 EXPECT_STREQ(tests[i].expected_credentials, auth_token.c_str());
53 } 57 }
54 } 58 }
55 59
56 TEST(HttpAuthHandlerBasicTest, HandleAnotherChallenge) { 60 TEST(HttpAuthHandlerBasicTest, HandleAnotherChallenge) {
57 static const struct { 61 static const struct {
58 const char* challenge; 62 const char* challenge;
59 HttpAuth::AuthorizationResult expected_rv; 63 HttpAuth::AuthorizationResult expected_rv;
60 } tests[] = { 64 } tests[] = {
61 // The handler is initialized using this challenge. The first 65 // The handler is initialized using this challenge. The first
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 int rv = factory.CreateAuthHandlerFromString( 200 int rv = factory.CreateAuthHandlerFromString(
197 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, BoundNetLog(), 201 challenge, HttpAuth::AUTH_SERVER, null_ssl_info, origin, BoundNetLog(),
198 &basic); 202 &basic);
199 EXPECT_EQ(tests[i].expected_rv, rv); 203 EXPECT_EQ(tests[i].expected_rv, rv);
200 if (rv == OK) 204 if (rv == OK)
201 EXPECT_EQ(tests[i].expected_realm, basic->realm()); 205 EXPECT_EQ(tests[i].expected_realm, basic->realm());
202 } 206 }
203 } 207 }
204 208
205 } // namespace net 209 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_cache_based_quic_server_info_unittest.cc ('k') | net/http/http_auth_handler_digest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698