OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #endif | 10 #endif |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
19 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
24 #include "base/string_number_conversions.h" | 24 #include "base/string_number_conversions.h" |
25 #include "base/string_piece.h" | 25 #include "base/string_piece.h" |
| 26 #include "base/string_split.h" |
26 #include "base/string_util.h" | 27 #include "base/string_util.h" |
27 #include "base/stringprintf.h" | 28 #include "base/stringprintf.h" |
28 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
29 #include "net/base/cookie_monster.h" | 30 #include "net/base/cookie_monster.h" |
30 #include "net/base/cookie_store_test_helpers.h" | 31 #include "net/base/cookie_store_test_helpers.h" |
31 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
32 #include "net/base/mock_host_resolver.h" | 33 #include "net/base/mock_host_resolver.h" |
33 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
34 #include "net/base/net_log.h" | 35 #include "net/base/net_log.h" |
35 #include "net/base/net_log_unittest.h" | 36 #include "net/base/net_log_unittest.h" |
36 #include "net/base/net_module.h" | 37 #include "net/base/net_module.h" |
37 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
38 #include "net/base/ssl_connection_status_flags.h" | 39 #include "net/base/ssl_connection_status_flags.h" |
39 #include "net/base/upload_data.h" | 40 #include "net/base/upload_data.h" |
40 #include "net/disk_cache/disk_cache.h" | 41 #include "net/disk_cache/disk_cache.h" |
41 #include "net/ftp/ftp_network_layer.h" | 42 #include "net/ftp/ftp_network_layer.h" |
42 #include "net/http/http_cache.h" | 43 #include "net/http/http_cache.h" |
43 #include "net/http/http_network_layer.h" | 44 #include "net/http/http_network_layer.h" |
| 45 #include "net/http/http_network_session.h" |
44 #include "net/http/http_request_headers.h" | 46 #include "net/http/http_request_headers.h" |
45 #include "net/http/http_response_headers.h" | 47 #include "net/http/http_response_headers.h" |
46 #include "net/proxy/proxy_service.h" | 48 #include "net/proxy/proxy_service.h" |
| 49 #include "net/socket/ssl_client_socket.h" |
47 #include "net/test/test_server.h" | 50 #include "net/test/test_server.h" |
48 #include "net/url_request/url_request.h" | 51 #include "net/url_request/url_request.h" |
49 #include "net/url_request/url_request_file_dir_job.h" | 52 #include "net/url_request/url_request_file_dir_job.h" |
50 #include "net/url_request/url_request_http_job.h" | 53 #include "net/url_request/url_request_http_job.h" |
51 #include "net/url_request/url_request_job_factory.h" | 54 #include "net/url_request/url_request_job_factory.h" |
52 #include "net/url_request/url_request_redirect_job.h" | 55 #include "net/url_request/url_request_redirect_job.h" |
53 #include "net/url_request/url_request_test_job.h" | 56 #include "net/url_request/url_request_test_job.h" |
54 #include "net/url_request/url_request_test_util.h" | 57 #include "net/url_request/url_request_test_util.h" |
55 #include "testing/gtest/include/gtest/gtest.h" | 58 #include "testing/gtest/include/gtest/gtest.h" |
56 #include "testing/platform_test.h" | 59 #include "testing/platform_test.h" |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 r.ContinueWithCertificate(NULL); | 1177 r.ContinueWithCertificate(NULL); |
1175 | 1178 |
1176 MessageLoop::current()->Run(); | 1179 MessageLoop::current()->Run(); |
1177 | 1180 |
1178 EXPECT_EQ(1, d.response_started_count()); | 1181 EXPECT_EQ(1, d.response_started_count()); |
1179 EXPECT_FALSE(d.received_data_before_response()); | 1182 EXPECT_FALSE(d.received_data_before_response()); |
1180 EXPECT_NE(0, d.bytes_received()); | 1183 EXPECT_NE(0, d.bytes_received()); |
1181 } | 1184 } |
1182 } | 1185 } |
1183 | 1186 |
| 1187 TEST_F(HTTPSRequestTest, ResumeTest) { |
| 1188 // Test that we attempt a session resume when making two connections to the |
| 1189 // same host. |
| 1190 TestServer::HTTPSOptions https_options; |
| 1191 https_options.record_resume = true; |
| 1192 TestServer test_server(https_options, |
| 1193 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1194 ASSERT_TRUE(test_server.Start()); |
| 1195 |
| 1196 SSLClientSocket::ClearSessionCache(); |
| 1197 |
| 1198 { |
| 1199 TestDelegate d; |
| 1200 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1201 r.set_context(default_context_); |
| 1202 |
| 1203 r.Start(); |
| 1204 EXPECT_TRUE(r.is_pending()); |
| 1205 |
| 1206 MessageLoop::current()->Run(); |
| 1207 |
| 1208 EXPECT_EQ(1, d.response_started_count()); |
| 1209 } |
| 1210 |
| 1211 reinterpret_cast<HttpCache*>(default_context_->http_transaction_factory())-> |
| 1212 CloseAllConnections(); |
| 1213 |
| 1214 { |
| 1215 TestDelegate d; |
| 1216 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1217 r.set_context(default_context_); |
| 1218 |
| 1219 r.Start(); |
| 1220 EXPECT_TRUE(r.is_pending()); |
| 1221 |
| 1222 MessageLoop::current()->Run(); |
| 1223 |
| 1224 // The response will look like; |
| 1225 // insert abc |
| 1226 // lookup abc |
| 1227 // insert xyz |
| 1228 // |
| 1229 // With a newline at the end which makes the split think that there are |
| 1230 // four lines. |
| 1231 |
| 1232 EXPECT_EQ(1, d.response_started_count()); |
| 1233 std::vector<std::string> lines; |
| 1234 base::SplitString(d.data_received(), '\n', &lines); |
| 1235 ASSERT_EQ(4u, lines.size()) << d.data_received(); |
| 1236 |
| 1237 std::string session_id; |
| 1238 |
| 1239 for (size_t i = 0; i < 2; i++) { |
| 1240 std::vector<std::string> parts; |
| 1241 base::SplitString(lines[i], '\t', &parts); |
| 1242 ASSERT_EQ(2u, parts.size()); |
| 1243 if (i == 0) { |
| 1244 EXPECT_EQ("insert", parts[0]); |
| 1245 session_id = parts[1]; |
| 1246 } else { |
| 1247 EXPECT_EQ("lookup", parts[0]); |
| 1248 EXPECT_EQ(session_id, parts[1]); |
| 1249 } |
| 1250 } |
| 1251 } |
| 1252 } |
| 1253 |
| 1254 TEST_F(HTTPSRequestTest, SSLSessionCacheShardTest) { |
| 1255 // Test that sessions aren't resumed when the value of ssl_session_cache_shard |
| 1256 // differs. |
| 1257 TestServer::HTTPSOptions https_options; |
| 1258 https_options.record_resume = true; |
| 1259 TestServer test_server(https_options, |
| 1260 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1261 ASSERT_TRUE(test_server.Start()); |
| 1262 |
| 1263 SSLClientSocket::ClearSessionCache(); |
| 1264 |
| 1265 { |
| 1266 TestDelegate d; |
| 1267 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1268 r.set_context(default_context_); |
| 1269 |
| 1270 r.Start(); |
| 1271 EXPECT_TRUE(r.is_pending()); |
| 1272 |
| 1273 MessageLoop::current()->Run(); |
| 1274 |
| 1275 EXPECT_EQ(1, d.response_started_count()); |
| 1276 } |
| 1277 |
| 1278 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
| 1279 HttpNetworkSession::Params params; |
| 1280 params.host_resolver = default_context_->host_resolver(); |
| 1281 params.cert_verifier = default_context_->cert_verifier(); |
| 1282 params.proxy_service = default_context_->proxy_service(); |
| 1283 params.ssl_config_service = default_context_->ssl_config_service(); |
| 1284 params.http_auth_handler_factory = |
| 1285 default_context_->http_auth_handler_factory(); |
| 1286 params.network_delegate = default_context_->network_delegate(); |
| 1287 params.http_server_properties = default_context_->http_server_properties(); |
| 1288 params.ssl_session_cache_shard = "alternate"; |
| 1289 |
| 1290 scoped_ptr<net::HttpCache> cache(new net::HttpCache( |
| 1291 new net::HttpNetworkSession(params), |
| 1292 net::HttpCache::DefaultBackend::InMemory(0))); |
| 1293 |
| 1294 default_context_->set_http_transaction_factory(cache.get()); |
| 1295 |
| 1296 { |
| 1297 TestDelegate d; |
| 1298 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1299 r.set_context(default_context_); |
| 1300 |
| 1301 r.Start(); |
| 1302 EXPECT_TRUE(r.is_pending()); |
| 1303 |
| 1304 MessageLoop::current()->Run(); |
| 1305 |
| 1306 // The response will look like; |
| 1307 // insert abc |
| 1308 // insert xyz |
| 1309 // |
| 1310 // With a newline at the end which makes the split think that there are |
| 1311 // three lines. |
| 1312 |
| 1313 EXPECT_EQ(1, d.response_started_count()); |
| 1314 std::vector<std::string> lines; |
| 1315 base::SplitString(d.data_received(), '\n', &lines); |
| 1316 ASSERT_EQ(3u, lines.size()); |
| 1317 |
| 1318 std::string session_id; |
| 1319 for (size_t i = 0; i < 2; i++) { |
| 1320 std::vector<std::string> parts; |
| 1321 base::SplitString(lines[i], '\t', &parts); |
| 1322 ASSERT_EQ(2u, parts.size()); |
| 1323 EXPECT_EQ("insert", parts[0]); |
| 1324 if (i == 0) { |
| 1325 session_id = parts[1]; |
| 1326 } else { |
| 1327 EXPECT_NE(session_id, parts[1]); |
| 1328 } |
| 1329 } |
| 1330 } |
| 1331 } |
| 1332 |
1184 TEST_F(URLRequestTestHTTP, CancelTest) { | 1333 TEST_F(URLRequestTestHTTP, CancelTest) { |
1185 TestDelegate d; | 1334 TestDelegate d; |
1186 { | 1335 { |
1187 TestURLRequest r(GURL("http://www.google.com/"), &d); | 1336 TestURLRequest r(GURL("http://www.google.com/"), &d); |
1188 r.set_context(default_context_); | 1337 r.set_context(default_context_); |
1189 | 1338 |
1190 r.Start(); | 1339 r.Start(); |
1191 EXPECT_TRUE(r.is_pending()); | 1340 EXPECT_TRUE(r.is_pending()); |
1192 | 1341 |
1193 r.Cancel(); | 1342 r.Cancel(); |
(...skipping 2476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3670 req.SetExtraRequestHeaders(headers); | 3819 req.SetExtraRequestHeaders(headers); |
3671 req.Start(); | 3820 req.Start(); |
3672 MessageLoop::current()->Run(); | 3821 MessageLoop::current()->Run(); |
3673 // If the net tests are being run with ChromeFrame then we need to allow for | 3822 // If the net tests are being run with ChromeFrame then we need to allow for |
3674 // the 'chromeframe' suffix which is added to the user agent before the | 3823 // the 'chromeframe' suffix which is added to the user agent before the |
3675 // closing parentheses. | 3824 // closing parentheses. |
3676 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3825 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
3677 } | 3826 } |
3678 | 3827 |
3679 } // namespace net | 3828 } // namespace net |
OLD | NEW |