OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_BASE_TEST_HOST_RESOLVER_OBSERVER_H_ | |
6 #define NET_BASE_TEST_HOST_RESOLVER_OBSERVER_H_ | |
7 #pragma once | |
8 | |
9 #include "net/base/host_resolver.h" | |
10 | |
11 #include <vector> | |
12 | |
13 namespace net { | |
14 | |
15 bool operator==(const HostResolver::RequestInfo& a, | |
16 const HostResolver::RequestInfo& b); | |
17 | |
18 // Observer that just makes note of how it was called. The test code can then | |
19 // inspect to make sure it was called with the right parameters. Used by | |
20 // HostResolverImpl and AsyncHostResolver unit tests. | |
21 class TestHostResolverObserver : public HostResolver::Observer { | |
22 public: | |
23 TestHostResolverObserver(); | |
24 virtual ~TestHostResolverObserver(); | |
25 | |
26 // HostResolver::Observer methods: | |
27 virtual void OnStartResolution(int id, const HostResolver::RequestInfo& info); | |
28 virtual void OnFinishResolutionWithStatus( | |
29 int id, | |
30 bool was_resolved, | |
31 const HostResolver::RequestInfo& info); | |
32 virtual void OnCancelResolution( | |
33 int id, | |
34 const HostResolver::RequestInfo& info); | |
35 | |
36 // Tuple (id, info). | |
37 struct StartOrCancelEntry { | |
38 StartOrCancelEntry(int id, const HostResolver::RequestInfo& info) | |
39 : id(id), info(info) {} | |
40 | |
41 bool operator==(const StartOrCancelEntry& other) const { | |
42 return id == other.id && info == other.info; | |
43 } | |
44 | |
45 int id; | |
46 HostResolver::RequestInfo info; | |
47 }; | |
48 | |
49 // Tuple (id, was_resolved, info). | |
50 struct FinishEntry { | |
51 FinishEntry(int id, bool was_resolved, | |
52 const HostResolver::RequestInfo& info) | |
53 : id(id), was_resolved(was_resolved), info(info) {} | |
54 | |
55 bool operator==(const FinishEntry& other) const { | |
56 return id == other.id && | |
57 was_resolved == other.was_resolved && | |
58 info == other.info; | |
59 } | |
60 | |
61 int id; | |
62 bool was_resolved; | |
63 HostResolver::RequestInfo info; | |
64 }; | |
65 | |
66 std::vector<StartOrCancelEntry> start_log; | |
67 std::vector<FinishEntry> finish_log; | |
68 std::vector<StartOrCancelEntry> cancel_log; | |
69 }; | |
70 | |
71 } // namespace net | |
72 | |
73 #endif // NET_BASE_TEST_HOST_RESOLVER_OBSERVER_H_ | |
OLD | NEW |