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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 1409243003: Revert of Implement $Secure- cookie prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 OnAreExperimentalCookieFeaturesEnabled() const override { return true; }
668 };
669
670 } // namespace 665 } // namespace
671 666
672 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 667 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
673 class URLRequestTest : public PlatformTest { 668 class URLRequestTest : public PlatformTest {
674 public: 669 public:
675 URLRequestTest() : default_context_(true) { 670 URLRequestTest() : default_context_(true) {
676 default_context_.set_network_delegate(&default_network_delegate_); 671 default_context_.set_network_delegate(&default_network_delegate_);
677 default_context_.set_net_log(&net_log_); 672 default_context_.set_net_log(&net_log_);
678 job_factory_impl_ = new URLRequestJobFactoryImpl(); 673 job_factory_impl_ = new URLRequestJobFactoryImpl();
679 job_factory_.reset(job_factory_impl_); 674 job_factory_.reset(job_factory_impl_);
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 req->Start(); 2715 req->Start();
2721 base::RunLoop().Run(); 2716 base::RunLoop().Run();
2722 2717
2723 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2718 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2724 std::string::npos); 2719 std::string::npos);
2725 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2720 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2726 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2721 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2727 } 2722 }
2728 } 2723 }
2729 2724
2730 // Tests that $Secure- cookies can't be set on non-secure origins.
2731 TEST_F(URLRequestTest, SecureCookiePrefixOnNonsecureOrigin) {
2732 LocalHttpTestServer test_server;
2733 ASSERT_TRUE(test_server.Start());
2734 SpawnedTestServer test_server_https(
2735 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
2736 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
2737 ASSERT_TRUE(test_server_https.Start());
2738
2739 TestExperimentalFeaturesNetworkDelegate network_delegate;
2740 TestURLRequestContext context(true);
2741 context.set_network_delegate(&network_delegate);
2742 context.Init();
2743
2744 // Try to set a Secure $Secure- cookie, with experimental features
2745 // enabled.
2746 {
2747 TestDelegate d;
2748 scoped_ptr<URLRequest> req(context.CreateRequest(
2749 test_server.GetURL("set-cookie?$Secure-nonsecure-origin=1;Secure"),
2750 DEFAULT_PRIORITY, &d));
2751 req->Start();
2752 base::RunLoop().Run();
2753 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2754 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2755 }
2756
2757 // Verify that the cookie is not set.
2758 {
2759 TestDelegate d;
2760 scoped_ptr<URLRequest> req(context.CreateRequest(
2761 test_server_https.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2762 req->Start();
2763 base::RunLoop().Run();
2764
2765 EXPECT_TRUE(d.data_received().find("$Secure-nonsecure-origin=1") ==
2766 std::string::npos);
2767 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2768 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2769 }
2770 }
2771
2772 TEST_F(URLRequestTest, SecureCookiePrefixNonexperimental) {
2773 SpawnedTestServer test_server(
2774 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
2775 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
2776 ASSERT_TRUE(test_server.Start());
2777
2778 TestNetworkDelegate network_delegate;
2779 TestURLRequestContext context(true);
2780 context.set_network_delegate(&network_delegate);
2781 context.Init();
2782
2783 // Without experimental features, there should be no restrictions on
2784 // $Secure- cookies.
2785
2786 // Set a non-Secure cookie with the $Secure- prefix.
2787 {
2788 TestDelegate d;
2789 scoped_ptr<URLRequest> req(context.CreateRequest(
2790 test_server.GetURL("set-cookie?$Secure-nonsecure-not-experimental=1"),
2791 DEFAULT_PRIORITY, &d));
2792 req->Start();
2793 base::RunLoop().Run();
2794 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2795 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2796 }
2797
2798 // Set a Secure cookie with the $Secure- prefix.
2799 {
2800 TestDelegate d;
2801 scoped_ptr<URLRequest> req(context.CreateRequest(
2802 test_server.GetURL(
2803 "set-cookie?$Secure-secure-not-experimental=1;Secure"),
2804 DEFAULT_PRIORITY, &d));
2805 req->Start();
2806 base::RunLoop().Run();
2807 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2808 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2809 }
2810
2811 // Verify that the cookies are set. Neither should have any
2812 // restrictions because the experimental flag is off.
2813 {
2814 TestDelegate d;
2815 scoped_ptr<URLRequest> req(context.CreateRequest(
2816 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2817 req->Start();
2818 base::RunLoop().Run();
2819
2820 EXPECT_TRUE(d.data_received().find("$Secure-secure-not-experimental=1") !=
2821 std::string::npos);
2822 EXPECT_TRUE(
2823 d.data_received().find("$Secure-nonsecure-not-experimental=1") !=
2824 std::string::npos);
2825 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2826 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2827 }
2828 }
2829
2830 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalNonsecure) {
2831 SpawnedTestServer test_server(
2832 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
2833 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
2834 ASSERT_TRUE(test_server.Start());
2835
2836 TestExperimentalFeaturesNetworkDelegate network_delegate;
2837 TestURLRequestContext context(true);
2838 context.set_network_delegate(&network_delegate);
2839 context.Init();
2840
2841 // Try to set a non-Secure $Secure- cookie, with experimental features
2842 // enabled.
2843 {
2844 TestDelegate d;
2845 scoped_ptr<URLRequest> req(context.CreateRequest(
2846 test_server.GetURL("set-cookie?$Secure-foo=1"), DEFAULT_PRIORITY, &d));
2847 req->Start();
2848 base::RunLoop().Run();
2849 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2850 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2851 }
2852
2853 // Verify that the cookie is not set.
2854 {
2855 TestDelegate d;
2856 scoped_ptr<URLRequest> req(context.CreateRequest(
2857 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2858 req->Start();
2859 base::RunLoop().Run();
2860
2861 EXPECT_TRUE(d.data_received().find("$Secure-foo=1") == std::string::npos);
2862 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2863 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2864 }
2865 }
2866
2867 TEST_F(URLRequestTest, SecureCookiePrefixExperimentalSecure) {
2868 SpawnedTestServer test_server(
2869 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::kLocalhost,
2870 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
2871 ASSERT_TRUE(test_server.Start());
2872
2873 TestExperimentalFeaturesNetworkDelegate network_delegate;
2874 TestURLRequestContext context(true);
2875 context.set_network_delegate(&network_delegate);
2876 context.Init();
2877
2878 // Try to set a Secure $Secure- cookie, with experimental features
2879 // enabled.
2880 {
2881 TestDelegate d;
2882 scoped_ptr<URLRequest> req(context.CreateRequest(
2883 test_server.GetURL("set-cookie?$Secure-bar=1;Secure"), DEFAULT_PRIORITY,
2884 &d));
2885 req->Start();
2886 base::RunLoop().Run();
2887 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2888 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2889 }
2890
2891 // Verify that the cookie is set.
2892 {
2893 TestDelegate d;
2894 scoped_ptr<URLRequest> req(context.CreateRequest(
2895 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2896 req->Start();
2897 base::RunLoop().Run();
2898
2899 EXPECT_TRUE(d.data_received().find("$Secure-bar=1") != std::string::npos);
2900 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2901 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2902 }
2903 }
2904
2905 // Tests that a request is cancelled while entering suspend mode. Uses mocks 2725 // Tests that a request is cancelled while entering suspend mode. Uses mocks
2906 // rather than a spawned test server because the connection used to talk to 2726 // rather than a spawned test server because the connection used to talk to
2907 // the test server is affected by entering suspend mode on Android. 2727 // the test server is affected by entering suspend mode on Android.
2908 TEST_F(URLRequestTest, CancelOnSuspend) { 2728 TEST_F(URLRequestTest, CancelOnSuspend) {
2909 TestPowerMonitorSource* power_monitor_source = new TestPowerMonitorSource(); 2729 TestPowerMonitorSource* power_monitor_source = new TestPowerMonitorSource();
2910 base::PowerMonitor power_monitor(make_scoped_ptr(power_monitor_source)); 2730 base::PowerMonitor power_monitor(make_scoped_ptr(power_monitor_source));
2911 2731
2912 URLRequestFailedJob::AddUrlHandler(); 2732 URLRequestFailedJob::AddUrlHandler();
2913 2733
2914 TestDelegate d; 2734 TestDelegate d;
(...skipping 6779 matching lines...) Expand 10 before | Expand all | Expand 10 after
9694 9514
9695 req->Start(); 9515 req->Start();
9696 req->Cancel(); 9516 req->Cancel();
9697 job->DetachRequest(); 9517 job->DetachRequest();
9698 base::RunLoop().RunUntilIdle(); 9518 base::RunLoop().RunUntilIdle();
9699 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 9519 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
9700 EXPECT_EQ(0, d.received_redirect_count()); 9520 EXPECT_EQ(0, d.received_redirect_count());
9701 } 9521 }
9702 9522
9703 } // namespace net 9523 } // namespace net
OLDNEW
« 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