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

Side by Side Diff: net/url_request/url_request_context_builder_unittest.cc

Issue 1151843002: DO NOT LAND Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More. Created 5 years, 7 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) 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 "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "net/base/request_priority.h" 9 #include "net/base/request_priority.h"
10 #include "net/http/http_auth_handler.h" 10 #include "net/http/http_auth_handler.h"
11 #include "net/http/http_auth_handler_factory.h" 11 #include "net/http/http_auth_handler_factory.h"
12 #include "net/test/spawned_test_server/spawned_test_server.h" 12 #include "net/test/spawned_test_server/spawned_test_server.h"
13 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
14 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
17 #include "url/origin.h"
17 18
18 #if defined(OS_LINUX) || defined(OS_ANDROID) 19 #if defined(OS_LINUX) || defined(OS_ANDROID)
19 #include "net/proxy/proxy_config.h" 20 #include "net/proxy/proxy_config.h"
20 #include "net/proxy/proxy_config_service_fixed.h" 21 #include "net/proxy/proxy_config_service_fixed.h"
21 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 22 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
22 23
23 namespace net { 24 namespace net {
24 25
25 namespace { 26 namespace {
26 27
27 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory { 28 class MockHttpAuthHandlerFactory : public HttpAuthHandlerFactory {
28 public: 29 public:
29 explicit MockHttpAuthHandlerFactory(int return_code) : 30 explicit MockHttpAuthHandlerFactory(int return_code) :
30 return_code_(return_code) {} 31 return_code_(return_code) {}
31 ~MockHttpAuthHandlerFactory() override {} 32 ~MockHttpAuthHandlerFactory() override {}
32 33
33 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge, 34 int CreateAuthHandler(HttpAuthChallengeTokenizer* challenge,
34 HttpAuth::Target target, 35 HttpAuth::Target target,
35 const GURL& origin, 36 const url::Origin& origin,
36 CreateReason reason, 37 CreateReason reason,
37 int nonce_count, 38 int nonce_count,
38 const BoundNetLog& net_log, 39 const BoundNetLog& net_log,
39 scoped_ptr<HttpAuthHandler>* handler) override { 40 scoped_ptr<HttpAuthHandler>* handler) override {
40 handler->reset(); 41 handler->reset();
41 return return_code_; 42 return return_code_;
42 } 43 }
43 44
44 private: 45 private:
45 int return_code_; 46 int return_code_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 scoped_ptr<URLRequest> request( 86 scoped_ptr<URLRequest> request(
86 context->CreateRequest(test_server_.GetURL("echoheader?User-Agent"), 87 context->CreateRequest(test_server_.GetURL("echoheader?User-Agent"),
87 DEFAULT_PRIORITY, &delegate)); 88 DEFAULT_PRIORITY, &delegate));
88 request->set_method("GET"); 89 request->set_method("GET");
89 request->Start(); 90 request->Start();
90 base::MessageLoop::current()->Run(); 91 base::MessageLoop::current()->Run();
91 EXPECT_EQ("Bar", delegate.data_received()); 92 EXPECT_EQ("Bar", delegate.data_received());
92 } 93 }
93 94
94 TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) { 95 TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) {
95 GURL gurl("www.google.com"); 96 url::Origin origin("www.google.com");
96 const int kBasicReturnCode = OK; 97 const int kBasicReturnCode = OK;
97 MockHttpAuthHandlerFactory* mock_factory_basic = 98 MockHttpAuthHandlerFactory* mock_factory_basic =
98 new MockHttpAuthHandlerFactory(kBasicReturnCode); 99 new MockHttpAuthHandlerFactory(kBasicReturnCode);
99 scoped_ptr<HttpAuthHandler> handler; 100 scoped_ptr<HttpAuthHandler> handler;
100 builder_.add_http_auth_handler_factory("ExtraScheme", mock_factory_basic); 101 builder_.add_http_auth_handler_factory("ExtraScheme", mock_factory_basic);
101 scoped_ptr<URLRequestContext> context(builder_.Build()); 102 scoped_ptr<URLRequestContext> context(builder_.Build());
102 // Verify that a handler is returned for and added scheme. 103 // Verify that a handler is returned for and added scheme.
103 EXPECT_EQ(kBasicReturnCode, 104 EXPECT_EQ(kBasicReturnCode,
104 context->http_auth_handler_factory()->CreateAuthHandlerFromString( 105 context->http_auth_handler_factory()->CreateAuthHandlerFromString(
105 "ExtraScheme", 106 "ExtraScheme", HttpAuth::AUTH_SERVER, origin, BoundNetLog(),
106 HttpAuth::AUTH_SERVER,
107 gurl,
108 BoundNetLog(),
109 &handler)); 107 &handler));
110 // Verify that a handler isn't returned for a bogus scheme. 108 // Verify that a handler isn't returned for a bogus scheme.
111 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, 109 EXPECT_EQ(
112 context->http_auth_handler_factory()->CreateAuthHandlerFromString( 110 ERR_UNSUPPORTED_AUTH_SCHEME,
113 "Bogus", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); 111 context->http_auth_handler_factory()->CreateAuthHandlerFromString(
112 "Bogus", HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &handler));
114 } 113 }
115 114
116 } // namespace 115 } // namespace
117 116
118 } // namespace net 117 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698