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

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

Issue 1043403003: Revert of Enable 'First-Party-Only' cookies by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after
2544 } 2544 }
2545 2545
2546 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { 2546 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
2547 LocalHttpTestServer test_server; 2547 LocalHttpTestServer test_server;
2548 ASSERT_TRUE(test_server.Start()); 2548 ASSERT_TRUE(test_server.Start());
2549 2549
2550 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where 2550 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
2551 // LocalHttpTestServer points). 2551 // LocalHttpTestServer points).
2552 { 2552 {
2553 TestNetworkDelegate network_delegate; 2553 TestNetworkDelegate network_delegate;
2554 network_delegate.set_first_party_only_cookies_enabled(true);
2554 default_context_.set_network_delegate(&network_delegate); 2555 default_context_.set_network_delegate(&network_delegate);
2555 2556
2556 TestDelegate d; 2557 TestDelegate d;
2557 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2558 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2558 test_server.GetURL( 2559 test_server.GetURL(
2559 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), 2560 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"),
2560 DEFAULT_PRIORITY, &d)); 2561 DEFAULT_PRIORITY, &d));
2561 req->Start(); 2562 req->Start();
2562 base::RunLoop().Run(); 2563 base::RunLoop().Run();
2563 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2564 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2564 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2565 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2565 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2566 EXPECT_EQ(1, network_delegate.set_cookie_count());
2566 } 2567 }
2567 2568
2568 // Verify that the cookie is sent for first-party requests. 2569 // Verify that the cookie is sent for first-party requests.
2569 { 2570 {
2570 TestNetworkDelegate network_delegate; 2571 TestNetworkDelegate network_delegate;
2572 network_delegate.set_first_party_only_cookies_enabled(true);
2571 default_context_.set_network_delegate(&network_delegate); 2573 default_context_.set_network_delegate(&network_delegate);
2572 TestDelegate d; 2574 TestDelegate d;
2573 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2575 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2574 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2576 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2575 req->set_first_party_for_cookies(test_server.GetURL("")); 2577 req->set_first_party_for_cookies(test_server.GetURL(""));
2576 req->Start(); 2578 req->Start();
2577 base::RunLoop().Run(); 2579 base::RunLoop().Run();
2578 2580
2579 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2581 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2580 std::string::npos); 2582 std::string::npos);
2581 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2583 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2582 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2584 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2583 } 2585 }
2584 2586
2585 // Verify that the cookie is not-sent for non-first-party requests. 2587 // Verify that the cookie is not-sent for non-first-party requests.
2586 { 2588 {
2587 TestNetworkDelegate network_delegate; 2589 TestNetworkDelegate network_delegate;
2590 network_delegate.set_first_party_only_cookies_enabled(true);
2588 default_context_.set_network_delegate(&network_delegate); 2591 default_context_.set_network_delegate(&network_delegate);
2589 TestDelegate d; 2592 TestDelegate d;
2590 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2593 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2591 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2594 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2592 req->set_first_party_for_cookies(GURL("http://third-party.test/")); 2595 req->set_first_party_for_cookies(GURL("http://third-party.test/"));
2593 req->Start(); 2596 req->Start();
2594 base::RunLoop().Run(); 2597 base::RunLoop().Run();
2595 2598
2596 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == 2599 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") ==
2597 std::string::npos); 2600 std::string::npos);
2598 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2601 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2599 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2602 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2603 }
2604 }
2605
2606 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) {
2607 LocalHttpTestServer test_server;
2608 ASSERT_TRUE(test_server.Start());
2609
2610 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
2611 // LocalHttpTestServer points).
2612 {
2613 TestNetworkDelegate network_delegate;
2614 network_delegate.set_first_party_only_cookies_enabled(false);
2615 default_context_.set_network_delegate(&network_delegate);
2616
2617 TestDelegate d;
2618 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2619 test_server.GetURL(
2620 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"),
2621 DEFAULT_PRIORITY, &d));
2622 req->Start();
2623 base::RunLoop().Run();
2624 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2625 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2626 EXPECT_EQ(1, network_delegate.set_cookie_count());
2627 }
2628
2629 // Verify that the cookie is sent for first-party requests.
2630 {
2631 TestNetworkDelegate network_delegate;
2632 network_delegate.set_first_party_only_cookies_enabled(false);
2633 default_context_.set_network_delegate(&network_delegate);
2634 TestDelegate d;
2635 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2636 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2637 req->set_first_party_for_cookies(test_server.GetURL(""));
2638 req->Start();
2639 base::RunLoop().Run();
2640
2641 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2642 std::string::npos);
2643 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2644 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2645 }
2646
2647 // Verify that the cookie is also sent for non-first-party requests.
2648 {
2649 TestNetworkDelegate network_delegate;
2650 network_delegate.set_first_party_only_cookies_enabled(false);
2651 default_context_.set_network_delegate(&network_delegate);
2652 TestDelegate d;
2653 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2654 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2655 req->set_first_party_for_cookies(GURL("http://third-party.test/"));
2656 req->Start();
2657 base::RunLoop().Run();
2658
2659 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2660 std::string::npos);
2661 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2662 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2600 } 2663 }
2601 } 2664 }
2602 2665
2603 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header 2666 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header
2604 // value for the |fixed_date| argument given to the constructor. 2667 // value for the |fixed_date| argument given to the constructor.
2605 class FixedDateNetworkDelegate : public TestNetworkDelegate { 2668 class FixedDateNetworkDelegate : public TestNetworkDelegate {
2606 public: 2669 public:
2607 explicit FixedDateNetworkDelegate(const std::string& fixed_date) 2670 explicit FixedDateNetworkDelegate(const std::string& fixed_date)
2608 : fixed_date_(fixed_date) {} 2671 : fixed_date_(fixed_date) {}
2609 ~FixedDateNetworkDelegate() override {} 2672 ~FixedDateNetworkDelegate() override {}
(...skipping 6252 matching lines...) Expand 10 before | Expand all | Expand 10 after
8862 8925
8863 EXPECT_FALSE(r->is_pending()); 8926 EXPECT_FALSE(r->is_pending());
8864 EXPECT_EQ(1, d->response_started_count()); 8927 EXPECT_EQ(1, d->response_started_count());
8865 EXPECT_FALSE(d->received_data_before_response()); 8928 EXPECT_FALSE(d->received_data_before_response());
8866 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8929 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8867 } 8930 }
8868 } 8931 }
8869 #endif // !defined(DISABLE_FTP_SUPPORT) 8932 #endif // !defined(DISABLE_FTP_SUPPORT)
8870 8933
8871 } // namespace net 8934 } // 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