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 DevToolsEventListener
;
21 // Accumulates WebDriver Logging API entries of a given type and minimum level.
22 // See https://code.google.com/p/selenium/wiki/Logging.
23 class WebDriverLog
: public Log
{
25 static const char kBrowserType
[];
26 static const char kDriverType
[];
27 static const char kPerformanceType
[];
29 // Converts WD wire protocol level name -> Level, false on bad name.
30 static bool NameToLevel(const std::string
& name
, Level
* out_level
);
32 // Creates a WebDriverLog with the given type and minimum level.
33 WebDriverLog(const std::string
& type
, Level min_level
);
34 virtual ~WebDriverLog();
36 // Returns entries accumulated so far, as a ListValue ready for serialization
37 // into the wire protocol response to the "/log" command.
38 // The caller assumes ownership of the ListValue, and the WebDriverLog
39 // creates and owns a new empty ListValue for further accumulation.
40 scoped_ptr
<base::ListValue
> GetAndClearEntries();
42 // Finds the first error message in the log and returns it. If none exist,
43 // returns an empty string. Does not clear entries.
44 std::string
GetFirstErrorMessage() const;
46 // Translates a Log entry level into a WebDriver level and stores the entry.
47 virtual void AddEntryTimestamped(const base::Time
& timestamp
,
49 const std::string
& source
,
50 const std::string
& message
) OVERRIDE
;
52 const std::string
& type() const;
53 void set_min_level(Level min_level
);
54 Level
min_level() const;
57 const std::string type_
; // WebDriver log type.
58 Level min_level_
; // Minimum level of entries to store.
59 scoped_ptr
<base::ListValue
> entries_
; // Accumulated entries.
61 DISALLOW_COPY_AND_ASSIGN(WebDriverLog
);
64 // Initializes logging system for ChromeDriver. Returns true on success.
67 // Creates Log's and DevToolsEventListener's based on logging preferences.
68 Status
CreateLogs(const Capabilities
& capabilities
,
69 ScopedVector
<WebDriverLog
>* out_logs
,
70 ScopedVector
<DevToolsEventListener
>* out_listeners
);
72 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_