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. 4 5 #ifndef CHROME_TEST_CHROMEDRIVER_LOGGING_H_ 6 #define CHROME_TEST_CHROMEDRIVER_LOGGING_H_ 7 8 #include <string> 9 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" 15 16 struct Capabilities; 17 class CommandListener; 18 class DevToolsEventListener; 19 class ListValue; 20 struct Session; 21 class Status; 22 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 { 26 public: 27 static const char kBrowserType[]; 28 static const char kDriverType[]; 29 static const char kPerformanceType[]; 30 31 // Converts WD wire protocol level name -> Level, false on bad name. 32 static bool NameToLevel(const std::string& name, Level* out_level); 33 34 // Creates a WebDriverLog with the given type and minimum level. 35 WebDriverLog(const std::string& type, Level min_level); 36 virtual ~WebDriverLog(); 37 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(); 43 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; 47 48 // Translates a Log entry level into a WebDriver level and stores the entry. 49 virtual void AddEntryTimestamped(const base::Time& timestamp, 50 Level level, 51 const std::string& source, 52 const std::string& message) OVERRIDE; 53 54 const std::string& type() const; 55 void set_min_level(Level min_level); 56 Level min_level() const; 57 58 private: 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. 62 63 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); 64 }; 65 66 // Initializes logging system for ChromeDriver. Returns true on success. 67 bool InitLogging(); 68 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); 76 77 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ 78