OLD | NEW |
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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "net/base/load_log_unittest.h" | 9 #include "net/base/load_log_unittest.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 const GURL kQueryUrl("http://www.google.com"); | 111 const GURL kQueryUrl("http://www.google.com"); |
112 const GURL kPacUrl; | 112 const GURL kPacUrl; |
113 | 113 |
114 | 114 |
115 TEST(ProxyResolverV8Test, Direct) { | 115 TEST(ProxyResolverV8Test, Direct) { |
116 ProxyResolverV8WithMockBindings resolver; | 116 ProxyResolverV8WithMockBindings resolver; |
117 int result = resolver.SetPacScriptFromDisk("direct.js"); | 117 int result = resolver.SetPacScriptFromDisk("direct.js"); |
118 EXPECT_EQ(OK, result); | 118 EXPECT_EQ(OK, result); |
119 | 119 |
120 ProxyInfo proxy_info; | 120 ProxyInfo proxy_info; |
121 scoped_refptr<LoadLog> log(new LoadLog); | 121 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); |
122 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 122 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); |
123 | 123 |
124 EXPECT_EQ(OK, result); | 124 EXPECT_EQ(OK, result); |
125 EXPECT_TRUE(proxy_info.is_direct()); | 125 EXPECT_TRUE(proxy_info.is_direct()); |
126 | 126 |
127 EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); | 127 EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
128 EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); | 128 EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
129 | 129 |
130 // No bindings were called, so no log entries. | 130 // No bindings were called, so no log entries. |
131 EXPECT_EQ(0u, log->events().size()); | 131 EXPECT_EQ(0u, log->events().size()); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 416 } |
417 | 417 |
418 // Test that calls to the myIpAddress() and dnsResolve() bindings get | 418 // Test that calls to the myIpAddress() and dnsResolve() bindings get |
419 // logged to the LoadLog parameter. | 419 // logged to the LoadLog parameter. |
420 TEST(ProxyResolverV8Test, LoadLog) { | 420 TEST(ProxyResolverV8Test, LoadLog) { |
421 ProxyResolverV8WithMockBindings resolver; | 421 ProxyResolverV8WithMockBindings resolver; |
422 int result = resolver.SetPacScriptFromDisk("simple.js"); | 422 int result = resolver.SetPacScriptFromDisk("simple.js"); |
423 EXPECT_EQ(OK, result); | 423 EXPECT_EQ(OK, result); |
424 | 424 |
425 ProxyInfo proxy_info; | 425 ProxyInfo proxy_info; |
426 scoped_refptr<LoadLog> log(new LoadLog); | 426 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); |
427 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 427 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); |
428 | 428 |
429 EXPECT_EQ(OK, result); | 429 EXPECT_EQ(OK, result); |
430 EXPECT_FALSE(proxy_info.is_direct()); | 430 EXPECT_FALSE(proxy_info.is_direct()); |
431 EXPECT_EQ("c:100", proxy_info.proxy_server().ToURI()); | 431 EXPECT_EQ("c:100", proxy_info.proxy_server().ToURI()); |
432 | 432 |
433 // Note that dnsResolve() was never called directly, but it appears | 433 // Note that dnsResolve() was never called directly, but it appears |
434 // in the LoadLog. This is because it gets called indirectly by | 434 // in the LoadLog. This is because it gets called indirectly by |
435 // isInNet() and isResolvable(). | 435 // isInNet() and isResolvable(). |
436 | 436 |
(...skipping 15 matching lines...) Expand all Loading... |
452 // Try loading a PAC script that ends with a comment and has no terminal | 452 // Try loading a PAC script that ends with a comment and has no terminal |
453 // newline. This should not cause problems with the PAC utility functions | 453 // newline. This should not cause problems with the PAC utility functions |
454 // that we add to the script's environment. | 454 // that we add to the script's environment. |
455 // http://crbug.com/22864 | 455 // http://crbug.com/22864 |
456 TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { | 456 TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { |
457 ProxyResolverV8WithMockBindings resolver; | 457 ProxyResolverV8WithMockBindings resolver; |
458 int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); | 458 int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); |
459 EXPECT_EQ(OK, result); | 459 EXPECT_EQ(OK, result); |
460 | 460 |
461 ProxyInfo proxy_info; | 461 ProxyInfo proxy_info; |
462 scoped_refptr<LoadLog> log(new LoadLog); | 462 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); |
463 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 463 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); |
464 | 464 |
465 EXPECT_EQ(OK, result); | 465 EXPECT_EQ(OK, result); |
466 EXPECT_FALSE(proxy_info.is_direct()); | 466 EXPECT_FALSE(proxy_info.is_direct()); |
467 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); | 467 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
468 } | 468 } |
469 | 469 |
470 // Try loading a PAC script that ends with a statement and has no terminal | 470 // Try loading a PAC script that ends with a statement and has no terminal |
471 // newline. This should not cause problems with the PAC utility functions | 471 // newline. This should not cause problems with the PAC utility functions |
472 // that we add to the script's environment. | 472 // that we add to the script's environment. |
473 // http://crbug.com/22864 | 473 // http://crbug.com/22864 |
474 TEST(ProxyResolverV8Test, EndsWithStatementNoNewline) { | 474 TEST(ProxyResolverV8Test, EndsWithStatementNoNewline) { |
475 ProxyResolverV8WithMockBindings resolver; | 475 ProxyResolverV8WithMockBindings resolver; |
476 int result = resolver.SetPacScriptFromDisk( | 476 int result = resolver.SetPacScriptFromDisk( |
477 "ends_with_statement_no_semicolon.js"); | 477 "ends_with_statement_no_semicolon.js"); |
478 EXPECT_EQ(OK, result); | 478 EXPECT_EQ(OK, result); |
479 | 479 |
480 ProxyInfo proxy_info; | 480 ProxyInfo proxy_info; |
481 scoped_refptr<LoadLog> log(new LoadLog); | 481 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); |
482 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); | 482 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, log); |
483 | 483 |
484 EXPECT_EQ(OK, result); | 484 EXPECT_EQ(OK, result); |
485 EXPECT_FALSE(proxy_info.is_direct()); | 485 EXPECT_FALSE(proxy_info.is_direct()); |
486 EXPECT_EQ("success:3", proxy_info.proxy_server().ToURI()); | 486 EXPECT_EQ("success:3", proxy_info.proxy_server().ToURI()); |
487 } | 487 } |
488 | 488 |
489 // Test the return values from myIpAddress(), myIpAddressEx(), dnsResolve(), | 489 // Test the return values from myIpAddress(), myIpAddressEx(), dnsResolve(), |
490 // dnsResolveEx(), isResolvable(), isResolvableEx(), when the the binding | 490 // dnsResolveEx(), isResolvable(), isResolvableEx(), when the the binding |
491 // returns empty string (failure). This simulates the return values from | 491 // returns empty string (failure). This simulates the return values from |
492 // those functions when the underlying DNS resolution fails. | 492 // those functions when the underlying DNS resolution fails. |
493 TEST(ProxyResolverV8Test, DNSResolutionFailure) { | 493 TEST(ProxyResolverV8Test, DNSResolutionFailure) { |
494 ProxyResolverV8WithMockBindings resolver; | 494 ProxyResolverV8WithMockBindings resolver; |
495 int result = resolver.SetPacScriptFromDisk("dns_fail.js"); | 495 int result = resolver.SetPacScriptFromDisk("dns_fail.js"); |
496 EXPECT_EQ(OK, result); | 496 EXPECT_EQ(OK, result); |
497 | 497 |
498 ProxyInfo proxy_info; | 498 ProxyInfo proxy_info; |
499 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); | 499 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); |
500 | 500 |
501 EXPECT_EQ(OK, result); | 501 EXPECT_EQ(OK, result); |
502 EXPECT_FALSE(proxy_info.is_direct()); | 502 EXPECT_FALSE(proxy_info.is_direct()); |
503 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); | 503 EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
504 } | 504 } |
505 | 505 |
506 } // namespace | 506 } // namespace |
507 } // namespace net | 507 } // namespace net |
OLD | NEW |