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