Home | History | Annotate | Download | only in chromedriver
      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   // Constants corresponding to log entry severity levels in the wire protocol.
     26   enum WebDriverLevel {
     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 
     38   // Creates a WebDriverLog with the given type and minimum level.
     39   WebDriverLog(const std::string& type, WebDriverLevel min_wd_level);
     40   virtual ~WebDriverLog();
     41 
     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
     46   // into the wire protocol response to the "/log" command.
     47   // The caller assumes ownership of the ListValue, and the WebDriverLog
     48   // creates and owns a new empty ListValue for further accumulation.
     49   scoped_ptr<base::ListValue> GetAndClearEntries();
     50 
     51   // Translates a Log entry level into a WebDriver level and stores the entry.
     52   virtual void AddEntryTimestamped(const base::Time& timestamp,
     53                                    Level level,
     54                                    const std::string& message) OVERRIDE;
     55 
     56  private:
     57   const std::string type_;  // WebDriver log type.
     58   const WebDriverLevel min_wd_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 // Creates Log's and DevToolsEventListener's for ones that are DevTools-based.
     65 Status CreateLogs(const Capabilities& capabilities,
     66                   ScopedVector<WebDriverLog>* out_devtools_logs,
     67                   ScopedVector<DevToolsEventListener>* out_listeners);
     68 
     69 #endif  // CHROME_TEST_CHROMEDRIVER_LOGGING_H_
     70