OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 } | 655 } |
656 | 656 |
657 const GURL& latest_report_uri() { return latest_report_uri_; } | 657 const GURL& latest_report_uri() { return latest_report_uri_; } |
658 const std::string& latest_report() { return latest_report_; } | 658 const std::string& latest_report() { return latest_report_; } |
659 | 659 |
660 private: | 660 private: |
661 GURL latest_report_uri_; | 661 GURL latest_report_uri_; |
662 std::string latest_report_; | 662 std::string latest_report_; |
663 }; | 663 }; |
664 | 664 |
665 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { | |
666 public: | |
667 bool OnExperimentalCookieFeaturesEnabled() const override { return true; } | |
668 }; | |
669 | |
665 } // namespace | 670 } // namespace |
666 | 671 |
667 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 672 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
668 class URLRequestTest : public PlatformTest { | 673 class URLRequestTest : public PlatformTest { |
669 public: | 674 public: |
670 URLRequestTest() : default_context_(true) { | 675 URLRequestTest() : default_context_(true) { |
671 default_context_.set_network_delegate(&default_network_delegate_); | 676 default_context_.set_network_delegate(&default_network_delegate_); |
672 default_context_.set_net_log(&net_log_); | 677 default_context_.set_net_log(&net_log_); |
673 job_factory_impl_ = new URLRequestJobFactoryImpl(); | 678 job_factory_impl_ = new URLRequestJobFactoryImpl(); |
674 job_factory_.reset(job_factory_impl_); | 679 job_factory_.reset(job_factory_impl_); |
(...skipping 8827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9502 AddTestInterceptor()->set_main_intercept_job(job); | 9507 AddTestInterceptor()->set_main_intercept_job(job); |
9503 | 9508 |
9504 req->Start(); | 9509 req->Start(); |
9505 req->Cancel(); | 9510 req->Cancel(); |
9506 job->DetachRequest(); | 9511 job->DetachRequest(); |
9507 base::RunLoop().RunUntilIdle(); | 9512 base::RunLoop().RunUntilIdle(); |
9508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9513 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
9509 EXPECT_EQ(0, d.received_redirect_count()); | 9514 EXPECT_EQ(0, d.received_redirect_count()); |
9510 } | 9515 } |
9511 | 9516 |
9517 TEST_F(URLRequestTest, SecureCookiePrefix) { | |
9518 SpawnedTestServer test_server( | |
9519 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost, | |
9520 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | |
9521 ASSERT_TRUE(test_server.Start()); | |
9522 | |
9523 // Without experimental features, there should be no restrictions on | |
9524 // $Secure- cookies. | |
9525 { | |
9526 TestNetworkDelegate network_delegate; | |
9527 default_context_.set_network_delegate(&network_delegate); | |
9528 TestDelegate d; | |
9529 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9530 test_server.GetURL("set-cookie?$Secure-not-experimental=1"), | |
9531 DEFAULT_PRIORITY, &d)); | |
9532 req->Start(); | |
9533 base::RunLoop().Run(); | |
9534 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9535 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9536 } | |
9537 | |
9538 // Verify that the cookie is set. | |
9539 { | |
9540 TestNetworkDelegate network_delegate; | |
9541 default_context_.set_network_delegate(&network_delegate); | |
9542 TestDelegate d; | |
9543 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9544 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
9545 req->Start(); | |
9546 base::RunLoop().Run(); | |
9547 | |
9548 EXPECT_TRUE(d.data_received().find("$Secure-not-experimental=1") != | |
9549 std::string::npos); | |
9550 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9551 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9552 } | |
9553 | |
9554 // Try to set a non-Secure $Secure- cookie, with experimental features | |
9555 // enabled. | |
9556 { | |
9557 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
9558 default_context_.set_network_delegate(&network_delegate); | |
9559 TestDelegate d; | |
9560 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9561 test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d)); | |
9562 req->Start(); | |
9563 base::RunLoop().Run(); | |
9564 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9565 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9566 } | |
9567 | |
9568 // Verify that the cookie is not set. | |
9569 { | |
9570 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
9571 default_context_.set_network_delegate(&network_delegate); | |
9572 TestDelegate d; | |
9573 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9574 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
9575 req->Start(); | |
9576 base::RunLoop().Run(); | |
9577 | |
9578 EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos); | |
9579 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9580 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9581 } | |
9582 | |
9583 // Try to set a Secure $Secure- cookie, with experimental features | |
9584 // enabled. | |
9585 { | |
9586 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
9587 default_context_.set_network_delegate(&network_delegate); | |
9588 TestDelegate d; | |
9589 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9590 test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY, | |
9591 &d)); | |
9592 req->Start(); | |
9593 base::RunLoop().Run(); | |
9594 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9595 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9596 } | |
9597 | |
9598 // 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.
| |
9599 { | |
9600 TestExperimentalFeaturesNetworkDelegate network_delegate; | |
9601 default_context_.set_network_delegate(&network_delegate); | |
9602 TestDelegate d; | |
9603 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
9604 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | |
9605 req->Start(); | |
9606 base::RunLoop().Run(); | |
9607 | |
9608 EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos); | |
9609 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | |
9610 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | |
9611 } | |
9612 } | |
9613 | |
9512 } // namespace net | 9614 } // namespace net |
OLD | NEW |