| 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 static const char kBrowserType[]; |
| 26 static const char kDriverType[]; |
| 27 static const char kPerformanceType[]; |
| 28 |
| 25 // Converts WD wire protocol level name -> Level, false on bad name. | 29 // Converts WD wire protocol level name -> Level, false on bad name. |
| 26 static bool NameToLevel(const std::string& name, Level* out_level); | 30 static bool NameToLevel(const std::string& name, Level* out_level); |
| 27 | 31 |
| 28 // Creates a WebDriverLog with the given type and minimum level. | 32 // Creates a WebDriverLog with the given type and minimum level. |
| 29 WebDriverLog(const std::string& type, Level min_level); | 33 WebDriverLog(const std::string& type, Level min_level); |
| 30 virtual ~WebDriverLog(); | 34 virtual ~WebDriverLog(); |
| 31 | 35 |
| 32 // Returns entries accumulated so far, as a ListValue ready for serialization | 36 // Returns entries accumulated so far, as a ListValue ready for serialization |
| 33 // into the wire protocol response to the "/log" command. | 37 // into the wire protocol response to the "/log" command. |
| 34 // The caller assumes ownership of the ListValue, and the WebDriverLog | 38 // The caller assumes ownership of the ListValue, and the WebDriverLog |
| 35 // creates and owns a new empty ListValue for further accumulation. | 39 // creates and owns a new empty ListValue for further accumulation. |
| 36 scoped_ptr<base::ListValue> GetAndClearEntries(); | 40 scoped_ptr<base::ListValue> GetAndClearEntries(); |
| 37 | 41 |
| 38 // Translates a Log entry level into a WebDriver level and stores the entry. | 42 // Translates a Log entry level into a WebDriver level and stores the entry. |
| 39 virtual void AddEntryTimestamped(const base::Time& timestamp, | 43 virtual void AddEntryTimestamped(const base::Time& timestamp, |
| 40 Level level, | 44 Level level, |
| 41 const std::string& message) OVERRIDE; | 45 const std::string& message) OVERRIDE; |
| 42 | 46 |
| 43 const std::string& type() const; | 47 const std::string& type() const; |
| 48 void set_min_level(Level min_level); |
| 44 Level min_level() const; | 49 Level min_level() const; |
| 45 | 50 |
| 46 private: | 51 private: |
| 47 const std::string type_; // WebDriver log type. | 52 const std::string type_; // WebDriver log type. |
| 48 const Level min_level_; // Minimum level of entries to store. | 53 Level min_level_; // Minimum level of entries to store. |
| 49 scoped_ptr<base::ListValue> entries_; // Accumulated entries. | 54 scoped_ptr<base::ListValue> entries_; // Accumulated entries. |
| 50 | 55 |
| 51 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); | 56 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 // Initializes logging system for ChromeDriver. Returns true on success. | 59 // Initializes logging system for ChromeDriver. Returns true on success. |
| 55 bool InitLogging(); | 60 bool InitLogging(); |
| 56 | 61 |
| 57 // Creates Log's and DevToolsEventListener's based on logging preferences. | 62 // Creates Log's and DevToolsEventListener's based on logging preferences. |
| 58 Status CreateLogs(const Capabilities& capabilities, | 63 Status CreateLogs(const Capabilities& capabilities, |
| 59 ScopedVector<WebDriverLog>* out_logs, | 64 ScopedVector<WebDriverLog>* out_logs, |
| 60 scoped_ptr<WebDriverLog>* out_driver_log, | |
| 61 ScopedVector<DevToolsEventListener>* out_listeners); | 65 ScopedVector<DevToolsEventListener>* out_listeners); |
| 62 | 66 |
| 63 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ | 67 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ |
| OLD | NEW |