Home | History | Annotate | Download | only in webdriver
      1 // Copyright (c) 2012 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_WEBDRIVER_WEBDRIVER_CAPABILITIES_PARSER_H_
      6 #define CHROME_TEST_WEBDRIVER_WEBDRIVER_CAPABILITIES_PARSER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/command_line.h"
     13 #include "base/files/file_path.h"
     14 #include "base/memory/scoped_ptr.h"
     15 #include "chrome/test/webdriver/webdriver_logging.h"
     16 
     17 namespace base {
     18 class DictionaryValue;
     19 class Value;
     20 }
     21 
     22 namespace webdriver {
     23 
     24 class Error;
     25 
     26 // Contains all the capabilities that a user may request when starting a
     27 // new session.
     28 struct Capabilities {
     29   Capabilities();
     30   ~Capabilities();
     31 
     32   // Command line to use for starting Chrome.
     33   CommandLine command;
     34 
     35   // Channel ID to use for connecting to an already running Chrome.
     36   std::string channel;
     37 
     38   // Whether the lifetime of the started Chrome browser process should be
     39   // bound to ChromeDriver's process. If true, Chrome will not quit if
     40   // ChromeDriver dies.
     41   bool detach;
     42 
     43   // List of paths for extensions to install on startup.
     44   std::vector<base::FilePath> extensions;
     45 
     46   // Whether Chrome should not block when loading.
     47   bool load_async;
     48 
     49   // Local state preferences to apply after Chrome starts but during session
     50   // initialization. These preferences apply to all profiles in the user
     51   // data directory that Chrome is running in.
     52   scoped_ptr<base::DictionaryValue> local_state;
     53 
     54   // The minimum level to log for each log type.
     55   LogLevel log_levels[LogType::kNum];
     56 
     57   // By default, ChromeDriver configures Chrome in such a way as convenient
     58   // for website testing. E.g., it configures Chrome so that sites are allowed
     59   // to use the geolocation API without requesting the user's consent.
     60   // If this is set to true, ChromeDriver will not modify Chrome's default
     61   // behavior.
     62   bool no_website_testing_defaults;
     63 
     64   // Set of switches which should be removed from default list when launching
     65   // Chrome.
     66   std::set<std::string> exclude_switches;
     67 
     68   // Profile-level preferences to apply after Chrome starts but during session
     69   // initialization.
     70   scoped_ptr<base::DictionaryValue> prefs;
     71 
     72   // Path to a custom profile to use.
     73   base::FilePath profile;
     74 };
     75 
     76 // Parses the given capabilities dictionary to produce a |Capabilities|
     77 // instance.
     78 // See webdriver's desired capabilities for more info.
     79 class CapabilitiesParser {
     80  public:
     81   // Create a new parser. |capabilities_dict| is the dictionary for all
     82   // of the user's desired capabilities. |root_path| is the root directory
     83   // to use for writing any necessary files to disk. This function will not
     84   // create it or delete it. All files written to disk will be placed in
     85   // this directory.
     86   CapabilitiesParser(const base::DictionaryValue* capabilities_dict,
     87                      const base::FilePath& root_path,
     88                      const Logger& logger,
     89                      Capabilities* capabilities);
     90   ~CapabilitiesParser();
     91 
     92   // Parses the capabilities. May return an error.
     93   Error* Parse();
     94 
     95  private:
     96   Error* ParseArgs(const base::Value* option);
     97   Error* ParseBinary(const base::Value* option);
     98   Error* ParseChannel(const base::Value* option);
     99   Error* ParseDetach(const base::Value* option);
    100   Error* ParseExcludeSwitches(const base::Value* options);
    101   Error* ParseExtensions(const base::Value* option);
    102   Error* ParseLoadAsync(const base::Value* option);
    103   Error* ParseLocalState(const base::Value* option);
    104   Error* ParseLoggingPrefs(const base::Value* option);
    105   Error* ParseNativeEvents(const base::Value* option);
    106   Error* ParseNoProxy(const base::Value* option);
    107   Error* ParseNoWebsiteTestingDefaults(const base::Value* option);
    108   Error* ParsePrefs(const base::Value* option);
    109   Error* ParseProfile(const base::Value* option);
    110   Error* ParseProxy(const base::Value* option);
    111   Error* ParseProxyAutoDetect(const base::DictionaryValue* options);
    112   Error* ParseProxyAutoconfigUrl(const base::DictionaryValue* options);
    113   Error* ParseProxyServers(const base::DictionaryValue* options);
    114 
    115 
    116   // The capabilities dictionary to parse.
    117   const base::DictionaryValue* dict_;
    118 
    119   // The root directory under which to write all files.
    120   const base::FilePath root_;
    121 
    122   // Reference to the logger to use.
    123   const Logger& logger_;
    124 
    125   // A pointer to the capabilities to modify while parsing.
    126   Capabilities* caps_;
    127 
    128   DISALLOW_COPY_AND_ASSIGN(CapabilitiesParser);
    129 };
    130 
    131 }  // namespace webdriver
    132 
    133 #endif  // CHROME_TEST_WEBDRIVER_WEBDRIVER_CAPABILITIES_PARSER_H_
    134