Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: net/proxy/proxy_resolver_js_bindings_unittest.cc

Issue 303022: Disable IPv6 results for the PAC bindings:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/proxy/proxy_resolver_js_bindings_unittest.cc
===================================================================
--- net/proxy/proxy_resolver_js_bindings_unittest.cc (revision 29678)
+++ net/proxy/proxy_resolver_js_bindings_unittest.cc (working copy)
@@ -5,17 +5,19 @@
#include "base/scoped_ptr.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/net_errors.h"
+#include "net/base/net_util.h"
#include "net/proxy/proxy_resolver_js_bindings.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace net {
namespace {
TEST(ProxyResolverJSBindingsTest, DnsResolve) {
- scoped_refptr<net::MockHostResolver> host_resolver(new net::MockHostResolver);
+ scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver);
// Get a hold of a DefaultJSBindings* (it is a hidden impl class).
- scoped_ptr<net::ProxyResolverJSBindings> bindings(
- net::ProxyResolverJSBindings::CreateDefault(host_resolver, NULL));
+ scoped_ptr<ProxyResolverJSBindings> bindings(
+ ProxyResolverJSBindings::CreateDefault(host_resolver, NULL));
// Empty string is not considered a valid host (even though on some systems
// requesting this will resolve to localhost).
@@ -33,11 +35,11 @@
// won't work on all systems.
}
-TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) {
+TEST(ProxyResolverJSBindingsTest, MyIpAddress) {
// Get a hold of a DefaultJSBindings* (it is a hidden impl class).
- scoped_ptr<net::ProxyResolverJSBindings> bindings(
- net::ProxyResolverJSBindings::CreateDefault(
- new net::MockHostResolver, NULL));
+ scoped_ptr<ProxyResolverJSBindings> bindings(
+ ProxyResolverJSBindings::CreateDefault(
+ new MockHostResolver, NULL));
// Our IP address is always going to be 127.0.0.1, since we are using a
// mock host resolver.
@@ -46,4 +48,43 @@
EXPECT_EQ("127.0.0.1", my_ip_address);
}
+// Tests that myIpAddress() and dnsResolve() pass the flag
+// ADDRESS_FAMILY_IPV4_ONLY to the host resolver, as we don't want them
+// to return IPv6 results.
+TEST(ProxyResolverJSBindingsTest, DontUseIPv6) {
+ scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver);
+
+ // Get a hold of a DefaultJSBindings* (it is a hidden impl class).
+ scoped_ptr<ProxyResolverJSBindings> bindings(
+ ProxyResolverJSBindings::CreateDefault(
+ host_resolver, NULL));
+
+ // Make it so requests resolve to particular address patterns based on family:
+ // IPV4_ONLY --> 192.168.1.*
+ // UNSPECIFIED --> 192.168.2.1
+ host_resolver->rules()->AddRuleForFamily(
+ "foo", ADDRESS_FAMILY_IPV4_ONLY, "192.168.1.1");
+ host_resolver->rules()->AddRuleForFamily(
+ "*", ADDRESS_FAMILY_IPV4_ONLY, "192.168.1.2");
+ host_resolver->rules()->AddRuleForFamily(
+ "*", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.1");
+
+ // Verify that our mock setups works as expected, and we get different results
+ // depending if the address family was IPV4_ONLY or not.
+ HostResolver::RequestInfo info("foo", 80);
+ AddressList address_list;
+ EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, NULL, NULL, NULL));
+ EXPECT_EQ("192.168.2.1", NetAddressToString(address_list.head()));
+
+ info.set_address_family(ADDRESS_FAMILY_IPV4_ONLY);
+ EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, NULL, NULL, NULL));
+ EXPECT_EQ("192.168.1.1", NetAddressToString(address_list.head()));
+
+ // Now the actual test.
+ EXPECT_EQ("192.168.1.2", bindings->MyIpAddress());
+ EXPECT_EQ("192.168.1.1", bindings->DnsResolve("foo"));
+ EXPECT_EQ("192.168.1.2", bindings->DnsResolve("foo2"));
+}
+
} // namespace
+} // namespace net
« net/proxy/proxy_resolver_js_bindings.cc ('K') | « net/proxy/proxy_resolver_js_bindings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698