OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 <windows.h> | 10 #include <windows.h> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 92 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
93 class URLRequestTest : public PlatformTest { | 93 class URLRequestTest : public PlatformTest { |
94 }; | 94 }; |
95 | 95 |
96 class URLRequestTestHTTP : public URLRequestTest { | 96 class URLRequestTestHTTP : public URLRequestTest { |
97 protected: | 97 protected: |
98 static void SetUpTestCase() { | 98 static void SetUpTestCase() { |
99 server_ = HTTPTestServer::CreateForkingServer( | 99 server_ = HTTPTestServer::CreateServer(L"net/data/url_request_unittest/"); |
100 L"net/data/url_request_unittest/"); | |
101 } | 100 } |
102 | 101 |
103 static void TearDownTestCase() { | 102 static void TearDownTestCase() { |
104 server_ = NULL; | 103 server_ = NULL; |
105 } | 104 } |
106 | 105 |
107 void HTTPUploadDataOperationTest(const std::string& method) { | 106 void HTTPUploadDataOperationTest(const std::string& method) { |
108 ASSERT_TRUE(NULL != server_.get()); | 107 ASSERT_TRUE(NULL != server_.get()); |
109 const int kMsgSize = 20000; // multiple of 10 | 108 const int kMsgSize = 20000; // multiple of 10 |
110 const int kIterations = 50; | 109 const int kIterations = 50; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 req.set_referrer("https://www.referrer.com/"); | 254 req.set_referrer("https://www.referrer.com/"); |
256 req.Start(); | 255 req.Start(); |
257 MessageLoop::current()->Run(); | 256 MessageLoop::current()->Run(); |
258 | 257 |
259 EXPECT_EQ(1, d.response_started_count()); | 258 EXPECT_EQ(1, d.response_started_count()); |
260 EXPECT_EQ(1, d.received_redirect_count()); | 259 EXPECT_EQ(1, d.received_redirect_count()); |
261 EXPECT_EQ(http_destination, req.url()); | 260 EXPECT_EQ(http_destination, req.url()); |
262 EXPECT_EQ(std::string(), req.referrer()); | 261 EXPECT_EQ(std::string(), req.referrer()); |
263 } | 262 } |
264 | 263 |
| 264 namespace { |
| 265 |
| 266 // Used by MakeGETRequest to implement sync load behavior. |
| 267 class SyncTestDelegate : public TestDelegate { |
| 268 public: |
| 269 SyncTestDelegate() : event_(false, false), success_(false) { |
| 270 } |
| 271 virtual void OnResponseCompleted(URLRequest* request) { |
| 272 MessageLoop::current()->DeleteSoon(FROM_HERE, request); |
| 273 success_ = request->status().is_success(); |
| 274 event_.Signal(); |
| 275 } |
| 276 bool Wait(int64 secs) { |
| 277 return event_.TimedWait(TimeDelta::FromSeconds(secs)); |
| 278 } |
| 279 bool did_succeed() const { return success_; } |
| 280 private: |
| 281 base::WaitableEvent event_; |
| 282 bool success_; |
| 283 DISALLOW_COPY_AND_ASSIGN(SyncTestDelegate); |
| 284 }; |
| 285 |
| 286 void StartGETRequest(const GURL& url, URLRequest::Delegate* delegate) { |
| 287 URLRequest* request = new URLRequest(url, delegate); |
| 288 request->set_context(new TestURLRequestContext()); |
| 289 request->set_method("GET"); |
| 290 request->Start(); |
| 291 EXPECT_TRUE(request->is_pending()); |
| 292 } |
| 293 |
| 294 bool MakeGETRequest(const GURL& url) { |
| 295 // Spin up a background thread for this request so that we have access to |
| 296 // an IO message loop, and in cases where this thread already has an IO |
| 297 // message loop, we also want to avoid spinning a nested message loop. |
| 298 SyncTestDelegate d; |
| 299 { |
| 300 base::Thread io_thread("MakeGETRequest"); |
| 301 base::Thread::Options options; |
| 302 options.message_loop_type = MessageLoop::TYPE_IO; |
| 303 io_thread.StartWithOptions(options); |
| 304 io_thread.message_loop()->PostTask(FROM_HERE, NewRunnableFunction( |
| 305 &StartGETRequest, url, &d)); |
| 306 |
| 307 const int kWaitSeconds = 30; |
| 308 if (!d.Wait(kWaitSeconds)) |
| 309 return false; |
| 310 } |
| 311 return d.did_succeed(); |
| 312 } |
| 313 |
| 314 } // namespace |
| 315 |
| 316 // Some tests use browser javascript to fetch a 'kill' url that causes |
| 317 // the server to exit by itself (rather than letting TestServerLauncher's |
| 318 // destructor kill it). We now unit test this mechanism. |
265 TEST_F(URLRequestTest, QuitTest) { | 319 TEST_F(URLRequestTest, QuitTest) { |
266 // Don't use shared server here because we order it to quit. | 320 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
267 // It would impact other tests. | |
268 scoped_refptr<HTTPTestServer> server = | |
269 HTTPTestServer::CreateServer(L"", NULL); | |
270 ASSERT_TRUE(NULL != server.get()); | 321 ASSERT_TRUE(NULL != server.get()); |
271 server->SendQuit(); | 322 // Append the time to avoid problems where the kill page |
| 323 // is being cached rather than being executed on the server |
| 324 std::string page_name = StringPrintf("kill?%u", |
| 325 static_cast<int>(base::Time::Now().ToInternalValue())); |
| 326 int retry_count = 5; |
| 327 while (retry_count > 0) { |
| 328 bool r = MakeGETRequest(server->TestServerPage(page_name)); |
| 329 // BUG #1048625 causes the kill GET to fail. For now we just retry. |
| 330 // Once the bug is fixed, we should remove the while loop and put back |
| 331 // the following DCHECK. |
| 332 // DCHECK(r); |
| 333 if (r) |
| 334 break; |
| 335 retry_count--; |
| 336 } |
| 337 // Make sure we were successful in stopping the testserver. |
| 338 EXPECT_LT(0, retry_count); |
272 EXPECT_TRUE(server->WaitToFinish(20000)); | 339 EXPECT_TRUE(server->WaitToFinish(20000)); |
273 } | 340 } |
274 | 341 |
275 class HTTPSRequestTest : public testing::Test { | 342 class HTTPSRequestTest : public testing::Test { |
276 }; | 343 }; |
277 | 344 |
278 | 345 |
279 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 346 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
280 // Note: tools/testserver/testserver.py does not need | 347 // Note: tools/testserver/testserver.py does not need |
281 // a working document root to server the pages / and /hello.html, | 348 // a working document root to server the pages / and /hello.html, |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 | 1249 |
1183 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 1250 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
1184 | 1251 |
1185 // Make sure we sent the cookie in the restarted transaction. | 1252 // Make sure we sent the cookie in the restarted transaction. |
1186 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 1253 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
1187 != std::string::npos); | 1254 != std::string::npos); |
1188 } | 1255 } |
1189 } | 1256 } |
1190 | 1257 |
1191 TEST_F(URLRequestTest, DoNotSendCookies) { | 1258 TEST_F(URLRequestTest, DoNotSendCookies) { |
1192 scoped_refptr<HTTPTestServer> server = | 1259 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1193 HTTPTestServer::CreateServer(L"", NULL); | |
1194 ASSERT_TRUE(NULL != server.get()); | 1260 ASSERT_TRUE(NULL != server.get()); |
1195 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1261 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); |
1196 | 1262 |
1197 // Set up a cookie. | 1263 // Set up a cookie. |
1198 { | 1264 { |
1199 TestDelegate d; | 1265 TestDelegate d; |
1200 URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); | 1266 URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); |
1201 req.set_context(context); | 1267 req.set_context(context); |
1202 req.Start(); | 1268 req.Start(); |
1203 MessageLoop::current()->Run(); | 1269 MessageLoop::current()->Run(); |
(...skipping 27 matching lines...) Expand all Loading... |
1231 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 1297 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
1232 == std::string::npos); | 1298 == std::string::npos); |
1233 | 1299 |
1234 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 1300 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
1235 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1301 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1236 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1302 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1237 } | 1303 } |
1238 } | 1304 } |
1239 | 1305 |
1240 TEST_F(URLRequestTest, DoNotSaveCookies) { | 1306 TEST_F(URLRequestTest, DoNotSaveCookies) { |
1241 scoped_refptr<HTTPTestServer> server = | 1307 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1242 HTTPTestServer::CreateServer(L"", NULL); | |
1243 ASSERT_TRUE(NULL != server.get()); | 1308 ASSERT_TRUE(NULL != server.get()); |
1244 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1309 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); |
1245 | 1310 |
1246 // Set up a cookie. | 1311 // Set up a cookie. |
1247 { | 1312 { |
1248 TestDelegate d; | 1313 TestDelegate d; |
1249 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), | 1314 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), |
1250 &d); | 1315 &d); |
1251 req.set_context(context); | 1316 req.set_context(context); |
1252 req.Start(); | 1317 req.Start(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1352 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
1288 != std::string::npos); | 1353 != std::string::npos); |
1289 | 1354 |
1290 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1355 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1291 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1356 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1292 EXPECT_EQ(0, d.set_cookie_count()); | 1357 EXPECT_EQ(0, d.set_cookie_count()); |
1293 } | 1358 } |
1294 } | 1359 } |
1295 | 1360 |
1296 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 1361 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
1297 scoped_refptr<HTTPTestServer> server = | 1362 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1298 HTTPTestServer::CreateServer(L"", NULL); | |
1299 ASSERT_TRUE(NULL != server.get()); | 1363 ASSERT_TRUE(NULL != server.get()); |
1300 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1364 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1301 | 1365 |
1302 // Set up a cookie. | 1366 // Set up a cookie. |
1303 { | 1367 { |
1304 TestDelegate d; | 1368 TestDelegate d; |
1305 URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); | 1369 URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); |
1306 req.set_context(context); | 1370 req.set_context(context); |
1307 req.Start(); | 1371 req.Start(); |
1308 MessageLoop::current()->Run(); | 1372 MessageLoop::current()->Run(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 == std::string::npos); | 1405 == std::string::npos); |
1342 | 1406 |
1343 context->set_cookie_policy(NULL); | 1407 context->set_cookie_policy(NULL); |
1344 | 1408 |
1345 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1409 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1346 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1410 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1347 } | 1411 } |
1348 } | 1412 } |
1349 | 1413 |
1350 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 1414 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
1351 scoped_refptr<HTTPTestServer> server = | 1415 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1352 HTTPTestServer::CreateServer(L"", NULL); | |
1353 ASSERT_TRUE(NULL != server.get()); | 1416 ASSERT_TRUE(NULL != server.get()); |
1354 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1417 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1355 | 1418 |
1356 // Set up a cookie. | 1419 // Set up a cookie. |
1357 { | 1420 { |
1358 TestDelegate d; | 1421 TestDelegate d; |
1359 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), | 1422 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), |
1360 &d); | 1423 &d); |
1361 req.set_context(context); | 1424 req.set_context(context); |
1362 req.Start(); | 1425 req.Start(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 == std::string::npos); | 1461 == std::string::npos); |
1399 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1462 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
1400 != std::string::npos); | 1463 != std::string::npos); |
1401 | 1464 |
1402 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1465 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1403 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1466 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1404 } | 1467 } |
1405 } | 1468 } |
1406 | 1469 |
1407 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 1470 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
1408 scoped_refptr<HTTPTestServer> server = | 1471 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1409 HTTPTestServer::CreateServer(L"", NULL); | |
1410 ASSERT_TRUE(NULL != server.get()); | 1472 ASSERT_TRUE(NULL != server.get()); |
1411 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1473 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1412 | 1474 |
1413 // Set up a cookie. | 1475 // Set up a cookie. |
1414 { | 1476 { |
1415 TestDelegate d; | 1477 TestDelegate d; |
1416 URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); | 1478 URLRequest req(server->TestServerPage("set-cookie?CookieToNotSend=1"), &d); |
1417 req.set_context(context); | 1479 req.set_context(context); |
1418 req.Start(); | 1480 req.Start(); |
1419 MessageLoop::current()->Run(); | 1481 MessageLoop::current()->Run(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 == std::string::npos); | 1515 == std::string::npos); |
1454 | 1516 |
1455 context->set_cookie_policy(NULL); | 1517 context->set_cookie_policy(NULL); |
1456 | 1518 |
1457 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1519 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1458 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1520 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1459 } | 1521 } |
1460 } | 1522 } |
1461 | 1523 |
1462 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 1524 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
1463 scoped_refptr<HTTPTestServer> server = | 1525 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1464 HTTPTestServer::CreateServer(L"", NULL); | |
1465 ASSERT_TRUE(NULL != server.get()); | 1526 ASSERT_TRUE(NULL != server.get()); |
1466 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1527 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1467 | 1528 |
1468 // Set up a cookie. | 1529 // Set up a cookie. |
1469 { | 1530 { |
1470 TestDelegate d; | 1531 TestDelegate d; |
1471 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), | 1532 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), |
1472 &d); | 1533 &d); |
1473 req.set_context(context); | 1534 req.set_context(context); |
1474 req.Start(); | 1535 req.Start(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 == std::string::npos); | 1571 == std::string::npos); |
1511 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1572 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
1512 != std::string::npos); | 1573 != std::string::npos); |
1513 | 1574 |
1514 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1575 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1515 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1576 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1516 } | 1577 } |
1517 } | 1578 } |
1518 | 1579 |
1519 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { | 1580 TEST_F(URLRequestTest, CancelTest_During_CookiePolicy) { |
1520 scoped_refptr<HTTPTestServer> server = | 1581 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1521 HTTPTestServer::CreateServer(L"", NULL); | |
1522 ASSERT_TRUE(NULL != server.get()); | 1582 ASSERT_TRUE(NULL != server.get()); |
1523 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1583 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1524 | 1584 |
1525 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); | 1585 TestCookiePolicy cookie_policy(TestCookiePolicy::ASYNC); |
1526 context->set_cookie_policy(&cookie_policy); | 1586 context->set_cookie_policy(&cookie_policy); |
1527 | 1587 |
1528 // Set up a cookie. | 1588 // Set up a cookie. |
1529 { | 1589 { |
1530 TestDelegate d; | 1590 TestDelegate d; |
1531 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), | 1591 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), |
1532 &d); | 1592 &d); |
1533 req.set_context(context); | 1593 req.set_context(context); |
1534 req.Start(); // Triggers an asynchronous cookie policy check. | 1594 req.Start(); // Triggers an asynchronous cookie policy check. |
1535 | 1595 |
1536 // But, now we cancel the request by letting it go out of scope. This | 1596 // But, now we cancel the request by letting it go out of scope. This |
1537 // should not cause a crash. | 1597 // should not cause a crash. |
1538 | 1598 |
1539 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1599 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1540 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1600 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1541 } | 1601 } |
1542 | 1602 |
1543 context->set_cookie_policy(NULL); | 1603 context->set_cookie_policy(NULL); |
1544 | 1604 |
1545 // Let the cookie policy complete. Make sure it handles the destruction of | 1605 // Let the cookie policy complete. Make sure it handles the destruction of |
1546 // the URLRequest properly. | 1606 // the URLRequest properly. |
1547 MessageLoop::current()->RunAllPending(); | 1607 MessageLoop::current()->RunAllPending(); |
1548 } | 1608 } |
1549 | 1609 |
1550 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { | 1610 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { |
1551 scoped_refptr<HTTPTestServer> server = | 1611 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1552 HTTPTestServer::CreateServer(L"", NULL); | |
1553 ASSERT_TRUE(NULL != server.get()); | 1612 ASSERT_TRUE(NULL != server.get()); |
1554 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1613 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1555 | 1614 |
1556 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); | 1615 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); |
1557 context->set_cookie_policy(&cookie_policy); | 1616 context->set_cookie_policy(&cookie_policy); |
1558 | 1617 |
1559 // Set up a cookie. | 1618 // Set up a cookie. |
1560 { | 1619 { |
1561 TestDelegate d; | 1620 TestDelegate d; |
1562 d.set_cancel_in_get_cookies_blocked(true); | 1621 d.set_cancel_in_get_cookies_blocked(true); |
1563 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), | 1622 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), |
1564 &d); | 1623 &d); |
1565 req.set_context(context); | 1624 req.set_context(context); |
1566 req.Start(); // Triggers an asynchronous cookie policy check. | 1625 req.Start(); // Triggers an asynchronous cookie policy check. |
1567 | 1626 |
1568 MessageLoop::current()->Run(); | 1627 MessageLoop::current()->Run(); |
1569 | 1628 |
1570 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1629 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1571 | 1630 |
1572 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1631 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1573 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1632 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1574 } | 1633 } |
1575 | 1634 |
1576 context->set_cookie_policy(NULL); | 1635 context->set_cookie_policy(NULL); |
1577 } | 1636 } |
1578 | 1637 |
1579 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { | 1638 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { |
1580 scoped_refptr<HTTPTestServer> server = | 1639 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1581 HTTPTestServer::CreateServer(L"", NULL); | |
1582 ASSERT_TRUE(NULL != server.get()); | 1640 ASSERT_TRUE(NULL != server.get()); |
1583 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1641 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1584 | 1642 |
1585 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1643 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
1586 context->set_cookie_policy(&cookie_policy); | 1644 context->set_cookie_policy(&cookie_policy); |
1587 | 1645 |
1588 // Set up a cookie. | 1646 // Set up a cookie. |
1589 { | 1647 { |
1590 TestDelegate d; | 1648 TestDelegate d; |
1591 d.set_cancel_in_set_cookie_blocked(true); | 1649 d.set_cancel_in_set_cookie_blocked(true); |
(...skipping 12 matching lines...) Expand all Loading... |
1604 // attempt to set further cookies. | 1662 // attempt to set further cookies. |
1605 | 1663 |
1606 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1664 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1607 EXPECT_EQ(1, d.blocked_set_cookie_count()); | 1665 EXPECT_EQ(1, d.blocked_set_cookie_count()); |
1608 } | 1666 } |
1609 | 1667 |
1610 context->set_cookie_policy(NULL); | 1668 context->set_cookie_policy(NULL); |
1611 } | 1669 } |
1612 | 1670 |
1613 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 1671 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
1614 scoped_refptr<HTTPTestServer> server = | 1672 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(L"")); |
1615 HTTPTestServer::CreateServer(L"", NULL); | |
1616 ASSERT_TRUE(NULL != server.get()); | 1673 ASSERT_TRUE(NULL != server.get()); |
1617 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1674 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1618 | 1675 |
1619 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); | 1676 TestCookiePolicy cookie_policy(TestCookiePolicy::FORCE_SESSION); |
1620 context->set_cookie_policy(&cookie_policy); | 1677 context->set_cookie_policy(&cookie_policy); |
1621 | 1678 |
1622 // Set up a cookie. | 1679 // Set up a cookie. |
1623 { | 1680 { |
1624 TestDelegate d; | 1681 TestDelegate d; |
1625 URLRequest req(server->TestServerPage( | 1682 URLRequest req(server->TestServerPage( |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 TestURLRequest | 2552 TestURLRequest |
2496 req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); | 2553 req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); |
2497 req.set_context(new TestURLRequestContext()); | 2554 req.set_context(new TestURLRequestContext()); |
2498 net::HttpRequestHeaders headers; | 2555 net::HttpRequestHeaders headers; |
2499 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2556 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
2500 req.SetExtraRequestHeaders(headers); | 2557 req.SetExtraRequestHeaders(headers); |
2501 req.Start(); | 2558 req.Start(); |
2502 MessageLoop::current()->Run(); | 2559 MessageLoop::current()->Run(); |
2503 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2560 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
2504 } | 2561 } |
OLD | NEW |