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 2569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2580 | 2580 |
2581 // Verify that the cookie is sent for first-party requests. | 2581 // Verify that the cookie is sent for first-party requests. |
2582 { | 2582 { |
2583 TestNetworkDelegate network_delegate; | 2583 TestNetworkDelegate network_delegate; |
2584 network_delegate.set_first_party_only_cookies_enabled(true); | 2584 network_delegate.set_first_party_only_cookies_enabled(true); |
2585 default_context_.set_network_delegate(&network_delegate); | 2585 default_context_.set_network_delegate(&network_delegate); |
2586 TestDelegate d; | 2586 TestDelegate d; |
2587 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2587 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2588 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2588 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2589 req->set_first_party_for_cookies(test_server.GetURL("")); | 2589 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2590 req->set_requestor_origin(url::Origin(test_server.GetURL(""))); |
2590 req->Start(); | 2591 req->Start(); |
2591 base::RunLoop().Run(); | 2592 base::RunLoop().Run(); |
2592 | 2593 |
2593 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2594 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
2594 std::string::npos); | 2595 std::string::npos); |
2595 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2596 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2596 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2597 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2597 } | 2598 } |
2598 | 2599 |
2599 // Verify that the cookie is not-sent for non-first-party requests. | 2600 // Verify that the cookie is not-sent for non-first-party requests. |
2600 { | 2601 { |
2601 TestNetworkDelegate network_delegate; | 2602 TestNetworkDelegate network_delegate; |
2602 network_delegate.set_first_party_only_cookies_enabled(true); | 2603 network_delegate.set_first_party_only_cookies_enabled(true); |
2603 default_context_.set_network_delegate(&network_delegate); | 2604 default_context_.set_network_delegate(&network_delegate); |
2604 TestDelegate d; | 2605 TestDelegate d; |
2605 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2606 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2606 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2607 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2607 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2608 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2609 req->set_requestor_origin(url::Origin(test_server.GetURL(""))); |
2608 req->Start(); | 2610 req->Start(); |
2609 base::RunLoop().Run(); | 2611 base::RunLoop().Run(); |
2610 | 2612 |
| 2613 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2614 std::string::npos); |
| 2615 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2616 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2617 } |
| 2618 |
| 2619 // Verify that the cookie is not sent when the requestor origin doesn't |
| 2620 // match, even for otherwise first-party requests. |
| 2621 { |
| 2622 TestNetworkDelegate network_delegate; |
| 2623 network_delegate.set_first_party_only_cookies_enabled(true); |
| 2624 default_context_.set_network_delegate(&network_delegate); |
| 2625 TestDelegate d; |
| 2626 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2627 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
| 2628 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2629 req->set_requestor_origin(url::Origin(GURL("https://third-party.test"))); |
| 2630 req->Start(); |
| 2631 base::RunLoop().Run(); |
| 2632 |
2611 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == | 2633 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
2612 std::string::npos); | 2634 std::string::npos); |
2613 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2635 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2614 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2636 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2615 } | 2637 } |
2616 } | 2638 } |
2617 | 2639 |
2618 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { | 2640 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { |
2619 LocalHttpTestServer test_server; | 2641 LocalHttpTestServer test_server; |
2620 ASSERT_TRUE(test_server.Start()); | 2642 ASSERT_TRUE(test_server.Start()); |
(...skipping 19 matching lines...) Expand all Loading... |
2640 | 2662 |
2641 // Verify that the cookie is sent for first-party requests. | 2663 // Verify that the cookie is sent for first-party requests. |
2642 { | 2664 { |
2643 TestNetworkDelegate network_delegate; | 2665 TestNetworkDelegate network_delegate; |
2644 network_delegate.set_first_party_only_cookies_enabled(false); | 2666 network_delegate.set_first_party_only_cookies_enabled(false); |
2645 default_context_.set_network_delegate(&network_delegate); | 2667 default_context_.set_network_delegate(&network_delegate); |
2646 TestDelegate d; | 2668 TestDelegate d; |
2647 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2669 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2648 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2670 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2649 req->set_first_party_for_cookies(test_server.GetURL("")); | 2671 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2672 req->set_requestor_origin(url::Origin(test_server.GetURL(""))); |
2650 req->Start(); | 2673 req->Start(); |
2651 base::RunLoop().Run(); | 2674 base::RunLoop().Run(); |
2652 | 2675 |
2653 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2676 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
2654 std::string::npos); | 2677 std::string::npos); |
2655 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2678 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2656 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2679 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2657 } | 2680 } |
2658 | 2681 |
2659 // Verify that the cookie is also sent for non-first-party requests. | 2682 // Verify that the cookie is also sent for non-first-party requests. |
2660 { | 2683 { |
2661 TestNetworkDelegate network_delegate; | 2684 TestNetworkDelegate network_delegate; |
2662 network_delegate.set_first_party_only_cookies_enabled(false); | 2685 network_delegate.set_first_party_only_cookies_enabled(false); |
2663 default_context_.set_network_delegate(&network_delegate); | 2686 default_context_.set_network_delegate(&network_delegate); |
2664 TestDelegate d; | 2687 TestDelegate d; |
2665 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2688 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2666 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2689 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2667 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2690 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2691 req->set_requestor_origin(url::Origin(test_server.GetURL(""))); |
2668 req->Start(); | 2692 req->Start(); |
2669 base::RunLoop().Run(); | 2693 base::RunLoop().Run(); |
2670 | 2694 |
| 2695 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
| 2696 std::string::npos); |
| 2697 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2698 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2699 } |
| 2700 |
| 2701 // Verify that the cookie is also sent when the requestor origin doesn't |
| 2702 // match, even for otherwise first-party requests. |
| 2703 { |
| 2704 TestNetworkDelegate network_delegate; |
| 2705 network_delegate.set_first_party_only_cookies_enabled(false); |
| 2706 default_context_.set_network_delegate(&network_delegate); |
| 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_requestor_origin(url::Origin(GURL("https://third-party.test"))); |
| 2712 req->Start(); |
| 2713 base::RunLoop().Run(); |
| 2714 |
2671 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2715 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
2672 std::string::npos); | 2716 std::string::npos); |
2673 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2717 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2674 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2718 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2675 } | 2719 } |
2676 } | 2720 } |
2677 | 2721 |
2678 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header | 2722 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header |
2679 // value for the |fixed_date| argument given to the constructor. | 2723 // value for the |fixed_date| argument given to the constructor. |
2680 class FixedDateNetworkDelegate : public TestNetworkDelegate { | 2724 class FixedDateNetworkDelegate : public TestNetworkDelegate { |
(...skipping 6542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9223 | 9267 |
9224 req->Start(); | 9268 req->Start(); |
9225 req->Cancel(); | 9269 req->Cancel(); |
9226 job->DetachRequest(); | 9270 job->DetachRequest(); |
9227 base::RunLoop().RunUntilIdle(); | 9271 base::RunLoop().RunUntilIdle(); |
9228 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 9272 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
9229 EXPECT_EQ(0, d.received_redirect_count()); | 9273 EXPECT_EQ(0, d.received_redirect_count()); |
9230 } | 9274 } |
9231 | 9275 |
9232 } // namespace net | 9276 } // namespace net |
OLD | NEW |