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 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2653 | 2653 |
2654 // Verify that the cookie is sent for first-party requests. | 2654 // Verify that the cookie is sent for first-party requests. |
2655 { | 2655 { |
2656 TestNetworkDelegate network_delegate; | 2656 TestNetworkDelegate network_delegate; |
2657 network_delegate.set_experimental_cookie_features_enabled(true); | 2657 network_delegate.set_experimental_cookie_features_enabled(true); |
2658 default_context_.set_network_delegate(&network_delegate); | 2658 default_context_.set_network_delegate(&network_delegate); |
2659 TestDelegate d; | 2659 TestDelegate d; |
2660 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2660 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2661 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2661 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2662 req->set_first_party_for_cookies(test_server.GetURL("")); | 2662 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2663 req->set_initiator(url::Origin(test_server.GetURL(""))); |
2663 req->Start(); | 2664 req->Start(); |
2664 base::RunLoop().Run(); | 2665 base::RunLoop().Run(); |
2665 | 2666 |
2666 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2667 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
2667 std::string::npos); | 2668 std::string::npos); |
2668 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2669 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2669 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2670 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2670 } | 2671 } |
2671 | 2672 |
2672 // Verify that the cookie is not-sent for non-first-party requests. | 2673 // Verify that the cookie is not sent for non-first-party requests. |
2673 { | 2674 { |
2674 TestNetworkDelegate network_delegate; | 2675 TestNetworkDelegate network_delegate; |
2675 network_delegate.set_experimental_cookie_features_enabled(true); | 2676 network_delegate.set_experimental_cookie_features_enabled(true); |
2676 default_context_.set_network_delegate(&network_delegate); | 2677 default_context_.set_network_delegate(&network_delegate); |
2677 TestDelegate d; | 2678 TestDelegate d; |
2678 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2679 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2679 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2680 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2680 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2681 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2682 req->set_initiator(url::Origin(GURL("http://third-party.test/"))); |
2681 req->Start(); | 2683 req->Start(); |
2682 base::RunLoop().Run(); | 2684 base::RunLoop().Run(); |
2683 | 2685 |
| 2686 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2687 std::string::npos); |
| 2688 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2689 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2690 } |
| 2691 |
| 2692 // Verify that the cookie is sent for non-first-party initiators when the |
| 2693 // method is "safe" |
| 2694 { |
| 2695 TestNetworkDelegate network_delegate; |
| 2696 network_delegate.set_experimental_cookie_features_enabled(true); |
| 2697 default_context_.set_network_delegate(&network_delegate); |
| 2698 TestDelegate d; |
| 2699 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2700 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2701 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2702 req->set_initiator(url::Origin(GURL("http://third-party.test/"))); |
| 2703 req->Start(); |
| 2704 base::RunLoop().Run(); |
| 2705 |
| 2706 EXPECT_FALSE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2707 std::string::npos); |
| 2708 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2709 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2710 } |
| 2711 |
| 2712 // Verify that the cookie is not sent for non-first-party initiators when the |
| 2713 // method is unsafe (e.g. POST). |
| 2714 { |
| 2715 TestNetworkDelegate network_delegate; |
| 2716 network_delegate.set_experimental_cookie_features_enabled(true); |
| 2717 default_context_.set_network_delegate(&network_delegate); |
| 2718 TestDelegate d; |
| 2719 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2720 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2721 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2722 req->set_initiator(url::Origin(GURL("http://third-party.test/"))); |
| 2723 req->set_method("POST"); |
| 2724 req->Start(); |
| 2725 base::RunLoop().Run(); |
| 2726 |
2684 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == | 2727 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
2685 std::string::npos); | 2728 std::string::npos); |
2686 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2729 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2687 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2730 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2688 } | 2731 } |
2689 } | 2732 } |
2690 | 2733 |
2691 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { | 2734 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { |
2692 LocalHttpTestServer test_server; | 2735 LocalHttpTestServer test_server; |
2693 ASSERT_TRUE(test_server.Start()); | 2736 ASSERT_TRUE(test_server.Start()); |
(...skipping 7022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9716 | 9759 |
9717 req->Start(); | 9760 req->Start(); |
9718 req->Cancel(); | 9761 req->Cancel(); |
9719 job->DetachRequest(); | 9762 job->DetachRequest(); |
9720 base::RunLoop().RunUntilIdle(); | 9763 base::RunLoop().RunUntilIdle(); |
9721 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9764 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
9722 EXPECT_EQ(0, d.received_redirect_count()); | 9765 EXPECT_EQ(0, d.received_redirect_count()); |
9723 } | 9766 } |
9724 | 9767 |
9725 } // namespace net | 9768 } // namespace net |
OLD | NEW |