blob: 769f6720ae6daa88d8bd725281a8113ae0591bc1 [file] [log] [blame]
eroman87c53d62015-04-02 06:51:071// 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.b62985ca92015-04-17 08:45:515#ifndef NET_LOG_TEST_NET_LOG_H_
6#define NET_LOG_TEST_NET_LOG_H_
eroman87c53d62015-04-02 06:51:077
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
eroman87c53d62015-04-02 06:51:0713#include "net/log/net_log.h"
mmenke43758e62015-05-04 21:09:4614#include "net/log/test_net_log_entry.h"
15#include "net/log/test_net_log_observer.h"
eroman87c53d62015-04-02 06:51:0716
17namespace net {
18
vishal.b62985ca92015-04-17 08:45:5119// TestNetLog is convenience class which combines a NetLog and a
mmenke43758e62015-05-04 21:09:4620// TestNetLogObserver. It is intended for testing only, and is part of the
eroman87c53d62015-04-02 06:51:0721// net_test_support project.
vishal.b62985ca92015-04-17 08:45:5122class TestNetLog : public NetLog {
eroman87c53d62015-04-02 06:51:0723 public:
vishal.b62985ca92015-04-17 08:45:5124 TestNetLog();
25 ~TestNetLog() override;
eroman87c53d62015-04-02 06:51:0726
eroman001c3742015-04-23 03:11:1727 void SetCaptureMode(NetLogCaptureMode capture_mode);
eroman87c53d62015-04-02 06:51:0728
mmenke43758e62015-05-04 21:09:4629 // Below methods are forwarded to test_net_log_observer_.
30 void GetEntries(TestNetLogEntry::List* entry_list) const;
mmenke16a7cbdd2015-04-24 23:00:5631 void GetEntriesForSource(Source source,
mmenke43758e62015-05-04 21:09:4632 TestNetLogEntry::List* entry_list) const;
eroman87c53d62015-04-02 06:51:0733 size_t GetSize() const;
34 void Clear();
35
36 private:
mmenke43758e62015-05-04 21:09:4637 TestNetLogObserver test_net_log_observer_;
eroman87c53d62015-04-02 06:51:0738
vishal.b62985ca92015-04-17 08:45:5139 DISALLOW_COPY_AND_ASSIGN(TestNetLog);
eroman87c53d62015-04-02 06:51:0740};
41
42// Helper class that exposes a similar API as BoundNetLog, but uses a
vishal.b62985ca92015-04-17 08:45:5143// TestNetLog rather than the more generic NetLog.
eroman87c53d62015-04-02 06:51:0744//
vishal.b62985ca92015-04-17 08:45:5145// A BoundTestNetLog can easily be converted to a BoundNetLog using the
eroman87c53d62015-04-02 06:51:0746// bound() method.
vishal.b62985ca92015-04-17 08:45:5147class BoundTestNetLog {
eroman87c53d62015-04-02 06:51:0748 public:
vishal.b62985ca92015-04-17 08:45:5149 BoundTestNetLog();
50 ~BoundTestNetLog();
eroman87c53d62015-04-02 06:51:0751
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.
mmenke43758e62015-05-04 21:09:4656 void GetEntries(TestNetLogEntry::List* entry_list) const;
eroman87c53d62015-04-02 06:51:0757
58 // Fills |entry_list| with all entries in the log from the specified Source.
vishal.b62985ca92015-04-17 08:45:5159 void GetEntriesForSource(NetLog::Source source,
mmenke43758e62015-05-04 21:09:4660 TestNetLogEntry::List* entry_list) const;
eroman87c53d62015-04-02 06:51:0761
62 // Returns number of entries in the log.
63 size_t GetSize() const;
64
65 void Clear();
66
eroman001c3742015-04-23 03:11:1767 // Sets the capture mode of the underlying TestNetLog.
68 void SetCaptureMode(NetLogCaptureMode capture_mode);
eroman87c53d62015-04-02 06:51:0769
70 private:
mmenke43758e62015-05-04 21:09:4671 TestNetLog test_net_log_;
eroman87c53d62015-04-02 06:51:0772 const BoundNetLog net_log_;
73
vishal.b62985ca92015-04-17 08:45:5174 DISALLOW_COPY_AND_ASSIGN(BoundTestNetLog);
eroman87c53d62015-04-02 06:51:0775};
76
77} // namespace net
78
vishal.b62985ca92015-04-17 08:45:5179#endif // NET_LOG_TEST_NET_LOG_H_