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

Side by Side Diff: net/proxy/proxy_service_mojo_unittest.cc

Issue 1076083002: Shut down proxy resolver utility processes when no longer needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-service-with-factory-restart
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_mojo.h" 5 #include "net/proxy/proxy_service_mojo.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback_helpers.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "net/base/load_flags.h" 11 #include "net/base/load_flags.h"
11 #include "net/base/test_completion_callback.h" 12 #include "net/base/test_completion_callback.h"
12 #include "net/dns/mock_host_resolver.h" 13 #include "net/dns/mock_host_resolver.h"
13 #include "net/log/net_log.h" 14 #include "net/log/net_log.h"
14 #include "net/proxy/dhcp_proxy_script_fetcher.h" 15 #include "net/proxy/dhcp_proxy_script_fetcher.h"
16 #include "net/proxy/in_process_mojo_proxy_resolver_factory.h"
15 #include "net/proxy/mock_proxy_script_fetcher.h" 17 #include "net/proxy/mock_proxy_script_fetcher.h"
18 #include "net/proxy/mojo_proxy_resolver_factory.h"
16 #include "net/proxy/proxy_config_service_fixed.h" 19 #include "net/proxy/proxy_config_service_fixed.h"
17 #include "net/proxy/proxy_service.h" 20 #include "net/proxy/proxy_service.h"
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 22 #include "url/gurl.h"
20 23
21 namespace net { 24 namespace net {
22 25
23 namespace { 26 namespace {
24 27
25 const char kPacUrl[] = "http://example.com/proxy.pac"; 28 const char kPacUrl[] = "http://example.com/proxy.pac";
26 const char kSimplePacScript[] = 29 const char kSimplePacScript[] =
27 "function FindProxyForURL(url, host) {\n" 30 "function FindProxyForURL(url, host) {\n"
28 " return 'PROXY foo:1234';\n" 31 " return 'PROXY foo:1234';\n"
29 "}"; 32 "}";
30 const char kDnsResolvePacScript[] = 33 const char kDnsResolvePacScript[] =
31 "function FindProxyForURL(url, host) {\n" 34 "function FindProxyForURL(url, host) {\n"
32 " if (dnsResolveEx('example.com') != '1.2.3.4')\n" 35 " if (dnsResolveEx('example.com') != '1.2.3.4')\n"
33 " return 'DIRECT';\n" 36 " return 'DIRECT';\n"
34 " return 'QUIC bar:4321';\n" 37 " return 'QUIC bar:4321';\n"
35 "}"; 38 "}";
36 39
40 class TestMojoProxyResolverFactory : public MojoProxyResolverFactory {
41 public:
42 explicit TestMojoProxyResolverFactory(MojoProxyResolverFactory* factory)
43 : factory_(factory) {}
44
45 scoped_ptr<base::ScopedClosureRunner> Create(
46 mojo::InterfaceRequest<interfaces::ProxyResolver> req,
47 interfaces::HostResolverPtr host_resolver) override {
48 factory_->Create(req.Pass(), host_resolver.Pass());
49 return make_scoped_ptr(new base::ScopedClosureRunner(closure_.closure()));
50 }
51
52 TestClosure& closure() { return closure_; }
53
54 private:
55 MojoProxyResolverFactory* factory_;
56 TestClosure closure_;
57 };
58
37 } // namespace 59 } // namespace
38 60
39 class ProxyServiceMojoTest : public testing::Test { 61 class ProxyServiceMojoTest : public testing::Test {
40 protected: 62 protected:
41 void SetUp() override { 63 void SetUp() override {
42 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4"); 64 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4");
43 65
44 fetcher_ = new MockProxyScriptFetcher; 66 fetcher_ = new MockProxyScriptFetcher;
45 proxy_service_.reset(CreateProxyServiceUsingMojoInProcess( 67 factory_.reset(new TestMojoProxyResolverFactory(
46 new ProxyConfigServiceFixed( 68 InProcessMojoProxyResolverFactory::GetInstance()));
47 ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))), 69 proxy_service_.reset(CreateProxyServiceUsingMojoFactory(
70 factory_.get(), new ProxyConfigServiceFixed(
71 ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))),
48 fetcher_, new DoNothingDhcpProxyScriptFetcher(), &mock_host_resolver_, 72 fetcher_, new DoNothingDhcpProxyScriptFetcher(), &mock_host_resolver_,
49 nullptr /* NetLog* */, nullptr /* NetworkDelegate* */)); 73 nullptr /* NetLog* */, nullptr /* NetworkDelegate* */));
50 } 74 }
51 75
52 MockHostResolver mock_host_resolver_; 76 MockHostResolver mock_host_resolver_;
53 MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|. 77 MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|.
78 scoped_ptr<TestMojoProxyResolverFactory> factory_;
54 scoped_ptr<ProxyService> proxy_service_; 79 scoped_ptr<ProxyService> proxy_service_;
55 }; 80 };
56 81
57 TEST_F(ProxyServiceMojoTest, Basic) { 82 TEST_F(ProxyServiceMojoTest, Basic) {
58 ProxyInfo info; 83 ProxyInfo info;
59 TestCompletionCallback callback; 84 TestCompletionCallback callback;
60 EXPECT_EQ(ERR_IO_PENDING, 85 EXPECT_EQ(ERR_IO_PENDING,
61 proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info, 86 proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info,
62 callback.callback(), nullptr, nullptr, 87 callback.callback(), nullptr, nullptr,
63 BoundNetLog())); 88 BoundNetLog()));
64 89
65 // Proxy script fetcher should have a fetch triggered by the first 90 // Proxy script fetcher should have a fetch triggered by the first
66 // |ResolveProxy()| request. 91 // |ResolveProxy()| request.
67 EXPECT_TRUE(fetcher_->has_pending_request()); 92 EXPECT_TRUE(fetcher_->has_pending_request());
68 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); 93 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
69 fetcher_->NotifyFetchCompletion(OK, kSimplePacScript); 94 fetcher_->NotifyFetchCompletion(OK, kSimplePacScript);
70 95
71 EXPECT_EQ(OK, callback.WaitForResult()); 96 EXPECT_EQ(OK, callback.WaitForResult());
72 EXPECT_EQ("PROXY foo:1234", info.ToPacString()); 97 EXPECT_EQ("PROXY foo:1234", info.ToPacString());
73 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); 98 EXPECT_EQ(0u, mock_host_resolver_.num_resolve());
99 proxy_service_.reset();
100 factory_->closure().WaitForResult();
74 } 101 }
75 102
76 TEST_F(ProxyServiceMojoTest, DnsResolution) { 103 TEST_F(ProxyServiceMojoTest, DnsResolution) {
77 ProxyInfo info; 104 ProxyInfo info;
78 TestCompletionCallback callback; 105 TestCompletionCallback callback;
79 EXPECT_EQ(ERR_IO_PENDING, 106 EXPECT_EQ(ERR_IO_PENDING,
80 proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info, 107 proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info,
81 callback.callback(), nullptr, nullptr, 108 callback.callback(), nullptr, nullptr,
82 BoundNetLog())); 109 BoundNetLog()));
83 110
84 // Proxy script fetcher should have a fetch triggered by the first 111 // Proxy script fetcher should have a fetch triggered by the first
85 // |ResolveProxy()| request. 112 // |ResolveProxy()| request.
86 EXPECT_TRUE(fetcher_->has_pending_request()); 113 EXPECT_TRUE(fetcher_->has_pending_request());
87 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); 114 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
88 fetcher_->NotifyFetchCompletion(OK, kDnsResolvePacScript); 115 fetcher_->NotifyFetchCompletion(OK, kDnsResolvePacScript);
89 116
90 EXPECT_EQ(OK, callback.WaitForResult()); 117 EXPECT_EQ(OK, callback.WaitForResult());
91 EXPECT_EQ("QUIC bar:4321", info.ToPacString()); 118 EXPECT_EQ("QUIC bar:4321", info.ToPacString());
92 EXPECT_EQ(1u, mock_host_resolver_.num_resolve()); 119 EXPECT_EQ(1u, mock_host_resolver_.num_resolve());
120 proxy_service_.reset();
121 factory_->closure().WaitForResult();
93 } 122 }
94 123
95 } // namespace net 124 } // namespace net
OLDNEW
« net/proxy/proxy_resolver_mojo.h ('K') | « net/proxy/proxy_service_mojo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698