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

Side by Side Diff: net/dns/mock_host_resolver.h

Issue 2837813004: Sync the browser test host resolver with the network process before a test runs. (Closed)
Patch Set: review comments Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « content/utility/utility_service_factory.cc ('k') | net/dns/mock_host_resolver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_DNS_MOCK_HOST_RESOLVER_H_ 5 #ifndef NET_DNS_MOCK_HOST_RESOLVER_H_
6 #define NET_DNS_MOCK_HOST_RESOLVER_H_ 6 #define NET_DNS_MOCK_HOST_RESOLVER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <string>
12 13
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
17 #include "base/threading/non_thread_safe.h" 18 #include "base/threading/non_thread_safe.h"
18 #include "net/dns/host_resolver.h" 19 #include "net/dns/host_resolver.h"
19 #include "net/dns/host_resolver_proc.h" 20 #include "net/dns/host_resolver_proc.h"
20 21
21 namespace net { 22 namespace net {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Make sure that |host| will not be re-mapped or even processed by underlying 206 // Make sure that |host| will not be re-mapped or even processed by underlying
206 // host resolver procedures. It can also be a pattern. 207 // host resolver procedures. It can also be a pattern.
207 void AllowDirectLookup(const std::string& host); 208 void AllowDirectLookup(const std::string& host);
208 209
209 // Simulate a lookup failure for |host| (it also can be a pattern). 210 // Simulate a lookup failure for |host| (it also can be a pattern).
210 void AddSimulatedFailure(const std::string& host); 211 void AddSimulatedFailure(const std::string& host);
211 212
212 // Deletes all the rules that have been added. 213 // Deletes all the rules that have been added.
213 void ClearRules(); 214 void ClearRules();
214 215
216 // Causes method calls that add or delete rules to assert.
217 // TODO(jam): once this class isn't used by tests that use an out of process
218 // network service, remove this method and make Rule private.
219 void DisableModifications();
220
215 // HostResolverProc methods: 221 // HostResolverProc methods:
216 int Resolve(const std::string& host, 222 int Resolve(const std::string& host,
217 AddressFamily address_family, 223 AddressFamily address_family,
218 HostResolverFlags host_resolver_flags, 224 HostResolverFlags host_resolver_flags,
219 AddressList* addrlist, 225 AddressList* addrlist,
220 int* os_error) override; 226 int* os_error) override;
221 227
222 private: 228 struct Rule {
223 struct Rule; 229 enum ResolverType {
230 kResolverTypeFail,
231 kResolverTypeSystem,
232 kResolverTypeIPLiteral,
233 };
234
235 Rule(ResolverType resolver_type,
236 const std::string& host_pattern,
237 AddressFamily address_family,
238 HostResolverFlags host_resolver_flags,
239 const std::string& replacement,
240 const std::string& canonical_name,
241 int latency_ms);
242 Rule(const Rule& other);
243
244 ResolverType resolver_type;
245 std::string host_pattern;
246 AddressFamily address_family;
247 HostResolverFlags host_resolver_flags;
248 std::string replacement;
249 std::string canonical_name;
250 int latency_ms; // In milliseconds.
251 };
252
224 typedef std::list<Rule> RuleList; 253 typedef std::list<Rule> RuleList;
225 254
255 RuleList GetRules();
256
257 private:
226 ~RuleBasedHostResolverProc() override; 258 ~RuleBasedHostResolverProc() override;
227 259
228 void AddRuleInternal(const Rule& rule); 260 void AddRuleInternal(const Rule& rule);
229 261
230 RuleList rules_; 262 RuleList rules_;
231 263
232 // Must be obtained before writing to or reading from |rules_|. 264 // Must be obtained before writing to or reading from |rules_|.
233 base::Lock rule_lock_; 265 base::Lock rule_lock_;
266
267 // Whether changes are allowed.
268 bool modifications_allowed_;
234 }; 269 };
235 270
236 // Create rules that map all requests to localhost. 271 // Create rules that map all requests to localhost.
237 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc(); 272 RuleBasedHostResolverProc* CreateCatchAllHostResolverProc();
238 273
239 // HangingHostResolver never completes its |Resolve| request. 274 // HangingHostResolver never completes its |Resolve| request.
240 class HangingHostResolver : public HostResolver { 275 class HangingHostResolver : public HostResolver {
241 public: 276 public:
242 int Resolve(const RequestInfo& info, 277 int Resolve(const RequestInfo& info,
243 RequestPriority priority, 278 RequestPriority priority,
(...skipping 25 matching lines...) Expand all
269 void Init(HostResolverProc* proc); 304 void Init(HostResolverProc* proc);
270 305
271 private: 306 private:
272 scoped_refptr<HostResolverProc> current_proc_; 307 scoped_refptr<HostResolverProc> current_proc_;
273 scoped_refptr<HostResolverProc> previous_proc_; 308 scoped_refptr<HostResolverProc> previous_proc_;
274 }; 309 };
275 310
276 } // namespace net 311 } // namespace net
277 312
278 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_ 313 #endif // NET_DNS_MOCK_HOST_RESOLVER_H_
OLDNEW
« no previous file with comments | « content/utility/utility_service_factory.cc ('k') | net/dns/mock_host_resolver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698