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

Unified Diff: net/url_request/url_request_unittest.cc

Issue 1253353004: WIP: Teach "First-Party-Only" cookies about the requestor origin. Base URL: https://chromium.googlesource.com/chromium/src.git@cookie-options
Patch Set: Created 5 years, 5 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
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ecff043877c54d88952a34bbccdcfb1eb4b96ee5..9184bec8b809de7a8b121a9074886170c0148430 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -2587,6 +2587,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_requestor_origin(url::Origin(test_server.GetURL("")));
req->Start();
base::RunLoop().Run();
@@ -2605,6 +2606,27 @@ 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_requestor_origin(url::Origin(test_server.GetURL("")));
+ 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 not sent when the requestor origin doesn't
+ // match, even for otherwise first-party requests.
+ {
+ TestNetworkDelegate network_delegate;
+ network_delegate.set_first_party_only_cookies_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_requestor_origin(url::Origin(GURL("https://third-party.test")));
req->Start();
base::RunLoop().Run();
@@ -2647,6 +2669,7 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) {
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_requestor_origin(url::Origin(test_server.GetURL("")));
req->Start();
base::RunLoop().Run();
@@ -2665,6 +2688,27 @@ TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) {
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_requestor_origin(url::Origin(test_server.GetURL("")));
+ 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 also sent when the requestor origin doesn't
+ // match, even for otherwise first-party requests.
+ {
+ TestNetworkDelegate network_delegate;
+ network_delegate.set_first_party_only_cookies_enabled(false);
+ 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_requestor_origin(url::Origin(GURL("https://third-party.test")));
req->Start();
base::RunLoop().Run();
« no previous file with comments | « 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