| 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 #ifndef NET_BASE_MOCK_HOST_RESOLVER_H_ | 5 #ifndef NET_BASE_MOCK_HOST_RESOLVER_H_ |
| 6 #define NET_BASE_MOCK_HOST_RESOLVER_H_ | 6 #define NET_BASE_MOCK_HOST_RESOLVER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 class RuleBasedHostResolverProc : public HostResolverProc { | 91 class RuleBasedHostResolverProc : public HostResolverProc { |
| 92 public: | 92 public: |
| 93 explicit RuleBasedHostResolverProc(HostResolverProc* previous); | 93 explicit RuleBasedHostResolverProc(HostResolverProc* previous); |
| 94 ~RuleBasedHostResolverProc(); | 94 ~RuleBasedHostResolverProc(); |
| 95 | 95 |
| 96 // Any hostname matching the given pattern will be replaced with the given | 96 // Any hostname matching the given pattern will be replaced with the given |
| 97 // replacement value. Usually, replacement should be an IP address literal. | 97 // replacement value. Usually, replacement should be an IP address literal. |
| 98 void AddRule(const std::string& host_pattern, | 98 void AddRule(const std::string& host_pattern, |
| 99 const std::string& replacement); | 99 const std::string& replacement); |
| 100 | 100 |
| 101 // Same as AddRule(), but the replacement is expected to be an IPV6 literal. |
| 102 // You should use this in place of AddRule(), since the system's host resolver |
| 103 // may not support IPv6 literals on all systems. Whereas this variant |
| 104 // constructs the socket address directly so it will always work. |
| 105 void AddIPv6Rule(const std::string& host_pattern, |
| 106 const std::string& ipv6_literal); |
| 107 |
| 101 void AddRuleWithLatency(const std::string& host_pattern, | 108 void AddRuleWithLatency(const std::string& host_pattern, |
| 102 const std::string& replacement, | 109 const std::string& replacement, |
| 103 int latency_ms); | 110 int latency_ms); |
| 104 | 111 |
| 105 // Make sure that |host| will not be re-mapped or even processed by underlying | 112 // Make sure that |host| will not be re-mapped or even processed by underlying |
| 106 // host resolver procedures. It can also be a pattern. | 113 // host resolver procedures. It can also be a pattern. |
| 107 void AllowDirectLookup(const std::string& host); | 114 void AllowDirectLookup(const std::string& host); |
| 108 | 115 |
| 109 // Simulate a lookup failure for |host| (it also can be a pattern). | 116 // Simulate a lookup failure for |host| (it also can be a pattern). |
| 110 void AddSimulatedFailure(const std::string& host); | 117 void AddSimulatedFailure(const std::string& host); |
| 111 | 118 |
| 112 // HostResolverProc methods: | 119 // HostResolverProc methods: |
| 113 virtual int Resolve(const std::string& host, AddressList* addrlist); | 120 virtual int Resolve(const std::string& host, AddressList* addrlist); |
| 114 | 121 |
| 115 private: | 122 private: |
| 116 struct Rule; | 123 struct Rule; |
| 117 typedef std::list<Rule> RuleList; | 124 typedef std::list<Rule> RuleList; |
| 125 |
| 118 RuleList rules_; | 126 RuleList rules_; |
| 119 }; | 127 }; |
| 120 | 128 |
| 121 // Using WaitingHostResolverProc you can simulate very long lookups. | 129 // Using WaitingHostResolverProc you can simulate very long lookups. |
| 122 class WaitingHostResolverProc : public HostResolverProc { | 130 class WaitingHostResolverProc : public HostResolverProc { |
| 123 public: | 131 public: |
| 124 explicit WaitingHostResolverProc(HostResolverProc* previous) | 132 explicit WaitingHostResolverProc(HostResolverProc* previous) |
| 125 : HostResolverProc(previous), event_(false, false) {} | 133 : HostResolverProc(previous), event_(false, false) {} |
| 126 | 134 |
| 127 void Signal() { | 135 void Signal() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 154 void Init(HostResolverProc* proc); | 162 void Init(HostResolverProc* proc); |
| 155 | 163 |
| 156 private: | 164 private: |
| 157 scoped_refptr<HostResolverProc> current_proc_; | 165 scoped_refptr<HostResolverProc> current_proc_; |
| 158 scoped_refptr<HostResolverProc> previous_proc_; | 166 scoped_refptr<HostResolverProc> previous_proc_; |
| 159 }; | 167 }; |
| 160 | 168 |
| 161 } // namespace net | 169 } // namespace net |
| 162 | 170 |
| 163 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ | 171 #endif // NET_BASE_MOCK_HOST_RESOLVER_H_ |
| OLD | NEW |