OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/proxy/proxy_service_mojo.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "net/base/load_flags.h" | |
11 #include "net/base/net_log.h" | |
12 #include "net/base/test_completion_callback.h" | |
13 #include "net/dns/mock_host_resolver.h" | |
14 #include "net/proxy/dhcp_proxy_script_fetcher.h" | |
15 #include "net/proxy/mock_proxy_script_fetcher.h" | |
16 #include "net/proxy/proxy_config_service_fixed.h" | |
17 #include "net/proxy/proxy_service.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 #include "url/gurl.h" | |
20 | |
21 namespace net { | |
22 | |
23 namespace { | |
24 | |
25 const char kPacUrl[] = "http://example.com/proxy.pac"; | |
26 const char kSimplePacScript[] = | |
27 "function FindProxyForURL(url, host) {\n" | |
28 " return 'PROXY foo:1234';\n" | |
29 "}"; | |
30 const char kDnsResolvePacScript[] = | |
31 "function FindProxyForURL(url, host) {\n" | |
32 " if (dnsResolveEx('example.com') != '1.2.3.4')\n" | |
33 " return 'DIRECT';\n" | |
34 " return 'QUIC bar:4321';\n" | |
35 "}"; | |
36 | |
37 } // namespace | |
38 | |
39 class ProxyServiceMojoTest : public testing::Test { | |
40 protected: | |
41 void SetUp() override { | |
42 mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4"); | |
43 | |
44 fetcher_ = new MockProxyScriptFetcher; | |
45 proxy_service_.reset(CreateProxyServiceUsingMojoInProcess( | |
46 new ProxyConfigServiceFixed( | |
47 ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))), | |
48 fetcher_, new DoNothingDhcpProxyScriptFetcher(), &mock_host_resolver_, | |
49 nullptr /* NetLog* */, nullptr /* NetworkDelegate* */)); | |
50 } | |
51 | |
52 MockHostResolver mock_host_resolver_; | |
53 MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|. | |
54 scoped_ptr<ProxyService> proxy_service_; | |
55 }; | |
56 | |
57 TEST_F(ProxyServiceMojoTest, Basic) { | |
58 ProxyInfo info; | |
59 TestCompletionCallback callback; | |
60 EXPECT_EQ(ERR_IO_PENDING, | |
61 proxy_service_->ResolveProxy(GURL("http://foo"), net::LOAD_NORMAL, | |
Sam McNally
2015/02/26 06:36:41
LOAD_NORMAL shouldn't need net::
Anand Mistry (off Chromium)
2015/02/27 03:00:58
Done.
| |
62 &info, callback.callback(), nullptr, | |
63 nullptr, BoundNetLog())); | |
64 | |
65 // Proxy script fetcher should have a fetch triggered by the first | |
66 // |ResolveProxy()| request. | |
67 EXPECT_TRUE(fetcher_->has_pending_request()); | |
68 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); | |
69 fetcher_->NotifyFetchCompletion(OK, kSimplePacScript); | |
70 | |
71 EXPECT_EQ(OK, callback.WaitForResult()); | |
72 EXPECT_EQ("PROXY foo:1234", info.ToPacString()); | |
73 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); | |
74 } | |
75 | |
76 TEST_F(ProxyServiceMojoTest, DnsResolution) { | |
77 ProxyInfo info; | |
78 TestCompletionCallback callback; | |
79 EXPECT_EQ(ERR_IO_PENDING, | |
80 proxy_service_->ResolveProxy(GURL("http://foo"), net::LOAD_NORMAL, | |
Sam McNally
2015/02/26 06:36:41
Same here.
Anand Mistry (off Chromium)
2015/02/27 03:00:58
Done.
| |
81 &info, callback.callback(), nullptr, | |
82 nullptr, BoundNetLog())); | |
83 | |
84 // Proxy script fetcher should have a fetch triggered by the first | |
85 // |ResolveProxy()| request. | |
86 EXPECT_TRUE(fetcher_->has_pending_request()); | |
87 EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url()); | |
88 fetcher_->NotifyFetchCompletion(OK, kDnsResolvePacScript); | |
89 | |
90 EXPECT_EQ(OK, callback.WaitForResult()); | |
91 EXPECT_EQ("QUIC bar:4321", info.ToPacString()); | |
92 EXPECT_EQ(1u, mock_host_resolver_.num_resolve()); | |
93 } | |
94 | |
95 } // namespace net | |
OLD | NEW |