OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 for (size_t i = 0; i < len; i++) { | 84 for (size_t i = 0; i < len; i++) { |
85 buffer[i] = static_cast<char>(rand()); | 85 buffer[i] = static_cast<char>(rand()); |
86 if (!buffer[i]) | 86 if (!buffer[i]) |
87 buffer[i] = 'g'; | 87 buffer[i] = 'g'; |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 scoped_refptr<net::UploadData> CreateSimpleUploadData(const char* data) { | 91 scoped_refptr<net::UploadData> CreateSimpleUploadData(const char* data) { |
92 scoped_refptr<net::UploadData> upload = new net::UploadData; | 92 scoped_refptr<net::UploadData> upload(new net::UploadData); |
93 upload->AppendBytes(data, strlen(data)); | 93 upload->AppendBytes(data, strlen(data)); |
94 return upload; | 94 return upload; |
95 } | 95 } |
96 | 96 |
97 // Verify that the SSLInfo of a successful SSL connection has valid values. | 97 // Verify that the SSLInfo of a successful SSL connection has valid values. |
98 void CheckSSLInfo(const net::SSLInfo& ssl_info) { | 98 void CheckSSLInfo(const net::SSLInfo& ssl_info) { |
99 // Allow ChromeFrame fake SSLInfo to get through. | 99 // Allow ChromeFrame fake SSLInfo to get through. |
100 if (ssl_info.cert.get() && | 100 if (ssl_info.cert.get() && |
101 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { | 101 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { |
102 // -1 means unknown. | 102 // -1 means unknown. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 ptr += 10; | 139 ptr += 10; |
140 if (idx % 100 == 0) { | 140 if (idx % 100 == 0) { |
141 ptr--; | 141 ptr--; |
142 *ptr++ = marker; | 142 *ptr++ = marker; |
143 if (++marker > 'z') | 143 if (++marker > 'z') |
144 marker = 'a'; | 144 marker = 'a'; |
145 } | 145 } |
146 } | 146 } |
147 uploadBytes[kMsgSize] = '\0'; | 147 uploadBytes[kMsgSize] = '\0'; |
148 | 148 |
149 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 149 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
150 | 150 |
151 for (int i = 0; i < kIterations; ++i) { | 151 for (int i = 0; i < kIterations; ++i) { |
152 TestDelegate d; | 152 TestDelegate d; |
153 URLRequest r(test_server_.GetURL("echo"), &d); | 153 URLRequest r(test_server_.GetURL("echo"), &d); |
154 r.set_context(context); | 154 r.set_context(context); |
155 r.set_method(method.c_str()); | 155 r.set_method(method.c_str()); |
156 | 156 |
157 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 157 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
158 | 158 |
159 r.Start(); | 159 r.Start(); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 520 |
521 // we won't actually get a received reponse here because we've never run the | 521 // we won't actually get a received reponse here because we've never run the |
522 // message loop | 522 // message loop |
523 EXPECT_FALSE(d.received_data_before_response()); | 523 EXPECT_FALSE(d.received_data_before_response()); |
524 EXPECT_EQ(0, d.bytes_received()); | 524 EXPECT_EQ(0, d.bytes_received()); |
525 } | 525 } |
526 | 526 |
527 TEST_F(URLRequestTestHTTP, CancelTest5) { | 527 TEST_F(URLRequestTestHTTP, CancelTest5) { |
528 ASSERT_TRUE(test_server_.Start()); | 528 ASSERT_TRUE(test_server_.Start()); |
529 | 529 |
530 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 530 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
531 | 531 |
532 // populate cache | 532 // populate cache |
533 { | 533 { |
534 TestDelegate d; | 534 TestDelegate d; |
535 URLRequest r(test_server_.GetURL("cachetime"), &d); | 535 URLRequest r(test_server_.GetURL("cachetime"), &d); |
536 r.set_context(context); | 536 r.set_context(context); |
537 r.Start(); | 537 r.Start(); |
538 MessageLoop::current()->Run(); | 538 MessageLoop::current()->Run(); |
539 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 539 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
540 } | 540 } |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 EXPECT_EQ(1, d.response_started_count()); | 1127 EXPECT_EQ(1, d.response_started_count()); |
1128 EXPECT_EQ(0, d.bytes_received()); | 1128 EXPECT_EQ(0, d.bytes_received()); |
1129 EXPECT_FALSE(d.received_data_before_response()); | 1129 EXPECT_FALSE(d.received_data_before_response()); |
1130 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1130 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1131 } | 1131 } |
1132 } | 1132 } |
1133 | 1133 |
1134 TEST_F(URLRequestTestHTTP, VaryHeader) { | 1134 TEST_F(URLRequestTestHTTP, VaryHeader) { |
1135 ASSERT_TRUE(test_server_.Start()); | 1135 ASSERT_TRUE(test_server_.Start()); |
1136 | 1136 |
1137 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1137 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1138 | 1138 |
1139 // populate the cache | 1139 // populate the cache |
1140 { | 1140 { |
1141 TestDelegate d; | 1141 TestDelegate d; |
1142 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); | 1142 URLRequest req(test_server_.GetURL("echoheader?foo"), &d); |
1143 req.set_context(context); | 1143 req.set_context(context); |
1144 net::HttpRequestHeaders headers; | 1144 net::HttpRequestHeaders headers; |
1145 headers.SetHeader("foo", "1"); | 1145 headers.SetHeader("foo", "1"); |
1146 req.SetExtraRequestHeaders(headers); | 1146 req.SetExtraRequestHeaders(headers); |
1147 req.Start(); | 1147 req.Start(); |
(...skipping 25 matching lines...) Expand all Loading... |
1173 req.Start(); | 1173 req.Start(); |
1174 MessageLoop::current()->Run(); | 1174 MessageLoop::current()->Run(); |
1175 | 1175 |
1176 EXPECT_FALSE(req.was_cached()); | 1176 EXPECT_FALSE(req.was_cached()); |
1177 } | 1177 } |
1178 } | 1178 } |
1179 | 1179 |
1180 TEST_F(URLRequestTestHTTP, BasicAuth) { | 1180 TEST_F(URLRequestTestHTTP, BasicAuth) { |
1181 ASSERT_TRUE(test_server_.Start()); | 1181 ASSERT_TRUE(test_server_.Start()); |
1182 | 1182 |
1183 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1183 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1184 | 1184 |
1185 // populate the cache | 1185 // populate the cache |
1186 { | 1186 { |
1187 TestDelegate d; | 1187 TestDelegate d; |
1188 d.set_username(kUser); | 1188 d.set_username(kUser); |
1189 d.set_password(kSecret); | 1189 d.set_password(kSecret); |
1190 | 1190 |
1191 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1191 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
1192 r.set_context(context); | 1192 r.set_context(context); |
1193 r.Start(); | 1193 r.Start(); |
(...skipping 29 matching lines...) Expand all Loading... |
1223 // http://crbug.com/6450 | 1223 // http://crbug.com/6450 |
1224 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 1224 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
1225 ASSERT_TRUE(test_server_.Start()); | 1225 ASSERT_TRUE(test_server_.Start()); |
1226 | 1226 |
1227 GURL url_requiring_auth = | 1227 GURL url_requiring_auth = |
1228 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 1228 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
1229 | 1229 |
1230 // Request a page that will give a 401 containing a Set-Cookie header. | 1230 // Request a page that will give a 401 containing a Set-Cookie header. |
1231 // Verify that when the transaction is restarted, it includes the new cookie. | 1231 // Verify that when the transaction is restarted, it includes the new cookie. |
1232 { | 1232 { |
1233 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1233 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1234 TestDelegate d; | 1234 TestDelegate d; |
1235 d.set_username(kUser); | 1235 d.set_username(kUser); |
1236 d.set_password(kSecret); | 1236 d.set_password(kSecret); |
1237 | 1237 |
1238 URLRequest r(url_requiring_auth, &d); | 1238 URLRequest r(url_requiring_auth, &d); |
1239 r.set_context(context); | 1239 r.set_context(context); |
1240 r.Start(); | 1240 r.Start(); |
1241 | 1241 |
1242 MessageLoop::current()->Run(); | 1242 MessageLoop::current()->Run(); |
1243 | 1243 |
1244 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 1244 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
1245 | 1245 |
1246 // Make sure we sent the cookie in the restarted transaction. | 1246 // Make sure we sent the cookie in the restarted transaction. |
1247 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1247 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1248 != std::string::npos); | 1248 != std::string::npos); |
1249 } | 1249 } |
1250 | 1250 |
1251 // Same test as above, except this time the restart is initiated earlier | 1251 // Same test as above, except this time the restart is initiated earlier |
1252 // (without user intervention since identity is embedded in the URL). | 1252 // (without user intervention since identity is embedded in the URL). |
1253 { | 1253 { |
1254 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1254 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1255 TestDelegate d; | 1255 TestDelegate d; |
1256 | 1256 |
1257 GURL::Replacements replacements; | 1257 GURL::Replacements replacements; |
1258 std::string username("user2"); | 1258 std::string username("user2"); |
1259 std::string password("secret"); | 1259 std::string password("secret"); |
1260 replacements.SetUsernameStr(username); | 1260 replacements.SetUsernameStr(username); |
1261 replacements.SetPasswordStr(password); | 1261 replacements.SetPasswordStr(password); |
1262 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 1262 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
1263 | 1263 |
1264 URLRequest r(url_with_identity, &d); | 1264 URLRequest r(url_with_identity, &d); |
1265 r.set_context(context); | 1265 r.set_context(context); |
1266 r.Start(); | 1266 r.Start(); |
1267 | 1267 |
1268 MessageLoop::current()->Run(); | 1268 MessageLoop::current()->Run(); |
1269 | 1269 |
1270 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 1270 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
1271 | 1271 |
1272 // Make sure we sent the cookie in the restarted transaction. | 1272 // Make sure we sent the cookie in the restarted transaction. |
1273 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1273 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1274 != std::string::npos); | 1274 != std::string::npos); |
1275 } | 1275 } |
1276 } | 1276 } |
1277 | 1277 |
1278 TEST_F(URLRequestTest, DoNotSendCookies) { | 1278 TEST_F(URLRequestTest, DoNotSendCookies) { |
1279 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1279 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1280 ASSERT_TRUE(test_server.Start()); | 1280 ASSERT_TRUE(test_server.Start()); |
1281 | 1281 |
1282 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1282 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1283 | 1283 |
1284 // Set up a cookie. | 1284 // Set up a cookie. |
1285 { | 1285 { |
1286 TestDelegate d; | 1286 TestDelegate d; |
1287 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1287 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
1288 req.set_context(context); | 1288 req.set_context(context); |
1289 req.Start(); | 1289 req.Start(); |
1290 MessageLoop::current()->Run(); | 1290 MessageLoop::current()->Run(); |
1291 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1291 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1292 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1292 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
(...skipping 28 matching lines...) Expand all Loading... |
1321 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 1321 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
1322 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1322 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1323 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1323 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1324 } | 1324 } |
1325 } | 1325 } |
1326 | 1326 |
1327 TEST_F(URLRequestTest, DoNotSaveCookies) { | 1327 TEST_F(URLRequestTest, DoNotSaveCookies) { |
1328 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1328 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1329 ASSERT_TRUE(test_server.Start()); | 1329 ASSERT_TRUE(test_server.Start()); |
1330 | 1330 |
1331 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1331 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); |
1332 | 1332 |
1333 // Set up a cookie. | 1333 // Set up a cookie. |
1334 { | 1334 { |
1335 TestDelegate d; | 1335 TestDelegate d; |
1336 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1336 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1337 &d); | 1337 &d); |
1338 req.set_context(context); | 1338 req.set_context(context); |
1339 req.Start(); | 1339 req.Start(); |
1340 MessageLoop::current()->Run(); | 1340 MessageLoop::current()->Run(); |
1341 | 1341 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1377 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1378 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1378 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1379 EXPECT_EQ(0, d.set_cookie_count()); | 1379 EXPECT_EQ(0, d.set_cookie_count()); |
1380 } | 1380 } |
1381 } | 1381 } |
1382 | 1382 |
1383 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 1383 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
1384 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1384 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1385 ASSERT_TRUE(test_server.Start()); | 1385 ASSERT_TRUE(test_server.Start()); |
1386 | 1386 |
1387 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1387 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1388 | 1388 |
1389 // Set up a cookie. | 1389 // Set up a cookie. |
1390 { | 1390 { |
1391 TestDelegate d; | 1391 TestDelegate d; |
1392 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1392 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
1393 req.set_context(context); | 1393 req.set_context(context); |
1394 req.Start(); | 1394 req.Start(); |
1395 MessageLoop::current()->Run(); | 1395 MessageLoop::current()->Run(); |
1396 | 1396 |
1397 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1397 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 | 1431 |
1432 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1432 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1433 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1433 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1434 } | 1434 } |
1435 } | 1435 } |
1436 | 1436 |
1437 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 1437 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
1438 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1438 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1439 ASSERT_TRUE(test_server.Start()); | 1439 ASSERT_TRUE(test_server.Start()); |
1440 | 1440 |
1441 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1441 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1442 | 1442 |
1443 // Set up a cookie. | 1443 // Set up a cookie. |
1444 { | 1444 { |
1445 TestDelegate d; | 1445 TestDelegate d; |
1446 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1446 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1447 &d); | 1447 &d); |
1448 req.set_context(context); | 1448 req.set_context(context); |
1449 req.Start(); | 1449 req.Start(); |
1450 MessageLoop::current()->Run(); | 1450 MessageLoop::current()->Run(); |
1451 | 1451 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 | 1488 |
1489 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1489 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1490 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1490 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1491 } | 1491 } |
1492 } | 1492 } |
1493 | 1493 |
1494 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 1494 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
1495 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1495 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1496 ASSERT_TRUE(test_server.Start()); | 1496 ASSERT_TRUE(test_server.Start()); |
1497 | 1497 |
1498 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1498 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1499 | 1499 |
1500 // Set up an empty cookie. | 1500 // Set up an empty cookie. |
1501 { | 1501 { |
1502 TestDelegate d; | 1502 TestDelegate d; |
1503 URLRequest req(test_server.GetURL("set-cookie"), &d); | 1503 URLRequest req(test_server.GetURL("set-cookie"), &d); |
1504 req.set_context(context); | 1504 req.set_context(context); |
1505 req.Start(); | 1505 req.Start(); |
1506 MessageLoop::current()->Run(); | 1506 MessageLoop::current()->Run(); |
1507 | 1507 |
1508 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1508 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1509 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1509 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1510 EXPECT_EQ(0, d.set_cookie_count()); | 1510 EXPECT_EQ(0, d.set_cookie_count()); |
1511 } | 1511 } |
1512 } | 1512 } |
1513 | 1513 |
1514 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 1514 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
1515 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1515 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1516 ASSERT_TRUE(test_server.Start()); | 1516 ASSERT_TRUE(test_server.Start()); |
1517 | 1517 |
1518 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1518 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1519 | 1519 |
1520 // Set up a cookie. | 1520 // Set up a cookie. |
1521 { | 1521 { |
1522 TestDelegate d; | 1522 TestDelegate d; |
1523 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 1523 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
1524 req.set_context(context); | 1524 req.set_context(context); |
1525 req.Start(); | 1525 req.Start(); |
1526 MessageLoop::current()->Run(); | 1526 MessageLoop::current()->Run(); |
1527 | 1527 |
1528 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1528 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 | 1563 |
1564 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1564 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1565 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1565 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1566 } | 1566 } |
1567 } | 1567 } |
1568 | 1568 |
1569 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 1569 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
1570 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1570 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1571 ASSERT_TRUE(test_server.Start()); | 1571 ASSERT_TRUE(test_server.Start()); |
1572 | 1572 |
1573 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1573 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1574 | 1574 |
1575 // Set up a cookie. | 1575 // Set up a cookie. |
1576 { | 1576 { |
1577 TestDelegate d; | 1577 TestDelegate d; |
1578 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), | 1578 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
1579 &d); | 1579 &d); |
1580 req.set_context(context); | 1580 req.set_context(context); |
1581 req.Start(); | 1581 req.Start(); |
1582 MessageLoop::current()->Run(); | 1582 MessageLoop::current()->Run(); |
1583 | 1583 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 | 1620 |
1621 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1621 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1622 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1622 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1623 } | 1623 } |
1624 } | 1624 } |
1625 | 1625 |
1626 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { | 1626 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { |
1627 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1627 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1628 ASSERT_TRUE(test_server.Start()); | 1628 ASSERT_TRUE(test_server.Start()); |
1629 | 1629 |
1630 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1630 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1631 | 1631 |
1632 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); | 1632 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); |
1633 context->set_cookie_policy(&cookie_policy); | 1633 context->set_cookie_policy(&cookie_policy); |
1634 | 1634 |
1635 // Set up a cookie. | 1635 // Set up a cookie. |
1636 { | 1636 { |
1637 TestDelegate d; | 1637 TestDelegate d; |
1638 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1638 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1639 &d); | 1639 &d); |
1640 req.set_context(context); | 1640 req.set_context(context); |
(...skipping 10 matching lines...) Expand all Loading... |
1651 | 1651 |
1652 // Let the cookie policy complete. Make sure it handles the destruction of | 1652 // Let the cookie policy complete. Make sure it handles the destruction of |
1653 // the URLRequest properly. | 1653 // the URLRequest properly. |
1654 MessageLoop::current()->RunAllPending(); | 1654 MessageLoop::current()->RunAllPending(); |
1655 } | 1655 } |
1656 | 1656 |
1657 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { | 1657 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { |
1658 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1658 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1659 ASSERT_TRUE(test_server.Start()); | 1659 ASSERT_TRUE(test_server.Start()); |
1660 | 1660 |
1661 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1661 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1662 | 1662 |
1663 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); | 1663 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); |
1664 context->set_cookie_policy(&cookie_policy); | 1664 context->set_cookie_policy(&cookie_policy); |
1665 | 1665 |
1666 // Set up a cookie. | 1666 // Set up a cookie. |
1667 { | 1667 { |
1668 TestDelegate d; | 1668 TestDelegate d; |
1669 d.set_cancel_in_get_cookies_blocked(true); | 1669 d.set_cancel_in_get_cookies_blocked(true); |
1670 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1670 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1671 &d); | 1671 &d); |
1672 req.set_context(context); | 1672 req.set_context(context); |
1673 req.Start(); // Triggers an asynchronous cookie policy check. | 1673 req.Start(); // Triggers an asynchronous cookie policy check. |
1674 | 1674 |
1675 MessageLoop::current()->Run(); | 1675 MessageLoop::current()->Run(); |
1676 | 1676 |
1677 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1677 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1678 | 1678 |
1679 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1679 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1680 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1680 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1681 } | 1681 } |
1682 | 1682 |
1683 context->set_cookie_policy(NULL); | 1683 context->set_cookie_policy(NULL); |
1684 } | 1684 } |
1685 | 1685 |
1686 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { | 1686 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { |
1687 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1687 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1688 ASSERT_TRUE(test_server.Start()); | 1688 ASSERT_TRUE(test_server.Start()); |
1689 | 1689 |
1690 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1690 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1691 | 1691 |
1692 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1692 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
1693 context->set_cookie_policy(&cookie_policy); | 1693 context->set_cookie_policy(&cookie_policy); |
1694 | 1694 |
1695 // Set up a cookie. | 1695 // Set up a cookie. |
1696 { | 1696 { |
1697 TestDelegate d; | 1697 TestDelegate d; |
1698 d.set_cancel_in_set_cookie_blocked(true); | 1698 d.set_cancel_in_set_cookie_blocked(true); |
1699 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), | 1699 URLRequest req(test_server.GetURL("set-cookie?A=1&B=2&C=3"), |
1700 &d); | 1700 &d); |
(...skipping 13 matching lines...) Expand all Loading... |
1714 EXPECT_EQ(1, d.blocked_set_cookie_count()); | 1714 EXPECT_EQ(1, d.blocked_set_cookie_count()); |
1715 } | 1715 } |
1716 | 1716 |
1717 context->set_cookie_policy(NULL); | 1717 context->set_cookie_policy(NULL); |
1718 } | 1718 } |
1719 | 1719 |
1720 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 1720 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
1721 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); | 1721 net::TestServer test_server(net::TestServer::TYPE_HTTP, FilePath()); |
1722 ASSERT_TRUE(test_server.Start()); | 1722 ASSERT_TRUE(test_server.Start()); |
1723 | 1723 |
1724 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1724 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
1725 | 1725 |
1726 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); | 1726 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); |
1727 context->set_cookie_policy(&cookie_policy); | 1727 context->set_cookie_policy(&cookie_policy); |
1728 | 1728 |
1729 // Set up a cookie. | 1729 // Set up a cookie. |
1730 { | 1730 { |
1731 TestDelegate d; | 1731 TestDelegate d; |
1732 URLRequest req(test_server.GetURL( | 1732 URLRequest req(test_server.GetURL( |
1733 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 1733 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); |
1734 req.set_context(context); | 1734 req.set_context(context); |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2631 TestURLRequest | 2631 TestURLRequest |
2632 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); | 2632 req(test_server_.GetURL("echoheaderoverride?Accept-Charset"), &d); |
2633 req.set_context(new TestURLRequestContext()); | 2633 req.set_context(new TestURLRequestContext()); |
2634 net::HttpRequestHeaders headers; | 2634 net::HttpRequestHeaders headers; |
2635 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2635 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
2636 req.SetExtraRequestHeaders(headers); | 2636 req.SetExtraRequestHeaders(headers); |
2637 req.Start(); | 2637 req.Start(); |
2638 MessageLoop::current()->Run(); | 2638 MessageLoop::current()->Run(); |
2639 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2639 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
2640 } | 2640 } |
OLD | NEW |