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 // Translates a Log entry level into a WebDriver level and stores the entry. 43 virtual void AddEntryTimestamped(const base::Time& timestamp, 44 Level level, 45 const std::string& source, 46 const std::string& message) OVERRIDE; 47 48 const std::string& type() const; 49 void set_min_level(Level min_level); 50 Level min_level() const; 51 52 private: 53 const std::string type_; // WebDriver log type. 54 Level min_level_; // Minimum level of entries to store. 55 scoped_ptr<base::ListValue> entries_; // Accumulated entries. 56 57 DISALLOW_COPY_AND_ASSIGN(WebDriverLog); 58 }; 59 60 // Initializes logging system for ChromeDriver. Returns true on success. 61 bool InitLogging(); 62 63 // Creates Log's and DevToolsEventListener's based on logging preferences. 64 Status CreateLogs(const Capabilities& capabilities, 65 ScopedVector<WebDriverLog>* out_logs, 66 ScopedVector<DevToolsEventListener>* out_listeners); 67 68 #endif // CHROME_TEST_CHROMEDRIVER_LOGGING_H_ 69