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..c2ab86730440f5693b432dddd39502ebbe6564aa 100644 |
--- a/net/url_request/url_request_unittest.cc |
+++ b/net/url_request/url_request_unittest.cc |
@@ -2678,6 +2678,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(); |
@@ -2687,7 +2688,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); |
@@ -2696,6 +2697,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" |
mmenke
2016/01/12 16:20:59
+period.
Mike West
2016/01/13 08:10:22
Done.
|
+ { |
+ TestNetworkDelegate network_delegate; |
+ network_delegate.set_experimental_cookie_features_enabled(true); |
mmenke
2016/01/12 16:20:59
Optional nit: Can we just make a single network d
Mike West
2016/01/13 08:10:22
Sure. Done.
|
+ 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(); |