Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2409)

Unified Diff: net/url_request/url_request_unittest.cc

Issue 1411813003: Teach URLRequest about initiator checks for First-Party-Only cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_request_unittest.cc
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 78e44c91c0a2e802250647daa29bee960a495899..b1bf6189c02de7bdc90090b8d799dc83fff0c9a5 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2650,13 +2650,13 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
LocalHttpTestServer test_server;
ASSERT_TRUE(test_server.Start());
+ TestNetworkDelegate network_delegate;
+ network_delegate.set_experimental_cookie_features_enabled(true);
+ default_context_.set_network_delegate(&network_delegate);
+
// Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
// LocalHttpTestServer points).
{
- TestNetworkDelegate network_delegate;
- network_delegate.set_experimental_cookie_features_enabled(true);
- default_context_.set_network_delegate(&network_delegate);
-
TestDelegate d;
scoped_ptr<URLRequest> req(default_context_.CreateRequest(
test_server.GetURL(
@@ -2671,13 +2671,11 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
// Verify that the cookie is sent for first-party requests.
{
- TestNetworkDelegate network_delegate;
- network_delegate.set_experimental_cookie_features_enabled(true);
- default_context_.set_network_delegate(&network_delegate);
TestDelegate d;
scoped_ptr<URLRequest> req(default_context_.CreateRequest(
test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
req->set_first_party_for_cookies(test_server.GetURL("/"));
+ req->set_initiator(url::Origin(test_server.GetURL("/")));
req->Start();
base::RunLoop().Run();
@@ -2687,15 +2685,48 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
}
- // Verify that the cookie is not-sent for non-first-party requests.
+ // Verify that the cookie is not sent for non-first-party requests.
{
- TestNetworkDelegate network_delegate;
- network_delegate.set_experimental_cookie_features_enabled(true);
- default_context_.set_network_delegate(&network_delegate);
TestDelegate d;
scoped_ptr<URLRequest> req(default_context_.CreateRequest(
test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
req->set_first_party_for_cookies(GURL("http://third-party.test/"));
+ req->set_initiator(url::Origin(GURL("http://third-party.test/")));
+ req->Start();
+ base::RunLoop().Run();
+
+ EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") ==
+ std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Verify that the cookie is sent for non-first-party initiators when the
+ // method is "safe".
+ {
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
+ req->set_first_party_for_cookies(test_server.GetURL("/"));
+ req->set_initiator(url::Origin(GURL("http://third-party.test/")));
+ req->Start();
+ base::RunLoop().Run();
+
+ EXPECT_FALSE(d.data_received().find("FirstPartyCookieToSet=1") ==
+ std::string::npos);
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
+ }
+
+ // Verify that the cookie is not sent for non-first-party initiators when the
+ // method is unsafe (e.g. POST).
+ {
+ TestDelegate d;
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest(
+ test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
+ req->set_first_party_for_cookies(test_server.GetURL("/"));
+ req->set_initiator(url::Origin(GURL("http://third-party.test/")));
+ req->set_method("POST");
req->Start();
base::RunLoop().Run();
« net/url_request/url_fetcher_core.cc ('K') | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698