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 DevToolsEventListener; 18 class ListValue; 19 class Status; 20 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 { 24 public: 25 static const char kBrowserType[]; 26 static const char kDriverType[]; 27 static const char kPerformanceType[]; 28 29 // Converts WD wire protocol level name -> Level, false on bad name. 30 static bool NameToLevel(const std::string& name, Level* out_level); 31 32 // Creates a WebDriverLog with the given type and minimum level. 33 WebDriverLog(const std::string& type, Level min_level); 34 virtual ~WebDriverLog(); 35 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(); 41 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; 45 46 // Translates a Log entry level into a WebDriver level and stores the entry. 47 virtual void AddEntryTimestamped(const base::Time& timestamp, 48 Level level, 49 const std::string& source, 50 const std::string& message) OVERRIDE; 51 52 const std::string& type() const; 53 void set_min_level(Level min_level); 54 Level min_level() const; 55 56 private: 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. 60 61 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); 62 }; 63 64 // Initializes logging system for ChromeDriver. Returns true on success. 65 bool InitLogging(); 66 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); 71 72 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ 73