-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathlogging.h
96 lines (75 loc) · 3.36 KB
/
logging.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_CHROMEDRIVER_LOGGING_H_
#define CHROME_TEST_CHROMEDRIVER_LOGGING_H_
#include <memory>
#include <string>
#include <vector>
#include "base/containers/circular_deque.h"
#include "base/values.h"
#include "chrome/test/chromedriver/chrome/log.h"
struct Capabilities;
class CommandListener;
class DevToolsEventListener;
struct Session;
class Status;
namespace internal {
static const size_t kMaxReturnedEntries = 100000;
} // namespace internal
// Accumulates WebDriver Logging API entries of a given type and minimum level.
// See https://code.google.com/p/selenium/wiki/Logging.
class WebDriverLog : public Log {
public:
static const char kBrowserType[];
static const char kDriverType[];
static const char kPerformanceType[];
static const char kDevToolsType[];
// Converts WD wire protocol level name -> Level, false on bad name.
static bool NameToLevel(const std::string& name, Level* out_level);
// Creates a WebDriverLog with the given type and minimum level.
WebDriverLog(const std::string& type, Level min_level);
WebDriverLog(const WebDriverLog&) = delete;
WebDriverLog& operator=(const WebDriverLog&) = delete;
~WebDriverLog() override;
// Returns entries accumulated so far, as a `base::Value::List` ready for
// serialization into the wire protocol response to the "/log" command. The
// caller assumes ownership of the list, and the WebDriverLog creates and owns
// a new empty list for further accumulation.
base::Value::List GetAndClearEntries();
// Finds the first error message in the log and returns it. If none exist,
// returns an empty string. Does not clear entries.
std::string GetFirstErrorMessage() const;
// Translates a Log entry level into a WebDriver level and stores the entry.
void AddEntryTimestamped(const base::Time& timestamp,
Level level,
const std::string& source,
const std::string& message) override;
// Whether or not batches_of_entries_ is empty when it is being emptied.
bool Emptied() const override;
const std::string& type() const;
void set_min_level(Level min_level);
Level min_level() const;
private:
const std::string type_; // WebDriver log type.
Level min_level_; // Minimum level of entries to store.
// Log is empty when it is emptied, or when it is initialized (because we
// want GetLog to collect trace events initially).
bool emptied_;
// A queue of batches of entries. Each batch can have no more than
// |kMaxReturnedEntries| values in it. This is to avoid HTTP response buffer
// overflow (crbug.com/681892).
base::circular_deque<base::Value::List> batches_of_entries_;
};
// Initializes logging system for ChromeDriver. Returns true on success.
bool InitLogging();
// Creates |Log|s, |DevToolsEventListener|s, and |CommandListener|s based on
// logging preferences.
Status CreateLogs(
const Capabilities& capabilities,
const Session* session,
std::vector<std::unique_ptr<WebDriverLog>>* out_logs,
std::vector<std::unique_ptr<DevToolsEventListener>>* out_devtools_listeners,
std::vector<std::unique_ptr<CommandListener>>* out_command_listeners);
const char* GetPortProtectionMessage();
#endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_