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

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

Issue 9572001: Do cookie checks in NetworkDelegate instead of the URLRequest::Delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TestShellNetworkDelegate Created 8 years, 9 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 | Annotate | Revision Log
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 <shlobj.h> 8 #include <shlobj.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
(...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 ASSERT_TRUE(test_server.Start()); 2562 ASSERT_TRUE(test_server.Start());
2563 2563
2564 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); 2564 scoped_refptr<URLRequestContext> context(new TestURLRequestContext());
2565 scoped_refptr<DelayedCookieMonster> delayed_cm = 2565 scoped_refptr<DelayedCookieMonster> delayed_cm =
2566 new DelayedCookieMonster(); 2566 new DelayedCookieMonster();
2567 scoped_refptr<CookieStore> cookie_store = delayed_cm; 2567 scoped_refptr<CookieStore> cookie_store = delayed_cm;
2568 context->set_cookie_store(delayed_cm); 2568 context->set_cookie_store(delayed_cm);
2569 2569
2570 // Set up a cookie. 2570 // Set up a cookie.
2571 { 2571 {
2572 TestNetworkDelegate network_delegate;
2573 context->set_network_delegate(&network_delegate);
2572 TestDelegate d; 2574 TestDelegate d;
2573 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 2575 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
2574 req.set_context(context); 2576 req.set_context(context);
2575 req.Start(); 2577 req.Start();
2576 MessageLoop::current()->Run(); 2578 MessageLoop::current()->Run();
2577 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2579 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2578 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2580 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2579 EXPECT_EQ(1, d.set_cookie_count()); 2581 EXPECT_EQ(1, network_delegate.set_cookie_count());
2580 } 2582 }
2581 2583
2582 // Verify that the cookie is set. 2584 // Verify that the cookie is set.
2583 { 2585 {
2586 TestNetworkDelegate network_delegate;
2587 context->set_network_delegate(&network_delegate);
2584 TestDelegate d; 2588 TestDelegate d;
2585 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2589 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2586 req.set_context(context); 2590 req.set_context(context);
2587 req.Start(); 2591 req.Start();
2588 MessageLoop::current()->Run(); 2592 MessageLoop::current()->Run();
2589 2593
2590 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2594 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2591 != std::string::npos); 2595 != std::string::npos);
2592 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2596 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2593 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2597 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2594 } 2598 }
2595 } 2599 }
2596 2600
2597 TEST_F(URLRequestTest, DoNotSendCookies) { 2601 TEST_F(URLRequestTest, DoNotSendCookies) {
2598 LocalHttpTestServer test_server; 2602 LocalHttpTestServer test_server;
2599 ASSERT_TRUE(test_server.Start()); 2603 ASSERT_TRUE(test_server.Start());
2600 2604
2601 // Set up a cookie. 2605 // Set up a cookie.
2602 { 2606 {
2607 TestNetworkDelegate network_delegate;
2608 default_context_->set_network_delegate(&network_delegate);
2603 TestDelegate d; 2609 TestDelegate d;
2604 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 2610 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
2605 req.set_context(default_context_); 2611 req.set_context(default_context_);
2606 req.Start(); 2612 req.Start();
2607 MessageLoop::current()->Run(); 2613 MessageLoop::current()->Run();
2608 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2614 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2609 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2615 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2610 } 2616 }
2611 2617
2612 // Verify that the cookie is set. 2618 // Verify that the cookie is set.
2613 { 2619 {
2620 TestNetworkDelegate network_delegate;
2621 default_context_->set_network_delegate(&network_delegate);
2614 TestDelegate d; 2622 TestDelegate d;
2615 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2623 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2616 req.set_context(default_context_); 2624 req.set_context(default_context_);
2617 req.Start(); 2625 req.Start();
2618 MessageLoop::current()->Run(); 2626 MessageLoop::current()->Run();
2619 2627
2620 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2628 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2621 != std::string::npos); 2629 != std::string::npos);
2622 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2630 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2623 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2631 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2624 } 2632 }
2625 2633
2626 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. 2634 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set.
2627 { 2635 {
2636 TestNetworkDelegate network_delegate;
2637 default_context_->set_network_delegate(&network_delegate);
2628 TestDelegate d; 2638 TestDelegate d;
2629 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2639 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2630 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); 2640 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES);
2631 req.set_context(default_context_); 2641 req.set_context(default_context_);
2632 req.Start(); 2642 req.Start();
2633 MessageLoop::current()->Run(); 2643 MessageLoop::current()->Run();
2634 2644
2635 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2645 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2636 == std::string::npos); 2646 == std::string::npos);
2637 2647
2638 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. 2648 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies.
2639 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2649 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2640 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2650 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2641 } 2651 }
2652
2653 default_context_->set_network_delegate(&default_network_delegate_);
2642 } 2654 }
2643 2655
2644 TEST_F(URLRequestTest, DoNotSaveCookies) { 2656 TEST_F(URLRequestTest, DoNotSaveCookies) {
2645 LocalHttpTestServer test_server; 2657 LocalHttpTestServer test_server;
2646 ASSERT_TRUE(test_server.Start()); 2658 ASSERT_TRUE(test_server.Start());
2647 2659
2648 // Set up a cookie. 2660 // Set up a cookie.
2649 { 2661 {
2662 TestNetworkDelegate network_delegate;
2663 default_context_->set_network_delegate(&network_delegate);
2650 TestDelegate d; 2664 TestDelegate d;
2651 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); 2665 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d);
2652 req.set_context(default_context_); 2666 req.set_context(default_context_);
2653 req.Start(); 2667 req.Start();
2654 MessageLoop::current()->Run(); 2668 MessageLoop::current()->Run();
2655 2669
2656 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2670 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2657 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2671 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2658 EXPECT_EQ(1, d.set_cookie_count()); 2672 EXPECT_EQ(1, network_delegate.set_cookie_count());
2659 } 2673 }
2660 2674
2661 // Try to set-up another cookie and update the previous cookie. 2675 // Try to set-up another cookie and update the previous cookie.
2662 { 2676 {
2677 TestNetworkDelegate network_delegate;
2678 default_context_->set_network_delegate(&network_delegate);
2663 TestDelegate d; 2679 TestDelegate d;
2664 URLRequest req(test_server.GetURL( 2680 URLRequest req(test_server.GetURL(
2665 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 2681 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
2666 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); 2682 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES);
2667 req.set_context(default_context_); 2683 req.set_context(default_context_);
2668 req.Start(); 2684 req.Start();
2669 2685
2670 MessageLoop::current()->Run(); 2686 MessageLoop::current()->Run();
2671 2687
2672 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. 2688 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie.
2673 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2689 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2674 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2690 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2675 EXPECT_EQ(0, d.set_cookie_count()); 2691 EXPECT_EQ(0, network_delegate.set_cookie_count());
2676 } 2692 }
2677 2693
2678 // Verify the cookies weren't saved or updated. 2694 // Verify the cookies weren't saved or updated.
2679 { 2695 {
2696 TestNetworkDelegate network_delegate;
2697 default_context_->set_network_delegate(&network_delegate);
2680 TestDelegate d; 2698 TestDelegate d;
2681 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2699 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2682 req.set_context(default_context_); 2700 req.set_context(default_context_);
2683 req.Start(); 2701 req.Start();
2684 MessageLoop::current()->Run(); 2702 MessageLoop::current()->Run();
2685 2703
2686 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2704 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2687 == std::string::npos); 2705 == std::string::npos);
2688 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2706 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2689 != std::string::npos); 2707 != std::string::npos);
2690 2708
2691 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2709 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2692 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2710 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2693 EXPECT_EQ(0, d.set_cookie_count()); 2711 EXPECT_EQ(0, network_delegate.set_cookie_count());
2694 } 2712 }
2713
2714 default_context_->set_network_delegate(&default_network_delegate_);
2695 } 2715 }
2696 2716
2697 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { 2717 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
2698 LocalHttpTestServer test_server; 2718 LocalHttpTestServer test_server;
2699 ASSERT_TRUE(test_server.Start()); 2719 ASSERT_TRUE(test_server.Start());
2700 2720
2701 // Set up a cookie. 2721 // Set up a cookie.
2702 { 2722 {
2723 TestNetworkDelegate network_delegate;
2724 default_context_->set_network_delegate(&network_delegate);
2703 TestDelegate d; 2725 TestDelegate d;
2704 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 2726 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
2705 req.set_context(default_context_); 2727 req.set_context(default_context_);
2706 req.Start(); 2728 req.Start();
2707 MessageLoop::current()->Run(); 2729 MessageLoop::current()->Run();
2708 2730
2709 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2731 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2710 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2732 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2711 } 2733 }
2712 2734
2713 // Verify that the cookie is set. 2735 // Verify that the cookie is set.
2714 { 2736 {
2737 TestNetworkDelegate network_delegate;
2738 default_context_->set_network_delegate(&network_delegate);
2715 TestDelegate d; 2739 TestDelegate d;
2716 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2740 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2717 req.set_context(default_context_); 2741 req.set_context(default_context_);
2718 req.Start(); 2742 req.Start();
2719 MessageLoop::current()->Run(); 2743 MessageLoop::current()->Run();
2720 2744
2721 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2745 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2722 != std::string::npos); 2746 != std::string::npos);
2723 2747
2724 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2748 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2725 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2749 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2726 } 2750 }
2727 2751
2728 // Verify that the cookie isn't sent. 2752 // Verify that the cookie isn't sent.
2729 { 2753 {
2754 TestNetworkDelegate network_delegate;
2755 default_context_->set_network_delegate(&network_delegate);
2730 TestDelegate d; 2756 TestDelegate d;
2731 d.set_cookie_options(TestDelegate::NO_GET_COOKIES); 2757 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2732 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2758 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2733 req.set_context(default_context_); 2759 req.set_context(default_context_);
2734 req.Start(); 2760 req.Start();
2735 MessageLoop::current()->Run(); 2761 MessageLoop::current()->Run();
2736 2762
2737 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2763 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2738 == std::string::npos); 2764 == std::string::npos);
2739 2765
2740 EXPECT_EQ(1, d.blocked_get_cookies_count()); 2766 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2741 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2767 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2742 } 2768 }
2769
2770 default_context_->set_network_delegate(&default_network_delegate_);
2743 } 2771 }
2744 2772
2745 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 2773 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
2746 LocalHttpTestServer test_server; 2774 LocalHttpTestServer test_server;
2747 ASSERT_TRUE(test_server.Start()); 2775 ASSERT_TRUE(test_server.Start());
2748 2776
2749 // Set up a cookie. 2777 // Set up a cookie.
2750 { 2778 {
2779 TestNetworkDelegate network_delegate;
2780 default_context_->set_network_delegate(&network_delegate);
2751 TestDelegate d; 2781 TestDelegate d;
2752 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); 2782 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d);
2753 req.set_context(default_context_); 2783 req.set_context(default_context_);
2754 req.Start(); 2784 req.Start();
2755 MessageLoop::current()->Run(); 2785 MessageLoop::current()->Run();
2756 2786
2757 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2787 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2758 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2788 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2759 } 2789 }
2760 2790
2761 // Try to set-up another cookie and update the previous cookie. 2791 // Try to set-up another cookie and update the previous cookie.
2762 { 2792 {
2793 TestNetworkDelegate network_delegate;
2794 default_context_->set_network_delegate(&network_delegate);
2763 TestDelegate d; 2795 TestDelegate d;
2764 d.set_cookie_options(TestDelegate::NO_SET_COOKIE); 2796 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2765 URLRequest req(test_server.GetURL( 2797 URLRequest req(test_server.GetURL(
2766 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 2798 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
2767 req.set_context(default_context_); 2799 req.set_context(default_context_);
2768 req.Start(); 2800 req.Start();
2769 2801
2770 MessageLoop::current()->Run(); 2802 MessageLoop::current()->Run();
2771 2803
2772 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2804 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2773 EXPECT_EQ(2, d.blocked_set_cookie_count()); 2805 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2774 } 2806 }
2775 2807
2776 2808
2777 // Verify the cookies weren't saved or updated. 2809 // Verify the cookies weren't saved or updated.
2778 { 2810 {
2811 TestNetworkDelegate network_delegate;
2812 default_context_->set_network_delegate(&network_delegate);
2779 TestDelegate d; 2813 TestDelegate d;
2780 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2814 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2781 req.set_context(default_context_); 2815 req.set_context(default_context_);
2782 req.Start(); 2816 req.Start();
2783 MessageLoop::current()->Run(); 2817 MessageLoop::current()->Run();
2784 2818
2785 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2819 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2786 == std::string::npos); 2820 == std::string::npos);
2787 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2821 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2788 != std::string::npos); 2822 != std::string::npos);
2789 2823
2790 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2824 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2791 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2825 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2792 } 2826 }
2827
2828 default_context_->set_network_delegate(&default_network_delegate_);
2793 } 2829 }
2794 2830
2795 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { 2831 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) {
2796 LocalHttpTestServer test_server; 2832 LocalHttpTestServer test_server;
2797 ASSERT_TRUE(test_server.Start()); 2833 ASSERT_TRUE(test_server.Start());
2798 2834
2799 // Set up an empty cookie. 2835 // Set up an empty cookie.
2800 { 2836 {
2837 TestNetworkDelegate network_delegate;
2838 default_context_->set_network_delegate(&network_delegate);
2801 TestDelegate d; 2839 TestDelegate d;
2802 URLRequest req(test_server.GetURL("set-cookie"), &d); 2840 URLRequest req(test_server.GetURL("set-cookie"), &d);
2803 req.set_context(default_context_); 2841 req.set_context(default_context_);
2804 req.Start(); 2842 req.Start();
2805 MessageLoop::current()->Run(); 2843 MessageLoop::current()->Run();
2806 2844
2807 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2845 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2808 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2846 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2809 EXPECT_EQ(0, d.set_cookie_count()); 2847 EXPECT_EQ(0, network_delegate.set_cookie_count());
2810 } 2848 }
2849
2850 default_context_->set_network_delegate(&default_network_delegate_);
2811 } 2851 }
2812 2852
2813 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { 2853 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
2814 LocalHttpTestServer test_server; 2854 LocalHttpTestServer test_server;
2815 ASSERT_TRUE(test_server.Start()); 2855 ASSERT_TRUE(test_server.Start());
2816 2856
2817 // Set up a cookie. 2857 // Set up a cookie.
2818 { 2858 {
2859 TestNetworkDelegate network_delegate;
2860 default_context_->set_network_delegate(&network_delegate);
2819 TestDelegate d; 2861 TestDelegate d;
2820 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); 2862 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d);
2821 req.set_context(default_context_); 2863 req.set_context(default_context_);
2822 req.Start(); 2864 req.Start();
2823 MessageLoop::current()->Run(); 2865 MessageLoop::current()->Run();
2824 2866
2825 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2867 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2826 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2868 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2827 } 2869 }
2828 2870
2829 // Verify that the cookie is set. 2871 // Verify that the cookie is set.
2830 { 2872 {
2873 TestNetworkDelegate network_delegate;
2874 default_context_->set_network_delegate(&network_delegate);
2831 TestDelegate d; 2875 TestDelegate d;
2832 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2876 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2833 req.set_context(default_context_); 2877 req.set_context(default_context_);
2834 req.Start(); 2878 req.Start();
2835 MessageLoop::current()->Run(); 2879 MessageLoop::current()->Run();
2836 2880
2837 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2881 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2838 != std::string::npos); 2882 != std::string::npos);
2839 2883
2840 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2884 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2841 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2885 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2842 } 2886 }
2843 2887
2844 // Verify that the cookie isn't sent. 2888 // Verify that the cookie isn't sent.
2845 { 2889 {
2890 TestNetworkDelegate network_delegate;
2891 default_context_->set_network_delegate(&network_delegate);
2846 TestDelegate d; 2892 TestDelegate d;
2847 d.set_cookie_options(TestDelegate::NO_GET_COOKIES); 2893 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2848 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2894 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2849 req.set_context(default_context_); 2895 req.set_context(default_context_);
2850 req.Start(); 2896 req.Start();
2851 MessageLoop::current()->Run(); 2897 MessageLoop::current()->Run();
2852 2898
2853 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2899 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2854 == std::string::npos); 2900 == std::string::npos);
2855 2901
2856 EXPECT_EQ(1, d.blocked_get_cookies_count()); 2902 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2857 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2903 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2858 } 2904 }
2905
2906 default_context_->set_network_delegate(&default_network_delegate_);
2859 } 2907 }
2860 2908
2861 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 2909 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
2862 LocalHttpTestServer test_server; 2910 LocalHttpTestServer test_server;
2863 ASSERT_TRUE(test_server.Start()); 2911 ASSERT_TRUE(test_server.Start());
2864 2912
2865 // Set up a cookie. 2913 // Set up a cookie.
2866 { 2914 {
2915 TestNetworkDelegate network_delegate;
2916 default_context_->set_network_delegate(&network_delegate);
2867 TestDelegate d; 2917 TestDelegate d;
2868 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); 2918 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d);
2869 req.set_context(default_context_); 2919 req.set_context(default_context_);
2870 req.Start(); 2920 req.Start();
2871 MessageLoop::current()->Run(); 2921 MessageLoop::current()->Run();
2872 2922
2873 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2923 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2874 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2924 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2875 } 2925 }
2876 2926
2877 // Try to set-up another cookie and update the previous cookie. 2927 // Try to set-up another cookie and update the previous cookie.
2878 { 2928 {
2929 TestNetworkDelegate network_delegate;
2930 default_context_->set_network_delegate(&network_delegate);
2879 TestDelegate d; 2931 TestDelegate d;
2880 d.set_cookie_options(TestDelegate::NO_SET_COOKIE); 2932 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2881 URLRequest req(test_server.GetURL( 2933 URLRequest req(test_server.GetURL(
2882 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); 2934 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d);
2883 req.set_context(default_context_); 2935 req.set_context(default_context_);
2884 req.Start(); 2936 req.Start();
2885 2937
2886 MessageLoop::current()->Run(); 2938 MessageLoop::current()->Run();
2887 2939
2888 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2940 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2889 EXPECT_EQ(2, d.blocked_set_cookie_count()); 2941 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2890 } 2942 }
2891 2943
2892 // Verify the cookies weren't saved or updated. 2944 // Verify the cookies weren't saved or updated.
2893 { 2945 {
2946 TestNetworkDelegate network_delegate;
2947 default_context_->set_network_delegate(&network_delegate);
2894 TestDelegate d; 2948 TestDelegate d;
2895 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); 2949 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d);
2896 req.set_context(default_context_); 2950 req.set_context(default_context_);
2897 req.Start(); 2951 req.Start();
2898 MessageLoop::current()->Run(); 2952 MessageLoop::current()->Run();
2899 2953
2900 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2954 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2901 == std::string::npos); 2955 == std::string::npos);
2902 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2956 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2903 != std::string::npos); 2957 != std::string::npos);
2904 2958
2905 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2959 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2906 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2960 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2907 } 2961 }
2962
2963 default_context_->set_network_delegate(&default_network_delegate_);
2908 } 2964 }
2909 2965
2910 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { 2966 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) {
2911 EXPECT_EQ(1U, cookies.size()); 2967 EXPECT_EQ(1U, cookies.size());
2912 EXPECT_FALSE(cookies[0].IsPersistent()); 2968 EXPECT_FALSE(cookies[0].IsPersistent());
2913 *was_run = true; 2969 *was_run = true;
2914 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 2970 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
2915 } 2971 }
2916 2972
2917 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { 2973 TEST_F(URLRequestTest, CookiePolicy_ForceSession) {
2918 LocalHttpTestServer test_server; 2974 LocalHttpTestServer test_server;
2919 ASSERT_TRUE(test_server.Start()); 2975 ASSERT_TRUE(test_server.Start());
2920 2976
2921 // Set up a cookie. 2977 // Set up a cookie.
2922 { 2978 {
2979 TestNetworkDelegate network_delegate;
2980 default_context_->set_network_delegate(&network_delegate);
2923 TestDelegate d; 2981 TestDelegate d;
2924 d.set_cookie_options(TestDelegate::FORCE_SESSION); 2982 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION);
2925 URLRequest req(test_server.GetURL( 2983 URLRequest req(test_server.GetURL(
2926 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); 2984 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d);
2927 req.set_context(default_context_); 2985 req.set_context(default_context_);
2928 req.Start(); // Triggers an asynchronous cookie policy check. 2986 req.Start(); // Triggers an asynchronous cookie policy check.
2929 2987
2930 MessageLoop::current()->Run(); 2988 MessageLoop::current()->Run();
2931 2989
2932 EXPECT_EQ(0, d.blocked_get_cookies_count()); 2990 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2933 EXPECT_EQ(0, d.blocked_set_cookie_count()); 2991 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2934 } 2992 }
2993 default_context_->set_network_delegate(&default_network_delegate_);
2935 2994
2936 // Now, check the cookie store. 2995 // Now, check the cookie store.
2937 bool was_run = false; 2996 bool was_run = false;
2938 default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync( 2997 default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync(
2939 base::Bind(&CheckCookiePolicyCallback, &was_run)); 2998 base::Bind(&CheckCookiePolicyCallback, &was_run));
2940 MessageLoop::current()->RunAllPending(); 2999 MessageLoop::current()->RunAllPending();
2941 DCHECK(was_run); 3000 DCHECK(was_run);
2942 } 3001 }
2943 3002
2944 // In this test, we do a POST which the server will 302 redirect. 3003 // In this test, we do a POST which the server will 302 redirect.
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after
4139 req.SetExtraRequestHeaders(headers); 4198 req.SetExtraRequestHeaders(headers);
4140 req.Start(); 4199 req.Start();
4141 MessageLoop::current()->Run(); 4200 MessageLoop::current()->Run();
4142 // If the net tests are being run with ChromeFrame then we need to allow for 4201 // If the net tests are being run with ChromeFrame then we need to allow for
4143 // the 'chromeframe' suffix which is added to the user agent before the 4202 // the 'chromeframe' suffix which is added to the user agent before the
4144 // closing parentheses. 4203 // closing parentheses.
4145 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); 4204 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true));
4146 } 4205 }
4147 4206
4148 } // namespace net 4207 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698