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.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 class MockErrorObserver : public ProxyResolverErrorObserver { | 69 class MockErrorObserver : public ProxyResolverErrorObserver { |
70 public: | 70 public: |
71 MockErrorObserver() : event_(true, false) {} | 71 MockErrorObserver() : event_(true, false) {} |
72 | 72 |
73 virtual void OnPACScriptError(int line_number, | 73 virtual void OnPACScriptError(int line_number, |
74 const base::string16& error) OVERRIDE { | 74 const base::string16& error) OVERRIDE { |
75 { | 75 { |
76 base::AutoLock l(lock_); | 76 base::AutoLock l(lock_); |
77 output += base::StringPrintf("Error: line %d: %s\n", line_number, | 77 output += base::StringPrintf("Error: line %d: %s\n", |
| 78 line_number, |
78 base::UTF16ToASCII(error).c_str()); | 79 base::UTF16ToASCII(error).c_str()); |
79 } | 80 } |
80 event_.Signal(); | 81 event_.Signal(); |
81 } | 82 } |
82 | 83 |
83 std::string GetOutput() { | 84 std::string GetOutput() { |
84 base::AutoLock l(lock_); | 85 base::AutoLock l(lock_); |
85 return output; | 86 return output; |
86 } | 87 } |
87 | 88 |
88 void WaitForOutput() { | 89 void WaitForOutput() { event_.Wait(); } |
89 event_.Wait(); | |
90 } | |
91 | 90 |
92 private: | 91 private: |
93 base::Lock lock_; | 92 base::Lock lock_; |
94 std::string output; | 93 std::string output; |
95 | 94 |
96 base::WaitableEvent event_; | 95 base::WaitableEvent event_; |
97 }; | 96 }; |
98 | 97 |
99 TEST_F(ProxyResolverV8TracingTest, Simple) { | 98 TEST_F(ProxyResolverV8TracingTest, Simple) { |
100 CapturingNetLog log; | 99 CapturingNetLog log; |
101 CapturingBoundNetLog request_log; | 100 CapturingBoundNetLog request_log; |
102 MockCachingHostResolver host_resolver; | 101 MockCachingHostResolver host_resolver; |
103 MockErrorObserver* error_observer = new MockErrorObserver; | 102 MockErrorObserver* error_observer = new MockErrorObserver; |
104 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 103 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
105 | 104 |
106 InitResolver(&resolver, "simple.js"); | 105 InitResolver(&resolver, "simple.js"); |
107 | 106 |
108 TestCompletionCallback callback; | 107 TestCompletionCallback callback; |
109 ProxyInfo proxy_info; | 108 ProxyInfo proxy_info; |
110 | 109 |
111 int rv = resolver.GetProxyForURL( | 110 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
112 GURL("http://foo/"), &proxy_info, callback.callback(), | 111 &proxy_info, |
113 NULL, request_log.bound()); | 112 callback.callback(), |
| 113 NULL, |
| 114 request_log.bound()); |
114 | 115 |
115 EXPECT_EQ(ERR_IO_PENDING, rv); | 116 EXPECT_EQ(ERR_IO_PENDING, rv); |
116 EXPECT_EQ(OK, callback.WaitForResult()); | 117 EXPECT_EQ(OK, callback.WaitForResult()); |
117 | 118 |
118 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); | 119 EXPECT_EQ("foo:99", proxy_info.proxy_server().ToURI()); |
119 | 120 |
120 EXPECT_EQ(0u, host_resolver.num_resolve()); | 121 EXPECT_EQ(0u, host_resolver.num_resolve()); |
121 | 122 |
122 // There were no errors. | 123 // There were no errors. |
123 EXPECT_EQ("", error_observer->GetOutput()); | 124 EXPECT_EQ("", error_observer->GetOutput()); |
124 | 125 |
125 // Check the NetLogs -- nothing was logged. | 126 // Check the NetLogs -- nothing was logged. |
126 EXPECT_EQ(0u, log.GetSize()); | 127 EXPECT_EQ(0u, log.GetSize()); |
127 EXPECT_EQ(0u, request_log.GetSize()); | 128 EXPECT_EQ(0u, request_log.GetSize()); |
128 } | 129 } |
129 | 130 |
130 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { | 131 TEST_F(ProxyResolverV8TracingTest, JavascriptError) { |
131 CapturingNetLog log; | 132 CapturingNetLog log; |
132 CapturingBoundNetLog request_log; | 133 CapturingBoundNetLog request_log; |
133 MockCachingHostResolver host_resolver; | 134 MockCachingHostResolver host_resolver; |
134 MockErrorObserver* error_observer = new MockErrorObserver; | 135 MockErrorObserver* error_observer = new MockErrorObserver; |
135 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 136 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
136 | 137 |
137 InitResolver(&resolver, "error.js"); | 138 InitResolver(&resolver, "error.js"); |
138 | 139 |
139 TestCompletionCallback callback; | 140 TestCompletionCallback callback; |
140 ProxyInfo proxy_info; | 141 ProxyInfo proxy_info; |
141 | 142 |
142 int rv = resolver.GetProxyForURL( | 143 int rv = resolver.GetProxyForURL(GURL("http://throw-an-error/"), |
143 GURL("http://throw-an-error/"), &proxy_info, callback.callback(), NULL, | 144 &proxy_info, |
144 request_log.bound()); | 145 callback.callback(), |
| 146 NULL, |
| 147 request_log.bound()); |
145 | 148 |
146 EXPECT_EQ(ERR_IO_PENDING, rv); | 149 EXPECT_EQ(ERR_IO_PENDING, rv); |
147 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 150 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
148 | 151 |
149 EXPECT_EQ(0u, host_resolver.num_resolve()); | 152 EXPECT_EQ(0u, host_resolver.num_resolve()); |
150 | 153 |
151 EXPECT_EQ("Error: line 5: Uncaught TypeError: Cannot read property 'split' " | 154 EXPECT_EQ( |
152 "of null\n", error_observer->GetOutput()); | 155 "Error: line 5: Uncaught TypeError: Cannot read property 'split' " |
| 156 "of null\n", |
| 157 error_observer->GetOutput()); |
153 | 158 |
154 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they | 159 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they |
155 // were output to both the global log, and per-request log. | 160 // were output to both the global log, and per-request log. |
156 CapturingNetLog::CapturedEntryList entries_list[2]; | 161 CapturingNetLog::CapturedEntryList entries_list[2]; |
157 log.GetEntries(&entries_list[0]); | 162 log.GetEntries(&entries_list[0]); |
158 request_log.GetEntries(&entries_list[1]); | 163 request_log.GetEntries(&entries_list[1]); |
159 | 164 |
160 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 165 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
161 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 166 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; |
162 EXPECT_EQ(2u, entries.size()); | 167 EXPECT_EQ(2u, entries.size()); |
163 EXPECT_TRUE( | 168 EXPECT_TRUE(LogContainsEvent( |
164 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 169 entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
165 NetLog::PHASE_NONE)); | 170 EXPECT_TRUE(LogContainsEvent( |
166 EXPECT_TRUE( | 171 entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, NetLog::PHASE_NONE)); |
167 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, | |
168 NetLog::PHASE_NONE)); | |
169 | 172 |
170 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); | 173 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); |
171 EXPECT_EQ("{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " | 174 EXPECT_EQ( |
172 "read property 'split' of null\"}", entries[1].GetParamsJson()); | 175 "{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " |
| 176 "read property 'split' of null\"}", |
| 177 entries[1].GetParamsJson()); |
173 } | 178 } |
174 } | 179 } |
175 | 180 |
176 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { | 181 TEST_F(ProxyResolverV8TracingTest, TooManyAlerts) { |
177 CapturingNetLog log; | 182 CapturingNetLog log; |
178 CapturingBoundNetLog request_log; | 183 CapturingBoundNetLog request_log; |
179 MockCachingHostResolver host_resolver; | 184 MockCachingHostResolver host_resolver; |
180 MockErrorObserver* error_observer = new MockErrorObserver; | 185 MockErrorObserver* error_observer = new MockErrorObserver; |
181 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 186 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
182 | 187 |
183 InitResolver(&resolver, "too_many_alerts.js"); | 188 InitResolver(&resolver, "too_many_alerts.js"); |
184 | 189 |
185 TestCompletionCallback callback; | 190 TestCompletionCallback callback; |
186 ProxyInfo proxy_info; | 191 ProxyInfo proxy_info; |
187 | 192 |
188 int rv = resolver.GetProxyForURL( | 193 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
189 GURL("http://foo/"), | 194 &proxy_info, |
190 &proxy_info, | 195 callback.callback(), |
191 callback.callback(), | 196 NULL, |
192 NULL, | 197 request_log.bound()); |
193 request_log.bound()); | |
194 | 198 |
195 EXPECT_EQ(ERR_IO_PENDING, rv); | 199 EXPECT_EQ(ERR_IO_PENDING, rv); |
196 EXPECT_EQ(OK, callback.WaitForResult()); | 200 EXPECT_EQ(OK, callback.WaitForResult()); |
197 | 201 |
198 // Iteration1 does a DNS resolve | 202 // Iteration1 does a DNS resolve |
199 // Iteration2 exceeds the alert buffer | 203 // Iteration2 exceeds the alert buffer |
200 // Iteration3 runs in blocking mode and completes | 204 // Iteration3 runs in blocking mode and completes |
201 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 205 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
202 | 206 |
203 EXPECT_EQ(1u, host_resolver.num_resolve()); | 207 EXPECT_EQ(1u, host_resolver.num_resolve()); |
204 | 208 |
205 // No errors. | 209 // No errors. |
206 EXPECT_EQ("", error_observer->GetOutput()); | 210 EXPECT_EQ("", error_observer->GetOutput()); |
207 | 211 |
208 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 212 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
209 // to both the global and per-request logs. | 213 // to both the global and per-request logs. |
210 CapturingNetLog::CapturedEntryList entries_list[2]; | 214 CapturingNetLog::CapturedEntryList entries_list[2]; |
211 log.GetEntries(&entries_list[0]); | 215 log.GetEntries(&entries_list[0]); |
212 request_log.GetEntries(&entries_list[1]); | 216 request_log.GetEntries(&entries_list[1]); |
213 | 217 |
214 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 218 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
215 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 219 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; |
216 EXPECT_EQ(50u, entries.size()); | 220 EXPECT_EQ(50u, entries.size()); |
217 for (size_t i = 0; i < entries.size(); ++i) { | 221 for (size_t i = 0; i < entries.size(); ++i) { |
218 ASSERT_TRUE( | 222 ASSERT_TRUE(LogContainsEvent( |
219 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 223 entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
220 NetLog::PHASE_NONE)); | |
221 } | 224 } |
222 } | 225 } |
223 } | 226 } |
224 | 227 |
225 // Verify that buffered alerts cannot grow unboundedly, even when the message is | 228 // Verify that buffered alerts cannot grow unboundedly, even when the message is |
226 // empty string. | 229 // empty string. |
227 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { | 230 TEST_F(ProxyResolverV8TracingTest, TooManyEmptyAlerts) { |
228 CapturingNetLog log; | 231 CapturingNetLog log; |
229 CapturingBoundNetLog request_log; | 232 CapturingBoundNetLog request_log; |
230 MockCachingHostResolver host_resolver; | 233 MockCachingHostResolver host_resolver; |
231 MockErrorObserver* error_observer = new MockErrorObserver; | 234 MockErrorObserver* error_observer = new MockErrorObserver; |
232 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 235 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
233 | 236 |
234 InitResolver(&resolver, "too_many_empty_alerts.js"); | 237 InitResolver(&resolver, "too_many_empty_alerts.js"); |
235 | 238 |
236 TestCompletionCallback callback; | 239 TestCompletionCallback callback; |
237 ProxyInfo proxy_info; | 240 ProxyInfo proxy_info; |
238 | 241 |
239 int rv = resolver.GetProxyForURL( | 242 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
240 GURL("http://foo/"), | 243 &proxy_info, |
241 &proxy_info, | 244 callback.callback(), |
242 callback.callback(), | 245 NULL, |
243 NULL, | 246 request_log.bound()); |
244 request_log.bound()); | |
245 | 247 |
246 EXPECT_EQ(ERR_IO_PENDING, rv); | 248 EXPECT_EQ(ERR_IO_PENDING, rv); |
247 EXPECT_EQ(OK, callback.WaitForResult()); | 249 EXPECT_EQ(OK, callback.WaitForResult()); |
248 | 250 |
249 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); | 251 EXPECT_EQ("foo:3", proxy_info.proxy_server().ToURI()); |
250 | 252 |
251 EXPECT_EQ(1u, host_resolver.num_resolve()); | 253 EXPECT_EQ(1u, host_resolver.num_resolve()); |
252 | 254 |
253 // No errors. | 255 // No errors. |
254 EXPECT_EQ("", error_observer->GetOutput()); | 256 EXPECT_EQ("", error_observer->GetOutput()); |
255 | 257 |
256 // Check the NetLogs -- the script generated 50 alerts, which were mirrored | 258 // Check the NetLogs -- the script generated 50 alerts, which were mirrored |
257 // to both the global and per-request logs. | 259 // to both the global and per-request logs. |
258 CapturingNetLog::CapturedEntryList entries_list[2]; | 260 CapturingNetLog::CapturedEntryList entries_list[2]; |
259 log.GetEntries(&entries_list[0]); | 261 log.GetEntries(&entries_list[0]); |
260 request_log.GetEntries(&entries_list[1]); | 262 request_log.GetEntries(&entries_list[1]); |
261 | 263 |
262 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 264 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
263 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 265 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; |
264 EXPECT_EQ(1000u, entries.size()); | 266 EXPECT_EQ(1000u, entries.size()); |
265 for (size_t i = 0; i < entries.size(); ++i) { | 267 for (size_t i = 0; i < entries.size(); ++i) { |
266 ASSERT_TRUE( | 268 ASSERT_TRUE(LogContainsEvent( |
267 LogContainsEvent(entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 269 entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
268 NetLog::PHASE_NONE)); | |
269 } | 270 } |
270 } | 271 } |
271 } | 272 } |
272 | 273 |
273 // This test runs a PAC script that issues a sequence of DNS resolves. The test | 274 // This test runs a PAC script that issues a sequence of DNS resolves. The test |
274 // verifies the final result, and that the underlying DNS resolver received | 275 // verifies the final result, and that the underlying DNS resolver received |
275 // the correct set of queries. | 276 // the correct set of queries. |
276 TEST_F(ProxyResolverV8TracingTest, Dns) { | 277 TEST_F(ProxyResolverV8TracingTest, Dns) { |
277 CapturingNetLog log; | 278 CapturingNetLog log; |
278 CapturingBoundNetLog request_log; | 279 CapturingBoundNetLog request_log; |
279 MockCachingHostResolver host_resolver; | 280 MockCachingHostResolver host_resolver; |
280 MockErrorObserver* error_observer = new MockErrorObserver; | 281 MockErrorObserver* error_observer = new MockErrorObserver; |
281 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 282 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
282 | 283 |
283 host_resolver.rules()->AddRuleForAddressFamily( | 284 host_resolver.rules()->AddRuleForAddressFamily( |
284 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 285 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); |
285 host_resolver.rules() | 286 host_resolver.rules()->AddIPLiteralRule( |
286 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 287 "host1", "::1,192.168.1.1", std::string()); |
287 host_resolver.rules()->AddSimulatedFailure("host2"); | 288 host_resolver.rules()->AddSimulatedFailure("host2"); |
288 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 289 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
289 host_resolver.rules()->AddRule("host5", "166.155.144.55"); | 290 host_resolver.rules()->AddRule("host5", "166.155.144.55"); |
290 host_resolver.rules()->AddSimulatedFailure("host6"); | 291 host_resolver.rules()->AddSimulatedFailure("host6"); |
291 host_resolver.rules()->AddRuleForAddressFamily( | 292 host_resolver.rules()->AddRuleForAddressFamily( |
292 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); | 293 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); |
293 host_resolver.rules()->AddRule("*", "133.122.100.200"); | 294 host_resolver.rules()->AddRule("*", "133.122.100.200"); |
294 | 295 |
295 InitResolver(&resolver, "dns.js"); | 296 InitResolver(&resolver, "dns.js"); |
296 | 297 |
297 TestCompletionCallback callback; | 298 TestCompletionCallback callback; |
298 ProxyInfo proxy_info; | 299 ProxyInfo proxy_info; |
299 | 300 |
300 int rv = resolver.GetProxyForURL( | 301 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
301 GURL("http://foo/"), | 302 &proxy_info, |
302 &proxy_info, | 303 callback.callback(), |
303 callback.callback(), | 304 NULL, |
304 NULL, | 305 request_log.bound()); |
305 request_log.bound()); | |
306 | 306 |
307 EXPECT_EQ(ERR_IO_PENDING, rv); | 307 EXPECT_EQ(ERR_IO_PENDING, rv); |
308 EXPECT_EQ(OK, callback.WaitForResult()); | 308 EXPECT_EQ(OK, callback.WaitForResult()); |
309 | 309 |
310 // The test does 13 DNS resolution, however only 7 of them are unique. | 310 // The test does 13 DNS resolution, however only 7 of them are unique. |
311 EXPECT_EQ(7u, host_resolver.num_resolve()); | 311 EXPECT_EQ(7u, host_resolver.num_resolve()); |
312 | 312 |
313 const char* kExpectedResult = | 313 const char* kExpectedResult = |
314 "122.133.144.155-" // myIpAddress() | 314 "122.133.144.155-" // myIpAddress() |
315 "null-" // dnsResolve('') | 315 "null-" // dnsResolve('') |
316 "__1_192.168.1.1-" // dnsResolveEx('host1') | 316 "__1_192.168.1.1-" // dnsResolveEx('host1') |
317 "null-" // dnsResolve('host2') | 317 "null-" // dnsResolve('host2') |
318 "166.155.144.33-" // dnsResolve('host3') | 318 "166.155.144.33-" // dnsResolve('host3') |
319 "122.133.144.155-" // myIpAddress() | 319 "122.133.144.155-" // myIpAddress() |
320 "166.155.144.33-" // dnsResolve('host3') | 320 "166.155.144.33-" // dnsResolve('host3') |
321 "__1_192.168.1.1-" // dnsResolveEx('host1') | 321 "__1_192.168.1.1-" // dnsResolveEx('host1') |
322 "122.133.144.155-" // myIpAddress() | 322 "122.133.144.155-" // myIpAddress() |
323 "null-" // dnsResolve('host2') | 323 "null-" // dnsResolve('host2') |
324 "-" // dnsResolveEx('host6') | 324 "-" // dnsResolveEx('host6') |
325 "133.122.100.200-" // myIpAddressEx() | 325 "133.122.100.200-" // myIpAddressEx() |
326 "166.155.144.44" // dnsResolve('host1') | 326 "166.155.144.44" // dnsResolve('host1') |
327 ":99"; | 327 ":99"; |
328 | 328 |
329 EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI()); | 329 EXPECT_EQ(kExpectedResult, proxy_info.proxy_server().ToURI()); |
330 | 330 |
331 // No errors. | 331 // No errors. |
332 EXPECT_EQ("", error_observer->GetOutput()); | 332 EXPECT_EQ("", error_observer->GetOutput()); |
333 | 333 |
334 // Check the NetLogs -- the script generated 1 alert, mirrored to both | 334 // Check the NetLogs -- the script generated 1 alert, mirrored to both |
335 // the per-request and global logs. | 335 // the per-request and global logs. |
336 CapturingNetLog::CapturedEntryList entries_list[2]; | 336 CapturingNetLog::CapturedEntryList entries_list[2]; |
337 log.GetEntries(&entries_list[0]); | 337 log.GetEntries(&entries_list[0]); |
338 request_log.GetEntries(&entries_list[1]); | 338 request_log.GetEntries(&entries_list[1]); |
339 | 339 |
340 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 340 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
341 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 341 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; |
342 EXPECT_EQ(1u, entries.size()); | 342 EXPECT_EQ(1u, entries.size()); |
343 EXPECT_TRUE( | 343 EXPECT_TRUE(LogContainsEvent( |
344 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 344 entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
345 NetLog::PHASE_NONE)); | |
346 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); | 345 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); |
347 } | 346 } |
348 } | 347 } |
349 | 348 |
350 // This test runs a PAC script that does "myIpAddress()" followed by | 349 // This test runs a PAC script that does "myIpAddress()" followed by |
351 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's | 350 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's |
352 // cache is warmed, subsequent calls should take 0 restarts. | 351 // cache is warmed, subsequent calls should take 0 restarts. |
353 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { | 352 TEST_F(ProxyResolverV8TracingTest, DnsChecksCache) { |
354 CapturingNetLog log; | 353 CapturingNetLog log; |
355 CapturingBoundNetLog request_log; | 354 CapturingBoundNetLog request_log; |
356 MockCachingHostResolver host_resolver; | 355 MockCachingHostResolver host_resolver; |
357 MockErrorObserver* error_observer = new MockErrorObserver; | 356 MockErrorObserver* error_observer = new MockErrorObserver; |
358 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 357 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
359 | 358 |
360 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); | 359 host_resolver.rules()->AddRule("foopy", "166.155.144.11"); |
361 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 360 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
362 | 361 |
363 InitResolver(&resolver, "simple_dns.js"); | 362 InitResolver(&resolver, "simple_dns.js"); |
364 | 363 |
365 TestCompletionCallback callback1; | 364 TestCompletionCallback callback1; |
366 TestCompletionCallback callback2; | 365 TestCompletionCallback callback2; |
367 ProxyInfo proxy_info; | 366 ProxyInfo proxy_info; |
368 | 367 |
369 int rv = resolver.GetProxyForURL( | 368 int rv = resolver.GetProxyForURL(GURL("http://foopy/req1"), |
370 GURL("http://foopy/req1"), | 369 &proxy_info, |
371 &proxy_info, | 370 callback1.callback(), |
372 callback1.callback(), | 371 NULL, |
373 NULL, | 372 request_log.bound()); |
374 request_log.bound()); | |
375 | 373 |
376 EXPECT_EQ(ERR_IO_PENDING, rv); | 374 EXPECT_EQ(ERR_IO_PENDING, rv); |
377 EXPECT_EQ(OK, callback1.WaitForResult()); | 375 EXPECT_EQ(OK, callback1.WaitForResult()); |
378 | 376 |
379 // The test does 2 DNS resolutions. | 377 // The test does 2 DNS resolutions. |
380 EXPECT_EQ(2u, host_resolver.num_resolve()); | 378 EXPECT_EQ(2u, host_resolver.num_resolve()); |
381 | 379 |
382 // The first request took 2 restarts, hence on g_iteration=3. | 380 // The first request took 2 restarts, hence on g_iteration=3. |
383 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); | 381 EXPECT_EQ("166.155.144.11:3", proxy_info.proxy_server().ToURI()); |
384 | 382 |
385 rv = resolver.GetProxyForURL( | 383 rv = resolver.GetProxyForURL(GURL("http://foopy/req2"), |
386 GURL("http://foopy/req2"), | 384 &proxy_info, |
387 &proxy_info, | 385 callback2.callback(), |
388 callback2.callback(), | 386 NULL, |
389 NULL, | 387 request_log.bound()); |
390 request_log.bound()); | |
391 | 388 |
392 EXPECT_EQ(ERR_IO_PENDING, rv); | 389 EXPECT_EQ(ERR_IO_PENDING, rv); |
393 EXPECT_EQ(OK, callback2.WaitForResult()); | 390 EXPECT_EQ(OK, callback2.WaitForResult()); |
394 | 391 |
395 EXPECT_EQ(4u, host_resolver.num_resolve()); | 392 EXPECT_EQ(4u, host_resolver.num_resolve()); |
396 | 393 |
397 // This time no restarts were required, so g_iteration incremented by 1. | 394 // This time no restarts were required, so g_iteration incremented by 1. |
398 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); | 395 EXPECT_EQ("166.155.144.11:4", proxy_info.proxy_server().ToURI()); |
399 | 396 |
400 // No errors. | 397 // No errors. |
(...skipping 15 matching lines...) Expand all Loading... |
416 | 413 |
417 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 414 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
418 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); | 415 host_resolver.rules()->AddRule("crazy4", "133.199.111.4"); |
419 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 416 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
420 | 417 |
421 InitResolver(&resolver, "global_sideffects1.js"); | 418 InitResolver(&resolver, "global_sideffects1.js"); |
422 | 419 |
423 TestCompletionCallback callback; | 420 TestCompletionCallback callback; |
424 ProxyInfo proxy_info; | 421 ProxyInfo proxy_info; |
425 | 422 |
426 int rv = resolver.GetProxyForURL( | 423 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
427 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 424 &proxy_info, |
428 request_log.bound()); | 425 callback.callback(), |
| 426 NULL, |
| 427 request_log.bound()); |
429 EXPECT_EQ(ERR_IO_PENDING, rv); | 428 EXPECT_EQ(ERR_IO_PENDING, rv); |
430 EXPECT_EQ(OK, callback.WaitForResult()); | 429 EXPECT_EQ(OK, callback.WaitForResult()); |
431 | 430 |
432 // The script itself only does 2 DNS resolves per execution, however it | 431 // The script itself only does 2 DNS resolves per execution, however it |
433 // constructs the hostname using a global counter which changes on each | 432 // constructs the hostname using a global counter which changes on each |
434 // invocation. | 433 // invocation. |
435 EXPECT_EQ(3u, host_resolver.num_resolve()); | 434 EXPECT_EQ(3u, host_resolver.num_resolve()); |
436 | 435 |
437 EXPECT_EQ("166.155.144.11-133.199.111.4:100", | 436 EXPECT_EQ("166.155.144.11-133.199.111.4:100", |
438 proxy_info.proxy_server().ToURI()); | 437 proxy_info.proxy_server().ToURI()); |
439 | 438 |
440 // No errors. | 439 // No errors. |
441 EXPECT_EQ("", error_observer->GetOutput()); | 440 EXPECT_EQ("", error_observer->GetOutput()); |
442 | 441 |
443 // Check the NetLogs -- the script generated 1 alert, mirrored to both | 442 // Check the NetLogs -- the script generated 1 alert, mirrored to both |
444 // the per-request and global logs. | 443 // the per-request and global logs. |
445 CapturingNetLog::CapturedEntryList entries_list[2]; | 444 CapturingNetLog::CapturedEntryList entries_list[2]; |
446 log.GetEntries(&entries_list[0]); | 445 log.GetEntries(&entries_list[0]); |
447 request_log.GetEntries(&entries_list[1]); | 446 request_log.GetEntries(&entries_list[1]); |
448 | 447 |
449 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { | 448 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { |
450 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; | 449 const CapturingNetLog::CapturedEntryList& entries = entries_list[list_i]; |
451 EXPECT_EQ(1u, entries.size()); | 450 EXPECT_EQ(1u, entries.size()); |
452 EXPECT_TRUE( | 451 EXPECT_TRUE(LogContainsEvent( |
453 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 452 entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
454 NetLog::PHASE_NONE)); | |
455 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); | 453 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); |
456 } | 454 } |
457 } | 455 } |
458 | 456 |
459 // This test runs a weird PAC script that was designed to defeat the DNS tracing | 457 // This test runs a weird PAC script that was designed to defeat the DNS tracing |
460 // optimization. The proxy resolver should detect the inconsistency and | 458 // optimization. The proxy resolver should detect the inconsistency and |
461 // fall-back to synchronous mode execution. | 459 // fall-back to synchronous mode execution. |
462 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { | 460 TEST_F(ProxyResolverV8TracingTest, FallBackToSynchronous2) { |
463 CapturingNetLog log; | 461 CapturingNetLog log; |
464 CapturingBoundNetLog request_log; | 462 CapturingBoundNetLog request_log; |
465 MockCachingHostResolver host_resolver; | 463 MockCachingHostResolver host_resolver; |
466 MockErrorObserver* error_observer = new MockErrorObserver; | 464 MockErrorObserver* error_observer = new MockErrorObserver; |
467 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 465 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
468 | 466 |
469 host_resolver.rules()->AddRule("host1", "166.155.144.11"); | 467 host_resolver.rules()->AddRule("host1", "166.155.144.11"); |
470 host_resolver.rules()->AddRule("host2", "166.155.144.22"); | 468 host_resolver.rules()->AddRule("host2", "166.155.144.22"); |
471 host_resolver.rules()->AddRule("host3", "166.155.144.33"); | 469 host_resolver.rules()->AddRule("host3", "166.155.144.33"); |
472 host_resolver.rules()->AddRule("host4", "166.155.144.44"); | 470 host_resolver.rules()->AddRule("host4", "166.155.144.44"); |
473 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 471 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
474 | 472 |
475 InitResolver(&resolver, "global_sideffects2.js"); | 473 InitResolver(&resolver, "global_sideffects2.js"); |
476 | 474 |
477 TestCompletionCallback callback; | 475 TestCompletionCallback callback; |
478 ProxyInfo proxy_info; | 476 ProxyInfo proxy_info; |
479 | 477 |
480 int rv = resolver.GetProxyForURL( | 478 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
481 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 479 &proxy_info, |
482 request_log.bound()); | 480 callback.callback(), |
| 481 NULL, |
| 482 request_log.bound()); |
483 EXPECT_EQ(ERR_IO_PENDING, rv); | 483 EXPECT_EQ(ERR_IO_PENDING, rv); |
484 EXPECT_EQ(OK, callback.WaitForResult()); | 484 EXPECT_EQ(OK, callback.WaitForResult()); |
485 | 485 |
486 EXPECT_EQ(3u, host_resolver.num_resolve()); | 486 EXPECT_EQ(3u, host_resolver.num_resolve()); |
487 | 487 |
488 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); | 488 EXPECT_EQ("166.155.144.44:100", proxy_info.proxy_server().ToURI()); |
489 | 489 |
490 // No errors. | 490 // No errors. |
491 EXPECT_EQ("", error_observer->GetOutput()); | 491 EXPECT_EQ("", error_observer->GetOutput()); |
492 | 492 |
(...skipping 14 matching lines...) Expand all Loading... |
507 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 507 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
508 | 508 |
509 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 509 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
510 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 510 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
511 | 511 |
512 InitResolver(&resolver, "global_sideffects3.js"); | 512 InitResolver(&resolver, "global_sideffects3.js"); |
513 | 513 |
514 TestCompletionCallback callback; | 514 TestCompletionCallback callback; |
515 ProxyInfo proxy_info; | 515 ProxyInfo proxy_info; |
516 | 516 |
517 int rv = resolver.GetProxyForURL( | 517 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
518 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 518 &proxy_info, |
519 request_log.bound()); | 519 callback.callback(), |
| 520 NULL, |
| 521 request_log.bound()); |
520 EXPECT_EQ(ERR_IO_PENDING, rv); | 522 EXPECT_EQ(ERR_IO_PENDING, rv); |
521 EXPECT_EQ(OK, callback.WaitForResult()); | 523 EXPECT_EQ(OK, callback.WaitForResult()); |
522 | 524 |
523 EXPECT_EQ(20u, host_resolver.num_resolve()); | 525 EXPECT_EQ(20u, host_resolver.num_resolve()); |
524 | 526 |
525 EXPECT_EQ( | 527 EXPECT_EQ( |
526 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 528 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
527 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 529 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
528 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" | 530 "166.155.144.11-166.155.144.11-166.155.144.11-166.155.144.11-" |
529 "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-" |
530 "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-" |
531 "null:21", proxy_info.proxy_server().ToURI()); | 533 "null:21", |
| 534 proxy_info.proxy_server().ToURI()); |
532 | 535 |
533 // No errors. | 536 // No errors. |
534 EXPECT_EQ("", error_observer->GetOutput()); | 537 EXPECT_EQ("", error_observer->GetOutput()); |
535 | 538 |
536 // Check the NetLogs -- 1 alert was logged. | 539 // Check the NetLogs -- 1 alert was logged. |
537 EXPECT_EQ(1u, log.GetSize()); | 540 EXPECT_EQ(1u, log.GetSize()); |
538 EXPECT_EQ(1u, request_log.GetSize()); | 541 EXPECT_EQ(1u, request_log.GetSize()); |
539 } | 542 } |
540 | 543 |
541 // This test runs a weird PAC script that yields a never ending sequence | 544 // This test runs a weird PAC script that yields a never ending sequence |
542 // of DNS resolves when restarting. Running it will hit the maximum | 545 // of DNS resolves when restarting. Running it will hit the maximum |
543 // DNS resolves per request limit (20) after which every DNS resolve will | 546 // DNS resolves per request limit (20) after which every DNS resolve will |
544 // fail. | 547 // fail. |
545 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { | 548 TEST_F(ProxyResolverV8TracingTest, InfiniteDNSSequence2) { |
546 CapturingNetLog log; | 549 CapturingNetLog log; |
547 CapturingBoundNetLog request_log; | 550 CapturingBoundNetLog request_log; |
548 MockCachingHostResolver host_resolver; | 551 MockCachingHostResolver host_resolver; |
549 MockErrorObserver* error_observer = new MockErrorObserver; | 552 MockErrorObserver* error_observer = new MockErrorObserver; |
550 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 553 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
551 | 554 |
552 host_resolver.rules()->AddRule("host*", "166.155.144.11"); | 555 host_resolver.rules()->AddRule("host*", "166.155.144.11"); |
553 host_resolver.rules()->AddRule("*", "122.133.144.155"); | 556 host_resolver.rules()->AddRule("*", "122.133.144.155"); |
554 | 557 |
555 InitResolver(&resolver, "global_sideffects4.js"); | 558 InitResolver(&resolver, "global_sideffects4.js"); |
556 | 559 |
557 TestCompletionCallback callback; | 560 TestCompletionCallback callback; |
558 ProxyInfo proxy_info; | 561 ProxyInfo proxy_info; |
559 | 562 |
560 int rv = resolver.GetProxyForURL( | 563 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
561 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 564 &proxy_info, |
562 request_log.bound()); | 565 callback.callback(), |
| 566 NULL, |
| 567 request_log.bound()); |
563 EXPECT_EQ(ERR_IO_PENDING, rv); | 568 EXPECT_EQ(ERR_IO_PENDING, rv); |
564 EXPECT_EQ(OK, callback.WaitForResult()); | 569 EXPECT_EQ(OK, callback.WaitForResult()); |
565 | 570 |
566 EXPECT_EQ(20u, host_resolver.num_resolve()); | 571 EXPECT_EQ(20u, host_resolver.num_resolve()); |
567 | 572 |
568 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); | 573 EXPECT_EQ("null21:34", proxy_info.proxy_server().ToURI()); |
569 | 574 |
570 // No errors. | 575 // No errors. |
571 EXPECT_EQ("", error_observer->GetOutput()); | 576 EXPECT_EQ("", error_observer->GetOutput()); |
572 | 577 |
(...skipping 20 matching lines...) Expand all Loading... |
593 | 598 |
594 host_resolver.rules()->ClearRules(); | 599 host_resolver.rules()->ClearRules(); |
595 host_resolver.GetHostCache()->clear(); | 600 host_resolver.GetHostCache()->clear(); |
596 | 601 |
597 host_resolver.rules()->AddRule("host1", "145.88.13.3"); | 602 host_resolver.rules()->AddRule("host1", "145.88.13.3"); |
598 host_resolver.rules()->AddRule("host2", "137.89.8.45"); | 603 host_resolver.rules()->AddRule("host2", "137.89.8.45"); |
599 | 604 |
600 TestCompletionCallback callback; | 605 TestCompletionCallback callback; |
601 ProxyInfo proxy_info; | 606 ProxyInfo proxy_info; |
602 | 607 |
603 int rv = resolver.GetProxyForURL( | 608 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
604 GURL("http://foo/"), &proxy_info, callback.callback(), NULL, | 609 &proxy_info, |
605 request_log.bound()); | 610 callback.callback(), |
| 611 NULL, |
| 612 request_log.bound()); |
606 EXPECT_EQ(ERR_IO_PENDING, rv); | 613 EXPECT_EQ(ERR_IO_PENDING, rv); |
607 EXPECT_EQ(OK, callback.WaitForResult()); | 614 EXPECT_EQ(OK, callback.WaitForResult()); |
608 | 615 |
609 // Fetched host1 and host2 again, since the ones done during initialization | 616 // Fetched host1 and host2 again, since the ones done during initialization |
610 // should not have been cached. | 617 // should not have been cached. |
611 EXPECT_EQ(4u, host_resolver.num_resolve()); | 618 EXPECT_EQ(4u, host_resolver.num_resolve()); |
612 | 619 |
613 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", | 620 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", |
614 proxy_info.proxy_server().ToURI()); | 621 proxy_info.proxy_server().ToURI()); |
615 | 622 |
616 // Check the NetLogs -- the script generated 2 alerts during initialization. | 623 // Check the NetLogs -- the script generated 2 alerts during initialization. |
617 EXPECT_EQ(0u, request_log.GetSize()); | 624 EXPECT_EQ(0u, request_log.GetSize()); |
618 CapturingNetLog::CapturedEntryList entries; | 625 CapturingNetLog::CapturedEntryList entries; |
619 log.GetEntries(&entries); | 626 log.GetEntries(&entries); |
620 | 627 |
621 ASSERT_EQ(2u, entries.size()); | 628 ASSERT_EQ(2u, entries.size()); |
622 EXPECT_TRUE( | 629 EXPECT_TRUE(LogContainsEvent( |
623 LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 630 entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
624 NetLog::PHASE_NONE)); | 631 EXPECT_TRUE(LogContainsEvent( |
625 EXPECT_TRUE( | 632 entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); |
626 LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | |
627 NetLog::PHASE_NONE)); | |
628 | 633 |
629 EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson()); | 634 EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson()); |
630 EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson()); | 635 EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson()); |
631 } | 636 } |
632 | 637 |
633 // Tests a PAC script which does DNS resolves during initialization. | 638 // Tests a PAC script which does DNS resolves during initialization. |
634 TEST_F(ProxyResolverV8TracingTest, DnsDuringInit) { | 639 TEST_F(ProxyResolverV8TracingTest, DnsDuringInit) { |
635 // Test with both both a host resolver that always completes asynchronously, | 640 // Test with both both a host resolver that always completes asynchronously, |
636 // and then again with one that completes synchronously. | 641 // and then again with one that completes synchronously. |
637 DnsDuringInitHelper(false); | 642 DnsDuringInitHelper(false); |
(...skipping 16 matching lines...) Expand all Loading... |
654 | 659 |
655 host_resolver.rules()->AddSimulatedFailure("*"); | 660 host_resolver.rules()->AddSimulatedFailure("*"); |
656 | 661 |
657 InitResolver(&resolver, "dns.js"); | 662 InitResolver(&resolver, "dns.js"); |
658 | 663 |
659 const size_t kNumRequests = 5; | 664 const size_t kNumRequests = 5; |
660 ProxyInfo proxy_info[kNumRequests]; | 665 ProxyInfo proxy_info[kNumRequests]; |
661 ProxyResolver::RequestHandle request[kNumRequests]; | 666 ProxyResolver::RequestHandle request[kNumRequests]; |
662 | 667 |
663 for (size_t i = 0; i < kNumRequests; ++i) { | 668 for (size_t i = 0; i < kNumRequests; ++i) { |
664 int rv = resolver.GetProxyForURL( | 669 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
665 GURL("http://foo/"), &proxy_info[i], | 670 &proxy_info[i], |
666 base::Bind(&CrashCallback), &request[i], BoundNetLog()); | 671 base::Bind(&CrashCallback), |
| 672 &request[i], |
| 673 BoundNetLog()); |
667 EXPECT_EQ(ERR_IO_PENDING, rv); | 674 EXPECT_EQ(ERR_IO_PENDING, rv); |
668 } | 675 } |
669 | 676 |
670 for (size_t i = 0; i < kNumRequests; ++i) { | 677 for (size_t i = 0; i < kNumRequests; ++i) { |
671 resolver.CancelRequest(request[i]); | 678 resolver.CancelRequest(request[i]); |
672 } | 679 } |
673 } | 680 } |
674 | 681 |
675 // Note the execution order for this test can vary. Since multiple | 682 // Note the execution order for this test can vary. Since multiple |
676 // threads are involved, the cancellation may be received a different | 683 // threads are involved, the cancellation may be received a different |
677 // times. | 684 // times. |
678 TEST_F(ProxyResolverV8TracingTest, CancelSome) { | 685 TEST_F(ProxyResolverV8TracingTest, CancelSome) { |
679 MockCachingHostResolver host_resolver; | 686 MockCachingHostResolver host_resolver; |
680 MockErrorObserver* error_observer = new MockErrorObserver; | 687 MockErrorObserver* error_observer = new MockErrorObserver; |
681 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 688 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); |
682 | 689 |
683 host_resolver.rules()->AddSimulatedFailure("*"); | 690 host_resolver.rules()->AddSimulatedFailure("*"); |
684 | 691 |
685 InitResolver(&resolver, "dns.js"); | 692 InitResolver(&resolver, "dns.js"); |
686 | 693 |
687 ProxyInfo proxy_info1; | 694 ProxyInfo proxy_info1; |
688 ProxyInfo proxy_info2; | 695 ProxyInfo proxy_info2; |
689 ProxyResolver::RequestHandle request1; | 696 ProxyResolver::RequestHandle request1; |
690 ProxyResolver::RequestHandle request2; | 697 ProxyResolver::RequestHandle request2; |
691 TestCompletionCallback callback; | 698 TestCompletionCallback callback; |
692 | 699 |
693 int rv = resolver.GetProxyForURL( | 700 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
694 GURL("http://foo/"), &proxy_info1, | 701 &proxy_info1, |
695 base::Bind(&CrashCallback), &request1, BoundNetLog()); | 702 base::Bind(&CrashCallback), |
| 703 &request1, |
| 704 BoundNetLog()); |
696 EXPECT_EQ(ERR_IO_PENDING, rv); | 705 EXPECT_EQ(ERR_IO_PENDING, rv); |
697 | 706 |
698 rv = resolver.GetProxyForURL( | 707 rv = resolver.GetProxyForURL(GURL("http://foo/"), |
699 GURL("http://foo/"), &proxy_info2, | 708 &proxy_info2, |
700 callback.callback(), &request2, BoundNetLog()); | 709 callback.callback(), |
| 710 &request2, |
| 711 BoundNetLog()); |
701 EXPECT_EQ(ERR_IO_PENDING, rv); | 712 EXPECT_EQ(ERR_IO_PENDING, rv); |
702 | 713 |
703 resolver.CancelRequest(request1); | 714 resolver.CancelRequest(request1); |
704 | 715 |
705 EXPECT_EQ(OK, callback.WaitForResult()); | 716 EXPECT_EQ(OK, callback.WaitForResult()); |
706 } | 717 } |
707 | 718 |
708 // Cancel a request after it has finished running on the worker thread, and has | 719 // Cancel a request after it has finished running on the worker thread, and has |
709 // posted a task the completion task back to origin thread. | 720 // posted a task the completion task back to origin thread. |
710 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { | 721 TEST_F(ProxyResolverV8TracingTest, CancelWhilePendingCompletionTask) { |
711 MockCachingHostResolver host_resolver; | 722 MockCachingHostResolver host_resolver; |
712 MockErrorObserver* error_observer = new MockErrorObserver; | 723 MockErrorObserver* error_observer = new MockErrorObserver; |
713 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 724 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); |
714 | 725 |
715 host_resolver.rules()->AddSimulatedFailure("*"); | 726 host_resolver.rules()->AddSimulatedFailure("*"); |
716 | 727 |
717 InitResolver(&resolver, "error.js"); | 728 InitResolver(&resolver, "error.js"); |
718 | 729 |
719 ProxyInfo proxy_info1; | 730 ProxyInfo proxy_info1; |
720 ProxyInfo proxy_info2; | 731 ProxyInfo proxy_info2; |
721 ProxyInfo proxy_info3; | 732 ProxyInfo proxy_info3; |
722 ProxyResolver::RequestHandle request1; | 733 ProxyResolver::RequestHandle request1; |
723 ProxyResolver::RequestHandle request2; | 734 ProxyResolver::RequestHandle request2; |
724 ProxyResolver::RequestHandle request3; | 735 ProxyResolver::RequestHandle request3; |
725 TestCompletionCallback callback; | 736 TestCompletionCallback callback; |
726 | 737 |
727 int rv = resolver.GetProxyForURL( | 738 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
728 GURL("http://foo/"), &proxy_info1, | 739 &proxy_info1, |
729 base::Bind(&CrashCallback), &request1, BoundNetLog()); | 740 base::Bind(&CrashCallback), |
| 741 &request1, |
| 742 BoundNetLog()); |
730 EXPECT_EQ(ERR_IO_PENDING, rv); | 743 EXPECT_EQ(ERR_IO_PENDING, rv); |
731 | 744 |
732 rv = resolver.GetProxyForURL( | 745 rv = resolver.GetProxyForURL(GURL("http://throw-an-error/"), |
733 GURL("http://throw-an-error/"), &proxy_info2, | 746 &proxy_info2, |
734 callback.callback(), &request2, BoundNetLog()); | 747 callback.callback(), |
| 748 &request2, |
| 749 BoundNetLog()); |
735 EXPECT_EQ(ERR_IO_PENDING, rv); | 750 EXPECT_EQ(ERR_IO_PENDING, rv); |
736 | 751 |
737 // Wait until the first request has finished running on the worker thread. | 752 // Wait until the first request has finished running on the worker thread. |
738 // (The second request will output an error). | 753 // (The second request will output an error). |
739 error_observer->WaitForOutput(); | 754 error_observer->WaitForOutput(); |
740 | 755 |
741 // Cancel the first request, while it has a pending completion task on | 756 // Cancel the first request, while it has a pending completion task on |
742 // the origin thread. | 757 // the origin thread. |
743 resolver.CancelRequest(request1); | 758 resolver.CancelRequest(request1); |
744 | 759 |
745 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); | 760 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, callback.WaitForResult()); |
746 | 761 |
747 // Start another request, to make sure it is able to complete. | 762 // Start another request, to make sure it is able to complete. |
748 rv = resolver.GetProxyForURL( | 763 rv = resolver.GetProxyForURL(GURL("http://i-have-no-idea-what-im-doing/"), |
749 GURL("http://i-have-no-idea-what-im-doing/"), &proxy_info3, | 764 &proxy_info3, |
750 callback.callback(), &request3, BoundNetLog()); | 765 callback.callback(), |
| 766 &request3, |
| 767 BoundNetLog()); |
751 EXPECT_EQ(ERR_IO_PENDING, rv); | 768 EXPECT_EQ(ERR_IO_PENDING, rv); |
752 | 769 |
753 EXPECT_EQ(OK, callback.WaitForResult()); | 770 EXPECT_EQ(OK, callback.WaitForResult()); |
754 | 771 |
755 EXPECT_EQ("i-approve-this-message:42", | 772 EXPECT_EQ("i-approve-this-message:42", proxy_info3.proxy_server().ToURI()); |
756 proxy_info3.proxy_server().ToURI()); | |
757 } | 773 } |
758 | 774 |
759 // This implementation of HostResolver allows blocking until a resolve request | 775 // This implementation of HostResolver allows blocking until a resolve request |
760 // has been received. The resolve requests it receives will never be completed. | 776 // has been received. The resolve requests it receives will never be completed. |
761 class BlockableHostResolver : public HostResolver { | 777 class BlockableHostResolver : public HostResolver { |
762 public: | 778 public: |
763 BlockableHostResolver() | 779 BlockableHostResolver() |
764 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} | 780 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} |
765 | 781 |
766 virtual int Resolve(const RequestInfo& info, | 782 virtual int Resolve(const RequestInfo& info, |
(...skipping 27 matching lines...) Expand all Loading... |
794 const BoundNetLog& net_log) OVERRIDE { | 810 const BoundNetLog& net_log) OVERRIDE { |
795 NOTREACHED(); | 811 NOTREACHED(); |
796 return ERR_DNS_CACHE_MISS; | 812 return ERR_DNS_CACHE_MISS; |
797 } | 813 } |
798 | 814 |
799 virtual void CancelRequest(RequestHandle req) OVERRIDE { | 815 virtual void CancelRequest(RequestHandle req) OVERRIDE { |
800 EXPECT_EQ(reinterpret_cast<RequestHandle*>(1), req); | 816 EXPECT_EQ(reinterpret_cast<RequestHandle*>(1), req); |
801 num_cancelled_requests_++; | 817 num_cancelled_requests_++; |
802 } | 818 } |
803 | 819 |
804 void SetAction(const base::Callback<void(void)>& action) { | 820 void SetAction(const base::Callback<void(void)>& action) { action_ = action; } |
805 action_ = action; | |
806 } | |
807 | 821 |
808 // Waits until Resolve() has been called. | 822 // Waits until Resolve() has been called. |
809 void WaitUntilRequestIsReceived() { | 823 void WaitUntilRequestIsReceived() { |
810 waiting_for_resolve_ = true; | 824 waiting_for_resolve_ = true; |
811 base::MessageLoop::current()->Run(); | 825 base::MessageLoop::current()->Run(); |
812 DCHECK(waiting_for_resolve_); | 826 DCHECK(waiting_for_resolve_); |
813 waiting_for_resolve_ = false; | 827 waiting_for_resolve_ = false; |
814 } | 828 } |
815 | 829 |
816 int num_cancelled_requests() const { | 830 int num_cancelled_requests() const { return num_cancelled_requests_; } |
817 return num_cancelled_requests_; | |
818 } | |
819 | 831 |
820 private: | 832 private: |
821 int num_cancelled_requests_; | 833 int num_cancelled_requests_; |
822 bool waiting_for_resolve_; | 834 bool waiting_for_resolve_; |
823 base::Callback<void(void)> action_; | 835 base::Callback<void(void)> action_; |
824 }; | 836 }; |
825 | 837 |
826 // This cancellation test exercises a more predictable cancellation codepath -- | 838 // This cancellation test exercises a more predictable cancellation codepath -- |
827 // when the request has an outstanding DNS request in flight. | 839 // when the request has an outstanding DNS request in flight. |
828 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { | 840 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { |
829 BlockableHostResolver host_resolver; | 841 BlockableHostResolver host_resolver; |
830 MockErrorObserver* error_observer = new MockErrorObserver; | 842 MockErrorObserver* error_observer = new MockErrorObserver; |
831 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 843 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); |
832 | 844 |
833 InitResolver(&resolver, "dns.js"); | 845 InitResolver(&resolver, "dns.js"); |
834 | 846 |
835 ProxyInfo proxy_info1; | 847 ProxyInfo proxy_info1; |
836 ProxyInfo proxy_info2; | 848 ProxyInfo proxy_info2; |
837 ProxyResolver::RequestHandle request1; | 849 ProxyResolver::RequestHandle request1; |
838 ProxyResolver::RequestHandle request2; | 850 ProxyResolver::RequestHandle request2; |
839 | 851 |
840 int rv = resolver.GetProxyForURL( | 852 int rv = resolver.GetProxyForURL(GURL("http://foo/req1"), |
841 GURL("http://foo/req1"), &proxy_info1, | 853 &proxy_info1, |
842 base::Bind(&CrashCallback), &request1, BoundNetLog()); | 854 base::Bind(&CrashCallback), |
| 855 &request1, |
| 856 BoundNetLog()); |
843 | 857 |
844 EXPECT_EQ(ERR_IO_PENDING, rv); | 858 EXPECT_EQ(ERR_IO_PENDING, rv); |
845 | 859 |
846 host_resolver.WaitUntilRequestIsReceived(); | 860 host_resolver.WaitUntilRequestIsReceived(); |
847 | 861 |
848 rv = resolver.GetProxyForURL( | 862 rv = resolver.GetProxyForURL(GURL("http://foo/req2"), |
849 GURL("http://foo/req2"), &proxy_info2, | 863 &proxy_info2, |
850 base::Bind(&CrashCallback), &request2, BoundNetLog()); | 864 base::Bind(&CrashCallback), |
| 865 &request2, |
| 866 BoundNetLog()); |
851 | 867 |
852 EXPECT_EQ(ERR_IO_PENDING, rv); | 868 EXPECT_EQ(ERR_IO_PENDING, rv); |
853 | 869 |
854 host_resolver.WaitUntilRequestIsReceived(); | 870 host_resolver.WaitUntilRequestIsReceived(); |
855 | 871 |
856 resolver.CancelRequest(request1); | 872 resolver.CancelRequest(request1); |
857 resolver.CancelRequest(request2); | 873 resolver.CancelRequest(request2); |
858 | 874 |
859 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); | 875 EXPECT_EQ(2, host_resolver.num_cancelled_requests()); |
860 | 876 |
(...skipping 18 matching lines...) Expand all Loading... |
879 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { | 895 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns) { |
880 BlockableHostResolver host_resolver; | 896 BlockableHostResolver host_resolver; |
881 MockErrorObserver* error_observer = new MockErrorObserver; | 897 MockErrorObserver* error_observer = new MockErrorObserver; |
882 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 898 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); |
883 | 899 |
884 InitResolver(&resolver, "dns.js"); | 900 InitResolver(&resolver, "dns.js"); |
885 | 901 |
886 ProxyInfo proxy_info; | 902 ProxyInfo proxy_info; |
887 ProxyResolver::RequestHandle request; | 903 ProxyResolver::RequestHandle request; |
888 | 904 |
889 int rv = resolver.GetProxyForURL( | 905 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
890 GURL("http://foo/"), &proxy_info, | 906 &proxy_info, |
891 base::Bind(&CrashCallback), &request, BoundNetLog()); | 907 base::Bind(&CrashCallback), |
| 908 &request, |
| 909 BoundNetLog()); |
892 | 910 |
893 EXPECT_EQ(ERR_IO_PENDING, rv); | 911 EXPECT_EQ(ERR_IO_PENDING, rv); |
894 | 912 |
895 host_resolver.SetAction( | 913 host_resolver.SetAction( |
896 base::Bind(CancelRequestAndPause, &resolver, request)); | 914 base::Bind(CancelRequestAndPause, &resolver, request)); |
897 | 915 |
898 host_resolver.WaitUntilRequestIsReceived(); | 916 host_resolver.WaitUntilRequestIsReceived(); |
899 | 917 |
900 // At this point the host resolver ran Resolve(), and should have cancelled | 918 // At this point the host resolver ran Resolve(), and should have cancelled |
901 // the request. | 919 // the request. |
902 | 920 |
903 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 921 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
904 } | 922 } |
905 | 923 |
906 // Cancel the request while there is a pending DNS request, however before | 924 // Cancel the request while there is a pending DNS request, however before |
907 // the request is sent to the host resolver. | 925 // the request is sent to the host resolver. |
908 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { | 926 TEST_F(ProxyResolverV8TracingTest, CancelWhileBlockedInNonBlockingDns2) { |
909 MockCachingHostResolver host_resolver; | 927 MockCachingHostResolver host_resolver; |
910 MockErrorObserver* error_observer = new MockErrorObserver; | 928 MockErrorObserver* error_observer = new MockErrorObserver; |
911 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 929 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); |
912 | 930 |
913 InitResolver(&resolver, "dns.js"); | 931 InitResolver(&resolver, "dns.js"); |
914 | 932 |
915 ProxyInfo proxy_info; | 933 ProxyInfo proxy_info; |
916 ProxyResolver::RequestHandle request; | 934 ProxyResolver::RequestHandle request; |
917 | 935 |
918 int rv = resolver.GetProxyForURL( | 936 int rv = resolver.GetProxyForURL(GURL("http://foo/"), |
919 GURL("http://foo/"), &proxy_info, | 937 &proxy_info, |
920 base::Bind(&CrashCallback), &request, BoundNetLog()); | 938 base::Bind(&CrashCallback), |
| 939 &request, |
| 940 BoundNetLog()); |
921 | 941 |
922 EXPECT_EQ(ERR_IO_PENDING, rv); | 942 EXPECT_EQ(ERR_IO_PENDING, rv); |
923 | 943 |
924 // Wait a bit, so the DNS task has hopefully been posted. The test will | 944 // Wait a bit, so the DNS task has hopefully been posted. The test will |
925 // work whatever the delay is here, but it is most useful if the delay | 945 // work whatever the delay is here, but it is most useful if the delay |
926 // is large enough to allow a task to be posted back. | 946 // is large enough to allow a task to be posted back. |
927 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); | 947 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10)); |
928 resolver.CancelRequest(request); | 948 resolver.CancelRequest(request); |
929 | 949 |
930 EXPECT_EQ(0u, host_resolver.num_resolve()); | 950 EXPECT_EQ(0u, host_resolver.num_resolve()); |
931 } | 951 } |
932 | 952 |
933 TEST_F(ProxyResolverV8TracingTest, CancelSetPacWhileOutstandingBlockingDns) { | 953 TEST_F(ProxyResolverV8TracingTest, CancelSetPacWhileOutstandingBlockingDns) { |
934 BlockableHostResolver host_resolver; | 954 BlockableHostResolver host_resolver; |
935 MockErrorObserver* error_observer = new MockErrorObserver; | 955 MockErrorObserver* error_observer = new MockErrorObserver; |
936 | 956 |
937 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); | 957 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, NULL); |
938 | 958 |
939 int rv = | 959 int rv = resolver.SetPacScript(LoadScriptData("dns_during_init.js"), |
940 resolver.SetPacScript(LoadScriptData("dns_during_init.js"), | 960 base::Bind(&CrashCallback)); |
941 base::Bind(&CrashCallback)); | |
942 EXPECT_EQ(ERR_IO_PENDING, rv); | 961 EXPECT_EQ(ERR_IO_PENDING, rv); |
943 | 962 |
944 host_resolver.WaitUntilRequestIsReceived(); | 963 host_resolver.WaitUntilRequestIsReceived(); |
945 | 964 |
946 resolver.CancelSetPacScript(); | 965 resolver.CancelSetPacScript(); |
947 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); | 966 EXPECT_EQ(1, host_resolver.num_cancelled_requests()); |
948 } | 967 } |
949 | 968 |
950 // This tests that the execution of a PAC script is terminated when the DNS | 969 // This tests that the execution of a PAC script is terminated when the DNS |
951 // dependencies are missing. If the test fails, then it will hang. | 970 // dependencies are missing. If the test fails, then it will hang. |
952 TEST_F(ProxyResolverV8TracingTest, Terminate) { | 971 TEST_F(ProxyResolverV8TracingTest, Terminate) { |
953 CapturingNetLog log; | 972 CapturingNetLog log; |
954 CapturingBoundNetLog request_log; | 973 CapturingBoundNetLog request_log; |
955 MockCachingHostResolver host_resolver; | 974 MockCachingHostResolver host_resolver; |
956 MockErrorObserver* error_observer = new MockErrorObserver; | 975 MockErrorObserver* error_observer = new MockErrorObserver; |
957 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); | 976 ProxyResolverV8Tracing resolver(&host_resolver, error_observer, &log); |
958 | 977 |
959 host_resolver.rules()->AddRule("host1", "182.111.0.222"); | 978 host_resolver.rules()->AddRule("host1", "182.111.0.222"); |
960 host_resolver.rules()->AddRule("host2", "111.33.44.55"); | 979 host_resolver.rules()->AddRule("host2", "111.33.44.55"); |
961 | 980 |
962 InitResolver(&resolver, "terminate.js"); | 981 InitResolver(&resolver, "terminate.js"); |
963 | 982 |
964 TestCompletionCallback callback; | 983 TestCompletionCallback callback; |
965 ProxyInfo proxy_info; | 984 ProxyInfo proxy_info; |
966 | 985 |
967 int rv = resolver.GetProxyForURL( | 986 int rv = resolver.GetProxyForURL(GURL("http://foopy/req1"), |
968 GURL("http://foopy/req1"), | 987 &proxy_info, |
969 &proxy_info, | 988 callback.callback(), |
970 callback.callback(), | 989 NULL, |
971 NULL, | 990 request_log.bound()); |
972 request_log.bound()); | |
973 | 991 |
974 EXPECT_EQ(ERR_IO_PENDING, rv); | 992 EXPECT_EQ(ERR_IO_PENDING, rv); |
975 EXPECT_EQ(OK, callback.WaitForResult()); | 993 EXPECT_EQ(OK, callback.WaitForResult()); |
976 | 994 |
977 // The test does 2 DNS resolutions. | 995 // The test does 2 DNS resolutions. |
978 EXPECT_EQ(2u, host_resolver.num_resolve()); | 996 EXPECT_EQ(2u, host_resolver.num_resolve()); |
979 | 997 |
980 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); | 998 EXPECT_EQ("foopy:3", proxy_info.proxy_server().ToURI()); |
981 | 999 |
982 // No errors. | 1000 // No errors. |
983 EXPECT_EQ("", error_observer->GetOutput()); | 1001 EXPECT_EQ("", error_observer->GetOutput()); |
984 | 1002 |
985 EXPECT_EQ(0u, log.GetSize()); | 1003 EXPECT_EQ(0u, log.GetSize()); |
986 EXPECT_EQ(0u, request_log.GetSize()); | 1004 EXPECT_EQ(0u, request_log.GetSize()); |
987 } | 1005 } |
988 | 1006 |
989 // Tests that multiple instances of ProxyResolverV8Tracing can coexist and run | 1007 // Tests that multiple instances of ProxyResolverV8Tracing can coexist and run |
990 // correctly at the same time. This is relevant because at the moment (time | 1008 // correctly at the same time. This is relevant because at the moment (time |
991 // this test was written) each ProxyResolverV8Tracing creates its own thread to | 1009 // this test was written) each ProxyResolverV8Tracing creates its own thread to |
992 // run V8 on, however each thread is operating on the same v8::Isolate. | 1010 // run V8 on, however each thread is operating on the same v8::Isolate. |
993 TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) { | 1011 TEST_F(ProxyResolverV8TracingTest, MultipleResolvers) { |
994 // ------------------------ | 1012 // ------------------------ |
995 // Setup resolver0 | 1013 // Setup resolver0 |
996 // ------------------------ | 1014 // ------------------------ |
997 MockHostResolver host_resolver0; | 1015 MockHostResolver host_resolver0; |
998 host_resolver0.rules()->AddRuleForAddressFamily( | 1016 host_resolver0.rules()->AddRuleForAddressFamily( |
999 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); | 1017 "host1", ADDRESS_FAMILY_IPV4, "166.155.144.44"); |
1000 host_resolver0.rules() | 1018 host_resolver0.rules()->AddIPLiteralRule( |
1001 ->AddIPLiteralRule("host1", "::1,192.168.1.1", std::string()); | 1019 "host1", "::1,192.168.1.1", std::string()); |
1002 host_resolver0.rules()->AddSimulatedFailure("host2"); | 1020 host_resolver0.rules()->AddSimulatedFailure("host2"); |
1003 host_resolver0.rules()->AddRule("host3", "166.155.144.33"); | 1021 host_resolver0.rules()->AddRule("host3", "166.155.144.33"); |
1004 host_resolver0.rules()->AddRule("host5", "166.155.144.55"); | 1022 host_resolver0.rules()->AddRule("host5", "166.155.144.55"); |
1005 host_resolver0.rules()->AddSimulatedFailure("host6"); | 1023 host_resolver0.rules()->AddSimulatedFailure("host6"); |
1006 host_resolver0.rules()->AddRuleForAddressFamily( | 1024 host_resolver0.rules()->AddRuleForAddressFamily( |
1007 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); | 1025 "*", ADDRESS_FAMILY_IPV4, "122.133.144.155"); |
1008 host_resolver0.rules()->AddRule("*", "133.122.100.200"); | 1026 host_resolver0.rules()->AddRule("*", "133.122.100.200"); |
1009 ProxyResolverV8Tracing resolver0( | 1027 ProxyResolverV8Tracing resolver0( |
1010 &host_resolver0, new MockErrorObserver, NULL); | 1028 &host_resolver0, new MockErrorObserver, NULL); |
1011 InitResolver(&resolver0, "dns.js"); | 1029 InitResolver(&resolver0, "dns.js"); |
(...skipping 19 matching lines...) Expand all Loading... |
1031 host_resolver3.rules()->AddRule("foo", "166.155.144.33"); | 1049 host_resolver3.rules()->AddRule("foo", "166.155.144.33"); |
1032 ProxyResolverV8Tracing resolver3( | 1050 ProxyResolverV8Tracing resolver3( |
1033 &host_resolver3, new MockErrorObserver, NULL); | 1051 &host_resolver3, new MockErrorObserver, NULL); |
1034 InitResolver(&resolver3, "simple_dns.js"); | 1052 InitResolver(&resolver3, "simple_dns.js"); |
1035 | 1053 |
1036 // ------------------------ | 1054 // ------------------------ |
1037 // Queue up work for each resolver (which will be running in parallel). | 1055 // Queue up work for each resolver (which will be running in parallel). |
1038 // ------------------------ | 1056 // ------------------------ |
1039 | 1057 |
1040 ProxyResolverV8Tracing* resolver[] = { | 1058 ProxyResolverV8Tracing* resolver[] = { |
1041 &resolver0, &resolver1, &resolver2, &resolver3, | 1059 &resolver0, &resolver1, &resolver2, &resolver3, |
1042 }; | 1060 }; |
1043 | 1061 |
1044 const size_t kNumResolvers = arraysize(resolver); | 1062 const size_t kNumResolvers = arraysize(resolver); |
1045 const size_t kNumIterations = 20; | 1063 const size_t kNumIterations = 20; |
1046 const size_t kNumResults = kNumResolvers * kNumIterations; | 1064 const size_t kNumResults = kNumResolvers * kNumIterations; |
1047 TestCompletionCallback callback[kNumResults]; | 1065 TestCompletionCallback callback[kNumResults]; |
1048 ProxyInfo proxy_info[kNumResults]; | 1066 ProxyInfo proxy_info[kNumResults]; |
1049 | 1067 |
1050 for (size_t i = 0; i < kNumResults; ++i) { | 1068 for (size_t i = 0; i < kNumResults; ++i) { |
1051 size_t resolver_i = i % kNumResolvers; | 1069 size_t resolver_i = i % kNumResolvers; |
1052 int rv = resolver[resolver_i]->GetProxyForURL( | 1070 int rv = resolver[resolver_i]->GetProxyForURL(GURL("http://foo/"), |
1053 GURL("http://foo/"), &proxy_info[i], callback[i].callback(), NULL, | 1071 &proxy_info[i], |
1054 BoundNetLog()); | 1072 callback[i].callback(), |
| 1073 NULL, |
| 1074 BoundNetLog()); |
1055 EXPECT_EQ(ERR_IO_PENDING, rv); | 1075 EXPECT_EQ(ERR_IO_PENDING, rv); |
1056 } | 1076 } |
1057 | 1077 |
1058 // ------------------------ | 1078 // ------------------------ |
1059 // Verify all of the results. | 1079 // Verify all of the results. |
1060 // ------------------------ | 1080 // ------------------------ |
1061 | 1081 |
1062 const char* kExpectedForDnsJs = | 1082 const char* kExpectedForDnsJs = |
1063 "122.133.144.155-" // myIpAddress() | 1083 "122.133.144.155-" // myIpAddress() |
1064 "null-" // dnsResolve('') | 1084 "null-" // dnsResolve('') |
1065 "__1_192.168.1.1-" // dnsResolveEx('host1') | 1085 "__1_192.168.1.1-" // dnsResolveEx('host1') |
1066 "null-" // dnsResolve('host2') | 1086 "null-" // dnsResolve('host2') |
1067 "166.155.144.33-" // dnsResolve('host3') | 1087 "166.155.144.33-" // dnsResolve('host3') |
1068 "122.133.144.155-" // myIpAddress() | 1088 "122.133.144.155-" // myIpAddress() |
1069 "166.155.144.33-" // dnsResolve('host3') | 1089 "166.155.144.33-" // dnsResolve('host3') |
1070 "__1_192.168.1.1-" // dnsResolveEx('host1') | 1090 "__1_192.168.1.1-" // dnsResolveEx('host1') |
1071 "122.133.144.155-" // myIpAddress() | 1091 "122.133.144.155-" // myIpAddress() |
1072 "null-" // dnsResolve('host2') | 1092 "null-" // dnsResolve('host2') |
1073 "-" // dnsResolveEx('host6') | 1093 "-" // dnsResolveEx('host6') |
1074 "133.122.100.200-" // myIpAddressEx() | 1094 "133.122.100.200-" // myIpAddressEx() |
1075 "166.155.144.44" // dnsResolve('host1') | 1095 "166.155.144.44" // dnsResolve('host1') |
1076 ":99"; | 1096 ":99"; |
1077 | 1097 |
1078 for (size_t i = 0; i < kNumResults; ++i) { | 1098 for (size_t i = 0; i < kNumResults; ++i) { |
1079 size_t resolver_i = i % kNumResolvers; | 1099 size_t resolver_i = i % kNumResolvers; |
1080 EXPECT_EQ(OK, callback[i].WaitForResult()); | 1100 EXPECT_EQ(OK, callback[i].WaitForResult()); |
1081 | 1101 |
1082 std::string proxy_uri = proxy_info[i].proxy_server().ToURI(); | 1102 std::string proxy_uri = proxy_info[i].proxy_server().ToURI(); |
1083 | 1103 |
1084 if (resolver_i == 0 || resolver_i == 1) { | 1104 if (resolver_i == 0 || resolver_i == 1) { |
1085 EXPECT_EQ(kExpectedForDnsJs, proxy_uri); | 1105 EXPECT_EQ(kExpectedForDnsJs, proxy_uri); |
1086 } else if (resolver_i == 2) { | 1106 } else if (resolver_i == 2) { |
1087 EXPECT_EQ("foo:99", proxy_uri); | 1107 EXPECT_EQ("foo:99", proxy_uri); |
1088 } else if (resolver_i == 3) { | 1108 } else if (resolver_i == 3) { |
1089 EXPECT_EQ("166.155.144.33:", | 1109 EXPECT_EQ("166.155.144.33:", |
1090 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1110 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
1091 } else { | 1111 } else { |
1092 NOTREACHED(); | 1112 NOTREACHED(); |
1093 } | 1113 } |
1094 } | 1114 } |
1095 } | 1115 } |
1096 | 1116 |
1097 } // namespace | 1117 } // namespace |
1098 | 1118 |
1099 } // namespace net | 1119 } // namespace net |
OLD | NEW |