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 "base/memory/scoped_ptr.h" |
7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
8 #include "net/base/request_priority.h" | 9 #include "net/base/request_priority.h" |
9 #include "net/http/http_auth_handler.h" | 10 #include "net/http/http_auth_handler.h" |
10 #include "net/http/http_auth_handler_factory.h" | 11 #include "net/http/http_auth_handler_factory.h" |
11 #include "net/test/spawned_test_server/spawned_test_server.h" | 12 #include "net/test/spawned_test_server/spawned_test_server.h" |
12 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
13 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 | 17 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 73 |
73 LocalHttpTestServer test_server_; | 74 LocalHttpTestServer test_server_; |
74 URLRequestContextBuilder builder_; | 75 URLRequestContextBuilder builder_; |
75 }; | 76 }; |
76 | 77 |
77 TEST_F(URLRequestContextBuilderTest, DefaultSettings) { | 78 TEST_F(URLRequestContextBuilderTest, DefaultSettings) { |
78 ASSERT_TRUE(test_server_.Start()); | 79 ASSERT_TRUE(test_server_.Start()); |
79 | 80 |
80 scoped_ptr<URLRequestContext> context(builder_.Build()); | 81 scoped_ptr<URLRequestContext> context(builder_.Build()); |
81 TestDelegate delegate; | 82 TestDelegate delegate; |
82 URLRequest request(test_server_.GetURL("echoheader?Foo"), | 83 scoped_ptr<URLRequest> request( |
83 DEFAULT_PRIORITY, | 84 context->CreateRequest(test_server_.GetURL("echoheader?Foo"), |
84 &delegate, | 85 DEFAULT_PRIORITY, |
85 context.get()); | 86 &delegate, |
86 request.set_method("GET"); | 87 context->cookie_store())); |
87 request.SetExtraRequestHeaderByName("Foo", "Bar", false); | 88 request->set_method("GET"); |
88 request.Start(); | 89 request->SetExtraRequestHeaderByName("Foo", "Bar", false); |
| 90 request->Start(); |
89 base::MessageLoop::current()->Run(); | 91 base::MessageLoop::current()->Run(); |
90 EXPECT_EQ("Bar", delegate.data_received()); | 92 EXPECT_EQ("Bar", delegate.data_received()); |
91 } | 93 } |
92 | 94 |
93 TEST_F(URLRequestContextBuilderTest, UserAgent) { | 95 TEST_F(URLRequestContextBuilderTest, UserAgent) { |
94 ASSERT_TRUE(test_server_.Start()); | 96 ASSERT_TRUE(test_server_.Start()); |
95 | 97 |
96 builder_.set_user_agent("Bar"); | 98 builder_.set_user_agent("Bar"); |
97 scoped_ptr<URLRequestContext> context(builder_.Build()); | 99 scoped_ptr<URLRequestContext> context(builder_.Build()); |
98 TestDelegate delegate; | 100 TestDelegate delegate; |
99 URLRequest request(test_server_.GetURL("echoheader?User-Agent"), | 101 scoped_ptr<URLRequest> request( |
100 DEFAULT_PRIORITY, | 102 context->CreateRequest(test_server_.GetURL("echoheader?User-Agent"), |
101 &delegate, | 103 DEFAULT_PRIORITY, |
102 context.get()); | 104 &delegate, |
103 request.set_method("GET"); | 105 NULL)); |
104 request.Start(); | 106 request->set_method("GET"); |
| 107 request->Start(); |
105 base::MessageLoop::current()->Run(); | 108 base::MessageLoop::current()->Run(); |
106 EXPECT_EQ("Bar", delegate.data_received()); | 109 EXPECT_EQ("Bar", delegate.data_received()); |
107 } | 110 } |
108 | 111 |
109 TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) { | 112 TEST_F(URLRequestContextBuilderTest, ExtraHttpAuthHandlerFactory) { |
110 GURL gurl("www.google.com"); | 113 GURL gurl("www.google.com"); |
111 const int kBasicReturnCode = net::OK; | 114 const int kBasicReturnCode = net::OK; |
112 MockHttpAuthHandlerFactory* mock_factory_basic = | 115 MockHttpAuthHandlerFactory* mock_factory_basic = |
113 new MockHttpAuthHandlerFactory(kBasicReturnCode); | 116 new MockHttpAuthHandlerFactory(kBasicReturnCode); |
114 scoped_ptr<HttpAuthHandler> handler; | 117 scoped_ptr<HttpAuthHandler> handler; |
115 builder_.add_http_auth_handler_factory("ExtraScheme", mock_factory_basic); | 118 builder_.add_http_auth_handler_factory("ExtraScheme", mock_factory_basic); |
116 scoped_ptr<URLRequestContext> context(builder_.Build()); | 119 scoped_ptr<URLRequestContext> context(builder_.Build()); |
117 // Verify that a handler is returned for and added scheme. | 120 // Verify that a handler is returned for and added scheme. |
118 EXPECT_EQ(kBasicReturnCode, | 121 EXPECT_EQ(kBasicReturnCode, |
119 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 122 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
120 "ExtraScheme", | 123 "ExtraScheme", |
121 HttpAuth::AUTH_SERVER, | 124 HttpAuth::AUTH_SERVER, |
122 gurl, | 125 gurl, |
123 BoundNetLog(), | 126 BoundNetLog(), |
124 &handler)); | 127 &handler)); |
125 // Verify that a handler isn't returned for a bogus scheme. | 128 // Verify that a handler isn't returned for a bogus scheme. |
126 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, | 129 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, |
127 context->http_auth_handler_factory()->CreateAuthHandlerFromString( | 130 context->http_auth_handler_factory()->CreateAuthHandlerFromString( |
128 "Bogus", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); | 131 "Bogus", HttpAuth::AUTH_SERVER, gurl, BoundNetLog(), &handler)); |
129 } | 132 } |
130 | 133 |
131 } // namespace | 134 } // namespace |
132 | 135 |
133 } // namespace net | 136 } // namespace net |
OLD | NEW |