1 // Copyright (c) 2013 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 CHROME_TEST_CHROMEDRIVER_LOGGING_H_
6 #define CHROME_TEST_CHROMEDRIVER_LOGGING_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/values.h"
14 #include "chrome/test/chromedriver/chrome/log.h"
17 class CommandListener
;
18 class DevToolsEventListener
;
23 // Accumulates WebDriver Logging API entries of a given type and minimum level.
24 // See https://code.google.com/p/selenium/wiki/Logging.
25 class WebDriverLog
: public Log
{
27 static const char kBrowserType
[];
28 static const char kDriverType
[];
29 static const char kPerformanceType
[];
31 // Converts WD wire protocol level name -> Level, false on bad name.
32 static bool NameToLevel(const std::string
& name
, Level
* out_level
);
34 // Creates a WebDriverLog with the given type and minimum level.
35 WebDriverLog(const std::string
& type
, Level min_level
);
36 ~WebDriverLog() override
;
38 // Returns entries accumulated so far, as a ListValue ready for serialization
39 // into the wire protocol response to the "/log" command.
40 // The caller assumes ownership of the ListValue, and the WebDriverLog
41 // creates and owns a new empty ListValue for further accumulation.
42 scoped_ptr
<base::ListValue
> GetAndClearEntries();
44 // Finds the first error message in the log and returns it. If none exist,
45 // returns an empty string. Does not clear entries.
46 std::string
GetFirstErrorMessage() const;
48 // Translates a Log entry level into a WebDriver level and stores the entry.
49 void AddEntryTimestamped(const base::Time
& timestamp
,
51 const std::string
& source
,
52 const std::string
& message
) override
;
54 const std::string
& type() const;
55 void set_min_level(Level min_level
);
56 Level
min_level() const;
59 const std::string type_
; // WebDriver log type.
60 Level min_level_
; // Minimum level of entries to store.
61 scoped_ptr
<base::ListValue
> entries_
; // Accumulated entries.
63 DISALLOW_COPY_AND_ASSIGN(WebDriverLog
);
66 // Initializes logging system for ChromeDriver. Returns true on success.
69 // Creates |Log|s, |DevToolsEventListener|s, and |CommandListener|s based on
70 // logging preferences.
71 Status
CreateLogs(const Capabilities
& capabilities
,
72 const Session
* session
,
73 ScopedVector
<WebDriverLog
>* out_logs
,
74 ScopedVector
<DevToolsEventListener
>* out_devtools_listeners
,
75 ScopedVector
<CommandListener
>* out_command_listeners
);
77 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_