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 2525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2536 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
2537 == std::string::npos); | 2537 == std::string::npos); |
2538 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2538 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
2539 != std::string::npos); | 2539 != std::string::npos); |
2540 | 2540 |
2541 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2541 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
2542 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2542 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
2543 } | 2543 } |
2544 } | 2544 } |
2545 | 2545 |
| 2546 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { |
| 2547 LocalHttpTestServer test_server; |
| 2548 ASSERT_TRUE(test_server.Start()); |
| 2549 |
| 2550 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where |
| 2551 // LocalHttpTestServer points). |
| 2552 { |
| 2553 TestNetworkDelegate network_delegate; |
| 2554 network_delegate.set_first_party_only_cookies_enabled(true); |
| 2555 default_context_.set_network_delegate(&network_delegate); |
| 2556 |
| 2557 TestDelegate d; |
| 2558 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2559 test_server.GetURL( |
| 2560 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), |
| 2561 DEFAULT_PRIORITY, &d, NULL)); |
| 2562 req->Start(); |
| 2563 base::RunLoop().Run(); |
| 2564 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2565 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2566 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2567 } |
| 2568 |
| 2569 // Verify that the cookie is sent for first-party requests. |
| 2570 { |
| 2571 TestNetworkDelegate network_delegate; |
| 2572 network_delegate.set_first_party_only_cookies_enabled(true); |
| 2573 default_context_.set_network_delegate(&network_delegate); |
| 2574 TestDelegate d; |
| 2575 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2576 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2577 req->set_first_party_for_cookies(test_server.GetURL("")); |
| 2578 req->Start(); |
| 2579 base::RunLoop().Run(); |
| 2580 |
| 2581 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != |
| 2582 std::string::npos); |
| 2583 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2584 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2585 } |
| 2586 |
| 2587 // Verify that the cookie is not-sent for non-first-party requests. |
| 2588 { |
| 2589 TestNetworkDelegate network_delegate; |
| 2590 network_delegate.set_first_party_only_cookies_enabled(true); |
| 2591 default_context_.set_network_delegate(&network_delegate); |
| 2592 TestDelegate d; |
| 2593 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2594 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); |
| 2595 req->set_first_party_for_cookies(GURL("http://third-party.test/")); |
| 2596 req->Start(); |
| 2597 base::RunLoop().Run(); |
| 2598 |
| 2599 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == |
| 2600 std::string::npos); |
| 2601 EXPECT_EQ(0, network_delegate.blocked_get_cookies_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, NULL)); |
| 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, NULL)); |
| 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, NULL)); |
| 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 |
2546 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header | 2666 // FixedDateNetworkDelegate swaps out the server's HTTP Date response header |
2547 // value for the |fixed_date| argument given to the constructor. | 2667 // value for the |fixed_date| argument given to the constructor. |
2548 class FixedDateNetworkDelegate : public TestNetworkDelegate { | 2668 class FixedDateNetworkDelegate : public TestNetworkDelegate { |
2549 public: | 2669 public: |
2550 explicit FixedDateNetworkDelegate(const std::string& fixed_date) | 2670 explicit FixedDateNetworkDelegate(const std::string& fixed_date) |
2551 : fixed_date_(fixed_date) {} | 2671 : fixed_date_(fixed_date) {} |
2552 ~FixedDateNetworkDelegate() override {} | 2672 ~FixedDateNetworkDelegate() override {} |
2553 | 2673 |
2554 // NetworkDelegate implementation | 2674 // NetworkDelegate implementation |
2555 int OnHeadersReceived( | 2675 int OnHeadersReceived( |
(...skipping 6279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8835 | 8955 |
8836 EXPECT_FALSE(r->is_pending()); | 8956 EXPECT_FALSE(r->is_pending()); |
8837 EXPECT_EQ(1, d->response_started_count()); | 8957 EXPECT_EQ(1, d->response_started_count()); |
8838 EXPECT_FALSE(d->received_data_before_response()); | 8958 EXPECT_FALSE(d->received_data_before_response()); |
8839 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8959 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
8840 } | 8960 } |
8841 } | 8961 } |
8842 #endif // !defined(DISABLE_FTP_SUPPORT) | 8962 #endif // !defined(DISABLE_FTP_SUPPORT) |
8843 | 8963 |
8844 } // namespace net | 8964 } // namespace net |
OLD | NEW |