| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // This is a HostResolver that synchronously resolves all hosts to the | 27 // This is a HostResolver that synchronously resolves all hosts to the |
| 28 // following address list of length 3: | 28 // following address list of length 3: |
| 29 // 192.168.1.1 | 29 // 192.168.1.1 |
| 30 // 172.22.34.1 | 30 // 172.22.34.1 |
| 31 // 200.100.1.2 | 31 // 200.100.1.2 |
| 32 class MockHostResolverWithMultipleResults : public SyncHostResolver { | 32 class MockHostResolverWithMultipleResults : public SyncHostResolver { |
| 33 public: | 33 public: |
| 34 // HostResolver methods: | 34 // HostResolver methods: |
| 35 virtual int Resolve(const HostResolver::RequestInfo& info, | 35 virtual int Resolve(const HostResolver::RequestInfo& info, |
| 36 AddressList* addresses) OVERRIDE { | 36 AddressList* addresses, |
| 37 const net::BoundNetLog& bound_net_log) OVERRIDE { |
| 37 return ParseAddressList("192.168.1.1,172.22.34.1,200.100.1.2", "", | 38 return ParseAddressList("192.168.1.1,172.22.34.1,200.100.1.2", "", |
| 38 addresses); | 39 addresses); |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual void Shutdown() OVERRIDE {} | 42 virtual void Shutdown() OVERRIDE {} |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 virtual ~MockHostResolverWithMultipleResults() {} | 45 virtual ~MockHostResolverWithMultipleResults() {} |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 class MockFailingHostResolver : public SyncHostResolver { | 48 class MockFailingHostResolver : public SyncHostResolver { |
| 48 public: | 49 public: |
| 49 MockFailingHostResolver() : count_(0) {} | 50 MockFailingHostResolver() : count_(0) {} |
| 50 | 51 |
| 51 // HostResolver methods: | 52 // HostResolver methods: |
| 52 virtual int Resolve(const HostResolver::RequestInfo& info, | 53 virtual int Resolve(const HostResolver::RequestInfo& info, |
| 53 AddressList* addresses) OVERRIDE { | 54 AddressList* addresses, |
| 55 const net::BoundNetLog& bound_net_log) OVERRIDE { |
| 54 count_++; | 56 count_++; |
| 55 return ERR_NAME_NOT_RESOLVED; | 57 return ERR_NAME_NOT_RESOLVED; |
| 56 } | 58 } |
| 57 | 59 |
| 58 virtual void Shutdown() OVERRIDE {} | 60 virtual void Shutdown() OVERRIDE {} |
| 59 | 61 |
| 60 // Returns the number of times Resolve() has been called. | 62 // Returns the number of times Resolve() has been called. |
| 61 int count() const { return count_; } | 63 int count() const { return count_; } |
| 62 void ResetCount() { count_ = 0; } | 64 void ResetCount() { count_ = 0; } |
| 63 | 65 |
| 64 private: | 66 private: |
| 65 int count_; | 67 int count_; |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 class MockSyncHostResolver : public SyncHostResolver { | 70 class MockSyncHostResolver : public SyncHostResolver { |
| 69 public: | 71 public: |
| 70 MockSyncHostResolver() { | 72 MockSyncHostResolver() { |
| 71 resolver_.set_synchronous_mode(true); | 73 resolver_.set_synchronous_mode(true); |
| 72 } | 74 } |
| 73 | 75 |
| 74 virtual int Resolve(const HostResolver::RequestInfo& info, | 76 virtual int Resolve(const HostResolver::RequestInfo& info, |
| 75 AddressList* addresses) OVERRIDE { | 77 AddressList* addresses, |
| 78 const net::BoundNetLog& bound_net_log) OVERRIDE { |
| 76 return resolver_.Resolve(info, addresses, CompletionCallback(), NULL, | 79 return resolver_.Resolve(info, addresses, CompletionCallback(), NULL, |
| 77 BoundNetLog()); | 80 bound_net_log); |
| 78 } | 81 } |
| 79 | 82 |
| 80 virtual void Shutdown() OVERRIDE {} | 83 virtual void Shutdown() OVERRIDE {} |
| 81 | 84 |
| 82 RuleBasedHostResolverProc* rules() { | 85 RuleBasedHostResolverProc* rules() { |
| 83 return resolver_.rules(); | 86 return resolver_.rules(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 private: | 89 private: |
| 87 MockHostResolver resolver_; | 90 MockHostResolver resolver_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 "*", ADDRESS_FAMILY_IPV4, "192.168.1.2"); | 160 "*", ADDRESS_FAMILY_IPV4, "192.168.1.2"); |
| 158 host_resolver->rules()->AddRuleForAddressFamily( | 161 host_resolver->rules()->AddRuleForAddressFamily( |
| 159 "foo", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.1"); | 162 "foo", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.1"); |
| 160 host_resolver->rules()->AddRuleForAddressFamily( | 163 host_resolver->rules()->AddRuleForAddressFamily( |
| 161 "*", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.2"); | 164 "*", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.2"); |
| 162 | 165 |
| 163 // Verify that our mock setups works as expected, and we get different results | 166 // Verify that our mock setups works as expected, and we get different results |
| 164 // depending if the address family was IPV4_ONLY or not. | 167 // depending if the address family was IPV4_ONLY or not. |
| 165 HostResolver::RequestInfo info(HostPortPair("foo", 80)); | 168 HostResolver::RequestInfo info(HostPortPair("foo", 80)); |
| 166 AddressList address_list; | 169 AddressList address_list; |
| 167 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list)); | 170 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, BoundNetLog())); |
| 168 EXPECT_EQ("192.168.2.1", NetAddressToString(address_list.head())); | 171 EXPECT_EQ("192.168.2.1", NetAddressToString(address_list.head())); |
| 169 | 172 |
| 170 info.set_address_family(ADDRESS_FAMILY_IPV4); | 173 info.set_address_family(ADDRESS_FAMILY_IPV4); |
| 171 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list)); | 174 EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, BoundNetLog())); |
| 172 EXPECT_EQ("192.168.1.1", NetAddressToString(address_list.head())); | 175 EXPECT_EQ("192.168.1.1", NetAddressToString(address_list.head())); |
| 173 | 176 |
| 174 std::string ip_address; | 177 std::string ip_address; |
| 175 // Now the actual test. | 178 // Now the actual test. |
| 176 EXPECT_TRUE(bindings->MyIpAddress(&ip_address)); | 179 EXPECT_TRUE(bindings->MyIpAddress(&ip_address)); |
| 177 EXPECT_EQ("192.168.1.2", ip_address); // IPv4 restricted. | 180 EXPECT_EQ("192.168.1.2", ip_address); // IPv4 restricted. |
| 178 | 181 |
| 179 EXPECT_TRUE(bindings->DnsResolve("foo", &ip_address)); | 182 EXPECT_TRUE(bindings->DnsResolve("foo", &ip_address)); |
| 180 EXPECT_EQ("192.168.1.1", ip_address); // IPv4 restricted. | 183 EXPECT_EQ("192.168.1.1", ip_address); // IPv4 restricted. |
| 181 | 184 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 global_log.GetEntries(&global_log_entries); | 355 global_log.GetEntries(&global_log_entries); |
| 353 EXPECT_EQ(2u, global_log_entries.size()); | 356 EXPECT_EQ(2u, global_log_entries.size()); |
| 354 EXPECT_TRUE(LogContainsEvent( | 357 EXPECT_TRUE(LogContainsEvent( |
| 355 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | 358 global_log_entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, |
| 356 NetLog::PHASE_NONE)); | 359 NetLog::PHASE_NONE)); |
| 357 } | 360 } |
| 358 | 361 |
| 359 } // namespace | 362 } // namespace |
| 360 | 363 |
| 361 } // namespace net | 364 } // namespace net |
| OLD | NEW |