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 41dca32bed173c4ecc06fff6571b4697375ce0c1..5cd6657e1a35d42c12972706586d3338ffe10bca 100644 |
--- a/net/url_request/url_request_unittest.cc |
+++ b/net/url_request/url_request_unittest.cc |
@@ -662,6 +662,11 @@ class MockCertificateReportSender |
std::string latest_report_; |
}; |
+class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { |
+ public: |
+ bool OnExperimentalCookieFeaturesEnabled() const override { return true; } |
+}; |
+ |
} // namespace |
// Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
@@ -9509,4 +9514,101 @@ TEST_F(URLRequestTest, URLRequestRedirectJobDetachRequestNoCrash) { |
EXPECT_EQ(0, d.received_redirect_count()); |
} |
+TEST_F(URLRequestTest, SecureCookiePrefix) { |
+ SpawnedTestServer test_server( |
+ SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, |
+ base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
+ ASSERT_TRUE(test_server.Start()); |
+ |
+ // Without experimental features, there should be no restrictions on |
+ // $Secure- cookies. |
+ { |
+ TestNetworkDelegate network_delegate; |
+ default_context_.set_network_delegate(&network_delegate); |
+ TestDelegate d; |
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
+ test_server.GetURL("set-cookie?$Secure-not-experimental=1"), |
+ DEFAULT_PRIORITY, &d)); |
+ req->Start(); |
+ base::RunLoop().Run(); |
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
+ } |
+ |
+ // Verify that the cookie is set. |
+ { |
+ TestNetworkDelegate network_delegate; |
+ 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->Start(); |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_TRUE(d.data_received().find("$Secure-not-experimental=1") != |
+ std::string::npos); |
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
+ } |
+ |
+ // Try to set a non-Secure $Secure- cookie, with experimental features |
+ // enabled. |
+ { |
+ TestExperimentalFeaturesNetworkDelegate network_delegate; |
+ default_context_.set_network_delegate(&network_delegate); |
+ TestDelegate d; |
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
+ test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d)); |
+ req->Start(); |
+ base::RunLoop().Run(); |
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
+ } |
+ |
+ // Verify that the cookie is not set. |
+ { |
+ TestExperimentalFeaturesNetworkDelegate network_delegate; |
+ 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->Start(); |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos); |
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
+ } |
+ |
+ // Try to set a Secure $Secure- cookie, with experimental features |
+ // enabled. |
+ { |
+ TestExperimentalFeaturesNetworkDelegate network_delegate; |
+ default_context_.set_network_delegate(&network_delegate); |
+ TestDelegate d; |
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
+ test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY, |
+ &d)); |
+ req->Start(); |
+ base::RunLoop().Run(); |
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
+ } |
+ |
+ // Verify that the cookie is set. |
Mike West
2015/10/10 09:34:24
You've tested non-secure non-experimental, secure
estark
2015/10/12 09:27:53
Done.
|
+ { |
+ TestExperimentalFeaturesNetworkDelegate network_delegate; |
+ 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->Start(); |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos); |
+ EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
+ EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
+ } |
+} |
+ |
} // namespace net |