OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_resolver_v8_tracing.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing_wrapper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
(...skipping 10 matching lines...) Expand all Loading... |
26 #include "net/log/test_net_log_util.h" | 26 #include "net/log/test_net_log_util.h" |
27 #include "net/proxy/proxy_info.h" | 27 #include "net/proxy/proxy_info.h" |
28 #include "net/proxy/proxy_resolver_error_observer.h" | 28 #include "net/proxy/proxy_resolver_error_observer.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 namespace net { | 32 namespace net { |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 class ProxyResolverV8TracingTest : public testing::Test { | 36 class ProxyResolverV8TracingWrapperTest : public testing::Test { |
37 public: | 37 public: |
38 void TearDown() override { | 38 void TearDown() override { |
39 // Drain any pending messages, which may be left over from cancellation. | 39 // Drain any pending messages, which may be left over from cancellation. |
40 // This way they get reliably run as part of the current test, rather than | 40 // This way they get reliably run as part of the current test, rather than |
41 // spilling into the next test's execution. | 41 // spilling into the next test's execution. |
42 base::MessageLoop::current()->RunUntilIdle(); | 42 base::MessageLoop::current()->RunUntilIdle(); |
43 } | 43 } |
44 }; | 44 }; |
45 | 45 |
46 scoped_refptr<ProxyResolverScriptData> LoadScriptData(const char* filename) { | 46 scoped_refptr<ProxyResolverScriptData> LoadScriptData(const char* filename) { |
(...skipping 19 matching lines...) Expand all Loading... |
66 scoped_ptr<ProxyResolverErrorObserver> error_observer) { | 66 scoped_ptr<ProxyResolverErrorObserver> error_observer) { |
67 return error_observer; | 67 return error_observer; |
68 } | 68 } |
69 | 69 |
70 scoped_ptr<ProxyResolver> CreateResolver( | 70 scoped_ptr<ProxyResolver> CreateResolver( |
71 NetLog* net_log, | 71 NetLog* net_log, |
72 HostResolver* host_resolver, | 72 HostResolver* host_resolver, |
73 scoped_ptr<ProxyResolverErrorObserver> error_observer, | 73 scoped_ptr<ProxyResolverErrorObserver> error_observer, |
74 const char* filename) { | 74 const char* filename) { |
75 scoped_ptr<ProxyResolver> resolver; | 75 scoped_ptr<ProxyResolver> resolver; |
76 ProxyResolverFactoryV8Tracing factory( | 76 ProxyResolverFactoryV8TracingWrapper factory( |
77 host_resolver, net_log, ProxyResolver::LoadStateChangedCallback(), | 77 host_resolver, net_log, |
78 base::Bind(&ReturnErrorObserver, base::Passed(&error_observer))); | 78 base::Bind(&ReturnErrorObserver, base::Passed(&error_observer))); |
79 TestCompletionCallback callback; | 79 TestCompletionCallback callback; |
80 scoped_ptr<ProxyResolverFactory::Request> request; | 80 scoped_ptr<ProxyResolverFactory::Request> request; |
81 int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver, | 81 int rv = factory.CreateProxyResolver(LoadScriptData(filename), &resolver, |
82 callback.callback(), &request); | 82 callback.callback(), &request); |
83 EXPECT_EQ(ERR_IO_PENDING, rv); | 83 EXPECT_EQ(ERR_IO_PENDING, rv); |
84 EXPECT_EQ(OK, callback.WaitForResult()); | 84 EXPECT_EQ(OK, callback.WaitForResult()); |
85 EXPECT_TRUE(resolver); | 85 EXPECT_TRUE(resolver); |
86 return resolver.Pass(); | 86 return resolver.Pass(); |
87 } | 87 } |
88 | 88 |
89 class MockErrorObserver : public ProxyResolverErrorObserver { | 89 class MockErrorObserver : public ProxyResolverErrorObserver { |
90 public: | 90 public: |
91 MockErrorObserver() : event_(true, false) {} | 91 MockErrorObserver() : event_(true, false) {} |
92 | 92 |
93 void OnPACScriptError(int line_number, const base::string16& error) override { | 93 void OnPACScriptError(int line_number, const base::string16& error) override { |
94 { | 94 { |
95 base::AutoLock l(lock_); | 95 base::AutoLock l(lock_); |
96 output += base::StringPrintf("Error: line %d: %s\n", line_number, | 96 output += base::StringPrintf("Error: line %d: %s\n", line_number, |
97 base::UTF16ToASCII(error).c_str()); | 97 base::UTF16ToASCII(error).c_str()); |
98 } | 98 } |
99 event_.Signal(); | 99 event_.Signal(); |
100 } | 100 } |
101 | 101 |
102 std::string GetOutput() { | 102 std::string GetOutput() { |
103 base::AutoLock l(lock_); | 103 base::AutoLock l(lock_); |
104 return output; | 104 return output; |
105 } | 105 } |
106 | 106 |
107 void WaitForOutput() { | 107 void WaitForOutput() { event_.Wait(); } |
108 event_.Wait(); | |
109 } | |
110 | 108 |
111 private: | 109 private: |
112 base::Lock lock_; | 110 base::Lock lock_; |
113 std::string output; | 111 std::string output; |
114 | 112 |
115 base::WaitableEvent event_; | 113 base::WaitableEvent event_; |
116 }; | 114 }; |
117 | 115 |
118 TEST_F(ProxyResolverV8TracingTest, Simple) { | 116 TEST_F(ProxyResolverV8TracingWrapperTest, Simple) { |
119 TestNetLog log; | 117 TestNetLog log; |
120 BoundTestNetLog request_log; | 118 BoundTestNetLog request_log; |
121 MockCachingHostResolver host_resolver; | 119 MockCachingHostResolver host_resolver; |
122 MockErrorObserver* error_observer = new MockErrorObserver; | 120 MockErrorObserver* error_observer = new MockErrorObserver; |
123 | 121 |
124 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 122 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
125 &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js"); | 123 &log, &host_resolver, make_scoped_ptr(error_observer), "simple.js"); |
126 | 124 |
127 TestCompletionCallback callback; | 125 TestCompletionCallback callback; |
128 ProxyInfo proxy_info; | 126 ProxyInfo proxy_info; |
(...skipping 10 matching lines...) Expand all Loading... |
139 EXPECT_EQ(0u, host_resolver.num_resolve()); | 137 EXPECT_EQ(0u, host_resolver.num_resolve()); |
140 | 138 |
141 // There were no errors. | 139 // There were no errors. |
142 EXPECT_EQ("", error_observer->GetOutput()); | 140 EXPECT_EQ("", error_observer->GetOutput()); |
143 | 141 |
144 // Check the NetLogs -- nothing was logged. | 142 // Check the NetLogs -- nothing was logged. |
145 EXPECT_EQ(0u, log.GetSize()); | 143 EXPECT_EQ(0u, log.GetSize()); |
146 EXPECT_EQ(0u, request_log.GetSize()); | 144 EXPECT_EQ(0u, request_log.GetSize()); |
147 } | 145 } |
148 | 146 |
149 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { | 147 TEST_F(ProxyResolverV8TracingWrapperTest, JavascriptError) { |
150 TestNetLog log; | 148 TestNetLog log; |
151 BoundTestNetLog request_log; | 149 BoundTestNetLog request_log; |
152 MockCachingHostResolver host_resolver; | 150 MockCachingHostResolver host_resolver; |
153 MockErrorObserver* error_observer = new MockErrorObserver; | 151 MockErrorObserver* error_observer = new MockErrorObserver; |
154 | 152 |
155 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 153 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
156 &log, &host_resolver, make_scoped_ptr(error_observer), "error.js"); | 154 &log, &host_resolver, make_scoped_ptr(error_observer), "error.js"); |
157 | 155 |
158 TestCompletionCallback callback; | 156 TestCompletionCallback callback; |
159 ProxyInfo proxy_info; | 157 ProxyInfo proxy_info; |
160 | 158 |
161 int rv = | 159 int rv = |
162 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, | 160 resolver->GetProxyForURL(GURL("http://throw-an-error/"), &proxy_info, |
163 callback.callback(), NULL, request_log.bound()); | 161 callback.callback(), NULL, request_log.bound()); |
164 | 162 |
165 EXPECT_EQ(ERR_IO_PENDING, rv); | 163 EXPECT_EQ(ERR_IO_PENDING, rv); |
166 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 164 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
167 | 165 |
168 EXPECT_EQ(0u, host_resolver.num_resolve()); | 166 EXPECT_EQ(0u, host_resolver.num_resolve()); |
169 | 167 |
170 EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' " | 168 EXPECT_EQ( |
171 "of null\n", error_observer->GetOutput()); | 169 "Error: line 5: Uncaught TypeError: Cannot read property 'split' " |
| 170 "of null\n", |
| 171 error_observer->GetOutput()); |
172 | 172 |
173 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they | 173 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they |
174 // were output to both the global log, and per-request log. | 174 // were output to both the global log, and per-request log. |
175 TestNetLogEntry::List entries_list[2]; | 175 TestNetLogEntry::List entries_list[2]; |
176 log.GetEntries(&entries_list[0]); | 176 log.GetEntries(&entries_list[0]); |
177 request_log.GetEntries(&entries_list[1]); | 177 request_log.GetEntries(&entries_list[1]); |
178 | 178 |
179 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 179 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
180 const TestNetLogEntry::List& entries = entries_list[list_i]; | 180 const TestNetLogEntry::List& entries = entries_list[list_i]; |
181 EXPECT_EQ(2u, entries.size()); | 181 EXPECT_EQ(2u, entries.size()); |
182 EXPECT_TRUE( | 182 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
183 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 183 NetLog::PHASE_NONE)); |
184 NetLog::PHASE_NONE)); | 184 EXPECT_TRUE(LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, |
185 EXPECT_TRUE( | 185 NetLog::PHASE_NONE)); |
186 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, | |
187 NetLog::PHASE_NONE)); | |
188 | 186 |
189 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); | 187 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); |
190 EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " | 188 EXPECT_EQ( |
191 "read property 'split' of null\"}", entries[1].GetParamsJson()); | 189 "{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " |
| 190 "read property 'split' of null\"}", |
| 191 entries[1].GetParamsJson()); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { | 195 TEST_F(ProxyResolverV8TracingWrapperTest, TooManyAlerts) { |
196 TestNetLog log; | 196 TestNetLog log; |
197 BoundTestNetLog request_log; | 197 BoundTestNetLog request_log; |
198 MockCachingHostResolver host_resolver; | 198 MockCachingHostResolver host_resolver; |
199 MockErrorObserver* error_observer = new MockErrorObserver; | 199 MockErrorObserver* error_observer = new MockErrorObserver; |
200 | 200 |
201 scoped_ptr<ProxyResolver> resolver = | 201 scoped_ptr<ProxyResolver> resolver = |
202 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 202 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
203 "too_many_alerts.js"); | 203 "too_many_alerts.js"); |
204 | 204 |
205 TestCompletionCallback callback; | 205 TestCompletionCallback callback; |
(...skipping 19 matching lines...) Expand all Loading... |
225 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 225 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
226 // to both the global and per-request logs. | 226 // to both the global and per-request logs. |
227 TestNetLogEntry::List entries_list[2]; | 227 TestNetLogEntry::List entries_list[2]; |
228 log.GetEntries(&entries_list[0]); | 228 log.GetEntries(&entries_list[0]); |
229 request_log.GetEntries(&entries_list[1]); | 229 request_log.GetEntries(&entries_list[1]); |
230 | 230 |
231 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 231 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
232 const TestNetLogEntry::List& entries = entries_list[list_i]; | 232 const TestNetLogEntry::List& entries = entries_list[list_i]; |
233 EXPECT_EQ(50u, entries.size()); | 233 EXPECT_EQ(50u, entries.size()); |
234 for (size_t i = 0; i < entries.size(); ++i) { | 234 for (size_t i = 0; i < entries.size(); ++i) { |
235 ASSERT_TRUE( | 235 ASSERT_TRUE(LogContainsEvent( |
236 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 236 entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
237 NetLog::PHASE_NONE)); | |
238 } | 237 } |
239 } | 238 } |
240 } | 239 } |
241 | 240 |
242 // Verify that buffered alerts cannot grow unboundedly, even when the message is | 241 // Verify that buffered alerts cannot grow unboundedly, even when the message is |
243 // empty string. | 242 // empty string. |
244 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { | 243 TEST_F(ProxyResolverV8TracingWrapperTest, TooManyEmptyAlerts) { |
245 TestNetLog log; | 244 TestNetLog log; |
246 BoundTestNetLog request_log; | 245 BoundTestNetLog request_log; |
247 MockCachingHostResolver host_resolver; | 246 MockCachingHostResolver host_resolver; |
248 MockErrorObserver* error_observer = new MockErrorObserver; | 247 MockErrorObserver* error_observer = new MockErrorObserver; |
249 | 248 |
250 scoped_ptr<ProxyResolver> resolver = | 249 scoped_ptr<ProxyResolver> resolver = |
251 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 250 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
252 "too_many_empty_alerts.js"); | 251 "too_many_empty_alerts.js"); |
253 | 252 |
254 TestCompletionCallback callback; | 253 TestCompletionCallback callback; |
(...skipping 16 matching lines...) Expand all Loading... |
271 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 270 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
272 // to both the global and per-request logs. | 271 // to both the global and per-request logs. |
273 TestNetLogEntry::List entries_list[2]; | 272 TestNetLogEntry::List entries_list[2]; |
274 log.GetEntries(&entries_list[0]); | 273 log.GetEntries(&entries_list[0]); |
275 request_log.GetEntries(&entries_list[1]); | 274 request_log.GetEntries(&entries_list[1]); |
276 | 275 |
277 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 276 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
278 const TestNetLogEntry::List& entries = entries_list[list_i]; | 277 const TestNetLogEntry::List& entries = entries_list[list_i]; |
279 EXPECT_EQ(1000u, entries.size()); | 278 EXPECT_EQ(1000u, entries.size()); |
280 for (size_t i = 0; i < entries.size(); ++i) { | 279 for (size_t i = 0; i < entries.size(); ++i) { |
281 ASSERT_TRUE( | 280 ASSERT_TRUE(LogContainsEvent( |
282 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 281 entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
283 NetLog::PHASE_NONE)); | |
284 } | 282 } |
285 } | 283 } |
286 } | 284 } |
287 | 285 |
288 // This test runs a PAC script that issues a sequence of DNS resolves. The test | 286 // This test runs a PAC script that issues a sequence of DNS resolves. The test |
289 // verifies the final result, and that the underlying DNS resolver received | 287 // verifies the final result, and that the underlying DNS resolver received |
290 // the correct set of queries. | 288 // the correct set of queries. |
291 TEST_F(ProxyResolverV8TracingTest, Dns) { | 289 TEST_F(ProxyResolverV8TracingWrapperTest, Dns) { |
292 TestNetLog log; | 290 TestNetLog log; |
293 BoundTestNetLog request_log; | 291 BoundTestNetLog request_log; |
294 MockCachingHostResolver host_resolver; | 292 MockCachingHostResolver host_resolver; |
295 MockErrorObserver* error_observer = new MockErrorObserver; | 293 MockErrorObserver* error_observer = new MockErrorObserver; |
296 | 294 |
297 host_resolver.rules()->AddRuleForAddressFamily( | 295 host_resolver.rules()->AddRuleForAddressFamily("host1", ADDRESS_FAMILY_IPV4, |
298 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 296 "166.155.144.44"); |
299 host_resolver.rules() | 297 host_resolver.rules()->AddIPLiteralRule("host1", "::1,192.168.1.1", |
300 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 298 std::string()); |
301 host_resolver.rules()->AddSimulatedFailure("host2"); | 299 host_resolver.rules()->AddSimulatedFailure("host2"); |
302 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 300 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
303 host_resolver.rules()->AddRule("host5", "166.155.144.55"); | 301 host_resolver.rules()->AddRule("host5", "166.155.144.55"); |
304 host_resolver.rules()->AddSimulatedFailure("host6"); | 302 host_resolver.rules()->AddSimulatedFailure("host6"); |
305 host_resolver.rules()->AddRuleForAddressFamily( | 303 host_resolver.rules()->AddRuleForAddressFamily("*", ADDRESS_FAMILY_IPV4, |
306 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); | 304 "122.133.144.155"); |
307 host_resolver.rules()->AddRule("*", "133.122.100.200"); | 305 host_resolver.rules()->AddRule("*", "133.122.100.200"); |
308 | 306 |
309 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 307 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
310 &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 308 &log, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
311 | 309 |
312 TestCompletionCallback callback; | 310 TestCompletionCallback callback; |
313 ProxyInfo proxy_info; | 311 ProxyInfo proxy_info; |
314 | 312 |
315 int rv = | 313 int rv = |
316 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 314 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
317 callback.callback(), NULL, request_log.bound()); | 315 callback.callback(), NULL, request_log.bound()); |
318 | 316 |
319 EXPECT_EQ(ERR_IO_PENDING, rv); | 317 EXPECT_EQ(ERR_IO_PENDING, rv); |
320 EXPECT_EQ(OK, callback.WaitForResult()); | 318 EXPECT_EQ(OK, callback.WaitForResult()); |
321 | 319 |
322 // The test does 13 DNS resolution, however only 7 of them are unique. | 320 // The test does 13 DNS resolution, however only 7 of them are unique. |
323 EXPECT_EQ(7u, host_resolver.num_resolve()); | 321 EXPECT_EQ(7u, host_resolver.num_resolve()); |
324 | 322 |
325 const char* kExpectedResult = | 323 const char* kExpectedResult = |
326 "122.133.144.155-" // myIpAddress() | 324 "122.133.144.155-" // myIpAddress() |
327 "null-" // dnsResolve('') | 325 "null-" // dnsResolve('') |
328 "__1_192.168.1.1-" // dnsResolveEx('host1') | 326 "__1_192.168.1.1-" // dnsResolveEx('host1') |
329 "null-" // dnsResolve('host2') | 327 "null-" // dnsResolve('host2') |
330 "166.155.144.33-" // dnsResolve('host3') | 328 "166.155.144.33-" // dnsResolve('host3') |
331 "122.133.144.155-" // myIpAddress() | 329 "122.133.144.155-" // myIpAddress() |
332 "166.155.144.33-" // dnsResolve('host3') | 330 "166.155.144.33-" // dnsResolve('host3') |
333 "__1_192.168.1.1-" // dnsResolveEx('host1') | 331 "__1_192.168.1.1-" // dnsResolveEx('host1') |
334 "122.133.144.155-" // myIpAddress() | 332 "122.133.144.155-" // myIpAddress() |
335 "null-" // dnsResolve('host2') | 333 "null-" // dnsResolve('host2') |
336 "-" // dnsResolveEx('host6') | 334 "-" // dnsResolveEx('host6') |
337 "133.122.100.200-" // myIpAddressEx() | 335 "133.122.100.200-" // myIpAddressEx() |
338 "166.155.144.44" // dnsResolve('host1') | 336 "166.155.144.44" // dnsResolve('host1') |
339 ":99"; | 337 ":99"; |
340 | 338 |
341 EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI()); | 339 EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI()); |
342 | 340 |
343 // No errors. | 341 // No errors. |
344 EXPECT_EQ("", error_observer->GetOutput()); | 342 EXPECT_EQ("", error_observer->GetOutput()); |
345 | 343 |
346 // Check the NetLogs -- the script generated 1 alert, mirrored to both | 344 // Check the NetLogs -- the script generated 1 alert, mirrored to both |
347 // the per-request and global logs. | 345 // the per-request and global logs. |
348 TestNetLogEntry::List entries_list[2]; | 346 TestNetLogEntry::List entries_list[2]; |
349 log.GetEntries(&entries_list[0]); | 347 log.GetEntries(&entries_list[0]); |
350 request_log.GetEntries(&entries_list[1]); | 348 request_log.GetEntries(&entries_list[1]); |
351 | 349 |
352 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 350 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
353 const TestNetLogEntry::List& entries = entries_list[list_i]; | 351 const TestNetLogEntry::List& entries = entries_list[list_i]; |
354 EXPECT_EQ(1u, entries.size()); | 352 EXPECT_EQ(1u, entries.size()); |
355 EXPECT_TRUE( | 353 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
356 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 354 NetLog::PHASE_NONE)); |
357 NetLog::PHASE_NONE)); | |
358 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); | 355 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); |
359 } | 356 } |
360 } | 357 } |
361 | 358 |
362 // This test runs a PAC script that does "myIpAddress()" followed by | 359 // This test runs a PAC script that does "myIpAddress()" followed by |
363 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's | 360 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's |
364 // cache is warmed, subsequent calls should take 0 restarts. | 361 // cache is warmed, subsequent calls should take 0 restarts. |
365 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { | 362 TEST_F(ProxyResolverV8TracingWrapperTest, DnsChecksCache) { |
366 TestNetLog log; | 363 TestNetLog log; |
367 BoundTestNetLog request_log; | 364 BoundTestNetLog request_log; |
368 MockCachingHostResolver host_resolver; | 365 MockCachingHostResolver host_resolver; |
369 MockErrorObserver* error_observer = new MockErrorObserver; | 366 MockErrorObserver* error_observer = new MockErrorObserver; |
370 | 367 |
371 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); | 368 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); |
372 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 369 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
373 | 370 |
374 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 371 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
375 &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js"); | 372 &log, &host_resolver, make_scoped_ptr(error_observer), "simple_dns.js"); |
(...skipping 30 matching lines...) Expand all Loading... |
406 // No errors. | 403 // No errors. |
407 EXPECT_EQ("", error_observer->GetOutput()); | 404 EXPECT_EQ("", error_observer->GetOutput()); |
408 | 405 |
409 EXPECT_EQ(0u, log.GetSize()); | 406 EXPECT_EQ(0u, log.GetSize()); |
410 EXPECT_EQ(0u, request_log.GetSize()); | 407 EXPECT_EQ(0u, request_log.GetSize()); |
411 } | 408 } |
412 | 409 |
413 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 410 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
414 // optimization. The proxy resolver should detect the inconsistency and | 411 // optimization. The proxy resolver should detect the inconsistency and |
415 // fall-back to synchronous mode execution. | 412 // fall-back to synchronous mode execution. |
416 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous1) { | 413 TEST_F(ProxyResolverV8TracingWrapperTest, FallBackToSynchronous1) { |
417 TestNetLog log; | 414 TestNetLog log; |
418 BoundTestNetLog request_log; | 415 BoundTestNetLog request_log; |
419 MockCachingHostResolver host_resolver; | 416 MockCachingHostResolver host_resolver; |
420 MockErrorObserver* error_observer = new MockErrorObserver; | 417 MockErrorObserver* error_observer = new MockErrorObserver; |
421 | 418 |
422 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 419 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
423 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); | 420 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); |
424 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 421 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
425 | 422 |
426 scoped_ptr<ProxyResolver> resolver = | 423 scoped_ptr<ProxyResolver> resolver = |
(...skipping 22 matching lines...) Expand all Loading... |
449 | 446 |
450 // Check the NetLogs -- the script generated 1 alert, mirrored to both | 447 // Check the NetLogs -- the script generated 1 alert, mirrored to both |
451 // the per-request and global logs. | 448 // the per-request and global logs. |
452 TestNetLogEntry::List entries_list[2]; | 449 TestNetLogEntry::List entries_list[2]; |
453 log.GetEntries(&entries_list[0]); | 450 log.GetEntries(&entries_list[0]); |
454 request_log.GetEntries(&entries_list[1]); | 451 request_log.GetEntries(&entries_list[1]); |
455 | 452 |
456 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 453 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
457 const TestNetLogEntry::List& entries = entries_list[list_i]; | 454 const TestNetLogEntry::List& entries = entries_list[list_i]; |
458 EXPECT_EQ(1u, entries.size()); | 455 EXPECT_EQ(1u, entries.size()); |
459 EXPECT_TRUE( | 456 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
460 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 457 NetLog::PHASE_NONE)); |
461 NetLog::PHASE_NONE)); | |
462 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); | 458 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); |
463 } | 459 } |
464 } | 460 } |
465 | 461 |
466 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 462 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
467 // optimization. The proxy resolver should detect the inconsistency and | 463 // optimization. The proxy resolver should detect the inconsistency and |
468 // fall-back to synchronous mode execution. | 464 // fall-back to synchronous mode execution. |
469 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { | 465 TEST_F(ProxyResolverV8TracingWrapperTest, FallBackToSynchronous2) { |
470 TestNetLog log; | 466 TestNetLog log; |
471 BoundTestNetLog request_log; | 467 BoundTestNetLog request_log; |
472 MockCachingHostResolver host_resolver; | 468 MockCachingHostResolver host_resolver; |
473 MockErrorObserver* error_observer = new MockErrorObserver; | 469 MockErrorObserver* error_observer = new MockErrorObserver; |
474 | 470 |
475 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 471 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
476 host_resolver.rules()->AddRule("host2", "166.155.144.22"); | 472 host_resolver.rules()->AddRule("host2", "166.155.144.22"); |
477 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 473 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
478 host_resolver.rules()->AddRule("host4", "166.155.144.44"); | 474 host_resolver.rules()->AddRule("host4", "166.155.144.44"); |
479 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 475 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
(...skipping 20 matching lines...) Expand all Loading... |
500 | 496 |
501 // Check the NetLogs -- nothing was logged. | 497 // Check the NetLogs -- nothing was logged. |
502 EXPECT_EQ(0u, log.GetSize()); | 498 EXPECT_EQ(0u, log.GetSize()); |
503 EXPECT_EQ(0u, request_log.GetSize()); | 499 EXPECT_EQ(0u, request_log.GetSize()); |
504 } | 500 } |
505 | 501 |
506 // This test runs a weird PAC script that yields a never ending sequence | 502 // This test runs a weird PAC script that yields a never ending sequence |
507 // of DNS resolves when restarting. Running it will hit the maximum | 503 // of DNS resolves when restarting. Running it will hit the maximum |
508 // DNS resolves per request limit (20) after which every DNS resolve will | 504 // DNS resolves per request limit (20) after which every DNS resolve will |
509 // fail. | 505 // fail. |
510 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence) { | 506 TEST_F(ProxyResolverV8TracingWrapperTest, InfiniteDNSSequence) { |
511 TestNetLog log; | 507 TestNetLog log; |
512 BoundTestNetLog request_log; | 508 BoundTestNetLog request_log; |
513 MockCachingHostResolver host_resolver; | 509 MockCachingHostResolver host_resolver; |
514 MockErrorObserver* error_observer = new MockErrorObserver; | 510 MockErrorObserver* error_observer = new MockErrorObserver; |
515 | 511 |
516 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 512 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
517 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 513 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
518 | 514 |
519 scoped_ptr<ProxyResolver> resolver = | 515 scoped_ptr<ProxyResolver> resolver = |
520 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 516 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
521 "global_sideffects3.js"); | 517 "global_sideffects3.js"); |
522 | 518 |
523 TestCompletionCallback callback; | 519 TestCompletionCallback callback; |
524 ProxyInfo proxy_info; | 520 ProxyInfo proxy_info; |
525 | 521 |
526 int rv = | 522 int rv = |
527 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 523 resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
528 callback.callback(), NULL, request_log.bound()); | 524 callback.callback(), NULL, request_log.bound()); |
529 EXPECT_EQ(ERR_IO_PENDING, rv); | 525 EXPECT_EQ(ERR_IO_PENDING, rv); |
530 EXPECT_EQ(OK, callback.WaitForResult()); | 526 EXPECT_EQ(OK, callback.WaitForResult()); |
531 | 527 |
532 EXPECT_EQ(20u, host_resolver.num_resolve()); | 528 EXPECT_EQ(20u, host_resolver.num_resolve()); |
533 | 529 |
534 EXPECT_EQ( | 530 EXPECT_EQ( |
535 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 531 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
536 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 532 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
537 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 533 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
538 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 534 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
539 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 535 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
540 "null:21", proxy_info.proxy_server().ToURI()); | 536 "null:21", |
| 537 proxy_info.proxy_server().ToURI()); |
541 | 538 |
542 // No errors. | 539 // No errors. |
543 EXPECT_EQ("", error_observer->GetOutput()); | 540 EXPECT_EQ("", error_observer->GetOutput()); |
544 | 541 |
545 // Check the NetLogs -- 1 alert was logged. | 542 // Check the NetLogs -- 1 alert was logged. |
546 EXPECT_EQ(1u, log.GetSize()); | 543 EXPECT_EQ(1u, log.GetSize()); |
547 EXPECT_EQ(1u, request_log.GetSize()); | 544 EXPECT_EQ(1u, request_log.GetSize()); |
548 } | 545 } |
549 | 546 |
550 // This test runs a weird PAC script that yields a never ending sequence | 547 // This test runs a weird PAC script that yields a never ending sequence |
551 // of DNS resolves when restarting. Running it will hit the maximum | 548 // of DNS resolves when restarting. Running it will hit the maximum |
552 // DNS resolves per request limit (20) after which every DNS resolve will | 549 // DNS resolves per request limit (20) after which every DNS resolve will |
553 // fail. | 550 // fail. |
554 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { | 551 TEST_F(ProxyResolverV8TracingWrapperTest, InfiniteDNSSequence2) { |
555 TestNetLog log; | 552 TestNetLog log; |
556 BoundTestNetLog request_log; | 553 BoundTestNetLog request_log; |
557 MockCachingHostResolver host_resolver; | 554 MockCachingHostResolver host_resolver; |
558 MockErrorObserver* error_observer = new MockErrorObserver; | 555 MockErrorObserver* error_observer = new MockErrorObserver; |
559 | 556 |
560 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 557 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
561 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 558 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
562 | 559 |
563 scoped_ptr<ProxyResolver> resolver = | 560 scoped_ptr<ProxyResolver> resolver = |
564 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), | 561 CreateResolver(&log, &host_resolver, make_scoped_ptr(error_observer), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 620 |
624 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", | 621 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", |
625 proxy_info.proxy_server().ToURI()); | 622 proxy_info.proxy_server().ToURI()); |
626 | 623 |
627 // Check the NetLogs -- the script generated 2 alerts during initialization. | 624 // Check the NetLogs -- the script generated 2 alerts during initialization. |
628 EXPECT_EQ(0u, request_log.GetSize()); | 625 EXPECT_EQ(0u, request_log.GetSize()); |
629 TestNetLogEntry::List entries; | 626 TestNetLogEntry::List entries; |
630 log.GetEntries(&entries); | 627 log.GetEntries(&entries); |
631 | 628 |
632 ASSERT_EQ(2u, entries.size()); | 629 ASSERT_EQ(2u, entries.size()); |
633 EXPECT_TRUE( | 630 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
634 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 631 NetLog::PHASE_NONE)); |
635 NetLog::PHASE_NONE)); | 632 EXPECT_TRUE(LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
636 EXPECT_TRUE( | 633 NetLog::PHASE_NONE)); |
637 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | |
638 NetLog::PHASE_NONE)); | |
639 | 634 |
640 EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson()); | 635 EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson()); |
641 EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson()); | 636 EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson()); |
642 } | 637 } |
643 | 638 |
644 // Tests a PAC script which does DNS resolves during initialization. | 639 // Tests a PAC script which does DNS resolves during initialization. |
645 TEST_F(ProxyResolverV8TracingTest, DnsDuringInit) { | 640 TEST_F(ProxyResolverV8TracingWrapperTest, DnsDuringInit) { |
646 // Test with both both a host resolver that always completes asynchronously, | 641 // Test with both both a host resolver that always completes asynchronously, |
647 // and then again with one that completes synchronously. | 642 // and then again with one that completes synchronously. |
648 DnsDuringInitHelper(false); | 643 DnsDuringInitHelper(false); |
649 DnsDuringInitHelper(true); | 644 DnsDuringInitHelper(true); |
650 } | 645 } |
651 | 646 |
652 void CrashCallback(int) { | 647 void CrashCallback(int) { |
653 // Be extra sure that if the callback ever gets invoked, the test will fail. | 648 // Be extra sure that if the callback ever gets invoked, the test will fail. |
654 CHECK(false); | 649 CHECK(false); |
655 } | 650 } |
656 | 651 |
657 // Start some requests, cancel them all, and then destroy the resolver. | 652 // Start some requests, cancel them all, and then destroy the resolver. |
658 // Note the execution order for this test can vary. Since multiple | 653 // Note the execution order for this test can vary. Since multiple |
659 // threads are involved, the cancellation may be received a different | 654 // threads are involved, the cancellation may be received a different |
660 // times. | 655 // times. |
661 TEST_F(ProxyResolverV8TracingTest, CancelAll) { | 656 TEST_F(ProxyResolverV8TracingWrapperTest, CancelAll) { |
662 MockCachingHostResolver host_resolver; | 657 MockCachingHostResolver host_resolver; |
663 MockErrorObserver* error_observer = new MockErrorObserver; | 658 MockErrorObserver* error_observer = new MockErrorObserver; |
664 | 659 |
665 host_resolver.rules()->AddSimulatedFailure("*"); | 660 host_resolver.rules()->AddSimulatedFailure("*"); |
666 | 661 |
667 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 662 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
668 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 663 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
669 | 664 |
670 const size_t kNumRequests = 5; | 665 const size_t kNumRequests = 5; |
671 ProxyInfo proxy_info[kNumRequests]; | 666 ProxyInfo proxy_info[kNumRequests]; |
672 ProxyResolver::RequestHandle request[kNumRequests]; | 667 ProxyResolver::RequestHandle request[kNumRequests]; |
673 | 668 |
674 for (size_t i = 0; i < kNumRequests; ++i) { | 669 for (size_t i = 0; i < kNumRequests; ++i) { |
675 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], | 670 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info[i], |
676 base::Bind(&CrashCallback), &request[i], | 671 base::Bind(&CrashCallback), &request[i], |
677 BoundNetLog()); | 672 BoundNetLog()); |
678 EXPECT_EQ(ERR_IO_PENDING, rv); | 673 EXPECT_EQ(ERR_IO_PENDING, rv); |
679 } | 674 } |
680 | 675 |
681 for (size_t i = 0; i < kNumRequests; ++i) { | 676 for (size_t i = 0; i < kNumRequests; ++i) { |
682 resolver->CancelRequest(request[i]); | 677 resolver->CancelRequest(request[i]); |
683 } | 678 } |
684 } | 679 } |
685 | 680 |
686 // Note the execution order for this test can vary. Since multiple | 681 // Note the execution order for this test can vary. Since multiple |
687 // threads are involved, the cancellation may be received a different | 682 // threads are involved, the cancellation may be received a different |
688 // times. | 683 // times. |
689 TEST_F(ProxyResolverV8TracingTest, CancelSome) { | 684 TEST_F(ProxyResolverV8TracingWrapperTest, CancelSome) { |
690 MockCachingHostResolver host_resolver; | 685 MockCachingHostResolver host_resolver; |
691 MockErrorObserver* error_observer = new MockErrorObserver; | 686 MockErrorObserver* error_observer = new MockErrorObserver; |
692 | 687 |
693 host_resolver.rules()->AddSimulatedFailure("*"); | 688 host_resolver.rules()->AddSimulatedFailure("*"); |
694 | 689 |
695 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 690 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
696 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 691 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
697 | 692 |
698 ProxyInfo proxy_info1; | 693 ProxyInfo proxy_info1; |
699 ProxyInfo proxy_info2; | 694 ProxyInfo proxy_info2; |
(...skipping 10 matching lines...) Expand all Loading... |
710 callback.callback(), &request2, BoundNetLog()); | 705 callback.callback(), &request2, BoundNetLog()); |
711 EXPECT_EQ(ERR_IO_PENDING, rv); | 706 EXPECT_EQ(ERR_IO_PENDING, rv); |
712 | 707 |
713 resolver->CancelRequest(request1); | 708 resolver->CancelRequest(request1); |
714 | 709 |
715 EXPECT_EQ(OK, callback.WaitForResult()); | 710 EXPECT_EQ(OK, callback.WaitForResult()); |
716 } | 711 } |
717 | 712 |
718 // Cancel a request after it has finished running on the worker thread, and has | 713 // Cancel a request after it has finished running on the worker thread, and has |
719 // posted a task the completion task back to origin thread. | 714 // posted a task the completion task back to origin thread. |
720 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { | 715 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhilePendingCompletionTask) { |
721 MockCachingHostResolver host_resolver; | 716 MockCachingHostResolver host_resolver; |
722 MockErrorObserver* error_observer = new MockErrorObserver; | 717 MockErrorObserver* error_observer = new MockErrorObserver; |
723 | 718 |
724 host_resolver.rules()->AddSimulatedFailure("*"); | 719 host_resolver.rules()->AddSimulatedFailure("*"); |
725 | 720 |
726 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 721 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
727 nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js"); | 722 nullptr, &host_resolver, make_scoped_ptr(error_observer), "error.js"); |
728 | 723 |
729 ProxyInfo proxy_info1; | 724 ProxyInfo proxy_info1; |
730 ProxyInfo proxy_info2; | 725 ProxyInfo proxy_info2; |
(...skipping 23 matching lines...) Expand all Loading... |
754 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 749 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
755 | 750 |
756 // Start another request, to make sure it is able to complete. | 751 // Start another request, to make sure it is able to complete. |
757 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), | 752 rv = resolver->GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), |
758 &proxy_info3, callback.callback(), &request3, | 753 &proxy_info3, callback.callback(), &request3, |
759 BoundNetLog()); | 754 BoundNetLog()); |
760 EXPECT_EQ(ERR_IO_PENDING, rv); | 755 EXPECT_EQ(ERR_IO_PENDING, rv); |
761 | 756 |
762 EXPECT_EQ(OK, callback.WaitForResult()); | 757 EXPECT_EQ(OK, callback.WaitForResult()); |
763 | 758 |
764 EXPECT_EQ("i-approve-this-message:42", | 759 EXPECT_EQ("i-approve-this-message:42", proxy_info3.proxy_server().ToURI()); |
765 proxy_info3.proxy_server().ToURI()); | |
766 } | 760 } |
767 | 761 |
768 // This implementation of HostResolver allows blocking until a resolve request | 762 // This implementation of HostResolver allows blocking until a resolve request |
769 // has been received. The resolve requests it receives will never be completed. | 763 // has been received. The resolve requests it receives will never be completed. |
770 class BlockableHostResolver : public HostResolver { | 764 class BlockableHostResolver : public HostResolver { |
771 public: | 765 public: |
772 BlockableHostResolver() | 766 BlockableHostResolver() |
773 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} | 767 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} |
774 | 768 |
775 int Resolve(const RequestInfo& info, | 769 int Resolve(const RequestInfo& info, |
(...skipping 27 matching lines...) Expand all Loading... |
803 const BoundNetLog& net_log) override { | 797 const BoundNetLog& net_log) override { |
804 NOTREACHED(); | 798 NOTREACHED(); |
805 return ERR_DNS_CACHE_MISS; | 799 return ERR_DNS_CACHE_MISS; |
806 } | 800 } |
807 | 801 |
808 void CancelRequest(RequestHandle req) override { | 802 void CancelRequest(RequestHandle req) override { |
809 EXPECT_EQ(reinterpret_cast<RequestHandle*>(1), req); | 803 EXPECT_EQ(reinterpret_cast<RequestHandle*>(1), req); |
810 num_cancelled_requests_++; | 804 num_cancelled_requests_++; |
811 } | 805 } |
812 | 806 |
813 void SetAction(const base::Callback<void(void)>& action) { | 807 void SetAction(const base::Callback<void(void)>& action) { action_ = action; } |
814 action_ = action; | |
815 } | |
816 | 808 |
817 // Waits until Resolve() has been called. | 809 // Waits until Resolve() has been called. |
818 void WaitUntilRequestIsReceived() { | 810 void WaitUntilRequestIsReceived() { |
819 waiting_for_resolve_ = true; | 811 waiting_for_resolve_ = true; |
820 base::MessageLoop::current()->Run(); | 812 base::MessageLoop::current()->Run(); |
821 DCHECK(waiting_for_resolve_); | 813 DCHECK(waiting_for_resolve_); |
822 waiting_for_resolve_ = false; | 814 waiting_for_resolve_ = false; |
823 } | 815 } |
824 | 816 |
825 int num_cancelled_requests() const { | 817 int num_cancelled_requests() const { return num_cancelled_requests_; } |
826 return num_cancelled_requests_; | |
827 } | |
828 | 818 |
829 private: | 819 private: |
830 int num_cancelled_requests_; | 820 int num_cancelled_requests_; |
831 bool waiting_for_resolve_; | 821 bool waiting_for_resolve_; |
832 base::Callback<void(void)> action_; | 822 base::Callback<void(void)> action_; |
833 }; | 823 }; |
834 | 824 |
835 // This cancellation test exercises a more predictable cancellation codepath -- | 825 // This cancellation test exercises a more predictable cancellation codepath -- |
836 // when the request has an outstanding DNS request in flight. | 826 // when the request has an outstanding DNS request in flight. |
837 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { | 827 TEST_F(ProxyResolverV8TracingWrapperTest, |
| 828 CancelWhileOutstandingNonBlockingDns) { |
838 BlockableHostResolver host_resolver; | 829 BlockableHostResolver host_resolver; |
839 MockErrorObserver* error_observer = new MockErrorObserver; | 830 MockErrorObserver* error_observer = new MockErrorObserver; |
840 | 831 |
841 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 832 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
842 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 833 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
843 | 834 |
844 ProxyInfo proxy_info1; | 835 ProxyInfo proxy_info1; |
845 ProxyInfo proxy_info2; | 836 ProxyInfo proxy_info2; |
846 ProxyResolver::RequestHandle request1; | 837 ProxyResolver::RequestHandle request1; |
847 ProxyResolver::RequestHandle request2; | 838 ProxyResolver::RequestHandle request2; |
(...skipping 30 matching lines...) Expand all Loading... |
878 | 869 |
879 // Sleep for a little bit. This makes it more likely for the worker | 870 // Sleep for a little bit. This makes it more likely for the worker |
880 // thread to have returned from its call, and serves as a regression | 871 // thread to have returned from its call, and serves as a regression |
881 // test for http://crbug.com/173373. | 872 // test for http://crbug.com/173373. |
882 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); | 873 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(30)); |
883 } | 874 } |
884 | 875 |
885 // In non-blocking mode, the worker thread actually does block for | 876 // In non-blocking mode, the worker thread actually does block for |
886 // a short time to see if the result is in the DNS cache. Test | 877 // a short time to see if the result is in the DNS cache. Test |
887 // cancellation while the worker thread is waiting on this event. | 878 // cancellation while the worker thread is waiting on this event. |
888 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { | 879 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns) { |
889 BlockableHostResolver host_resolver; | 880 BlockableHostResolver host_resolver; |
890 MockErrorObserver* error_observer = new MockErrorObserver; | 881 MockErrorObserver* error_observer = new MockErrorObserver; |
891 | 882 |
892 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 883 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
893 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 884 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
894 | 885 |
895 ProxyInfo proxy_info; | 886 ProxyInfo proxy_info; |
896 ProxyResolver::RequestHandle request; | 887 ProxyResolver::RequestHandle request; |
897 | 888 |
898 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 889 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
899 base::Bind(&CrashCallback), &request, | 890 base::Bind(&CrashCallback), &request, |
900 BoundNetLog()); | 891 BoundNetLog()); |
901 | 892 |
902 EXPECT_EQ(ERR_IO_PENDING, rv); | 893 EXPECT_EQ(ERR_IO_PENDING, rv); |
903 | 894 |
904 host_resolver.SetAction( | 895 host_resolver.SetAction( |
905 base::Bind(CancelRequestAndPause, resolver.get(), request)); | 896 base::Bind(CancelRequestAndPause, resolver.get(), request)); |
906 | 897 |
907 host_resolver.WaitUntilRequestIsReceived(); | 898 host_resolver.WaitUntilRequestIsReceived(); |
908 | 899 |
909 // At this point the host resolver ran Resolve(), and should have cancelled | 900 // At this point the host resolver ran Resolve(), and should have cancelled |
910 // the request. | 901 // the request. |
911 | 902 |
912 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 903 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
913 } | 904 } |
914 | 905 |
915 // Cancel the request while there is a pending DNS request, however before | 906 // Cancel the request while there is a pending DNS request, however before |
916 // the request is sent to the host resolver. | 907 // the request is sent to the host resolver. |
917 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { | 908 TEST_F(ProxyResolverV8TracingWrapperTest, CancelWhileBlockedInNonBlockingDns2) { |
918 MockCachingHostResolver host_resolver; | 909 MockCachingHostResolver host_resolver; |
919 MockErrorObserver* error_observer = new MockErrorObserver; | 910 MockErrorObserver* error_observer = new MockErrorObserver; |
920 | 911 |
921 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 912 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
922 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); | 913 nullptr, &host_resolver, make_scoped_ptr(error_observer), "dns.js"); |
923 | 914 |
924 ProxyInfo proxy_info; | 915 ProxyInfo proxy_info; |
925 ProxyResolver::RequestHandle request; | 916 ProxyResolver::RequestHandle request; |
926 | 917 |
927 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, | 918 int rv = resolver->GetProxyForURL(GURL("http://foo/"), &proxy_info, |
928 base::Bind(&CrashCallback), &request, | 919 base::Bind(&CrashCallback), &request, |
929 BoundNetLog()); | 920 BoundNetLog()); |
930 | 921 |
931 EXPECT_EQ(ERR_IO_PENDING, rv); | 922 EXPECT_EQ(ERR_IO_PENDING, rv); |
932 | 923 |
933 // Wait a bit, so the DNS task has hopefully been posted. The test will | 924 // Wait a bit, so the DNS task has hopefully been posted. The test will |
934 // work whatever the delay is here, but it is most useful if the delay | 925 // work whatever the delay is here, but it is most useful if the delay |
935 // is large enough to allow a task to be posted back. | 926 // is large enough to allow a task to be posted back. |
936 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 927 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
937 resolver->CancelRequest(request); | 928 resolver->CancelRequest(request); |
938 | 929 |
939 EXPECT_EQ(0u, host_resolver.num_resolve()); | 930 EXPECT_EQ(0u, host_resolver.num_resolve()); |
940 } | 931 } |
941 | 932 |
942 TEST_F(ProxyResolverV8TracingTest, | 933 TEST_F(ProxyResolverV8TracingWrapperTest, |
943 CancelCreateResolverWhileOutstandingBlockingDns) { | 934 CancelCreateResolverWhileOutstandingBlockingDns) { |
944 BlockableHostResolver host_resolver; | 935 BlockableHostResolver host_resolver; |
945 MockErrorObserver* error_observer = new MockErrorObserver; | 936 MockErrorObserver* error_observer = new MockErrorObserver; |
946 | 937 |
947 ProxyResolverFactoryV8Tracing factory( | 938 ProxyResolverFactoryV8TracingWrapper factory( |
948 &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(), | 939 &host_resolver, nullptr, |
949 base::Bind(&ReturnErrorObserver, | 940 base::Bind(&ReturnErrorObserver, |
950 base::Passed(make_scoped_ptr(error_observer)))); | 941 base::Passed(make_scoped_ptr(error_observer)))); |
951 | 942 |
952 scoped_ptr<ProxyResolver> resolver; | 943 scoped_ptr<ProxyResolver> resolver; |
953 scoped_ptr<ProxyResolverFactory::Request> request; | 944 scoped_ptr<ProxyResolverFactory::Request> request; |
954 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), | 945 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), |
955 &resolver, base::Bind(&CrashCallback), | 946 &resolver, base::Bind(&CrashCallback), |
956 &request); | 947 &request); |
957 EXPECT_EQ(ERR_IO_PENDING, rv); | 948 EXPECT_EQ(ERR_IO_PENDING, rv); |
958 | 949 |
959 host_resolver.WaitUntilRequestIsReceived(); | 950 host_resolver.WaitUntilRequestIsReceived(); |
960 | 951 |
961 request.reset(); | 952 request.reset(); |
962 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 953 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
963 } | 954 } |
964 | 955 |
965 TEST_F(ProxyResolverV8TracingTest, DeleteFactoryWhileOutstandingBlockingDns) { | 956 TEST_F(ProxyResolverV8TracingWrapperTest, |
| 957 DeleteFactoryWhileOutstandingBlockingDns) { |
966 BlockableHostResolver host_resolver; | 958 BlockableHostResolver host_resolver; |
967 MockErrorObserver* error_observer = new MockErrorObserver; | 959 MockErrorObserver* error_observer = new MockErrorObserver; |
968 | 960 |
969 scoped_ptr<ProxyResolver> resolver; | 961 scoped_ptr<ProxyResolver> resolver; |
970 scoped_ptr<ProxyResolverFactory::Request> request; | 962 scoped_ptr<ProxyResolverFactory::Request> request; |
971 { | 963 { |
972 ProxyResolverFactoryV8Tracing factory( | 964 ProxyResolverFactoryV8TracingWrapper factory( |
973 &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(), | 965 &host_resolver, nullptr, |
974 base::Bind(&ReturnErrorObserver, | 966 base::Bind(&ReturnErrorObserver, |
975 base::Passed(make_scoped_ptr(error_observer)))); | 967 base::Passed(make_scoped_ptr(error_observer)))); |
976 | 968 |
977 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), | 969 int rv = factory.CreateProxyResolver(LoadScriptData("dns_during_init.js"), |
978 &resolver, base::Bind(&CrashCallback), | 970 &resolver, base::Bind(&CrashCallback), |
979 &request); | 971 &request); |
980 EXPECT_EQ(ERR_IO_PENDING, rv); | 972 EXPECT_EQ(ERR_IO_PENDING, rv); |
981 host_resolver.WaitUntilRequestIsReceived(); | 973 host_resolver.WaitUntilRequestIsReceived(); |
982 } | 974 } |
983 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 975 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
984 } | 976 } |
985 | 977 |
986 TEST_F(ProxyResolverV8TracingTest, ErrorLoadingScript) { | 978 TEST_F(ProxyResolverV8TracingWrapperTest, ErrorLoadingScript) { |
987 BlockableHostResolver host_resolver; | 979 BlockableHostResolver host_resolver; |
988 MockErrorObserver* error_observer = new MockErrorObserver; | 980 MockErrorObserver* error_observer = new MockErrorObserver; |
989 | 981 |
990 ProxyResolverFactoryV8Tracing factory( | 982 ProxyResolverFactoryV8TracingWrapper factory( |
991 &host_resolver, nullptr, ProxyResolver::LoadStateChangedCallback(), | 983 &host_resolver, nullptr, |
992 base::Bind(&ReturnErrorObserver, | 984 base::Bind(&ReturnErrorObserver, |
993 base::Passed(make_scoped_ptr(error_observer)))); | 985 base::Passed(make_scoped_ptr(error_observer)))); |
994 | 986 |
995 scoped_ptr<ProxyResolver> resolver; | 987 scoped_ptr<ProxyResolver> resolver; |
996 scoped_ptr<ProxyResolverFactory::Request> request; | 988 scoped_ptr<ProxyResolverFactory::Request> request; |
997 TestCompletionCallback callback; | 989 TestCompletionCallback callback; |
998 int rv = | 990 int rv = |
999 factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver, | 991 factory.CreateProxyResolver(LoadScriptData("error_on_load.js"), &resolver, |
1000 callback.callback(), &request); | 992 callback.callback(), &request); |
1001 EXPECT_EQ(ERR_IO_PENDING, rv); | 993 EXPECT_EQ(ERR_IO_PENDING, rv); |
1002 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 994 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
1003 EXPECT_FALSE(resolver); | 995 EXPECT_FALSE(resolver); |
1004 } | 996 } |
1005 | 997 |
1006 // This tests that the execution of a PAC script is terminated when the DNS | 998 // This tests that the execution of a PAC script is terminated when the DNS |
1007 // dependencies are missing. If the test fails, then it will hang. | 999 // dependencies are missing. If the test fails, then it will hang. |
1008 TEST_F(ProxyResolverV8TracingTest, Terminate) { | 1000 TEST_F(ProxyResolverV8TracingWrapperTest, Terminate) { |
1009 TestNetLog log; | 1001 TestNetLog log; |
1010 BoundTestNetLog request_log; | 1002 BoundTestNetLog request_log; |
1011 MockCachingHostResolver host_resolver; | 1003 MockCachingHostResolver host_resolver; |
1012 MockErrorObserver* error_observer = new MockErrorObserver; | 1004 MockErrorObserver* error_observer = new MockErrorObserver; |
1013 | 1005 |
1014 host_resolver.rules()->AddRule("host1", "182.111.0.222"); | 1006 host_resolver.rules()->AddRule("host1", "182.111.0.222"); |
1015 host_resolver.rules()->AddRule("host2", "111.33.44.55"); | 1007 host_resolver.rules()->AddRule("host2", "111.33.44.55"); |
1016 | 1008 |
1017 scoped_ptr<ProxyResolver> resolver = CreateResolver( | 1009 scoped_ptr<ProxyResolver> resolver = CreateResolver( |
1018 &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js"); | 1010 &log, &host_resolver, make_scoped_ptr(error_observer), "terminate.js"); |
(...skipping 13 matching lines...) Expand all Loading... |
1032 | 1024 |
1033 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); | 1025 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); |
1034 | 1026 |
1035 // No errors. | 1027 // No errors. |
1036 EXPECT_EQ("", error_observer->GetOutput()); | 1028 EXPECT_EQ("", error_observer->GetOutput()); |
1037 | 1029 |
1038 EXPECT_EQ(0u, log.GetSize()); | 1030 EXPECT_EQ(0u, log.GetSize()); |
1039 EXPECT_EQ(0u, request_log.GetSize()); | 1031 EXPECT_EQ(0u, request_log.GetSize()); |
1040 } | 1032 } |
1041 | 1033 |
1042 // Tests that multiple instances of ProxyResolverV8Tracing can coexist and run | 1034 // Tests that multiple instances of ProxyResolverV8TracingWrapper can coexist |
1043 // correctly at the same time. This is relevant because at the moment (time | 1035 // and run correctly at the same time. This is relevant because at the moment |
1044 // this test was written) each ProxyResolverV8Tracing creates its own thread to | 1036 // (time this test was written) each ProxyResolverV8TracingWrapper creates its |
1045 // run V8 on, however each thread is operating on the same v8::Isolate. | 1037 // own thread to run V8 on, however each thread is operating on the same |
1046 TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) { | 1038 // v8::Isolate. |
| 1039 TEST_F(ProxyResolverV8TracingWrapperTest, MultipleResolvers) { |
1047 // ------------------------ | 1040 // ------------------------ |
1048 // Setup resolver0 | 1041 // Setup resolver0 |
1049 // ------------------------ | 1042 // ------------------------ |
1050 MockHostResolver host_resolver0; | 1043 MockHostResolver host_resolver0; |
1051 host_resolver0.rules()->AddRuleForAddressFamily( | 1044 host_resolver0.rules()->AddRuleForAddressFamily("host1", ADDRESS_FAMILY_IPV4, |
1052 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 1045 "166.155.144.44"); |
1053 host_resolver0.rules() | 1046 host_resolver0.rules()->AddIPLiteralRule("host1", "::1,192.168.1.1", |
1054 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 1047 std::string()); |
1055 host_resolver0.rules()->AddSimulatedFailure("host2"); | 1048 host_resolver0.rules()->AddSimulatedFailure("host2"); |
1056 host_resolver0.rules()->AddRule("host3", "166.155.144.33"); | 1049 host_resolver0.rules()->AddRule("host3", "166.155.144.33"); |
1057 host_resolver0.rules()->AddRule("host5", "166.155.144.55"); | 1050 host_resolver0.rules()->AddRule("host5", "166.155.144.55"); |
1058 host_resolver0.rules()->AddSimulatedFailure("host6"); | 1051 host_resolver0.rules()->AddSimulatedFailure("host6"); |
1059 host_resolver0.rules()->AddRuleForAddressFamily( | 1052 host_resolver0.rules()->AddRuleForAddressFamily("*", ADDRESS_FAMILY_IPV4, |
1060 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); | 1053 "122.133.144.155"); |
1061 host_resolver0.rules()->AddRule("*", "133.122.100.200"); | 1054 host_resolver0.rules()->AddRule("*", "133.122.100.200"); |
1062 scoped_ptr<ProxyResolver> resolver0 = | 1055 scoped_ptr<ProxyResolver> resolver0 = |
1063 CreateResolver(nullptr, &host_resolver0, | 1056 CreateResolver(nullptr, &host_resolver0, |
1064 make_scoped_ptr(new MockErrorObserver), "dns.js"); | 1057 make_scoped_ptr(new MockErrorObserver), "dns.js"); |
1065 | 1058 |
1066 // ------------------------ | 1059 // ------------------------ |
1067 // Setup resolver1 | 1060 // Setup resolver1 |
1068 // ------------------------ | 1061 // ------------------------ |
1069 scoped_ptr<ProxyResolver> resolver1 = | 1062 scoped_ptr<ProxyResolver> resolver1 = |
1070 CreateResolver(nullptr, &host_resolver0, | 1063 CreateResolver(nullptr, &host_resolver0, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, | 1099 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, |
1107 BoundNetLog()); | 1100 BoundNetLog()); |
1108 EXPECT_EQ(ERR_IO_PENDING, rv); | 1101 EXPECT_EQ(ERR_IO_PENDING, rv); |
1109 } | 1102 } |
1110 | 1103 |
1111 // ------------------------ | 1104 // ------------------------ |
1112 // Verify all of the results. | 1105 // Verify all of the results. |
1113 // ------------------------ | 1106 // ------------------------ |
1114 | 1107 |
1115 const char* kExpectedForDnsJs = | 1108 const char* kExpectedForDnsJs = |
1116 "122.133.144.155-" // myIpAddress() | 1109 "122.133.144.155-" // myIpAddress() |
1117 "null-" // dnsResolve('') | 1110 "null-" // dnsResolve('') |
1118 "__1_192.168.1.1-" // dnsResolveEx('host1') | 1111 "__1_192.168.1.1-" // dnsResolveEx('host1') |
1119 "null-" // dnsResolve('host2') | 1112 "null-" // dnsResolve('host2') |
1120 "166.155.144.33-" // dnsResolve('host3') | 1113 "166.155.144.33-" // dnsResolve('host3') |
1121 "122.133.144.155-" // myIpAddress() | 1114 "122.133.144.155-" // myIpAddress() |
1122 "166.155.144.33-" // dnsResolve('host3') | 1115 "166.155.144.33-" // dnsResolve('host3') |
1123 "__1_192.168.1.1-" // dnsResolveEx('host1') | 1116 "__1_192.168.1.1-" // dnsResolveEx('host1') |
1124 "122.133.144.155-" // myIpAddress() | 1117 "122.133.144.155-" // myIpAddress() |
1125 "null-" // dnsResolve('host2') | 1118 "null-" // dnsResolve('host2') |
1126 "-" // dnsResolveEx('host6') | 1119 "-" // dnsResolveEx('host6') |
1127 "133.122.100.200-" // myIpAddressEx() | 1120 "133.122.100.200-" // myIpAddressEx() |
1128 "166.155.144.44" // dnsResolve('host1') | 1121 "166.155.144.44" // dnsResolve('host1') |
1129 ":99"; | 1122 ":99"; |
1130 | 1123 |
1131 for (size_t i = 0; i < kNumResults; ++i) { | 1124 for (size_t i = 0; i < kNumResults; ++i) { |
1132 size_t resolver_i = i % kNumResolvers; | 1125 size_t resolver_i = i % kNumResolvers; |
1133 EXPECT_EQ(OK, callback[i].WaitForResult()); | 1126 EXPECT_EQ(OK, callback[i].WaitForResult()); |
1134 | 1127 |
1135 std::string proxy_uri = proxy_info[i].proxy_server().ToURI(); | 1128 std::string proxy_uri = proxy_info[i].proxy_server().ToURI(); |
1136 | 1129 |
1137 if (resolver_i == 0 || resolver_i == 1) { | 1130 if (resolver_i == 0 || resolver_i == 1) { |
1138 EXPECT_EQ(kExpectedForDnsJs, proxy_uri); | 1131 EXPECT_EQ(kExpectedForDnsJs, proxy_uri); |
1139 } else if (resolver_i == 2) { | 1132 } else if (resolver_i == 2) { |
1140 EXPECT_EQ("foo:99", proxy_uri); | 1133 EXPECT_EQ("foo:99", proxy_uri); |
1141 } else if (resolver_i == 3) { | 1134 } else if (resolver_i == 3) { |
1142 EXPECT_EQ("166.155.144.33:", | 1135 EXPECT_EQ("166.155.144.33:", |
1143 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1136 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
1144 } else { | 1137 } else { |
1145 NOTREACHED(); | 1138 NOTREACHED(); |
1146 } | 1139 } |
1147 } | 1140 } |
1148 } | 1141 } |
1149 | 1142 |
1150 } // namespace | 1143 } // namespace |
1151 | 1144 |
1152 } // namespace net | 1145 } // namespace net |
OLD | NEW |