eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5 | #ifndef NET_LOG_TEST_NET_LOG_H_ |
6 | #define NET_LOG_TEST_NET_LOG_H_ | ||||
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | #include <vector> | ||||
10 | |||||
11 | #include "base/basictypes.h" | ||||
12 | #include "base/compiler_specific.h" | ||||
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 13 | #include "net/log/net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 14 | #include "net/log/test_net_log_entry.h" |
15 | #include "net/log/test_net_log_observer.h" | ||||
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 16 | |
17 | namespace net { | ||||
18 | |||||
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 19 | // TestNetLog is convenience class which combines a NetLog and a |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 20 | // TestNetLogObserver. It is intended for testing only, and is part of the |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 21 | // net_test_support project. |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 22 | class TestNetLog : public NetLog { |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 23 | public: |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 24 | TestNetLog(); |
25 | ~TestNetLog() override; | ||||
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 26 | |
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 27 | void SetCaptureMode(NetLogCaptureMode capture_mode); |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 28 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 29 | // Below methods are forwarded to test_net_log_observer_. |
30 | void GetEntries(TestNetLogEntry::List* entry_list) const; | ||||
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 31 | void GetEntriesForSource(Source source, |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 32 | TestNetLogEntry::List* entry_list) const; |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 33 | size_t GetSize() const; |
34 | void Clear(); | ||||
35 | |||||
36 | private: | ||||
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 37 | TestNetLogObserver test_net_log_observer_; |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 38 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 39 | DISALLOW_COPY_AND_ASSIGN(TestNetLog); |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 40 | }; |
41 | |||||
42 | // Helper class that exposes a similar API as BoundNetLog, but uses a | ||||
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 43 | // TestNetLog rather than the more generic NetLog. |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 44 | // |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 45 | // A BoundTestNetLog can easily be converted to a BoundNetLog using the |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 46 | // bound() method. |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 47 | class BoundTestNetLog { |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 48 | public: |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 49 | BoundTestNetLog(); |
50 | ~BoundTestNetLog(); | ||||
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 51 | |
52 | // The returned BoundNetLog is only valid while |this| is alive. | ||||
53 | BoundNetLog bound() const { return net_log_; } | ||||
54 | |||||
55 | // Fills |entry_list| with all entries in the log. | ||||
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 56 | void GetEntries(TestNetLogEntry::List* entry_list) const; |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | |
58 | // Fills |entry_list| with all entries in the log from the specified Source. | ||||
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 59 | void GetEntriesForSource(NetLog::Source source, |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 60 | TestNetLogEntry::List* entry_list) const; |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 61 | |
62 | // Returns number of entries in the log. | ||||
63 | size_t GetSize() const; | ||||
64 | |||||
65 | void Clear(); | ||||
66 | |||||
eroman | 001c374 | 2015-04-23 03:11:17 | [diff] [blame] | 67 | // Sets the capture mode of the underlying TestNetLog. |
68 | void SetCaptureMode(NetLogCaptureMode capture_mode); | ||||
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 69 | |
70 | private: | ||||
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 71 | TestNetLog test_net_log_; |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 72 | const BoundNetLog net_log_; |
73 | |||||
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog); |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 75 | }; |
76 | |||||
77 | } // namespace net | ||||
78 | |||||
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 79 | #endif // NET_LOG_TEST_NET_LOG_H_ |