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

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: test Created 5 years, 2 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 530c3e6e117e793ac3ca58f1cbe9783d40f1aa0a..712beeaf64be9329f613f3be7165621d91a8794f 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2660,6 +2660,7 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
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();
@@ -2669,7 +2670,7 @@ 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);
@@ -2678,6 +2679,48 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
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"
+ {
+ 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(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).
+ {
+ 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(GURL("http://third-party.test/")));
+ req->set_method("POST");
req->Start();
base::RunLoop().Run();
« net/url_request/url_request_http_job.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