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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 3667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3678 EXPECT_EQ( | 3678 EXPECT_EQ( |
3679 GURL(test.sanitized_url_unstripped), | 3679 GURL(test.sanitized_url_unstripped), |
3680 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); | 3680 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); |
3681 | 3681 |
3682 EXPECT_EQ( | 3682 EXPECT_EQ( |
3683 GURL(test.sanitized_url), | 3683 GURL(test.sanitized_url), |
3684 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); | 3684 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); |
3685 } | 3685 } |
3686 } | 3686 } |
3687 | 3687 |
| 3688 TEST_F(ProxyServiceTest, RequestsHangAfterShutdown) { |
| 3689 MockAsyncProxyResolverFactory* factory = |
| 3690 new MockAsyncProxyResolverFactory(false); |
| 3691 ProxyService service( |
| 3692 base::MakeUnique<MockProxyConfigService>(ProxyConfig::CreateDirect()), |
| 3693 base::WrapUnique(factory), nullptr); |
| 3694 |
| 3695 GURL url("http://www.google.com/"); |
| 3696 |
| 3697 service.ShutDown(); |
| 3698 |
| 3699 ProxyInfo info; |
| 3700 TestCompletionCallback callback; |
| 3701 ProxyService::PacRequest* request; |
| 3702 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 3703 &request, nullptr, NetLogWithSource()); |
| 3704 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3705 EXPECT_TRUE(factory->pending_requests().empty()); |
| 3706 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
| 3707 EXPECT_FALSE(callback.have_result()); |
| 3708 |
| 3709 base::RunLoop().RunUntilIdle(); |
| 3710 EXPECT_FALSE(callback.have_result()); |
| 3711 service.CancelPacRequest(request); |
| 3712 |
| 3713 EXPECT_FALSE(service.TryResolveProxySynchronously( |
| 3714 url, std::string(), &info, nullptr, NetLogWithSource())); |
| 3715 } |
| 3716 |
| 3717 TEST_F(ProxyServiceTest, ProxyResolverShutdownDuringPacRequest) { |
| 3718 MockProxyConfigService* config_service = |
| 3719 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 3720 |
| 3721 MockAsyncProxyResolver resolver; |
| 3722 MockAsyncProxyResolverFactory* factory = |
| 3723 new MockAsyncProxyResolverFactory(false); |
| 3724 |
| 3725 ProxyService service(base::WrapUnique(config_service), |
| 3726 base::WrapUnique(factory), nullptr); |
| 3727 |
| 3728 // Start request. |
| 3729 GURL url("http://www.google.com/"); |
| 3730 ProxyInfo info; |
| 3731 ProxyService::PacRequest* request; |
| 3732 TestCompletionCallback callback; |
| 3733 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 3734 &request, nullptr, NetLogWithSource()); |
| 3735 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3736 |
| 3737 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 3738 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 3739 factory->pending_requests()[0]->script_data()->url()); |
| 3740 |
| 3741 service.ShutDown(); |
| 3742 EXPECT_EQ(0u, factory->pending_requests().size()); |
| 3743 EXPECT_EQ(1u, factory->cancelled_requests().size()); |
| 3744 |
| 3745 base::RunLoop().RunUntilIdle(); |
| 3746 EXPECT_FALSE(callback.have_result()); |
| 3747 service.CancelPacRequest(request); |
| 3748 } |
| 3749 |
| 3750 TEST_F(ProxyServiceTest, ProxyResolverShutdownAfterPacRequestDuringResolve) { |
| 3751 MockProxyConfigService* config_service = |
| 3752 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 3753 |
| 3754 MockAsyncProxyResolver resolver; |
| 3755 MockAsyncProxyResolverFactory* factory = |
| 3756 new MockAsyncProxyResolverFactory(false); |
| 3757 |
| 3758 ProxyService service(base::WrapUnique(config_service), |
| 3759 base::WrapUnique(factory), nullptr); |
| 3760 |
| 3761 // Start request. |
| 3762 GURL url("http://www.google.com/"); |
| 3763 ProxyInfo info; |
| 3764 ProxyService::PacRequest* request; |
| 3765 TestCompletionCallback callback; |
| 3766 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
| 3767 &request, nullptr, NetLogWithSource()); |
| 3768 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 3769 |
| 3770 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 3771 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 3772 factory->pending_requests()[0]->script_data()->url()); |
| 3773 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 3774 EXPECT_EQ(0u, factory->pending_requests().size()); |
| 3775 // Checks that the one resolve job for |url| is outstanding. |
| 3776 GetPendingJobsForURLs(resolver, url); |
| 3777 |
| 3778 service.ShutDown(); |
| 3779 EXPECT_EQ(0u, factory->cancelled_requests().size()); |
| 3780 // Checks that no resolve jobs are outstanding. |
| 3781 GetPendingJobsForURLs(resolver); |
| 3782 |
| 3783 base::RunLoop().RunUntilIdle(); |
| 3784 EXPECT_FALSE(callback.have_result()); |
| 3785 service.CancelPacRequest(request); |
| 3786 } |
| 3787 |
3688 } // namespace net | 3788 } // namespace net |
OLD | NEW |