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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 2632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2643 | 2643 |
2644 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2644 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2645 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2645 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2646 } | 2646 } |
2647 } | 2647 } |
2648 | 2648 |
2649 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { | 2649 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { |
2650 LocalHttpTestServer test_server; | 2650 LocalHttpTestServer test_server; |
2651 ASSERT_TRUE(test_server.Start()); | 2651 ASSERT_TRUE(test_server.Start()); |
2652 | 2652 |
| 2653 TestNetworkDelegate network_delegate; |
| 2654 network_delegate.set_experimental_cookie_features_enabled(true); |
| 2655 default_context_.set_network_delegate(&network_delegate); |
| 2656 |
2653 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where | 2657 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where |
2654 // LocalHttpTestServer points). | 2658 // LocalHttpTestServer points). |
2655 { | 2659 { |
2656 TestNetworkDelegate network_delegate; | |
2657 network_delegate.set_experimental_cookie_features_enabled(true); | |
2658 default_context_.set_network_delegate(&network_delegate); | |
2659 | |
2660 TestDelegate d; | 2660 TestDelegate d; |
2661 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2661 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2662 test_server.GetURL( | 2662 test_server.GetURL( |
2663 "/set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), | 2663 "/set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), |
2664 DEFAULT_PRIORITY, &d)); | 2664 DEFAULT_PRIORITY, &d)); |
2665 req->Start(); | 2665 req->Start(); |
2666 base::RunLoop().Run(); | 2666 base::RunLoop().Run(); |
2667 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2667 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2668 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2668 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2669 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2669 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
2670 } | 2670 } |
2671 | 2671 |
2672 // Verify that the cookie is sent for first-party requests. | 2672 // Verify that the cookie is sent for first-party requests. |
2673 { | 2673 { |
2674 TestNetworkDelegate network_delegate; | |
2675 network_delegate.set_experimental_cookie_features_enabled(true); | |
2676 default_context_.set_network_delegate(&network_delegate); | |
2677 TestDelegate d; | 2674 TestDelegate d; |
2678 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2675 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2679 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2676 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2680 req->set_first_party_for_cookies(test_server.GetURL("/")); | 2677 req->set_first_party_for_cookies(test_server.GetURL("/")); |
| 2678 req->set_initiator(url::Origin(test_server.GetURL("/"))); |
2681 req->Start(); | 2679 req->Start(); |
2682 base::RunLoop().Run(); | 2680 base::RunLoop().Run(); |
2683 | 2681 |
2684 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2682 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
2685 std::string::npos); | 2683 std::string::npos); |
2686 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2684 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2687 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2685 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2688 } | 2686 } |
2689 | 2687 |
2690 // Verify that the cookie is not-sent for non-first-party requests. | 2688 // Verify that the cookie is not sent for non-first-party requests. |
2691 { | 2689 { |
2692 TestNetworkDelegate network_delegate; | |
2693 network_delegate.set_experimental_cookie_features_enabled(true); | |
2694 default_context_.set_network_delegate(&network_delegate); | |
2695 TestDelegate d; | 2690 TestDelegate d; |
2696 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2691 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2697 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2692 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2698 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2693 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2694 req->set_initiator(url::Origin(GURL("http://third-party.test/"))); |
2699 req->Start(); | 2695 req->Start(); |
2700 base::RunLoop().Run(); | 2696 base::RunLoop().Run(); |
2701 | 2697 |
| 2698 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2699 std::string::npos); |
| 2700 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2701 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2702 } |
| 2703 |
| 2704 // Verify that the cookie is sent for non-first-party initiators when the |
| 2705 // method is "safe". |
| 2706 { |
| 2707 TestDelegate d; |
| 2708 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2709 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2710 req->set_first_party_for_cookies(test_server.GetURL("/")); |
| 2711 req->set_initiator(url::Origin(GURL("http://third-party.test/"))); |
| 2712 req->Start(); |
| 2713 base::RunLoop().Run(); |
| 2714 |
| 2715 EXPECT_FALSE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2716 std::string::npos); |
| 2717 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2718 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2719 } |
| 2720 |
| 2721 // Verify that the cookie is not sent for non-first-party initiators when the |
| 2722 // method is unsafe (e.g. POST). |
| 2723 { |
| 2724 TestDelegate d; |
| 2725 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2726 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2727 req->set_first_party_for_cookies(test_server.GetURL("/")); |
| 2728 req->set_initiator(url::Origin(GURL("http://third-party.test/"))); |
| 2729 req->set_method("POST"); |
| 2730 req->Start(); |
| 2731 base::RunLoop().Run(); |
| 2732 |
2702 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == | 2733 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
2703 std::string::npos); | 2734 std::string::npos); |
2704 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2735 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2705 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2736 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2706 } | 2737 } |
2707 } | 2738 } |
2708 | 2739 |
2709 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { | 2740 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { |
2710 LocalHttpTestServer test_server; | 2741 LocalHttpTestServer test_server; |
2711 ASSERT_TRUE(test_server.Start()); | 2742 ASSERT_TRUE(test_server.Start()); |
(...skipping 7056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9768 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 9799 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
9769 | 9800 |
9770 req->Start(); | 9801 req->Start(); |
9771 req->Cancel(); | 9802 req->Cancel(); |
9772 base::RunLoop().RunUntilIdle(); | 9803 base::RunLoop().RunUntilIdle(); |
9773 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9804 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
9774 EXPECT_EQ(0, d.received_redirect_count()); | 9805 EXPECT_EQ(0, d.received_redirect_count()); |
9775 } | 9806 } |
9776 | 9807 |
9777 } // namespace net | 9808 } // namespace net |
OLD | NEW |