| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/proxy/proxy_resolver_js_bindings.h" | 5 #include "net/proxy/proxy_resolver_js_bindings.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| 11 #include "net/base/host_cache.h" | 11 #include "net/base/host_cache.h" |
| 12 #include "net/base/mock_host_resolver.h" | 12 #include "net/base/mock_host_resolver.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_log.h" | 14 #include "net/base/net_log.h" |
| 15 #include "net/base/net_log_unittest.h" | 15 #include "net/base/net_log_unittest.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "net/base/sys_addrinfo.h" | |
| 18 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
| 19 #include "net/proxy/proxy_resolver_request_context.h" | 18 #include "net/proxy/proxy_resolver_request_context.h" |
| 20 #include "net/proxy/sync_host_resolver.h" | 19 #include "net/proxy/sync_host_resolver.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 namespace net { | 22 namespace net { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 // This is a HostResolver that synchronously resolves all hosts to the | 26 // This is a HostResolver that synchronously resolves all hosts to the |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 host_resolver->rules()->AddRuleForAddressFamily( | 160 host_resolver->rules()->AddRuleForAddressFamily( |
| 162 "foo", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.1"); | 161 "foo", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.1"); |
| 163 host_resolver->rules()->AddRuleForAddressFamily( | 162 host_resolver->rules()->AddRuleForAddressFamily( |
| 164 "*", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.2"); | 163 "*", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.2"); |
| 165 | 164 |
| 166 // Verify that our mock setups works as expected, and we get different results | 165 // Verify that our mock setups works as expected, and we get different results |
| 167 // depending if the address family was IPV4_ONLY or not. | 166 // depending if the address family was IPV4_ONLY or not. |
| 168 HostResolver::RequestInfo info(HostPortPair("foo", 80)); | 167 HostResolver::RequestInfo info(HostPortPair("foo", 80)); |
| 169 AddressList address_list; | 168 AddressList address_list; |
| 170 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, BoundNetLog())); | 169 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, BoundNetLog())); |
| 171 EXPECT_EQ("192.168.2.1", NetAddressToString(address_list.head())); | 170 ASSERT_FALSE(address_list.empty()); |
| 171 EXPECT_EQ("192.168.2.1", address_list.front().ToStringWithoutPort()); |
| 172 | 172 |
| 173 info.set_address_family(ADDRESS_FAMILY_IPV4); | 173 info.set_address_family(ADDRESS_FAMILY_IPV4); |
| 174 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, BoundNetLog())); | 174 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, BoundNetLog())); |
| 175 EXPECT_EQ("192.168.1.1", NetAddressToString(address_list.head())); | 175 ASSERT_FALSE(address_list.empty()); |
| 176 EXPECT_EQ("192.168.1.1", address_list.front().ToStringWithoutPort()); |
| 176 | 177 |
| 177 std::string ip_address; | 178 std::string ip_address; |
| 178 // Now the actual test. | 179 // Now the actual test. |
| 179 EXPECT_TRUE(bindings->MyIpAddress(&ip_address)); | 180 EXPECT_TRUE(bindings->MyIpAddress(&ip_address)); |
| 180 EXPECT_EQ("192.168.1.2", ip_address); // IPv4 restricted. | 181 EXPECT_EQ("192.168.1.2", ip_address); // IPv4 restricted. |
| 181 | 182 |
| 182 EXPECT_TRUE(bindings->DnsResolve("foo", &ip_address)); | 183 EXPECT_TRUE(bindings->DnsResolve("foo", &ip_address)); |
| 183 EXPECT_EQ("192.168.1.1", ip_address); // IPv4 restricted. | 184 EXPECT_EQ("192.168.1.1", ip_address); // IPv4 restricted. |
| 184 | 185 |
| 185 EXPECT_TRUE(bindings->DnsResolve("foo2", &ip_address)); | 186 EXPECT_TRUE(bindings->DnsResolve("foo2", &ip_address)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 global_log.GetEntries(&global_log_entries); | 356 global_log.GetEntries(&global_log_entries); |
| 356 EXPECT_EQ(2u, global_log_entries.size()); | 357 EXPECT_EQ(2u, global_log_entries.size()); |
| 357 EXPECT_TRUE(LogContainsEvent( | 358 EXPECT_TRUE(LogContainsEvent( |
| 358 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 359 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 359 NetLog::PHASE_NONE)); | 360 NetLog::PHASE_NONE)); |
| 360 } | 361 } |
| 361 | 362 |
| 362 } // namespace | 363 } // namespace |
| 363 | 364 |
| 364 } // namespace net | 365 } // namespace net |
| OLD | NEW |