diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 21:30:46 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 21:30:46 +0000 |
commit | eba291345caec278ef7b8f2a8c73b8b6c60f7364 (patch) | |
tree | 368f0fd8b38f05fe1d1d447d390823bf4bc0b7b6 /net/proxy | |
parent | 2455e073eb458b2ab5a7edbb337781152868b8c0 (diff) | |
download | chromium_src-eba291345caec278ef7b8f2a8c73b8b6c60f7364.zip chromium_src-eba291345caec278ef7b8f2a8c73b8b6c60f7364.tar.gz chromium_src-eba291345caec278ef7b8f2a8c73b8b6c60f7364.tar.bz2 |
Implement the PAC js-binding for "myIpAddress()".
BUG=2764
Review URL: http://codereview.chromium.org/38001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy')
-rw-r--r-- | net/proxy/proxy_resolver_v8.cc | 12 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_v8_unittest.cc | 15 |
2 files changed, 23 insertions, 4 deletions
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc index 81c1138..ef4ffd8 100644 --- a/net/proxy/proxy_resolver_v8.cc +++ b/net/proxy/proxy_resolver_v8.cc @@ -60,13 +60,17 @@ class DefaultJSBindings : public ProxyResolverV8::JSBindings { // Handler for "myIpAddress()". Returns empty string on failure. virtual std::string MyIpAddress() { - // TODO(eroman): - NOTIMPLEMENTED(); - return "127.0.0.1"; + // DnsResolve("") returns "", so no need to check for failure. + return DnsResolve(GetMyHostName()); } // Handler for "dnsResolve(host)". Returns empty string on failure. virtual std::string DnsResolve(const std::string& host) { + // TODO(eroman): Should this return our IP address, or fail, or + // simply be unspecified (works differently on windows and mac os x). + if (host.empty()) + return std::string(); + // Try to resolve synchronously. net::AddressList address_list; const int kPort = 80; // Doesn't matter what this is. @@ -236,6 +240,8 @@ class ProxyResolverV8::Context { // We shouldn't be called with any arguments, but will not complain if // we are. std::string result = context->js_bindings_->MyIpAddress(); + if (result.empty()) + result = "127.0.0.1"; return StdStringToV8String(result); } diff --git a/net/proxy/proxy_resolver_v8_unittest.cc b/net/proxy/proxy_resolver_v8_unittest.cc index c2ddb9f..5cbdfd4 100644 --- a/net/proxy/proxy_resolver_v8_unittest.cc +++ b/net/proxy/proxy_resolver_v8_unittest.cc @@ -380,12 +380,14 @@ TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { net::ProxyResolverV8 resolver; net::ProxyResolverV8::JSBindings* bindings = resolver.js_bindings(); + // Considered an error. + EXPECT_EQ("", bindings->DnsResolve("")); + const struct { const char* input; const char* expected; } tests[] = { {"www.google.com", "127.0.0.1"}, - {"", ""}, {".", ""}, {"foo@google.com", ""}, {"@google.com", ""}, @@ -424,3 +426,14 @@ TEST(ProxyResolverV8DefaultBindingsTest, DnsResolve) { } } +TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { + // Get a hold of a DefaultJSBindings* (it is a hidden impl class). + net::ProxyResolverV8 resolver; + net::ProxyResolverV8::JSBindings* bindings = resolver.js_bindings(); + + // Our ip address is always going to be 127.0.0.1, since we are using a + // mock host mapper when running in unit-test mode. + std::string my_ip_address = bindings->MyIpAddress(); + + EXPECT_EQ("127.0.0.1", my_ip_address); +} |