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.
5 #ifndef NET_LOG_TEST_NET_LOG_H_
6 #define NET_LOG_TEST_NET_LOG_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "net/log/net_log.h"
14 #include "net/log/test_net_log_entry.h"
18 // TestNetLog is NetLog subclass which records all NetLog events that occur and
19 // their parameters. It is intended for testing only, and is part of the
20 // net_test_support project.
21 class TestNetLog
: public NetLog
{
24 ~TestNetLog() override
;
26 void SetCaptureMode(NetLogCaptureMode capture_mode
);
28 // Below methods are forwarded to test_net_log_observer_.
29 void GetEntries(TestNetLogEntry::List
* entry_list
) const;
30 void GetEntriesForSource(Source source
,
31 TestNetLogEntry::List
* entry_list
) const;
32 size_t GetSize() const;
35 // Returns a NetLog observer that will write entries to the TestNetLog's event
36 // store. For testing code that bypasses NetLogs and adds events directly to
38 NetLog::ThreadSafeObserver
* GetObserver() const;
41 // The underlying observer class that does all the work.
44 scoped_ptr
<Observer
> observer_
;
46 DISALLOW_COPY_AND_ASSIGN(TestNetLog
);
49 // Helper class that exposes a similar API as BoundNetLog, but uses a
50 // TestNetLog rather than the more generic NetLog.
52 // A BoundTestNetLog can easily be converted to a BoundNetLog using the
54 class BoundTestNetLog
{
59 // The returned BoundNetLog is only valid while |this| is alive.
60 BoundNetLog
bound() const { return net_log_
; }
62 // Fills |entry_list| with all entries in the log.
63 void GetEntries(TestNetLogEntry::List
* entry_list
) const;
65 // Fills |entry_list| with all entries in the log from the specified Source.
66 void GetEntriesForSource(NetLog::Source source
,
67 TestNetLogEntry::List
* entry_list
) const;
69 // Returns number of entries in the log.
70 size_t GetSize() const;
74 // Sets the capture mode of the underlying TestNetLog.
75 void SetCaptureMode(NetLogCaptureMode capture_mode
);
78 TestNetLog test_net_log_
;
79 const BoundNetLog net_log_
;
81 DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog
);
86 #endif // NET_LOG_TEST_NET_LOG_H_