| 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/host_resolver.h" |
| 9 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 10 #include "net/proxy/proxy_resolver_v8.h" | 11 #include "net/proxy/proxy_resolver_v8.h" |
| 11 #include "net/proxy/proxy_info.h" | 12 #include "net/proxy/proxy_info.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Javascript bindings for ProxyResolverV8, which returns mock values. | 17 // Javascript bindings for ProxyResolverV8, which returns mock values. |
| 17 // Each time one of the bindings is called into, we push the input into a | 18 // Each time one of the bindings is called into, we push the input into a |
| 18 // list, for later verification. | 19 // list, for later verification. |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 EXPECT_EQ("3", bindings->dns_resolves[6]); | 371 EXPECT_EQ("3", bindings->dns_resolves[6]); |
| 371 | 372 |
| 372 EXPECT_EQ("arg1", bindings->dns_resolves[7]); | 373 EXPECT_EQ("arg1", bindings->dns_resolves[7]); |
| 373 | 374 |
| 374 // MyIpAddress was called two times. | 375 // MyIpAddress was called two times. |
| 375 EXPECT_EQ(2, bindings->my_ip_address_count); | 376 EXPECT_EQ(2, bindings->my_ip_address_count); |
| 376 } | 377 } |
| 377 | 378 |
| 378 TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { | 379 TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { |
| 379 // Get a hold of a DefaultJSBindings* (it is a hidden impl class). | 380 // Get a hold of a DefaultJSBindings* (it is a hidden impl class). |
| 380 net::ProxyResolverV8 resolver; | 381 net::HostResolver host_resolver; |
| 381 net::ProxyResolverV8::JSBindings* bindings = resolver.js_bindings(); | 382 scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( |
| 383 net::ProxyResolverV8::CreateDefaultBindings(&host_resolver, NULL)); |
| 382 | 384 |
| 383 // Considered an error. | 385 // Considered an error. |
| 384 EXPECT_EQ("", bindings->DnsResolve("")); | 386 EXPECT_EQ("", bindings->DnsResolve("")); |
| 385 | 387 |
| 386 const struct { | 388 const struct { |
| 387 const char* input; | 389 const char* input; |
| 388 const char* expected; | 390 const char* expected; |
| 389 } tests[] = { | 391 } tests[] = { |
| 390 {"www.google.com", "127.0.0.1"}, | 392 {"www.google.com", "127.0.0.1"}, |
| 391 {".", ""}, | 393 {".", ""}, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 421 // For now we just check that it maps to 127.0.0.1. | 423 // For now we just check that it maps to 127.0.0.1. |
| 422 std::string expected = tests[i].expected; | 424 std::string expected = tests[i].expected; |
| 423 if (expected == "") | 425 if (expected == "") |
| 424 expected = "127.0.0.1"; | 426 expected = "127.0.0.1"; |
| 425 EXPECT_EQ(expected, actual); | 427 EXPECT_EQ(expected, actual); |
| 426 } | 428 } |
| 427 } | 429 } |
| 428 | 430 |
| 429 TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { | 431 TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { |
| 430 // Get a hold of a DefaultJSBindings* (it is a hidden impl class). | 432 // Get a hold of a DefaultJSBindings* (it is a hidden impl class). |
| 431 net::ProxyResolverV8 resolver; | 433 net::HostResolver host_resolver; |
| 432 net::ProxyResolverV8::JSBindings* bindings = resolver.js_bindings(); | 434 scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( |
| 435 net::ProxyResolverV8::CreateDefaultBindings(&host_resolver, NULL)); |
| 433 | 436 |
| 434 // Our ip address is always going to be 127.0.0.1, since we are using a | 437 // Our ip address is always going to be 127.0.0.1, since we are using a |
| 435 // mock host mapper when running in unit-test mode. | 438 // mock host mapper when running in unit-test mode. |
| 436 std::string my_ip_address = bindings->MyIpAddress(); | 439 std::string my_ip_address = bindings->MyIpAddress(); |
| 437 | 440 |
| 438 EXPECT_EQ("127.0.0.1", my_ip_address); | 441 EXPECT_EQ("127.0.0.1", my_ip_address); |
| 439 } | 442 } |
| OLD | NEW |