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

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

Issue 2405483002: Make the request initiator Optional (Closed)
Patch Set: Introduce NullableOrigin to use for request initiator Created 4 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
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 2695 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2706 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2707 EXPECT_EQ(2, network_delegate.set_cookie_count()); 2707 EXPECT_EQ(2, network_delegate.set_cookie_count());
2708 } 2708 }
2709 2709
2710 // Verify that both cookies are sent for same-site requests. 2710 // Verify that both cookies are sent for same-site requests.
2711 { 2711 {
2712 TestDelegate d; 2712 TestDelegate d;
2713 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2713 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2714 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2714 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2715 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); 2715 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/"));
2716 req->set_initiator(url::Origin(test_server.GetURL(kHost, "/"))); 2716 req->set_initiator(new url::NullableOrigin(test_server.GetURL(kHost, "/")));
2717 req->Start(); 2717 req->Start();
2718 base::RunLoop().Run(); 2718 base::RunLoop().Run();
2719 2719
2720 EXPECT_NE(std::string::npos, 2720 EXPECT_NE(std::string::npos,
2721 d.data_received().find("StrictSameSiteCookie=1")); 2721 d.data_received().find("StrictSameSiteCookie=1"));
2722 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); 2722 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1"));
2723 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2723 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2724 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2724 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2725 } 2725 }
2726 2726
2727 // Verify that both cookies are sent for same-registrable-domain requests. 2727 // Verify that both cookies are sent for same-registrable-domain requests.
2728 { 2728 {
2729 TestDelegate d; 2729 TestDelegate d;
2730 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2730 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2731 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2731 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2732 req->set_first_party_for_cookies(test_server.GetURL(kSubHost, "/")); 2732 req->set_first_party_for_cookies(test_server.GetURL(kSubHost, "/"));
2733 req->set_initiator(url::Origin(test_server.GetURL(kSubHost, "/"))); 2733 req->set_initiator(
2734 new url::NullableOrigin(test_server.GetURL(kSubHost, "/")));
2734 req->Start(); 2735 req->Start();
2735 base::RunLoop().Run(); 2736 base::RunLoop().Run();
2736 2737
2737 EXPECT_NE(std::string::npos, 2738 EXPECT_NE(std::string::npos,
2738 d.data_received().find("StrictSameSiteCookie=1")); 2739 d.data_received().find("StrictSameSiteCookie=1"));
2739 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); 2740 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1"));
2740 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2741 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2741 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2742 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2742 } 2743 }
2743 2744
2744 // Verify that neither cookie is not sent for cross-site requests. 2745 // Verify that neither cookie is not sent for cross-site requests.
2745 { 2746 {
2746 TestDelegate d; 2747 TestDelegate d;
2747 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2748 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2748 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2749 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2749 req->set_first_party_for_cookies(test_server.GetURL(kCrossHost, "/")); 2750 req->set_first_party_for_cookies(test_server.GetURL(kCrossHost, "/"));
2750 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); 2751 req->set_initiator(
2752 new url::NullableOrigin(test_server.GetURL(kCrossHost, "/")));
2751 req->Start(); 2753 req->Start();
2752 base::RunLoop().Run(); 2754 base::RunLoop().Run();
2753 2755
2754 EXPECT_EQ(std::string::npos, 2756 EXPECT_EQ(std::string::npos,
2755 d.data_received().find("StrictSameSiteCookie=1")); 2757 d.data_received().find("StrictSameSiteCookie=1"));
2756 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); 2758 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1"));
2757 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2759 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2758 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2760 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2759 } 2761 }
2760 2762
2761 // Verify that the lax cookie is sent for cross-site initiators when the 2763 // Verify that the lax cookie is sent for cross-site initiators when the
2762 // method is "safe". 2764 // method is "safe".
2763 { 2765 {
2764 TestDelegate d; 2766 TestDelegate d;
2765 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2767 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2766 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2768 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2767 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); 2769 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/"));
2768 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); 2770 req->set_initiator(
2771 new url::NullableOrigin(test_server.GetURL(kCrossHost, "/")));
2769 req->set_method("GET"); 2772 req->set_method("GET");
2770 req->Start(); 2773 req->Start();
2771 base::RunLoop().Run(); 2774 base::RunLoop().Run();
2772 2775
2773 EXPECT_EQ(std::string::npos, 2776 EXPECT_EQ(std::string::npos,
2774 d.data_received().find("StrictSameSiteCookie=1")); 2777 d.data_received().find("StrictSameSiteCookie=1"));
2775 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); 2778 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1"));
2776 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2779 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2777 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2780 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2778 } 2781 }
2779 2782
2780 // Verify that neither cookie is sent for cross-site initiators when the 2783 // Verify that neither cookie is sent for cross-site initiators when the
2781 // method is unsafe (e.g. POST). 2784 // method is unsafe (e.g. POST).
2782 { 2785 {
2783 TestDelegate d; 2786 TestDelegate d;
2784 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2787 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2785 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); 2788 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2786 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); 2789 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/"));
2787 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); 2790 req->set_initiator(
2791 new url::NullableOrigin(test_server.GetURL(kCrossHost, "/")));
2788 req->set_method("POST"); 2792 req->set_method("POST");
2789 req->Start(); 2793 req->Start();
2790 base::RunLoop().Run(); 2794 base::RunLoop().Run();
2791 2795
2792 EXPECT_EQ(std::string::npos, 2796 EXPECT_EQ(std::string::npos,
2793 d.data_received().find("StrictSameSiteCookie=1")); 2797 d.data_received().find("StrictSameSiteCookie=1"));
2794 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); 2798 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1"));
2795 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2799 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2796 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2800 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2797 } 2801 }
(...skipping 7419 matching lines...) Expand 10 before | Expand all | Expand 10 after
10217 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10221 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10218 10222
10219 req->Start(); 10223 req->Start();
10220 req->Cancel(); 10224 req->Cancel();
10221 base::RunLoop().RunUntilIdle(); 10225 base::RunLoop().RunUntilIdle();
10222 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10226 EXPECT_EQ(ERR_ABORTED, d.request_status());
10223 EXPECT_EQ(0, d.received_redirect_count()); 10227 EXPECT_EQ(0, d.received_redirect_count());
10224 } 10228 }
10225 10229
10226 } // namespace net 10230 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698