OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_TEST_CHROMEDRIVER_LOGGING_H_ | 5 #ifndef CHROME_TEST_CHROMEDRIVER_LOGGING_H_ |
6 #define CHROME_TEST_CHROMEDRIVER_LOGGING_H_ | 6 #define CHROME_TEST_CHROMEDRIVER_LOGGING_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/test/chromedriver/chrome/log.h" | 14 #include "chrome/test/chromedriver/chrome/log.h" |
15 | 15 |
16 struct Capabilities; | 16 struct Capabilities; |
17 class DevToolsEventListener; | 17 class DevToolsEventListener; |
18 class ListValue; | 18 class ListValue; |
19 class Status; | 19 class Status; |
20 | 20 |
21 // Accumulates WebDriver Logging API entries of a given type and minimum level. | 21 // Accumulates WebDriver Logging API entries of a given type and minimum level. |
22 // See https://code.google.com/p/selenium/wiki/Logging. | 22 // See https://code.google.com/p/selenium/wiki/Logging. |
23 class WebDriverLog : public Log { | 23 class WebDriverLog : public Log { |
24 public: | 24 public: |
25 // Constants corresponding to log entry severity levels in the wire protocol. | 25 // Converts WD wire protocol level name -> Level, false on bad name. |
26 enum WebDriverLevel { | 26 static bool NameToLevel(const std::string& name, Level* out_level); |
27 kWdAll, | |
28 kWdDebug, | |
29 kWdInfo, | |
30 kWdWarning, | |
31 kWdSevere, | |
32 kWdOff | |
33 }; | |
34 | |
35 // Converts WD wire protocol level name -> WebDriverLevel, false on bad name. | |
36 static bool NameToLevel(const std::string& name, WebDriverLevel* out_level); | |
37 | 27 |
38 // Creates a WebDriverLog with the given type and minimum level. | 28 // Creates a WebDriverLog with the given type and minimum level. |
39 WebDriverLog(const std::string& type, WebDriverLevel min_wd_level); | 29 WebDriverLog(const std::string& type, Level min_level); |
40 virtual ~WebDriverLog(); | 30 virtual ~WebDriverLog(); |
41 | 31 |
42 // Returns this log's type, for the WD wire protocol "/log" and "/log/types". | |
43 const std::string& GetType(); | |
44 | |
45 // Returns entries accumulated so far, as a ListValue ready for serialization | 32 // Returns entries accumulated so far, as a ListValue ready for serialization |
46 // into the wire protocol response to the "/log" command. | 33 // into the wire protocol response to the "/log" command. |
47 // The caller assumes ownership of the ListValue, and the WebDriverLog | 34 // The caller assumes ownership of the ListValue, and the WebDriverLog |
48 // creates and owns a new empty ListValue for further accumulation. | 35 // creates and owns a new empty ListValue for further accumulation. |
49 scoped_ptr<base::ListValue> GetAndClearEntries(); | 36 scoped_ptr<base::ListValue> GetAndClearEntries(); |
50 | 37 |
51 // Translates a Log entry level into a WebDriver level and stores the entry. | 38 // Translates a Log entry level into a WebDriver level and stores the entry. |
52 virtual void AddEntryTimestamped(const base::Time& timestamp, | 39 virtual void AddEntryTimestamped(const base::Time& timestamp, |
53 Level level, | 40 Level level, |
54 const std::string& message) OVERRIDE; | 41 const std::string& message) OVERRIDE; |
55 | 42 |
| 43 const std::string& type() const; |
| 44 Level min_level() const; |
| 45 |
56 private: | 46 private: |
57 const std::string type_; // WebDriver log type. | 47 const std::string type_; // WebDriver log type. |
58 const WebDriverLevel min_wd_level_; // Minimum level of entries to store. | 48 const Level min_level_; // Minimum level of entries to store. |
59 scoped_ptr<base::ListValue> entries_; // Accumulated entries. | 49 scoped_ptr<base::ListValue> entries_; // Accumulated entries. |
60 | 50 |
61 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); | 51 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); |
62 }; | 52 }; |
63 | 53 |
64 // Creates Log's and DevToolsEventListener's for ones that are DevTools-based. | 54 // Initializes logging system for ChromeDriver. Returns true on success. |
| 55 bool InitLogging(); |
| 56 |
| 57 // Creates Log's and DevToolsEventListener's based on logging preferences. |
65 Status CreateLogs(const Capabilities& capabilities, | 58 Status CreateLogs(const Capabilities& capabilities, |
66 ScopedVector<WebDriverLog>* out_devtools_logs, | 59 ScopedVector<WebDriverLog>* out_logs, |
| 60 scoped_ptr<WebDriverLog>* out_driver_log, |
67 ScopedVector<DevToolsEventListener>* out_listeners); | 61 ScopedVector<DevToolsEventListener>* out_listeners); |
68 | 62 |
69 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ | 63 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ |
OLD | NEW |