| 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "net/base/net_log_unittest.h" | 12 #include "net/base/net_log_unittest.h" |
| 12 #include "net/proxy/proxy_info.h" | 13 #include "net/proxy/proxy_info.h" |
| 13 #include "net/proxy/proxy_resolver_js_bindings.h" | 14 #include "net/proxy/proxy_resolver_js_bindings.h" |
| 14 #include "net/proxy/proxy_resolver_v8.h" | 15 #include "net/proxy/proxy_resolver_v8.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 TEST(ProxyResolverV8Test, SideEffects) { | 270 TEST(ProxyResolverV8Test, SideEffects) { |
| 270 ProxyResolverV8WithMockBindings resolver; | 271 ProxyResolverV8WithMockBindings resolver; |
| 271 int result = resolver.SetPacScriptFromDisk("side_effects.js"); | 272 int result = resolver.SetPacScriptFromDisk("side_effects.js"); |
| 272 | 273 |
| 273 // The PAC script increments a counter each time we invoke it. | 274 // The PAC script increments a counter each time we invoke it. |
| 274 for (int i = 0; i < 3; ++i) { | 275 for (int i = 0; i < 3; ++i) { |
| 275 ProxyInfo proxy_info; | 276 ProxyInfo proxy_info; |
| 276 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, | 277 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 277 BoundNetLog()); | 278 BoundNetLog()); |
| 278 EXPECT_EQ(OK, result); | 279 EXPECT_EQ(OK, result); |
| 279 EXPECT_EQ(StringPrintf("sideffect_%d:80", i), | 280 EXPECT_EQ(base::StringPrintf("sideffect_%d:80", i), |
| 280 proxy_info.proxy_server().ToURI()); | 281 proxy_info.proxy_server().ToURI()); |
| 281 } | 282 } |
| 282 | 283 |
| 283 // Reload the script -- the javascript environment should be reset, hence | 284 // Reload the script -- the javascript environment should be reset, hence |
| 284 // the counter starts over. | 285 // the counter starts over. |
| 285 result = resolver.SetPacScriptFromDisk("side_effects.js"); | 286 result = resolver.SetPacScriptFromDisk("side_effects.js"); |
| 286 EXPECT_EQ(OK, result); | 287 EXPECT_EQ(OK, result); |
| 287 | 288 |
| 288 for (int i = 0; i < 3; ++i) { | 289 for (int i = 0; i < 3; ++i) { |
| 289 ProxyInfo proxy_info; | 290 ProxyInfo proxy_info; |
| 290 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, | 291 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 291 BoundNetLog()); | 292 BoundNetLog()); |
| 292 EXPECT_EQ(OK, result); | 293 EXPECT_EQ(OK, result); |
| 293 EXPECT_EQ(StringPrintf("sideffect_%d:80", i), | 294 EXPECT_EQ(base::StringPrintf("sideffect_%d:80", i), |
| 294 proxy_info.proxy_server().ToURI()); | 295 proxy_info.proxy_server().ToURI()); |
| 295 } | 296 } |
| 296 } | 297 } |
| 297 | 298 |
| 298 // Execute a PAC script which throws an exception in FindProxyForURL. | 299 // Execute a PAC script which throws an exception in FindProxyForURL. |
| 299 TEST(ProxyResolverV8Test, UnhandledException) { | 300 TEST(ProxyResolverV8Test, UnhandledException) { |
| 300 ProxyResolverV8WithMockBindings resolver; | 301 ProxyResolverV8WithMockBindings resolver; |
| 301 int result = resolver.SetPacScriptFromDisk("unhandled_exception.js"); | 302 int result = resolver.SetPacScriptFromDisk("unhandled_exception.js"); |
| 302 EXPECT_EQ(OK, result); | 303 EXPECT_EQ(OK, result); |
| 303 | 304 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 537 |
| 537 ASSERT_EQ(1u, bindings->dns_resolves.size()); | 538 ASSERT_EQ(1u, bindings->dns_resolves.size()); |
| 538 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves[0]); | 539 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves[0]); |
| 539 | 540 |
| 540 ASSERT_EQ(1u, bindings->dns_resolves_ex.size()); | 541 ASSERT_EQ(1u, bindings->dns_resolves_ex.size()); |
| 541 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves_ex[0]); | 542 EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves_ex[0]); |
| 542 } | 543 } |
| 543 | 544 |
| 544 } // namespace | 545 } // namespace |
| 545 } // namespace net | 546 } // namespace net |
| OLD | NEW |