summaryrefslogtreecommitdiffstats
path: root/net/log/test_net_log_entry.h
blob: a13297a752c0c7d42da311b64fe8c4928d221550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_LOG_TEST_NET_LOG_ENTRY_H_
#define NET_LOG_TEST_NET_LOG_ENTRY_H_

#include <string>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "net/log/net_log.h"

namespace base {
class DictionaryValue;
class ListValue;
}

namespace net {

// TestNetLogEntry is much like NetLog::Entry, except it has its own copy of all
// log data, so a list of entries can be gathered over the course of a test, and
// then inspected at the end.  It is intended for testing only, and is part of
// the net_test_support project.
struct TestNetLogEntry {
  // Ordered set of logged entries.
  typedef std::vector<TestNetLogEntry> List;

  TestNetLogEntry(NetLog::EventType type,
                  const base::TimeTicks& time,
                  NetLog::Source source,
                  NetLog::EventPhase phase,
                  scoped_ptr<base::DictionaryValue> params);
  // Copy constructor needed to store in a std::vector because of the
  // scoped_ptr.
  TestNetLogEntry(const TestNetLogEntry& entry);

  ~TestNetLogEntry();

  // Equality operator needed to store in a std::vector because of the
  // scoped_ptr.
  TestNetLogEntry& operator=(const TestNetLogEntry& entry);

  // Attempt to retrieve an value of the specified type with the given name
  // from |params|.  Returns true on success, false on failure.  Does not
  // modify |value| on failure.
  bool GetStringValue(const std::string& name, std::string* value) const;
  bool GetIntegerValue(const std::string& name, int* value) const;
  bool GetBooleanValue(const std::string& name, bool* value) const;
  bool GetListValue(const std::string& name, base::ListValue** value) const;

  // Same as GetIntegerValue, but returns the error code associated with a
  // log entry.
  bool GetNetErrorCode(int* value) const;

  // Returns the parameters as a JSON string, or empty string if there are no
  // parameters.
  std::string GetParamsJson() const;

  NetLog::EventType type;
  base::TimeTicks time;
  NetLog::Source source;
  NetLog::EventPhase phase;
  scoped_ptr<base::DictionaryValue> params;
};

}  // namespace net

#endif  // NET_LOG_TEST_NET_LOG_ENTRY_H_