| 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..f5e1f1f25cc1b9ae04bf30ec1b2043d6280bd876 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,132 @@ TEST_F(URLRequestTest, URLRequestRedirectJobDetachRequestNoCrash) {
|
| EXPECT_EQ(0, d.received_redirect_count());
|
| }
|
|
|
| +TEST_F(URLRequestTest, SecureCookiePrefixNonexperimental) {
|
| + 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-nonsecure-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());
|
| + }
|
| +
|
| + {
|
| + 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-secure-not-experimental=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 cookies are 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-secure-not-experimental=1") !=
|
| + std::string::npos);
|
| + EXPECT_TRUE(
|
| + d.data_received().find("$Secure-nonsecure-not-experimental=1") !=
|
| + std::string::npos);
|
| + EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
|
| + EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
|
| + }
|
| +}
|
| +
|
| +TEST_F(URLRequestTest, SecureCookiePrefixExperimentalNonSecure) {
|
| + SpawnedTestServer test_server(
|
| + SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
|
| + base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
|
| + ASSERT_TRUE(test_server.Start());
|
| +
|
| + // 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());
|
| + }
|
| +}
|
| +
|
| +TEST_F(URLRequestTest, SecureCookiePrefixExperimentalSecure) {
|
| + SpawnedTestServer test_server(
|
| + SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
|
| + base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
|
| + ASSERT_TRUE(test_server.Start());
|
| +
|
| + // 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.
|
| + {
|
| + 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
|
|
|