OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
6 #include "net/base/mock_host_resolver.h" | 6 #include "net/base/mock_host_resolver.h" |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.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/url_security_manager.h" | 11 #include "net/http/url_security_manager.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { | 18 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { |
18 public: | 19 public: |
19 explicit MockHttpAuthHandlerFactory(int return_code) : | 20 explicit MockHttpAuthHandlerFactory(int return_code) : |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 registry_factory.CreateAuthHandlerFromString( | 91 registry_factory.CreateAuthHandlerFromString( |
91 "Basic", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); | 92 "Basic", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); |
92 EXPECT_EQ(kDigestReturnCodeReplace, | 93 EXPECT_EQ(kDigestReturnCodeReplace, |
93 registry_factory.CreateAuthHandlerFromString( | 94 registry_factory.CreateAuthHandlerFromString( |
94 "Digest", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), | 95 "Digest", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), |
95 &handler)); | 96 &handler)); |
96 } | 97 } |
97 | 98 |
98 TEST(HttpAuthHandlerFactoryTest, DefaultFactory) { | 99 TEST(HttpAuthHandlerFactoryTest, DefaultFactory) { |
99 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); | 100 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); |
100 URLSecurityManagerAllow url_security_manager; | 101 MockAllowURLSecurityManager url_security_manager; |
101 scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( | 102 scoped_ptr<HttpAuthHandlerRegistryFactory> http_auth_handler_factory( |
102 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); | 103 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); |
103 http_auth_handler_factory->SetURLSecurityManager( | 104 http_auth_handler_factory->SetURLSecurityManager( |
104 "negotiate", &url_security_manager); | 105 "negotiate", &url_security_manager); |
105 GURL server_origin("http://www.example.com"); | 106 GURL server_origin("http://www.example.com"); |
106 GURL proxy_origin("http://cache.example.com:3128"); | 107 GURL proxy_origin("http://cache.example.com:3128"); |
107 { | 108 { |
108 scoped_ptr<HttpAuthHandler> handler; | 109 scoped_ptr<HttpAuthHandler> handler; |
109 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( | 110 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( |
110 "Basic realm=\"FooBar\"", | 111 "Basic realm=\"FooBar\"", |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 ASSERT_FALSE(handler.get() == NULL); | 176 ASSERT_FALSE(handler.get() == NULL); |
176 EXPECT_EQ(HttpAuth::AUTH_SCHEME_NEGOTIATE, handler->auth_scheme()); | 177 EXPECT_EQ(HttpAuth::AUTH_SCHEME_NEGOTIATE, handler->auth_scheme()); |
177 EXPECT_STREQ("", handler->realm().c_str()); | 178 EXPECT_STREQ("", handler->realm().c_str()); |
178 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); | 179 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); |
179 EXPECT_TRUE(handler->encrypts_identity()); | 180 EXPECT_TRUE(handler->encrypts_identity()); |
180 EXPECT_TRUE(handler->is_connection_based()); | 181 EXPECT_TRUE(handler->is_connection_based()); |
181 } | 182 } |
182 } | 183 } |
183 | 184 |
184 } // namespace net | 185 } // namespace net |
OLD | NEW |