| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "net/log/net_log.h" | 15 #include "net/log/net_log.h" |
| 16 #include "net/log/net_log_with_source.h" |
| 16 #include "net/log/test_net_log_entry.h" | 17 #include "net/log/test_net_log_entry.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 21 class NetLogCaptureMode; |
| 22 struct NetLogSource; |
| 23 |
| 20 // TestNetLog is NetLog subclass which records all NetLog events that occur and | 24 // TestNetLog is NetLog subclass which records all NetLog events that occur and |
| 21 // their parameters. It is intended for testing only, and is part of the | 25 // their parameters. It is intended for testing only, and is part of the |
| 22 // net_test_support project. | 26 // net_test_support project. |
| 23 class TestNetLog : public NetLog { | 27 class TestNetLog : public NetLog { |
| 24 public: | 28 public: |
| 25 TestNetLog(); | 29 TestNetLog(); |
| 26 ~TestNetLog() override; | 30 ~TestNetLog() override; |
| 27 | 31 |
| 28 void SetCaptureMode(NetLogCaptureMode capture_mode); | 32 void SetCaptureMode(NetLogCaptureMode capture_mode); |
| 29 | 33 |
| 30 // Below methods are forwarded to test_net_log_observer_. | 34 // Below methods are forwarded to test_net_log_observer_. |
| 31 void GetEntries(TestNetLogEntry::List* entry_list) const; | 35 void GetEntries(TestNetLogEntry::List* entry_list) const; |
| 32 void GetEntriesForSource(Source source, | 36 void GetEntriesForSource(NetLogSource source, |
| 33 TestNetLogEntry::List* entry_list) const; | 37 TestNetLogEntry::List* entry_list) const; |
| 34 size_t GetSize() const; | 38 size_t GetSize() const; |
| 35 void Clear(); | 39 void Clear(); |
| 36 | 40 |
| 37 // Returns a NetLog observer that will write entries to the TestNetLog's event | 41 // Returns a NetLog observer that will write entries to the TestNetLog's event |
| 38 // store. For testing code that bypasses NetLogs and adds events directly to | 42 // store. For testing code that bypasses NetLogs and adds events directly to |
| 39 // an observer. | 43 // an observer. |
| 40 NetLog::ThreadSafeObserver* GetObserver() const; | 44 NetLog::ThreadSafeObserver* GetObserver() const; |
| 41 | 45 |
| 42 private: | 46 private: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 BoundTestNetLog(); | 62 BoundTestNetLog(); |
| 59 ~BoundTestNetLog(); | 63 ~BoundTestNetLog(); |
| 60 | 64 |
| 61 // The returned NetLogWithSource is only valid while |this| is alive. | 65 // The returned NetLogWithSource is only valid while |this| is alive. |
| 62 NetLogWithSource bound() const { return net_log_; } | 66 NetLogWithSource bound() const { return net_log_; } |
| 63 | 67 |
| 64 // Fills |entry_list| with all entries in the log. | 68 // Fills |entry_list| with all entries in the log. |
| 65 void GetEntries(TestNetLogEntry::List* entry_list) const; | 69 void GetEntries(TestNetLogEntry::List* entry_list) const; |
| 66 | 70 |
| 67 // Fills |entry_list| with all entries in the log from the specified Source. | 71 // Fills |entry_list| with all entries in the log from the specified Source. |
| 68 void GetEntriesForSource(NetLog::Source source, | 72 void GetEntriesForSource(NetLogSource source, |
| 69 TestNetLogEntry::List* entry_list) const; | 73 TestNetLogEntry::List* entry_list) const; |
| 70 | 74 |
| 71 // Returns number of entries in the log. | 75 // Returns number of entries in the log. |
| 72 size_t GetSize() const; | 76 size_t GetSize() const; |
| 73 | 77 |
| 74 void Clear(); | 78 void Clear(); |
| 75 | 79 |
| 76 // Sets the capture mode of the underlying TestNetLog. | 80 // Sets the capture mode of the underlying TestNetLog. |
| 77 void SetCaptureMode(NetLogCaptureMode capture_mode); | 81 void SetCaptureMode(NetLogCaptureMode capture_mode); |
| 78 | 82 |
| 79 private: | 83 private: |
| 80 TestNetLog test_net_log_; | 84 TestNetLog test_net_log_; |
| 81 const NetLogWithSource net_log_; | 85 const NetLogWithSource net_log_; |
| 82 | 86 |
| 83 DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog); | 87 DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog); |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 } // namespace net | 90 } // namespace net |
| 87 | 91 |
| 88 #endif // NET_LOG_TEST_NET_LOG_H_ | 92 #endif // NET_LOG_TEST_NET_LOG_H_ |
| OLD | NEW |