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 1247 matching lines...) Loading... |
1258 TestDelegate d; | 1258 TestDelegate d; |
1259 TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); | 1259 TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); |
1260 req.set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); | 1260 req.set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); |
1261 req.set_context(context); | 1261 req.set_context(context); |
1262 req.Start(); | 1262 req.Start(); |
1263 MessageLoop::current()->Run(); | 1263 MessageLoop::current()->Run(); |
1264 | 1264 |
1265 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 1265 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
1266 == std::string::npos); | 1266 == std::string::npos); |
1267 | 1267 |
1268 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookiesBlocked. | 1268 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
1269 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1269 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1270 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1270 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1271 } | 1271 } |
1272 } | 1272 } |
1273 | 1273 |
1274 TEST_F(URLRequestTest, DoNotSaveCookies) { | 1274 TEST_F(URLRequestTest, DoNotSaveCookies) { |
1275 scoped_refptr<HTTPTestServer> server = | 1275 scoped_refptr<HTTPTestServer> server = |
1276 HTTPTestServer::CreateServer(L"", NULL); | 1276 HTTPTestServer::CreateServer(L"", NULL); |
1277 ASSERT_TRUE(NULL != server.get()); | 1277 ASSERT_TRUE(NULL != server.get()); |
1278 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); | 1278 scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); |
1279 | 1279 |
1280 // Set up a cookie. | 1280 // Set up a cookie. |
1281 { | 1281 { |
1282 TestDelegate d; | 1282 TestDelegate d; |
1283 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), | 1283 URLRequest req(server->TestServerPage("set-cookie?CookieToNotUpdate=2"), |
1284 &d); | 1284 &d); |
1285 req.set_context(context); | 1285 req.set_context(context); |
1286 req.Start(); | 1286 req.Start(); |
1287 MessageLoop::current()->Run(); | 1287 MessageLoop::current()->Run(); |
1288 | 1288 |
1289 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1289 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1290 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1290 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1291 EXPECT_EQ(1, d.set_cookie_count()); |
1291 } | 1292 } |
1292 | 1293 |
1293 // Try to set-up another cookie and update the previous cookie. | 1294 // Try to set-up another cookie and update the previous cookie. |
1294 { | 1295 { |
1295 TestDelegate d; | 1296 TestDelegate d; |
1296 URLRequest req(server->TestServerPage( | 1297 URLRequest req(server->TestServerPage( |
1297 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 1298 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
1298 req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); | 1299 req.set_load_flags(net::LOAD_DO_NOT_SAVE_COOKIES); |
1299 req.set_context(context); | 1300 req.set_context(context); |
1300 req.Start(); | 1301 req.Start(); |
1301 | 1302 |
1302 MessageLoop::current()->Run(); | 1303 MessageLoop::current()->Run(); |
1303 | 1304 |
1304 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookieBlocked. | 1305 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
1305 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1306 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1306 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1307 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1308 EXPECT_EQ(0, d.set_cookie_count()); |
1307 } | 1309 } |
1308 | 1310 |
1309 // Verify the cookies weren't saved or updated. | 1311 // Verify the cookies weren't saved or updated. |
1310 { | 1312 { |
1311 TestDelegate d; | 1313 TestDelegate d; |
1312 TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); | 1314 TestURLRequest req(server->TestServerPage("echoheader?Cookie"), &d); |
1313 req.set_context(context); | 1315 req.set_context(context); |
1314 req.Start(); | 1316 req.Start(); |
1315 MessageLoop::current()->Run(); | 1317 MessageLoop::current()->Run(); |
1316 | 1318 |
1317 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 1319 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
1318 == std::string::npos); | 1320 == std::string::npos); |
1319 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 1321 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
1320 != std::string::npos); | 1322 != std::string::npos); |
1321 | 1323 |
1322 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1324 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1323 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1325 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
| 1326 EXPECT_EQ(0, d.set_cookie_count()); |
1324 } | 1327 } |
1325 } | 1328 } |
1326 | 1329 |
1327 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 1330 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
1328 scoped_refptr<HTTPTestServer> server = | 1331 scoped_refptr<HTTPTestServer> server = |
1329 HTTPTestServer::CreateServer(L"", NULL); | 1332 HTTPTestServer::CreateServer(L"", NULL); |
1330 ASSERT_TRUE(NULL != server.get()); | 1333 ASSERT_TRUE(NULL != server.get()); |
1331 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1334 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1332 | 1335 |
1333 // Set up a cookie. | 1336 // Set up a cookie. |
(...skipping 237 matching lines...) Loading... |
1571 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1574 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1572 } | 1575 } |
1573 | 1576 |
1574 context->set_cookie_policy(NULL); | 1577 context->set_cookie_policy(NULL); |
1575 | 1578 |
1576 // Let the cookie policy complete. Make sure it handles the destruction of | 1579 // Let the cookie policy complete. Make sure it handles the destruction of |
1577 // the URLRequest properly. | 1580 // the URLRequest properly. |
1578 MessageLoop::current()->RunAllPending(); | 1581 MessageLoop::current()->RunAllPending(); |
1579 } | 1582 } |
1580 | 1583 |
1581 TEST_F(URLRequestTest, CancelTest_During_OnGetCookiesBlocked) { | 1584 TEST_F(URLRequestTest, CancelTest_During_OnGetCookies) { |
1582 scoped_refptr<HTTPTestServer> server = | 1585 scoped_refptr<HTTPTestServer> server = |
1583 HTTPTestServer::CreateServer(L"", NULL); | 1586 HTTPTestServer::CreateServer(L"", NULL); |
1584 ASSERT_TRUE(NULL != server.get()); | 1587 ASSERT_TRUE(NULL != server.get()); |
1585 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1588 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1586 | 1589 |
1587 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); | 1590 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_GET_COOKIES); |
1588 context->set_cookie_policy(&cookie_policy); | 1591 context->set_cookie_policy(&cookie_policy); |
1589 | 1592 |
1590 // Set up a cookie. | 1593 // Set up a cookie. |
1591 { | 1594 { |
1592 TestDelegate d; | 1595 TestDelegate d; |
1593 d.set_cancel_in_get_cookies_blocked(true); | 1596 d.set_cancel_in_get_cookies_blocked(true); |
1594 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), | 1597 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), |
1595 &d); | 1598 &d); |
1596 req.set_context(context); | 1599 req.set_context(context); |
1597 req.Start(); // Triggers an asynchronous cookie policy check. | 1600 req.Start(); // Triggers an asynchronous cookie policy check. |
1598 | 1601 |
1599 MessageLoop::current()->Run(); | 1602 MessageLoop::current()->Run(); |
1600 | 1603 |
1601 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1604 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1602 | 1605 |
1603 EXPECT_EQ(1, d.blocked_get_cookies_count()); | 1606 EXPECT_EQ(1, d.blocked_get_cookies_count()); |
1604 EXPECT_EQ(0, d.blocked_set_cookie_count()); | 1607 EXPECT_EQ(0, d.blocked_set_cookie_count()); |
1605 } | 1608 } |
1606 | 1609 |
1607 context->set_cookie_policy(NULL); | 1610 context->set_cookie_policy(NULL); |
1608 } | 1611 } |
1609 | 1612 |
1610 TEST_F(URLRequestTest, CancelTest_During_OnSetCookieBlocked) { | 1613 TEST_F(URLRequestTest, CancelTest_During_OnSetCookie) { |
1611 scoped_refptr<HTTPTestServer> server = | 1614 scoped_refptr<HTTPTestServer> server = |
1612 HTTPTestServer::CreateServer(L"", NULL); | 1615 HTTPTestServer::CreateServer(L"", NULL); |
1613 ASSERT_TRUE(NULL != server.get()); | 1616 ASSERT_TRUE(NULL != server.get()); |
1614 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); | 1617 scoped_refptr<TestURLRequestContext> context = new TestURLRequestContext(); |
1615 | 1618 |
1616 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); | 1619 TestCookiePolicy cookie_policy(TestCookiePolicy::NO_SET_COOKIE); |
1617 context->set_cookie_policy(&cookie_policy); | 1620 context->set_cookie_policy(&cookie_policy); |
1618 | 1621 |
1619 // Set up a cookie. | 1622 // Set up a cookie. |
1620 { | 1623 { |
1621 TestDelegate d; | 1624 TestDelegate d; |
1622 d.set_cancel_in_set_cookie_blocked(true); | 1625 d.set_cancel_in_set_cookie_blocked(true); |
1623 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), | 1626 URLRequest req(server->TestServerPage("set-cookie?A=1&B=2&C=3"), |
1624 &d); | 1627 &d); |
1625 req.set_context(context); | 1628 req.set_context(context); |
1626 req.Start(); // Triggers an asynchronous cookie policy check. | 1629 req.Start(); // Triggers an asynchronous cookie policy check. |
1627 | 1630 |
1628 MessageLoop::current()->Run(); | 1631 MessageLoop::current()->Run(); |
1629 | 1632 |
1630 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 1633 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
1631 | 1634 |
1632 // Even though the response will contain 3 set-cookie headers, we expect | 1635 // Even though the response will contain 3 set-cookie headers, we expect |
1633 // only one to be blocked as that first one will cause OnSetCookieBlocked | 1636 // only one to be blocked as that first one will cause OnSetCookie to be |
1634 // to be called, which will cancel the request. Once canceled, it should | 1637 // called, which will cancel the request. Once canceled, it should not |
1635 // not attempt to set further cookies. | 1638 // attempt to set further cookies. |
1636 | 1639 |
1637 EXPECT_EQ(0, d.blocked_get_cookies_count()); | 1640 EXPECT_EQ(0, d.blocked_get_cookies_count()); |
1638 EXPECT_EQ(1, d.blocked_set_cookie_count()); | 1641 EXPECT_EQ(1, d.blocked_set_cookie_count()); |
1639 } | 1642 } |
1640 | 1643 |
1641 context->set_cookie_policy(NULL); | 1644 context->set_cookie_policy(NULL); |
1642 } | 1645 } |
1643 | 1646 |
1644 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 1647 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
1645 scoped_refptr<HTTPTestServer> server = | 1648 scoped_refptr<HTTPTestServer> server = |
(...skipping 880 matching lines...) Loading... |
2526 TestURLRequest | 2529 TestURLRequest |
2527 req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); | 2530 req(server_->TestServerPage("echoheaderoverride?Accept-Charset"), &d); |
2528 req.set_context(new TestURLRequestContext()); | 2531 req.set_context(new TestURLRequestContext()); |
2529 net::HttpRequestHeaders headers; | 2532 net::HttpRequestHeaders headers; |
2530 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 2533 headers.SetHeader(net::HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
2531 req.SetExtraRequestHeaders(headers); | 2534 req.SetExtraRequestHeaders(headers); |
2532 req.Start(); | 2535 req.Start(); |
2533 MessageLoop::current()->Run(); | 2536 MessageLoop::current()->Run(); |
2534 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 2537 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
2535 } | 2538 } |
OLD | NEW |