OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_unittest.h" | 5 #include "net/url_request/url_request_unittest.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 proxy_service_ = net::ProxyService::CreateNull(); | 55 proxy_service_ = net::ProxyService::CreateNull(); |
56 ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); | 56 ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); |
57 ssl_config_service_ = new net::SSLConfigServiceDefaults; | 57 ssl_config_service_ = new net::SSLConfigServiceDefaults; |
58 http_transaction_factory_ = | 58 http_transaction_factory_ = |
59 new net::HttpCache( | 59 new net::HttpCache( |
60 net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_, | 60 net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_, |
61 ssl_config_service_), | 61 ssl_config_service_), |
62 disk_cache::CreateInMemoryCacheBackend(0)); | 62 disk_cache::CreateInMemoryCacheBackend(0)); |
63 // In-memory cookie store. | 63 // In-memory cookie store. |
64 cookie_store_ = new net::CookieMonster(); | 64 cookie_store_ = new net::CookieMonster(); |
| 65 accept_language_ = "en-us,fr"; |
| 66 accept_charset_ = "iso-8859-1,*,utf-8"; |
65 } | 67 } |
66 | 68 |
67 virtual ~URLRequestTestContext() { | 69 virtual ~URLRequestTestContext() { |
68 delete ftp_transaction_factory_; | 70 delete ftp_transaction_factory_; |
69 delete http_transaction_factory_; | 71 delete http_transaction_factory_; |
70 } | 72 } |
71 }; | 73 }; |
72 | 74 |
73 class TestURLRequest : public URLRequest { | 75 class TestURLRequest : public URLRequest { |
74 public: | 76 public: |
(...skipping 2137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2212 | 2214 |
2213 int64 file_size = 0; | 2215 int64 file_size = 0; |
2214 file_util::GetFileSize(app_path, &file_size); | 2216 file_util::GetFileSize(app_path, &file_size); |
2215 | 2217 |
2216 EXPECT_FALSE(r.is_pending()); | 2218 EXPECT_FALSE(r.is_pending()); |
2217 EXPECT_EQ(1, d->response_started_count()); | 2219 EXPECT_EQ(1, d->response_started_count()); |
2218 EXPECT_FALSE(d->received_data_before_response()); | 2220 EXPECT_FALSE(d->received_data_before_response()); |
2219 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 2221 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
2220 } | 2222 } |
2221 } | 2223 } |
| 2224 |
| 2225 // Check that default A-L header is sent. |
| 2226 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
| 2227 ASSERT_TRUE(NULL != server_.get()); |
| 2228 TestDelegate d; |
| 2229 TestURLRequest req(server_->TestServerPage("echoheader?Accept-Language"), &d); |
| 2230 req.set_context(new URLRequestTestContext()); |
| 2231 req.Start(); |
| 2232 MessageLoop::current()->Run(); |
| 2233 EXPECT_EQ(req.context()->accept_language(), d.data_received()); |
| 2234 } |
| 2235 |
| 2236 // Check that if request overrides the A-L header, the default is not appended. |
| 2237 // See http://crbug.com/20894 |
| 2238 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 2239 ASSERT_TRUE(NULL != server_.get()); |
| 2240 TestDelegate d; |
| 2241 TestURLRequest req(server_->TestServerPage("echoheader?Accept-Language"), &d); |
| 2242 req.set_context(new URLRequestTestContext()); |
| 2243 req.SetExtraRequestHeaders("Accept-Language: ru"); |
| 2244 req.Start(); |
| 2245 MessageLoop::current()->Run(); |
| 2246 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 2247 } |
| 2248 |
| 2249 // Check that default A-C header is sent. |
| 2250 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
| 2251 ASSERT_TRUE(NULL != server_.get()); |
| 2252 TestDelegate d; |
| 2253 TestURLRequest req(server_->TestServerPage("echoheader?Accept-Charset"), &d); |
| 2254 req.set_context(new URLRequestTestContext()); |
| 2255 req.Start(); |
| 2256 MessageLoop::current()->Run(); |
| 2257 EXPECT_EQ(req.context()->accept_charset(), d.data_received()); |
| 2258 } |
| 2259 |
| 2260 // Check that if request overrides the A-C header, the default is not appended. |
| 2261 // See http://crbug.com/20894 |
| 2262 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { |
| 2263 ASSERT_TRUE(NULL != server_.get()); |
| 2264 TestDelegate d; |
| 2265 TestURLRequest req(server_->TestServerPage("echoheader?Accept-Charset"), &d); |
| 2266 req.set_context(new URLRequestTestContext()); |
| 2267 req.SetExtraRequestHeaders("Accept-Charset: koi-8r"); |
| 2268 req.Start(); |
| 2269 MessageLoop::current()->Run(); |
| 2270 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 2271 } |
| 2272 |
OLD | NEW |