| OLD | NEW |
| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "net/base/net_errors.h" | 6 #include "net/base/net_errors.h" |
| 7 #include "net/dns/mock_host_resolver.h" | 7 #include "net/dns/mock_host_resolver.h" |
| 8 #include "net/http/http_auth_handler.h" | 8 #include "net/http/http_auth_handler.h" |
| 9 #include "net/http/http_auth_handler_factory.h" | 9 #include "net/http/http_auth_handler_factory.h" |
| 10 #include "net/http/mock_allow_url_security_manager.h" | 10 #include "net/http/http_auth_scheme.h" |
| 11 #include "net/http/mock_allow_http_auth_preferences.h" |
| 11 #include "net/http/url_security_manager.h" | 12 #include "net/http/url_security_manager.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { | 19 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { |
| 19 public: | 20 public: |
| 20 explicit MockHttpAuthHandlerFactory(int return_code) : | 21 explicit MockHttpAuthHandlerFactory(int return_code) : |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 registry_factory.CreateAuthHandlerFromString( | 92 registry_factory.CreateAuthHandlerFromString( |
| 92 "Basic", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); | 93 "Basic", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); |
| 93 EXPECT_EQ(kDigestReturnCodeReplace, | 94 EXPECT_EQ(kDigestReturnCodeReplace, |
| 94 registry_factory.CreateAuthHandlerFromString( | 95 registry_factory.CreateAuthHandlerFromString( |
| 95 "Digest", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), | 96 "Digest", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), |
| 96 &handler)); | 97 &handler)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 TEST(HttpAuthHandlerFactoryTest, DefaultFactory) { | 100 TEST(HttpAuthHandlerFactoryTest, DefaultFactory) { |
| 100 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); | 101 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); |
| 101 MockAllowURLSecurityManager url_security_manager; | 102 MockAllowHttpAuthPreferences http_auth_preferences; |
| 102 scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( | 103 scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( |
| 103 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); | 104 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); |
| 104 http_auth_handler_factory->SetURLSecurityManager( | 105 http_auth_handler_factory->SetHttpAuthPreferences(kNegotiateAuthScheme, |
| 105 "negotiate", &url_security_manager); | 106 &http_auth_preferences); |
| 106 GURL server_origin("http://www.example.com"); | 107 GURL server_origin("http://www.example.com"); |
| 107 GURL proxy_origin("http://cache.example.com:3128"); | 108 GURL proxy_origin("http://cache.example.com:3128"); |
| 108 { | 109 { |
| 109 scoped_ptr<HttpAuthHandler> handler; | 110 scoped_ptr<HttpAuthHandler> handler; |
| 110 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( | 111 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( |
| 111 "Basic realm=\"FooBar\"", | 112 "Basic realm=\"FooBar\"", |
| 112 HttpAuth::AUTH_SERVER, | 113 HttpAuth::AUTH_SERVER, |
| 113 server_origin, | 114 server_origin, |
| 114 BoundNetLog(), | 115 BoundNetLog(), |
| 115 &handler); | 116 &handler); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 EXPECT_TRUE(handler->encrypts_identity()); | 183 EXPECT_TRUE(handler->encrypts_identity()); |
| 183 EXPECT_TRUE(handler->is_connection_based()); | 184 EXPECT_TRUE(handler->is_connection_based()); |
| 184 #else | 185 #else |
| 185 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); | 186 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); |
| 186 EXPECT_TRUE(handler.get() == NULL); | 187 EXPECT_TRUE(handler.get() == NULL); |
| 187 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) | 188 #endif // defined(USE_KERBEROS) && !defined(OS_ANDROID) |
| 188 } | 189 } |
| 189 } | 190 } |
| 190 | 191 |
| 191 } // namespace net | 192 } // namespace net |
| OLD | NEW |