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 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); | |
2555 default_context_.set_network_delegate(&network_delegate); | 2554 default_context_.set_network_delegate(&network_delegate); |
2556 | 2555 |
2557 TestDelegate d; | 2556 TestDelegate d; |
2558 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2557 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2559 test_server.GetURL( | 2558 test_server.GetURL( |
2560 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), | 2559 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), |
2561 DEFAULT_PRIORITY, &d)); | 2560 DEFAULT_PRIORITY, &d)); |
2562 req->Start(); | 2561 req->Start(); |
2563 base::RunLoop().Run(); | 2562 base::RunLoop().Run(); |
2564 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2563 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2565 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2564 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2566 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2565 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
2567 } | 2566 } |
2568 | 2567 |
2569 // Verify that the cookie is sent for first-party requests. | 2568 // Verify that the cookie is sent for first-party requests. |
2570 { | 2569 { |
2571 TestNetworkDelegate network_delegate; | 2570 TestNetworkDelegate network_delegate; |
2572 network_delegate.set_first_party_only_cookies_enabled(true); | |
2573 default_context_.set_network_delegate(&network_delegate); | 2571 default_context_.set_network_delegate(&network_delegate); |
2574 TestDelegate d; | 2572 TestDelegate d; |
2575 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2573 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2576 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2574 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2577 req->set_first_party_for_cookies(test_server.GetURL("")); | 2575 req->set_first_party_for_cookies(test_server.GetURL("")); |
2578 req->Start(); | 2576 req->Start(); |
2579 base::RunLoop().Run(); | 2577 base::RunLoop().Run(); |
2580 | 2578 |
2581 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != | 2579 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
2582 std::string::npos); | 2580 std::string::npos); |
2583 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2581 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2584 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2582 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2585 } | 2583 } |
2586 | 2584 |
2587 // Verify that the cookie is not-sent for non-first-party requests. | 2585 // Verify that the cookie is not-sent for non-first-party requests. |
2588 { | 2586 { |
2589 TestNetworkDelegate network_delegate; | 2587 TestNetworkDelegate network_delegate; |
2590 network_delegate.set_first_party_only_cookies_enabled(true); | |
2591 default_context_.set_network_delegate(&network_delegate); | 2588 default_context_.set_network_delegate(&network_delegate); |
2592 TestDelegate d; | 2589 TestDelegate d; |
2593 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 2590 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
2594 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2591 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d)); |
2595 req->set_first_party_for_cookies(GURL("http://third-party.test/")); | 2592 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
2596 req->Start(); | 2593 req->Start(); |
2597 base::RunLoop().Run(); | 2594 base::RunLoop().Run(); |
2598 | 2595 |
2599 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == | 2596 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
2600 std::string::npos); | 2597 std::string::npos); |
2601 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2598 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2602 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2599 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2603 } | 2600 } |
2604 } | 2601 } |
2605 | 2602 |
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()); | |
2663 } | |
2664 } | |
2665 | |
2666 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header | 2603 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header |
2667 // value for the |fixed_date| argument given to the constructor. | 2604 // value for the |fixed_date| argument given to the constructor. |
2668 class FixedDateNetworkDelegate : public TestNetworkDelegate { | 2605 class FixedDateNetworkDelegate : public TestNetworkDelegate { |
2669 public: | 2606 public: |
2670 explicit FixedDateNetworkDelegate(const std::string& fixed_date) | 2607 explicit FixedDateNetworkDelegate(const std::string& fixed_date) |
2671 : fixed_date_(fixed_date) {} | 2608 : fixed_date_(fixed_date) {} |
2672 ~FixedDateNetworkDelegate() override {} | 2609 ~FixedDateNetworkDelegate() override {} |
2673 | 2610 |
2674 // NetworkDelegate implementation | 2611 // NetworkDelegate implementation |
2675 int OnHeadersReceived( | 2612 int OnHeadersReceived( |
(...skipping 6249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8925 | 8862 |
8926 EXPECT_FALSE(r->is_pending()); | 8863 EXPECT_FALSE(r->is_pending()); |
8927 EXPECT_EQ(1, d->response_started_count()); | 8864 EXPECT_EQ(1, d->response_started_count()); |
8928 EXPECT_FALSE(d->received_data_before_response()); | 8865 EXPECT_FALSE(d->received_data_before_response()); |
8929 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8866 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
8930 } | 8867 } |
8931 } | 8868 } |
8932 #endif // !defined(DISABLE_FTP_SUPPORT) | 8869 #endif // !defined(DISABLE_FTP_SUPPORT) |
8933 | 8870 |
8934 } // namespace net | 8871 } // namespace net |
OLD | NEW |