| 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/mock_host_resolver.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/proxy/proxy_resolver_v8.h" | 11 #include "net/proxy/proxy_resolver_v8.h" |
| 12 #include "net/proxy/proxy_info.h" | 12 #include "net/proxy/proxy_info.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Javascript bindings for ProxyResolverV8, which returns mock values. | 17 // Javascript bindings for ProxyResolverV8, which returns mock values. |
| 18 // 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 |
| 19 // list, for later verification. | 19 // list, for later verification. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 372 |
| 373 EXPECT_EQ("arg1", bindings->dns_resolves[7]); | 373 EXPECT_EQ("arg1", bindings->dns_resolves[7]); |
| 374 | 374 |
| 375 // MyIpAddress was called two times. | 375 // MyIpAddress was called two times. |
| 376 EXPECT_EQ(2, bindings->my_ip_address_count); | 376 EXPECT_EQ(2, bindings->my_ip_address_count); |
| 377 } | 377 } |
| 378 | 378 |
| 379 TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { | 379 TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { |
| 380 // 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). |
| 381 scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( | 381 scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( |
| 382 net::ProxyResolverV8::CreateDefaultBindings(new net::HostResolver, NULL)); | 382 net::ProxyResolverV8::CreateDefaultBindings( |
| 383 new net::MockHostResolver, NULL)); |
| 383 | 384 |
| 384 // Considered an error. | 385 // Considered an error. |
| 385 EXPECT_EQ("", bindings->DnsResolve("")); | 386 EXPECT_EQ("", bindings->DnsResolve("")); |
| 386 | 387 |
| 387 const struct { | 388 const struct { |
| 388 const char* input; | 389 const char* input; |
| 389 const char* expected; | 390 const char* expected; |
| 390 } tests[] = { | 391 } tests[] = { |
| 391 {"www.google.com", "127.0.0.1"}, | 392 {"www.google.com", "127.0.0.1"}, |
| 392 {".", ""}, | 393 {".", ""}, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 404 | 405 |
| 405 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 406 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 406 std::string actual = bindings->DnsResolve(tests[i].input); | 407 std::string actual = bindings->DnsResolve(tests[i].input); |
| 407 | 408 |
| 408 // ######################################################################## | 409 // ######################################################################## |
| 409 // TODO(eroman) | 410 // TODO(eroman) |
| 410 // ######################################################################## | 411 // ######################################################################## |
| 411 // THIS TEST IS CURRENTLY FLAWED. | 412 // THIS TEST IS CURRENTLY FLAWED. |
| 412 // | 413 // |
| 413 // Since we are running in unit-test mode, the HostResolve is using a | 414 // Since we are running in unit-test mode, the HostResolve is using a |
| 414 // mock HostMapper, which will always return 127.0.0.1, without going | 415 // mock HostResolverProc, which will always return 127.0.0.1, without going |
| 415 // through the real codepaths. | 416 // through the real codepaths. |
| 416 // | 417 // |
| 417 // It is important that these tests be run with the real thing, since we | 418 // It is important that these tests be run with the real thing, since we |
| 418 // need to verify that HostResolver doesn't blow up when you send it | 419 // need to verify that HostResolver doesn't blow up when you send it |
| 419 // weird inputs. This is necessary since the data reach it is UNSANITIZED. | 420 // weird inputs. This is necessary since the data reach it is UNSANITIZED. |
| 420 // It comes directly from the PAC javascript. | 421 // It comes directly from the PAC javascript. |
| 421 // | 422 // |
| 422 // 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. |
| 423 std::string expected = tests[i].expected; | 424 std::string expected = tests[i].expected; |
| 424 if (expected == "") | 425 if (expected == "") |
| 425 expected = "127.0.0.1"; | 426 expected = "127.0.0.1"; |
| 426 EXPECT_EQ(expected, actual); | 427 EXPECT_EQ(expected, actual); |
| 427 } | 428 } |
| 428 } | 429 } |
| 429 | 430 |
| 430 TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { | 431 TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { |
| 431 // 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). |
| 432 scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( | 433 scoped_ptr<net::ProxyResolverV8::JSBindings> bindings( |
| 433 net::ProxyResolverV8::CreateDefaultBindings(new net::HostResolver, NULL)); | 434 net::ProxyResolverV8::CreateDefaultBindings( |
| 435 new net::MockHostResolver, NULL)); |
| 434 | 436 |
| 435 // 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 |
| 436 // mock host mapper when running in unit-test mode. | 438 // mock host resolver. |
| 437 std::string my_ip_address = bindings->MyIpAddress(); | 439 std::string my_ip_address = bindings->MyIpAddress(); |
| 438 | 440 |
| 439 EXPECT_EQ("127.0.0.1", my_ip_address); | 441 EXPECT_EQ("127.0.0.1", my_ip_address); |
| 440 } | 442 } |
| OLD | NEW |