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

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

Issue 4118004: Update NetLog to be thread safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final sync with trunk Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/net.gyp ('k') | net/proxy/multi_threaded_proxy_resolver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <vector> 5 #include <vector>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/base/net_log.h" 10 #include "net/base/net_log.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac"); 175 Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac");
176 176
177 TestCompletionCallback callback; 177 TestCompletionCallback callback;
178 CapturingNetLog log(CapturingNetLog::kUnbounded); 178 CapturingNetLog log(CapturingNetLog::kUnbounded);
179 InitProxyResolver init(&resolver, &fetcher, &log); 179 InitProxyResolver init(&resolver, &fetcher, &log);
180 EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), NULL, &callback)); 180 EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), NULL, &callback));
181 EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); 181 EXPECT_EQ(rule.text(), resolver.script_data()->utf16());
182 182
183 // Check the NetLog was filled correctly. 183 // Check the NetLog was filled correctly.
184 EXPECT_EQ(6u, log.entries().size()); 184 net::CapturingNetLog::EntryList entries;
185 log.GetEntries(&entries);
186
187 EXPECT_EQ(6u, entries.size());
185 EXPECT_TRUE(LogContainsBeginEvent( 188 EXPECT_TRUE(LogContainsBeginEvent(
186 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); 189 entries, 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
187 EXPECT_TRUE(LogContainsBeginEvent( 190 EXPECT_TRUE(LogContainsBeginEvent(
188 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 191 entries, 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
189 EXPECT_TRUE(LogContainsEndEvent( 192 EXPECT_TRUE(LogContainsEndEvent(
190 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 193 entries, 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
191 EXPECT_TRUE(LogContainsBeginEvent( 194 EXPECT_TRUE(LogContainsBeginEvent(
192 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); 195 entries, 3, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
193 EXPECT_TRUE(LogContainsEndEvent( 196 EXPECT_TRUE(LogContainsEndEvent(
194 log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); 197 entries, 4, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
195 EXPECT_TRUE(LogContainsEndEvent( 198 EXPECT_TRUE(LogContainsEndEvent(
196 log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER)); 199 entries, 5, NetLog::TYPE_INIT_PROXY_RESOLVER));
197 } 200 }
198 201
199 // Fail downloading the custom PAC script. 202 // Fail downloading the custom PAC script.
200 TEST(InitProxyResolverTest, CustomPacFails1) { 203 TEST(InitProxyResolverTest, CustomPacFails1) {
201 Rules rules; 204 Rules rules;
202 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); 205 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/);
203 RuleBasedProxyScriptFetcher fetcher(&rules); 206 RuleBasedProxyScriptFetcher fetcher(&rules);
204 207
205 ProxyConfig config; 208 ProxyConfig config;
206 config.set_pac_url(GURL("http://custom/proxy.pac")); 209 config.set_pac_url(GURL("http://custom/proxy.pac"));
207 210
208 rules.AddFailDownloadRule("http://custom/proxy.pac"); 211 rules.AddFailDownloadRule("http://custom/proxy.pac");
209 212
210 TestCompletionCallback callback; 213 TestCompletionCallback callback;
211 CapturingNetLog log(CapturingNetLog::kUnbounded); 214 CapturingNetLog log(CapturingNetLog::kUnbounded);
212 InitProxyResolver init(&resolver, &fetcher, &log); 215 InitProxyResolver init(&resolver, &fetcher, &log);
213 EXPECT_EQ(kFailedDownloading, 216 EXPECT_EQ(kFailedDownloading,
214 init.Init(config, base::TimeDelta(), NULL, &callback)); 217 init.Init(config, base::TimeDelta(), NULL, &callback));
215 EXPECT_EQ(NULL, resolver.script_data()); 218 EXPECT_EQ(NULL, resolver.script_data());
216 219
217 // Check the NetLog was filled correctly. 220 // Check the NetLog was filled correctly.
218 EXPECT_EQ(4u, log.entries().size()); 221 net::CapturingNetLog::EntryList entries;
222 log.GetEntries(&entries);
223
224 EXPECT_EQ(4u, entries.size());
219 EXPECT_TRUE(LogContainsBeginEvent( 225 EXPECT_TRUE(LogContainsBeginEvent(
220 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); 226 entries, 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
221 EXPECT_TRUE(LogContainsBeginEvent( 227 EXPECT_TRUE(LogContainsBeginEvent(
222 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 228 entries, 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
223 EXPECT_TRUE(LogContainsEndEvent( 229 EXPECT_TRUE(LogContainsEndEvent(
224 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 230 entries, 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
225 EXPECT_TRUE(LogContainsEndEvent( 231 EXPECT_TRUE(LogContainsEndEvent(
226 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER)); 232 entries, 3, NetLog::TYPE_INIT_PROXY_RESOLVER));
227 } 233 }
228 234
229 // Fail parsing the custom PAC script. 235 // Fail parsing the custom PAC script.
230 TEST(InitProxyResolverTest, CustomPacFails2) { 236 TEST(InitProxyResolverTest, CustomPacFails2) {
231 Rules rules; 237 Rules rules;
232 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); 238 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/);
233 RuleBasedProxyScriptFetcher fetcher(&rules); 239 RuleBasedProxyScriptFetcher fetcher(&rules);
234 240
235 ProxyConfig config; 241 ProxyConfig config;
236 config.set_pac_url(GURL("http://custom/proxy.pac")); 242 config.set_pac_url(GURL("http://custom/proxy.pac"));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); 325 EXPECT_EQ(rule.text(), resolver.script_data()->utf16());
320 326
321 // Verify that the effective configuration no longer contains auto detect or 327 // Verify that the effective configuration no longer contains auto detect or
322 // any of the manual settings. 328 // any of the manual settings.
323 EXPECT_TRUE(effective_config.Equals( 329 EXPECT_TRUE(effective_config.Equals(
324 ProxyConfig::CreateFromCustomPacURL(GURL("http://custom/proxy.pac")))); 330 ProxyConfig::CreateFromCustomPacURL(GURL("http://custom/proxy.pac"))));
325 331
326 // Check the NetLog was filled correctly. 332 // Check the NetLog was filled correctly.
327 // (Note that the Fetch and Set states are repeated since both WPAD and custom 333 // (Note that the Fetch and Set states are repeated since both WPAD and custom
328 // PAC scripts are tried). 334 // PAC scripts are tried).
329 EXPECT_EQ(11u, log.entries().size()); 335 net::CapturingNetLog::EntryList entries;
336 log.GetEntries(&entries);
337
338 EXPECT_EQ(11u, entries.size());
330 EXPECT_TRUE(LogContainsBeginEvent( 339 EXPECT_TRUE(LogContainsBeginEvent(
331 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); 340 entries, 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
332 EXPECT_TRUE(LogContainsBeginEvent( 341 EXPECT_TRUE(LogContainsBeginEvent(
333 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 342 entries, 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
334 EXPECT_TRUE(LogContainsEndEvent( 343 EXPECT_TRUE(LogContainsEndEvent(
335 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 344 entries, 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
336 EXPECT_TRUE(LogContainsBeginEvent( 345 EXPECT_TRUE(LogContainsBeginEvent(
337 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); 346 entries, 3, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
338 EXPECT_TRUE(LogContainsEndEvent( 347 EXPECT_TRUE(LogContainsEndEvent(
339 log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); 348 entries, 4, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
340 EXPECT_TRUE(LogContainsEvent( 349 EXPECT_TRUE(LogContainsEvent(
341 log.entries(), 5, 350 entries, 5,
342 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL, 351 NetLog::TYPE_INIT_PROXY_RESOLVER_FALLING_BACK_TO_NEXT_PAC_URL,
343 NetLog::PHASE_NONE)); 352 NetLog::PHASE_NONE));
344 EXPECT_TRUE(LogContainsBeginEvent( 353 EXPECT_TRUE(LogContainsBeginEvent(
345 log.entries(), 6, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 354 entries, 6, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
346 EXPECT_TRUE(LogContainsEndEvent( 355 EXPECT_TRUE(LogContainsEndEvent(
347 log.entries(), 7, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 356 entries, 7, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
348 EXPECT_TRUE(LogContainsBeginEvent( 357 EXPECT_TRUE(LogContainsBeginEvent(
349 log.entries(), 8, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); 358 entries, 8, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
350 EXPECT_TRUE(LogContainsEndEvent( 359 EXPECT_TRUE(LogContainsEndEvent(
351 log.entries(), 9, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT)); 360 entries, 9, NetLog::TYPE_INIT_PROXY_RESOLVER_SET_PAC_SCRIPT));
352 EXPECT_TRUE(LogContainsEndEvent( 361 EXPECT_TRUE(LogContainsEndEvent(
353 log.entries(), 10, NetLog::TYPE_INIT_PROXY_RESOLVER)); 362 entries, 10, NetLog::TYPE_INIT_PROXY_RESOLVER));
354 } 363 }
355 364
356 // Fails at WPAD (downloading), and fails at custom PAC (downloading). 365 // Fails at WPAD (downloading), and fails at custom PAC (downloading).
357 TEST(InitProxyResolverTest, AutodetectFailCustomFails1) { 366 TEST(InitProxyResolverTest, AutodetectFailCustomFails1) {
358 Rules rules; 367 Rules rules;
359 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); 368 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/);
360 RuleBasedProxyScriptFetcher fetcher(&rules); 369 RuleBasedProxyScriptFetcher fetcher(&rules);
361 370
362 ProxyConfig config; 371 ProxyConfig config;
363 config.set_auto_detect(true); 372 config.set_auto_detect(true);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 CapturingNetLog log(CapturingNetLog::kUnbounded); 440 CapturingNetLog log(CapturingNetLog::kUnbounded);
432 InitProxyResolver init(&resolver, &fetcher, &log); 441 InitProxyResolver init(&resolver, &fetcher, &log);
433 EXPECT_EQ(ERR_IO_PENDING, 442 EXPECT_EQ(ERR_IO_PENDING,
434 init.Init(config, base::TimeDelta::FromMilliseconds(1), 443 init.Init(config, base::TimeDelta::FromMilliseconds(1),
435 NULL, &callback)); 444 NULL, &callback));
436 445
437 EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); 446 EXPECT_EQ(kFailedDownloading, callback.WaitForResult());
438 EXPECT_EQ(NULL, resolver.script_data()); 447 EXPECT_EQ(NULL, resolver.script_data());
439 448
440 // Check the NetLog was filled correctly. 449 // Check the NetLog was filled correctly.
441 EXPECT_EQ(6u, log.entries().size()); 450 net::CapturingNetLog::EntryList entries;
451 log.GetEntries(&entries);
452
453 EXPECT_EQ(6u, entries.size());
442 EXPECT_TRUE(LogContainsBeginEvent( 454 EXPECT_TRUE(LogContainsBeginEvent(
443 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); 455 entries, 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
444 EXPECT_TRUE(LogContainsBeginEvent( 456 EXPECT_TRUE(LogContainsBeginEvent(
445 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT)); 457 entries, 1, NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT));
446 EXPECT_TRUE(LogContainsEndEvent( 458 EXPECT_TRUE(LogContainsEndEvent(
447 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT)); 459 entries, 2, NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT));
448 EXPECT_TRUE(LogContainsBeginEvent( 460 EXPECT_TRUE(LogContainsBeginEvent(
449 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 461 entries, 3, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
450 EXPECT_TRUE(LogContainsEndEvent( 462 EXPECT_TRUE(LogContainsEndEvent(
451 log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 463 entries, 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
452 EXPECT_TRUE(LogContainsEndEvent( 464 EXPECT_TRUE(LogContainsEndEvent(
453 log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER)); 465 entries, 5, NetLog::TYPE_INIT_PROXY_RESOLVER));
454 } 466 }
455 467
456 // This is a copy-paste of CustomPacFails1, with the exception that we give it 468 // This is a copy-paste of CustomPacFails1, with the exception that we give it
457 // a -5 second delay instead of a 0 ms delay. This change should have no effect 469 // a -5 second delay instead of a 0 ms delay. This change should have no effect
458 // so the rest of the test is unchanged. 470 // so the rest of the test is unchanged.
459 TEST(InitProxyResolverTest, CustomPacFails1_WithNegativeDelay) { 471 TEST(InitProxyResolverTest, CustomPacFails1_WithNegativeDelay) {
460 Rules rules; 472 Rules rules;
461 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); 473 RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/);
462 RuleBasedProxyScriptFetcher fetcher(&rules); 474 RuleBasedProxyScriptFetcher fetcher(&rules);
463 475
464 ProxyConfig config; 476 ProxyConfig config;
465 config.set_pac_url(GURL("http://custom/proxy.pac")); 477 config.set_pac_url(GURL("http://custom/proxy.pac"));
466 478
467 rules.AddFailDownloadRule("http://custom/proxy.pac"); 479 rules.AddFailDownloadRule("http://custom/proxy.pac");
468 480
469 TestCompletionCallback callback; 481 TestCompletionCallback callback;
470 CapturingNetLog log(CapturingNetLog::kUnbounded); 482 CapturingNetLog log(CapturingNetLog::kUnbounded);
471 InitProxyResolver init(&resolver, &fetcher, &log); 483 InitProxyResolver init(&resolver, &fetcher, &log);
472 EXPECT_EQ(kFailedDownloading, 484 EXPECT_EQ(kFailedDownloading,
473 init.Init(config, base::TimeDelta::FromSeconds(-5), 485 init.Init(config, base::TimeDelta::FromSeconds(-5),
474 NULL, &callback)); 486 NULL, &callback));
475 EXPECT_EQ(NULL, resolver.script_data()); 487 EXPECT_EQ(NULL, resolver.script_data());
476 488
477 // Check the NetLog was filled correctly. 489 // Check the NetLog was filled correctly.
478 EXPECT_EQ(4u, log.entries().size()); 490 net::CapturingNetLog::EntryList entries;
491 log.GetEntries(&entries);
492
493 EXPECT_EQ(4u, entries.size());
479 EXPECT_TRUE(LogContainsBeginEvent( 494 EXPECT_TRUE(LogContainsBeginEvent(
480 log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); 495 entries, 0, NetLog::TYPE_INIT_PROXY_RESOLVER));
481 EXPECT_TRUE(LogContainsBeginEvent( 496 EXPECT_TRUE(LogContainsBeginEvent(
482 log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 497 entries, 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
483 EXPECT_TRUE(LogContainsEndEvent( 498 EXPECT_TRUE(LogContainsEndEvent(
484 log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); 499 entries, 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT));
485 EXPECT_TRUE(LogContainsEndEvent( 500 EXPECT_TRUE(LogContainsEndEvent(
486 log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER)); 501 entries, 3, NetLog::TYPE_INIT_PROXY_RESOLVER));
487 } 502 }
488 503
489 } // namespace 504 } // namespace
490 } // namespace net 505 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | net/proxy/multi_threaded_proxy_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698