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

Side by Side Diff: net/http/http_auth_handler_factory_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_factory.h" 5 #include "net/http/http_auth_handler_factory.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/dns/mock_host_resolver.h" 10 #include "net/dns/mock_host_resolver.h"
11 #include "net/http/http_auth_handler.h" 11 #include "net/http/http_auth_handler.h"
12 #include "net/http/http_auth_scheme.h" 12 #include "net/http/http_auth_scheme.h"
13 #include "net/http/mock_allow_http_auth_preferences.h" 13 #include "net/http/mock_allow_http_auth_preferences.h"
14 #include "net/http/url_security_manager.h" 14 #include "net/http/url_security_manager.h"
15 #include "net/ssl/ssl_info.h" 15 #include "net/ssl/ssl_info.h"
16 #include "net/test/gtest_util.h"
17 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
20 using net::test::IsError;
21 using net::test::IsOk;
22
18 namespace net { 23 namespace net {
19 24
20 namespace { 25 namespace {
21 26
22 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { 27 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory {
23 public: 28 public:
24 explicit MockHttpAuthHandlerFactory(int return_code) : 29 explicit MockHttpAuthHandlerFactory(int return_code) :
25 return_code_(return_code) {} 30 return_code_(return_code) {}
26 ~MockHttpAuthHandlerFactory() override {} 31 ~MockHttpAuthHandlerFactory() override {}
27 32
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 http_auth_handler_factory->SetHttpAuthPreferences(kNegotiateAuthScheme, 116 http_auth_handler_factory->SetHttpAuthPreferences(kNegotiateAuthScheme,
112 &http_auth_preferences); 117 &http_auth_preferences);
113 GURL server_origin("http://www.example.com"); 118 GURL server_origin("http://www.example.com");
114 GURL proxy_origin("http://cache.example.com:3128"); 119 GURL proxy_origin("http://cache.example.com:3128");
115 SSLInfo null_ssl_info; 120 SSLInfo null_ssl_info;
116 { 121 {
117 std::unique_ptr<HttpAuthHandler> handler; 122 std::unique_ptr<HttpAuthHandler> handler;
118 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( 123 int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
119 "Basic realm=\"FooBar\"", HttpAuth::AUTH_SERVER, null_ssl_info, 124 "Basic realm=\"FooBar\"", HttpAuth::AUTH_SERVER, null_ssl_info,
120 server_origin, BoundNetLog(), &handler); 125 server_origin, BoundNetLog(), &handler);
121 EXPECT_EQ(OK, rv); 126 EXPECT_THAT(rv, IsOk());
122 ASSERT_FALSE(handler.get() == NULL); 127 ASSERT_FALSE(handler.get() == NULL);
123 EXPECT_EQ(HttpAuth::AUTH_SCHEME_BASIC, handler->auth_scheme()); 128 EXPECT_EQ(HttpAuth::AUTH_SCHEME_BASIC, handler->auth_scheme());
124 EXPECT_STREQ("FooBar", handler->realm().c_str()); 129 EXPECT_STREQ("FooBar", handler->realm().c_str());
125 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); 130 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
126 EXPECT_FALSE(handler->encrypts_identity()); 131 EXPECT_FALSE(handler->encrypts_identity());
127 EXPECT_FALSE(handler->is_connection_based()); 132 EXPECT_FALSE(handler->is_connection_based());
128 } 133 }
129 { 134 {
130 std::unique_ptr<HttpAuthHandler> handler; 135 std::unique_ptr<HttpAuthHandler> handler;
131 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( 136 int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
132 "UNSUPPORTED realm=\"FooBar\"", HttpAuth::AUTH_SERVER, null_ssl_info, 137 "UNSUPPORTED realm=\"FooBar\"", HttpAuth::AUTH_SERVER, null_ssl_info,
133 server_origin, BoundNetLog(), &handler); 138 server_origin, BoundNetLog(), &handler);
134 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); 139 EXPECT_THAT(rv, IsError(ERR_UNSUPPORTED_AUTH_SCHEME));
135 EXPECT_TRUE(handler.get() == NULL); 140 EXPECT_TRUE(handler.get() == NULL);
136 } 141 }
137 { 142 {
138 std::unique_ptr<HttpAuthHandler> handler; 143 std::unique_ptr<HttpAuthHandler> handler;
139 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( 144 int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
140 "Digest realm=\"FooBar\", nonce=\"xyz\"", HttpAuth::AUTH_PROXY, 145 "Digest realm=\"FooBar\", nonce=\"xyz\"", HttpAuth::AUTH_PROXY,
141 null_ssl_info, proxy_origin, BoundNetLog(), &handler); 146 null_ssl_info, proxy_origin, BoundNetLog(), &handler);
142 EXPECT_EQ(OK, rv); 147 EXPECT_THAT(rv, IsOk());
143 ASSERT_FALSE(handler.get() == NULL); 148 ASSERT_FALSE(handler.get() == NULL);
144 EXPECT_EQ(HttpAuth::AUTH_SCHEME_DIGEST, handler->auth_scheme()); 149 EXPECT_EQ(HttpAuth::AUTH_SCHEME_DIGEST, handler->auth_scheme());
145 EXPECT_STREQ("FooBar", handler->realm().c_str()); 150 EXPECT_STREQ("FooBar", handler->realm().c_str());
146 EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target()); 151 EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target());
147 EXPECT_TRUE(handler->encrypts_identity()); 152 EXPECT_TRUE(handler->encrypts_identity());
148 EXPECT_FALSE(handler->is_connection_based()); 153 EXPECT_FALSE(handler->is_connection_based());
149 } 154 }
150 { 155 {
151 std::unique_ptr<HttpAuthHandler> handler; 156 std::unique_ptr<HttpAuthHandler> handler;
152 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( 157 int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
153 "NTLM", HttpAuth::AUTH_SERVER, null_ssl_info, server_origin, 158 "NTLM", HttpAuth::AUTH_SERVER, null_ssl_info, server_origin,
154 BoundNetLog(), &handler); 159 BoundNetLog(), &handler);
155 EXPECT_EQ(OK, rv); 160 EXPECT_THAT(rv, IsOk());
156 ASSERT_FALSE(handler.get() == NULL); 161 ASSERT_FALSE(handler.get() == NULL);
157 EXPECT_EQ(HttpAuth::AUTH_SCHEME_NTLM, handler->auth_scheme()); 162 EXPECT_EQ(HttpAuth::AUTH_SCHEME_NTLM, handler->auth_scheme());
158 EXPECT_STREQ("", handler->realm().c_str()); 163 EXPECT_STREQ("", handler->realm().c_str());
159 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); 164 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
160 EXPECT_TRUE(handler->encrypts_identity()); 165 EXPECT_TRUE(handler->encrypts_identity());
161 EXPECT_TRUE(handler->is_connection_based()); 166 EXPECT_TRUE(handler->is_connection_based());
162 } 167 }
163 { 168 {
164 std::unique_ptr<HttpAuthHandler> handler; 169 std::unique_ptr<HttpAuthHandler> handler;
165 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( 170 int rv = http_auth_handler_factory->CreateAuthHandlerFromString(
166 "Negotiate", HttpAuth::AUTH_SERVER, null_ssl_info, server_origin, 171 "Negotiate", HttpAuth::AUTH_SERVER, null_ssl_info, server_origin,
167 BoundNetLog(), &handler); 172 BoundNetLog(), &handler);
168 // Note the default factory doesn't support Kerberos on Android 173 // Note the default factory doesn't support Kerberos on Android
169 #if defined(USE_KERBEROS) && !defined(OS_ANDROID) 174 #if defined(USE_KERBEROS) && !defined(OS_ANDROID)
170 EXPECT_EQ(OK, rv); 175 EXPECT_THAT(rv, IsOk());
171 ASSERT_FALSE(handler.get() == NULL); 176 ASSERT_FALSE(handler.get() == NULL);
172 EXPECT_EQ(HttpAuth::AUTH_SCHEME_NEGOTIATE, handler->auth_scheme()); 177 EXPECT_EQ(HttpAuth::AUTH_SCHEME_NEGOTIATE, handler->auth_scheme());
173 EXPECT_STREQ("", handler->realm().c_str()); 178 EXPECT_STREQ("", handler->realm().c_str());
174 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); 179 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
175 EXPECT_TRUE(handler->encrypts_identity()); 180 EXPECT_TRUE(handler->encrypts_identity());
176 EXPECT_TRUE(handler->is_connection_based()); 181 EXPECT_TRUE(handler->is_connection_based());
177 #else 182 #else
178 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); 183 EXPECT_THAT(rv, IsError(ERR_UNSUPPORTED_AUTH_SCHEME));
179 EXPECT_TRUE(handler.get() == NULL); 184 EXPECT_TRUE(handler.get() == NULL);
180 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) 185 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID)
181 } 186 }
182 } 187 }
183 188
184 } // namespace net 189 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_digest_unittest.cc ('k') | net/http/http_auth_handler_negotiate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698