| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/url_request/url_request_context_builder.h" | 5 #include "net/url_request/url_request_context_builder.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "net/base/request_priority.h" | 8 #include "net/base/request_priority.h" |
| 9 #include "net/http/http_auth_handler.h" | 9 #include "net/http/http_auth_handler.h" |
| 10 #include "net/http/http_auth_handler_factory.h" | 10 #include "net/http/http_auth_handler_factory.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 ScopedCustomUrlRequestTestHttpHost::value(), | 33 ScopedCustomUrlRequestTestHttpHost::value(), |
| 34 document_root) {} | 34 document_root) {} |
| 35 LocalHttpTestServer() | 35 LocalHttpTestServer() |
| 36 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | 36 : SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
| 37 ScopedCustomUrlRequestTestHttpHost::value(), | 37 ScopedCustomUrlRequestTestHttpHost::value(), |
| 38 base::FilePath()) {} | 38 base::FilePath()) {} |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { | 41 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { |
| 42 public: | 42 public: |
| 43 explicit MockHttpAuthHandlerFactory(int return_code) : | 43 explicit MockHttpAuthHandlerFactory(int return_code) |
| 44 return_code_(return_code) {} | 44 : return_code_(return_code) {} |
| 45 virtual ~MockHttpAuthHandlerFactory() {} | 45 virtual ~MockHttpAuthHandlerFactory() {} |
| 46 | 46 |
| 47 virtual int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, | 47 virtual int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, |
| 48 HttpAuth::Target target, | 48 HttpAuth::Target target, |
| 49 const GURL& origin, | 49 const GURL& origin, |
| 50 CreateReason reason, | 50 CreateReason reason, |
| 51 int nonce_count, | 51 int nonce_count, |
| 52 const BoundNetLog& net_log, | 52 const BoundNetLog& net_log, |
| 53 scoped_ptr<HttpAuthHandler>* handler) OVERRIDE { | 53 scoped_ptr<HttpAuthHandler>* handler) OVERRIDE { |
| 54 handler->reset(); | 54 handler->reset(); |
| 55 return return_code_; | 55 return return_code_; |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 int return_code_; | 59 int return_code_; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class URLRequestContextBuilderTest : public PlatformTest { | 62 class URLRequestContextBuilderTest : public PlatformTest { |
| 63 protected: | 63 protected: |
| 64 URLRequestContextBuilderTest() | 64 URLRequestContextBuilderTest() |
| 65 : test_server_( | 65 : test_server_(base::FilePath( |
| 66 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))) { | 66 FILE_PATH_LITERAL("net/data/url_request_unittest"))) { |
| 67 #if defined(OS_LINUX) || defined(OS_ANDROID) | 67 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 68 builder_.set_proxy_config_service( | 68 builder_.set_proxy_config_service( |
| 69 new ProxyConfigServiceFixed(ProxyConfig::CreateDirect())); | 69 new ProxyConfigServiceFixed(ProxyConfig::CreateDirect())); |
| 70 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 70 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 71 } | 71 } |
| 72 | 72 |
| 73 LocalHttpTestServer test_server_; | 73 LocalHttpTestServer test_server_; |
| 74 URLRequestContextBuilder builder_; | 74 URLRequestContextBuilder builder_; |
| 75 }; | 75 }; |
| 76 | 76 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) { | 109 TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) { |
| 110 GURL gurl("www.google.com"); | 110 GURL gurl("www.google.com"); |
| 111 const int kBasicReturnCode = net::OK; | 111 const int kBasicReturnCode = net::OK; |
| 112 MockHttpAuthHandlerFactory* mock_factory_basic = | 112 MockHttpAuthHandlerFactory* mock_factory_basic = |
| 113 new MockHttpAuthHandlerFactory(kBasicReturnCode); | 113 new MockHttpAuthHandlerFactory(kBasicReturnCode); |
| 114 scoped_ptr<HttpAuthHandler> handler; | 114 scoped_ptr<HttpAuthHandler> handler; |
| 115 builder_.add_http_auth_handler_factory("ExtraScheme", mock_factory_basic); | 115 builder_.add_http_auth_handler_factory("ExtraScheme", mock_factory_basic); |
| 116 scoped_ptr<URLRequestContext> context(builder_.Build()); | 116 scoped_ptr<URLRequestContext> context(builder_.Build()); |
| 117 // Verify that a handler is returned for and added scheme. | 117 // Verify that a handler is returned for and added scheme. |
| 118 EXPECT_EQ(kBasicReturnCode, | 118 EXPECT_EQ( |
| 119 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 119 kBasicReturnCode, |
| 120 "ExtraScheme", | 120 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
| 121 HttpAuth::AUTH_SERVER, | 121 "ExtraScheme", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); |
| 122 gurl, | |
| 123 BoundNetLog(), | |
| 124 &handler)); | |
| 125 // Verify that a handler isn't returned for a bogus scheme. | 122 // Verify that a handler isn't returned for a bogus scheme. |
| 126 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, | 123 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, |
| 127 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 124 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
| 128 "Bogus", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); | 125 "Bogus", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); |
| 129 } | 126 } |
| 130 | 127 |
| 131 } // namespace | 128 } // namespace |
| 132 | 129 |
| 133 } // namespace net | 130 } // namespace net |
| OLD | NEW |