Index: net/url_request/url_request_context_builder_unittest.cc |
diff --git a/net/url_request/url_request_context_builder_unittest.cc b/net/url_request/url_request_context_builder_unittest.cc |
index 51d39525e5cf198204c0cf103b696847994e57eb..064c7660ef67e1196ba091bc05cdf8ffabd94d22 100644 |
--- a/net/url_request/url_request_context_builder_unittest.cc |
+++ b/net/url_request/url_request_context_builder_unittest.cc |
@@ -9,6 +9,7 @@ |
#include "net/base/request_priority.h" |
#include "net/http/http_auth_handler.h" |
#include "net/http/http_auth_handler_factory.h" |
+#include "net/http/http_auth_handler_mock.h" |
#include "net/test/spawned_test_server/spawned_test_server.h" |
#include "net/url_request/url_request.h" |
#include "net/url_request/url_request_test_util.h" |
@@ -24,27 +25,6 @@ namespace net { |
namespace { |
-class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { |
- public: |
- explicit MockHttpAuthHandlerFactory(int return_code) : |
- return_code_(return_code) {} |
- ~MockHttpAuthHandlerFactory() override {} |
- |
- int CreateAuthHandler(const HttpAuthChallengeTokenizer& challenge, |
- HttpAuth::Target target, |
- const GURL& origin, |
- CreateReason reason, |
- int nonce_count, |
- const BoundNetLog& net_log, |
- scoped_ptr<HttpAuthHandler>* handler) override { |
- handler->reset(); |
- return return_code_; |
- } |
- |
- private: |
- int return_code_; |
-}; |
- |
class URLRequestContextBuilderTest : public PlatformTest { |
protected: |
URLRequestContextBuilderTest() |
@@ -92,25 +72,29 @@ TEST_F(URLRequestContextBuilderTest, UserAgent) { |
} |
TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) { |
+ const char kExtraScheme[] = "extrascheme"; |
GURL gurl("www.google.com"); |
- const int kBasicReturnCode = OK; |
- MockHttpAuthHandlerFactory* mock_factory_basic = |
- new MockHttpAuthHandlerFactory(kBasicReturnCode); |
+ scoped_ptr<HttpAuthHandlerMock::Factory> mock_auth_factory( |
+ new HttpAuthHandlerMock::Factory()); |
+ scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
+ mock_handler->set_expected_auth_scheme(kExtraScheme); |
+ mock_auth_factory->AddMockHandler(mock_handler.Pass(), |
+ HttpAuthHandlerCreateReason::CHALLENGE); |
+ |
scoped_ptr<HttpAuthHandler> handler; |
- builder_.add_http_auth_handler_factory("extrascheme", mock_factory_basic); |
+ builder_.add_http_auth_handler_factory(kExtraScheme, |
+ mock_auth_factory.release()); |
scoped_ptr<URLRequestContext> context(builder_.Build()); |
- // Verify that a handler is returned for and added scheme. |
- EXPECT_EQ(kBasicReturnCode, |
- context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
- "ExtraScheme", |
- HttpAuth::AUTH_SERVER, |
- gurl, |
- BoundNetLog(), |
- &handler)); |
- // Verify that a handler isn't returned for a bogus scheme. |
- EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, |
- context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
- "Bogus", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); |
+ // Verify that a handler is returned for a known scheme. |
+ scoped_ptr<HttpAuthHandler> auth_handler = |
+ context->http_auth_handler_factory()->CreateAuthHandlerForScheme( |
+ kExtraScheme); |
+ EXPECT_TRUE(auth_handler); |
+ |
+ // Verify that a handler is not returned for an unknown scheme. |
+ auth_handler = |
+ context->http_auth_handler_factory()->CreateAuthHandlerForScheme("bogus"); |
+ EXPECT_FALSE(auth_handler); |
} |
} // namespace |