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

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

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "net/base/network_delegate_impl.h" 16 #include "net/base/network_delegate_impl.h"
17 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
18 #include "net/dns/mock_host_resolver.h" 18 #include "net/dns/mock_host_resolver.h"
19 #include "net/log/net_log.h" 19 #include "net/log/net_log.h"
20 #include "net/log/net_log_event_type.h"
20 #include "net/log/test_net_log.h" 21 #include "net/log/test_net_log.h"
21 #include "net/log/test_net_log_entry.h" 22 #include "net/log/test_net_log_entry.h"
22 #include "net/proxy/dhcp_proxy_script_fetcher.h" 23 #include "net/proxy/dhcp_proxy_script_fetcher.h"
23 #include "net/proxy/in_process_mojo_proxy_resolver_factory.h" 24 #include "net/proxy/in_process_mojo_proxy_resolver_factory.h"
24 #include "net/proxy/mock_proxy_script_fetcher.h" 25 #include "net/proxy/mock_proxy_script_fetcher.h"
25 #include "net/proxy/mojo_proxy_resolver_factory.h" 26 #include "net/proxy/mojo_proxy_resolver_factory.h"
26 #include "net/proxy/proxy_config_service_fixed.h" 27 #include "net/proxy/proxy_config_service_fixed.h"
27 #include "net/proxy/proxy_service.h" 28 #include "net/proxy/proxy_service.h"
28 #include "net/test/event_waiter.h" 29 #include "net/test/event_waiter.h"
29 #include "net/test/gtest_util.h" 30 #include "net/test/gtest_util.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 EXPECT_TRUE(base::UTF16ToUTF8(error).find("error: http://foo") != 80 EXPECT_TRUE(base::UTF16ToUTF8(error).find("error: http://foo") !=
80 std::string::npos); 81 std::string::npos);
81 } 82 }
82 83
83 void CheckCapturedNetLogEntries(const TestNetLogEntry::List& entries) { 84 void CheckCapturedNetLogEntries(const TestNetLogEntry::List& entries) {
84 ASSERT_GT(entries.size(), 2u); 85 ASSERT_GT(entries.size(), 2u);
85 size_t i = 0; 86 size_t i = 0;
86 // ProxyService records its own NetLog entries, so skip forward until the 87 // ProxyService records its own NetLog entries, so skip forward until the
87 // expected event type. 88 // expected event type.
88 while (i < entries.size() && 89 while (i < entries.size() &&
89 entries[i].type != NetLog::TYPE_PAC_JAVASCRIPT_ALERT) { 90 entries[i].type != NetLogEventType::PAC_JAVASCRIPT_ALERT) {
90 i++; 91 i++;
91 } 92 }
92 ASSERT_LT(i, entries.size()); 93 ASSERT_LT(i, entries.size());
93 std::string message; 94 std::string message;
94 ASSERT_TRUE(entries[i].GetStringValue("message", &message)); 95 ASSERT_TRUE(entries[i].GetStringValue("message", &message));
95 EXPECT_EQ("alert: foo", message); 96 EXPECT_EQ("alert: foo", message);
96 ASSERT_FALSE(entries[i].params->HasKey("line_number")); 97 ASSERT_FALSE(entries[i].params->HasKey("line_number"));
97 98
98 while (i < entries.size() && 99 while (i < entries.size() &&
99 entries[i].type != NetLog::TYPE_PAC_JAVASCRIPT_ERROR) { 100 entries[i].type != NetLogEventType::PAC_JAVASCRIPT_ERROR) {
100 i++; 101 i++;
101 } 102 }
102 message.clear(); 103 message.clear();
103 ASSERT_TRUE(entries[i].GetStringValue("message", &message)); 104 ASSERT_TRUE(entries[i].GetStringValue("message", &message));
104 EXPECT_THAT(message, testing::HasSubstr("error: http://foo")); 105 EXPECT_THAT(message, testing::HasSubstr("error: http://foo"));
105 int line_number = 0; 106 int line_number = 0;
106 ASSERT_TRUE(entries[i].GetIntegerValue("line_number", &line_number)); 107 ASSERT_TRUE(entries[i].GetIntegerValue("line_number", &line_number));
107 EXPECT_EQ(3, line_number); 108 EXPECT_EQ(3, line_number);
108 } 109 }
109 110
110 class LoggingMockHostResolver : public MockHostResolver { 111 class LoggingMockHostResolver : public MockHostResolver {
111 public: 112 public:
112 int Resolve(const RequestInfo& info, 113 int Resolve(const RequestInfo& info,
113 RequestPriority priority, 114 RequestPriority priority,
114 AddressList* addresses, 115 AddressList* addresses,
115 const CompletionCallback& callback, 116 const CompletionCallback& callback,
116 std::unique_ptr<Request>* out_req, 117 std::unique_ptr<Request>* out_req,
117 const BoundNetLog& net_log) override { 118 const BoundNetLog& net_log) override {
118 net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB); 119 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB);
119 return MockHostResolver::Resolve(info, priority, addresses, callback, 120 return MockHostResolver::Resolve(info, priority, addresses, callback,
120 out_req, net_log); 121 out_req, net_log);
121 } 122 }
122 }; 123 };
123 124
124 } // namespace 125 } // namespace
125 126
126 class ProxyServiceMojoTest : public testing::Test, 127 class ProxyServiceMojoTest : public testing::Test,
127 public MojoProxyResolverFactory { 128 public MojoProxyResolverFactory {
128 protected: 129 protected:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 EXPECT_EQ(1u, mock_host_resolver_.num_resolve()); 197 EXPECT_EQ(1u, mock_host_resolver_.num_resolve());
197 proxy_service_.reset(); 198 proxy_service_.reset();
198 on_delete_closure_.WaitForResult(); 199 on_delete_closure_.WaitForResult();
199 200
200 TestNetLogEntry::List entries; 201 TestNetLogEntry::List entries;
201 bound_net_log.GetEntries(&entries); 202 bound_net_log.GetEntries(&entries);
202 // There should be one entry with type TYPE_HOST_RESOLVER_IMPL_JOB. 203 // There should be one entry with type TYPE_HOST_RESOLVER_IMPL_JOB.
203 EXPECT_EQ(1, std::count_if(entries.begin(), entries.end(), 204 EXPECT_EQ(1, std::count_if(entries.begin(), entries.end(),
204 [](const TestNetLogEntry& entry) { 205 [](const TestNetLogEntry& entry) {
205 return entry.type == 206 return entry.type ==
206 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB; 207 NetLogEventType::HOST_RESOLVER_IMPL_JOB;
207 })); 208 }));
208 } 209 }
209 210
210 TEST_F(ProxyServiceMojoTest, Error) { 211 TEST_F(ProxyServiceMojoTest, Error) {
211 ProxyInfo info; 212 ProxyInfo info;
212 TestCompletionCallback callback; 213 TestCompletionCallback callback;
213 BoundTestNetLog bound_net_log; 214 BoundTestNetLog bound_net_log;
214 EXPECT_EQ(ERR_IO_PENDING, 215 EXPECT_EQ(ERR_IO_PENDING,
215 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(), 216 proxy_service_->ResolveProxy(GURL("http://foo"), std::string(),
216 &info, callback.callback(), nullptr, 217 &info, callback.callback(), nullptr,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 EXPECT_THAT(callback.WaitForResult(), IsOk()); 258 EXPECT_THAT(callback.WaitForResult(), IsOk());
258 EXPECT_EQ("DIRECT", info.ToPacString()); 259 EXPECT_EQ("DIRECT", info.ToPacString());
259 EXPECT_EQ(0u, mock_host_resolver_.num_resolve()); 260 EXPECT_EQ(0u, mock_host_resolver_.num_resolve());
260 261
261 TestNetLogEntry::List entries; 262 TestNetLogEntry::List entries;
262 net_log_.GetEntries(&entries); 263 net_log_.GetEntries(&entries);
263 CheckCapturedNetLogEntries(entries); 264 CheckCapturedNetLogEntries(entries);
264 } 265 }
265 266
266 } // namespace net 267 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698