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 #ifndef NET_LOG_TEST_NET_LOG_H_ | 5 #ifndef NET_LOG_TEST_NET_LOG_H_ |
6 #define NET_LOG_TEST_NET_LOG_H_ | 6 #define NET_LOG_TEST_NET_LOG_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "net/log/captured_net_log_entry.h" | 13 #include "net/log/captured_net_log_entry.h" |
14 #include "net/log/capturing_net_log_observer.h" | 14 #include "net/log/capturing_net_log_observer.h" |
15 #include "net/log/net_log.h" | 15 #include "net/log/net_log.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 // TestNetLog is convenience class which combines a NetLog and a | 19 // TestNetLog is convenience class which combines a NetLog and a |
20 // CapturingNetLogObserver. It is intended for testing only, and is part of the | 20 // CapturingNetLogObserver. It is intended for testing only, and is part of the |
21 // net_test_support project. | 21 // net_test_support project. |
22 class TestNetLog : public NetLog { | 22 class TestNetLog : public NetLog { |
23 public: | 23 public: |
24 // TODO(mmenke): Get rid of these. | |
25 typedef CapturedNetLogEntry CapturedEntry; | |
26 typedef CapturedNetLogEntry::List CapturedEntryList; | |
27 | |
28 TestNetLog(); | 24 TestNetLog(); |
29 ~TestNetLog() override; | 25 ~TestNetLog() override; |
30 | 26 |
31 void SetCaptureMode(NetLogCaptureMode capture_mode); | 27 void SetCaptureMode(NetLogCaptureMode capture_mode); |
32 | 28 |
33 // Below methods are forwarded to capturing_net_log_observer_. | 29 // Below methods are forwarded to capturing_net_log_observer_. |
34 void GetEntries(CapturedEntryList* entry_list) const; | 30 void GetEntries(CapturedNetLogEntry::List* entry_list) const; |
35 void GetEntriesForSource(Source source, CapturedEntryList* entry_list) const; | 31 void GetEntriesForSource(Source source, |
| 32 CapturedNetLogEntry::List* entry_list) const; |
36 size_t GetSize() const; | 33 size_t GetSize() const; |
37 void Clear(); | 34 void Clear(); |
38 | 35 |
39 private: | 36 private: |
40 CapturingNetLogObserver capturing_net_log_observer_; | 37 CapturingNetLogObserver capturing_net_log_observer_; |
41 | 38 |
42 DISALLOW_COPY_AND_ASSIGN(TestNetLog); | 39 DISALLOW_COPY_AND_ASSIGN(TestNetLog); |
43 }; | 40 }; |
44 | 41 |
45 // Helper class that exposes a similar API as BoundNetLog, but uses a | 42 // Helper class that exposes a similar API as BoundNetLog, but uses a |
46 // TestNetLog rather than the more generic NetLog. | 43 // TestNetLog rather than the more generic NetLog. |
47 // | 44 // |
48 // A BoundTestNetLog can easily be converted to a BoundNetLog using the | 45 // A BoundTestNetLog can easily be converted to a BoundNetLog using the |
49 // bound() method. | 46 // bound() method. |
50 class BoundTestNetLog { | 47 class BoundTestNetLog { |
51 public: | 48 public: |
52 BoundTestNetLog(); | 49 BoundTestNetLog(); |
53 ~BoundTestNetLog(); | 50 ~BoundTestNetLog(); |
54 | 51 |
55 // The returned BoundNetLog is only valid while |this| is alive. | 52 // The returned BoundNetLog is only valid while |this| is alive. |
56 BoundNetLog bound() const { return net_log_; } | 53 BoundNetLog bound() const { return net_log_; } |
57 | 54 |
58 // Fills |entry_list| with all entries in the log. | 55 // Fills |entry_list| with all entries in the log. |
59 void GetEntries(TestNetLog::CapturedEntryList* entry_list) const; | 56 void GetEntries(CapturedNetLogEntry::List* entry_list) const; |
60 | 57 |
61 // Fills |entry_list| with all entries in the log from the specified Source. | 58 // Fills |entry_list| with all entries in the log from the specified Source. |
62 void GetEntriesForSource(NetLog::Source source, | 59 void GetEntriesForSource(NetLog::Source source, |
63 TestNetLog::CapturedEntryList* entry_list) const; | 60 CapturedNetLogEntry::List* entry_list) const; |
64 | 61 |
65 // Returns number of entries in the log. | 62 // Returns number of entries in the log. |
66 size_t GetSize() const; | 63 size_t GetSize() const; |
67 | 64 |
68 void Clear(); | 65 void Clear(); |
69 | 66 |
70 // Sets the capture mode of the underlying TestNetLog. | 67 // Sets the capture mode of the underlying TestNetLog. |
71 void SetCaptureMode(NetLogCaptureMode capture_mode); | 68 void SetCaptureMode(NetLogCaptureMode capture_mode); |
72 | 69 |
73 private: | 70 private: |
74 TestNetLog capturing_net_log_; | 71 TestNetLog capturing_net_log_; |
75 const BoundNetLog net_log_; | 72 const BoundNetLog net_log_; |
76 | 73 |
77 DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog); | 74 DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog); |
78 }; | 75 }; |
79 | 76 |
80 } // namespace net | 77 } // namespace net |
81 | 78 |
82 #endif // NET_LOG_TEST_NET_LOG_H_ | 79 #endif // NET_LOG_TEST_NET_LOG_H_ |
OLD | NEW |