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

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

Issue 1392853006: Rename NetworkDelegate first-party-only flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename to Are<blah> 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_test_util.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 2592 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 } 2603 }
2604 2604
2605 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { 2605 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
2606 LocalHttpTestServer test_server; 2606 LocalHttpTestServer test_server;
2607 ASSERT_TRUE(test_server.Start()); 2607 ASSERT_TRUE(test_server.Start());
2608 2608
2609 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where 2609 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
2610 // LocalHttpTestServer points). 2610 // LocalHttpTestServer points).
2611 { 2611 {
2612 TestNetworkDelegate network_delegate; 2612 TestNetworkDelegate network_delegate;
2613 network_delegate.set_first_party_only_cookies_enabled(true); 2613 network_delegate.set_experimental_cookie_features_enabled(true);
2614 default_context_.set_network_delegate(&network_delegate); 2614 default_context_.set_network_delegate(&network_delegate);
2615 2615
2616 TestDelegate d; 2616 TestDelegate d;
2617 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2617 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2618 test_server.GetURL( 2618 test_server.GetURL(
2619 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), 2619 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"),
2620 DEFAULT_PRIORITY, &d)); 2620 DEFAULT_PRIORITY, &d));
2621 req->Start(); 2621 req->Start();
2622 base::RunLoop().Run(); 2622 base::RunLoop().Run();
2623 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2623 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2624 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2624 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2625 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2625 EXPECT_EQ(1, network_delegate.set_cookie_count());
2626 } 2626 }
2627 2627
2628 // Verify that the cookie is sent for first-party requests. 2628 // Verify that the cookie is sent for first-party requests.
2629 { 2629 {
2630 TestNetworkDelegate network_delegate; 2630 TestNetworkDelegate network_delegate;
2631 network_delegate.set_first_party_only_cookies_enabled(true); 2631 network_delegate.set_experimental_cookie_features_enabled(true);
2632 default_context_.set_network_delegate(&network_delegate); 2632 default_context_.set_network_delegate(&network_delegate);
2633 TestDelegate d; 2633 TestDelegate d;
2634 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2634 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2635 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2635 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2636 req->set_first_party_for_cookies(test_server.GetURL("")); 2636 req->set_first_party_for_cookies(test_server.GetURL(""));
2637 req->Start(); 2637 req->Start();
2638 base::RunLoop().Run(); 2638 base::RunLoop().Run();
2639 2639
2640 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2640 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2641 std::string::npos); 2641 std::string::npos);
2642 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2642 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2643 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2643 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2644 } 2644 }
2645 2645
2646 // Verify that the cookie is not-sent for non-first-party requests. 2646 // Verify that the cookie is not-sent for non-first-party requests.
2647 { 2647 {
2648 TestNetworkDelegate network_delegate; 2648 TestNetworkDelegate network_delegate;
2649 network_delegate.set_first_party_only_cookies_enabled(true); 2649 network_delegate.set_experimental_cookie_features_enabled(true);
2650 default_context_.set_network_delegate(&network_delegate); 2650 default_context_.set_network_delegate(&network_delegate);
2651 TestDelegate d; 2651 TestDelegate d;
2652 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2652 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2653 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2653 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2654 req->set_first_party_for_cookies(GURL("http://third-party.test/")); 2654 req->set_first_party_for_cookies(GURL("http://third-party.test/"));
2655 req->Start(); 2655 req->Start();
2656 base::RunLoop().Run(); 2656 base::RunLoop().Run();
2657 2657
2658 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == 2658 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") ==
2659 std::string::npos); 2659 std::string::npos);
2660 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2660 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2661 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2661 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2662 } 2662 }
2663 } 2663 }
2664 2664
2665 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { 2665 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) {
2666 LocalHttpTestServer test_server; 2666 LocalHttpTestServer test_server;
2667 ASSERT_TRUE(test_server.Start()); 2667 ASSERT_TRUE(test_server.Start());
2668 2668
2669 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where 2669 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
2670 // LocalHttpTestServer points). 2670 // LocalHttpTestServer points).
2671 { 2671 {
2672 TestNetworkDelegate network_delegate; 2672 TestNetworkDelegate network_delegate;
2673 network_delegate.set_first_party_only_cookies_enabled(false); 2673 network_delegate.set_experimental_cookie_features_enabled(false);
2674 default_context_.set_network_delegate(&network_delegate); 2674 default_context_.set_network_delegate(&network_delegate);
2675 2675
2676 TestDelegate d; 2676 TestDelegate d;
2677 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2677 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2678 test_server.GetURL( 2678 test_server.GetURL(
2679 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), 2679 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"),
2680 DEFAULT_PRIORITY, &d)); 2680 DEFAULT_PRIORITY, &d));
2681 req->Start(); 2681 req->Start();
2682 base::RunLoop().Run(); 2682 base::RunLoop().Run();
2683 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2683 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2684 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2684 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2685 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2685 EXPECT_EQ(1, network_delegate.set_cookie_count());
2686 } 2686 }
2687 2687
2688 // Verify that the cookie is sent for first-party requests. 2688 // Verify that the cookie is sent for first-party requests.
2689 { 2689 {
2690 TestNetworkDelegate network_delegate; 2690 TestNetworkDelegate network_delegate;
2691 network_delegate.set_first_party_only_cookies_enabled(false); 2691 network_delegate.set_experimental_cookie_features_enabled(false);
2692 default_context_.set_network_delegate(&network_delegate); 2692 default_context_.set_network_delegate(&network_delegate);
2693 TestDelegate d; 2693 TestDelegate d;
2694 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2694 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2695 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2695 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2696 req->set_first_party_for_cookies(test_server.GetURL("")); 2696 req->set_first_party_for_cookies(test_server.GetURL(""));
2697 req->Start(); 2697 req->Start();
2698 base::RunLoop().Run(); 2698 base::RunLoop().Run();
2699 2699
2700 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2700 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2701 std::string::npos); 2701 std::string::npos);
2702 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2702 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2703 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2703 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2704 } 2704 }
2705 2705
2706 // Verify that the cookie is also sent for non-first-party requests. 2706 // Verify that the cookie is also sent for non-first-party requests.
2707 { 2707 {
2708 TestNetworkDelegate network_delegate; 2708 TestNetworkDelegate network_delegate;
2709 network_delegate.set_first_party_only_cookies_enabled(false); 2709 network_delegate.set_experimental_cookie_features_enabled(false);
2710 default_context_.set_network_delegate(&network_delegate); 2710 default_context_.set_network_delegate(&network_delegate);
2711 TestDelegate d; 2711 TestDelegate d;
2712 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2712 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2713 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2713 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2714 req->set_first_party_for_cookies(GURL("http://third-party.test/")); 2714 req->set_first_party_for_cookies(GURL("http://third-party.test/"));
2715 req->Start(); 2715 req->Start();
2716 base::RunLoop().Run(); 2716 base::RunLoop().Run();
2717 2717
2718 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2718 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2719 std::string::npos); 2719 std::string::npos);
(...skipping 6783 matching lines...) Expand 10 before | Expand all | Expand 10 after
9503 9503
9504 req->Start(); 9504 req->Start();
9505 req->Cancel(); 9505 req->Cancel();
9506 job->DetachRequest(); 9506 job->DetachRequest();
9507 base::RunLoop().RunUntilIdle(); 9507 base::RunLoop().RunUntilIdle();
9508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 9508 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
9509 EXPECT_EQ(0, d.received_redirect_count()); 9509 EXPECT_EQ(0, d.received_redirect_count());
9510 } 9510 }
9511 9511
9512 } // namespace net 9512 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698