1// Copyright 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// Swig Interface for PyAuto. 6// PyAuto makes the Automation Proxy interface available in Python 7// 8// Running swig as: 9// swig -python -c++ chrome/test/pyautolib/pyautolib.i 10// would generate pyautolib.py, pyautolib_wrap.cxx 11 12// When adding a new class or method, make sure you specify the doc string using 13// %feature("docstring", "doc string goes here") NODENAME; 14// and attach it to your node (class or method). This doc string will be 15// copied over in the generated python classes/methods. 16 17%module(docstring="Python interface to Automation Proxy.") pyautolib 18%feature("autodoc", "1"); 19 20%include <cpointer.i> 21%include <std_string.i> 22%include <std_wstring.i> 23 24%include "chrome/test/pyautolib/argc_argv.i" 25 26// NOTE: All files included in this file should also be listed under 27// pyautolib_sources in chrome_tests.gypi. 28 29// Headers that can be swigged directly. 30%include "chrome/app/chrome_command_ids.h" 31%include "chrome/app/chrome_dll_resource.h" 32%include "chrome/common/automation_constants.h" 33%include "chrome/common/pref_names.h" 34%include "content/public/common/page_type.h" 35%include "content/public/common/security_style.h" 36// Must come before cert_status_flags.h 37%include "net/base/net_export.h" 38%ignore net::MapNetErrorToCertStatus(int); 39%include "net/cert/cert_status_flags.h" 40 41#if defined(OS_CHROMEOS) 42%include "chrome/browser/chromeos/cros/network_constants.h" 43%{ 44#include "chrome/browser/chromeos/cros/network_constants.h" 45%} 46#endif 47 48%{ 49#include "chrome/common/automation_constants.h" 50#include "chrome/common/pref_names.h" 51#include "chrome/test/automation/browser_proxy.h" 52#include "chrome/test/automation/tab_proxy.h" 53#include "chrome/test/pyautolib/pyautolib.h" 54#include "content/public/common/security_style.h" 55#include "net/test/spawned_test_server/spawned_test_server.h" 56%} 57 58// Handle type uint32 conversions as int 59%apply int { uint32 }; 60 61// scoped_refptr 62template <class T> 63class scoped_refptr { 64 public: 65 scoped_refptr(); 66 scoped_refptr(T* p); 67 ~scoped_refptr(); 68 69 T* get() const; 70 T* operator->() const; 71}; 72 73// GURL 74%feature("docstring", "Represent a URL. Call spec() to get the string.") GURL; 75class GURL { 76 public: 77 GURL(); 78 explicit GURL(const std::string& url_string); 79 %feature("docstring", "Get the string representation.") spec; 80 const std::string& spec() const; 81}; 82 83// FilePath 84namespace base { 85%feature("docstring", 86 "Represent a file path. Call value() to get the string.") FilePath; 87class FilePath { 88 public: 89 %feature("docstring", "Get the string representation.") value; 90#ifdef SWIGWIN 91 typedef std::wstring StringType; 92#else 93 typedef std::string StringType; 94#endif // SWIGWIN 95 const StringType& value() const; 96 %feature("docstring", "Construct an empty FilePath from a string.") 97 FilePath; 98 FilePath(); 99 explicit FilePath(const StringType& path); 100}; 101} // namespace base 102 103class PyUITestSuiteBase { 104 public: 105 %feature("docstring", "Create the suite.") PyUITestSuiteBase; 106 PyUITestSuiteBase(int argc, char** argv); 107 virtual ~PyUITestSuiteBase(); 108 109 %feature("docstring", "Initialize from the path to browser dir.") 110 InitializeWithPath; 111 void InitializeWithPath(const base::FilePath& browser_dir); 112 %feature("docstring", "Set chrome source root path, used in some tests") 113 SetCrSourceRoot; 114 void SetCrSourceRoot(const base::FilePath& path); 115}; 116 117class PyUITestBase { 118 public: 119 PyUITestBase(bool clear_profile, std::wstring homepage); 120 121 %feature("docstring", "Initialize the entire setup. Should be called " 122 "before launching the browser. For internal use.") Initialize; 123 void Initialize(const base::FilePath& browser_dir); 124 125 %feature("docstring", "Appends a command-line switch (with associated value " 126 "if given) to the list of switches to be passed to the browser " 127 "upon launch. Should be called before launching the browser. " 128 "For internal use only.") 129 AppendBrowserLaunchSwitch; 130 void AppendBrowserLaunchSwitch(const char* name); 131 void AppendBrowserLaunchSwitch(const char* name, const char* value); 132 133 %feature("docstring", "Begins tracing with the given category_patterns " 134 "string.") 135 BeginTracing; 136 bool BeginTracing(const std::string& category_patterns); 137 138 %feature("docstring", "Ends tracing and returns the collected events.") 139 EndTracing; 140 std::string EndTracing(); 141 142 void UseNamedChannelID(const std::string& named_channel_id); 143 144 %feature("docstring", 145 "Fires up the browser and opens a window.") SetUp; 146 virtual void SetUp(); 147 %feature("docstring", 148 "Closes all windows and destroys the browser.") TearDown; 149 virtual void TearDown(); 150 151 %feature("docstring", "Launches the browser and IPC testing server.") 152 LaunchBrowserAndServer; 153 void LaunchBrowserAndServer(); 154 %feature("docstring", "Closes the browser and IPC testing server.") 155 CloseBrowserAndServer; 156 void CloseBrowserAndServer(); 157 158 %feature("docstring", "Determine if the profile is set to be cleared on " 159 "next startup.") get_clear_profile; 160 bool get_clear_profile() const; 161 %feature("docstring", "If False, sets the flag so that the profile is " 162 "not cleared on next startup. Useful for persisting profile " 163 "across restarts. By default the state is True, to clear profile.") 164 set_clear_profile; 165 void set_clear_profile(bool clear_profile); 166 167 %feature("docstring", "Get the path to profile directory.") user_data_dir; 168 base::FilePath user_data_dir() const; 169 170 // Meta-method 171 %feature("docstring", "Send a sync JSON request to Chrome. " 172 "Returns a JSON dict as a response. " 173 "Given timeout in milliseconds." 174 "Internal method.") 175 _SendJSONRequest; 176 std::string _SendJSONRequest(int window_index, 177 const std::string& request, 178 int timeout); 179 180 %feature("docstring", 181 "Returns empty string if there were no unexpected Chrome asserts or " 182 "crashes, a string describing the failures otherwise. As a side " 183 "effect, it will fail with EXPECT_EQ macros if this code runs " 184 "within a gtest harness.") GetErrorsAndCrashes; 185 std::string CheckErrorsAndCrashes() const; 186}; 187 188namespace net { 189// SpawnedTestServer 190%feature("docstring", 191 "SpawnedTestServer. Serves files in data dir over a local http server") 192 SpawnedTestServer; 193class SpawnedTestServer { 194 public: 195 enum Type { 196 TYPE_FTP, 197 TYPE_HTTP, 198 TYPE_HTTPS, 199 }; 200 201 // Initialize a SpawnedTestServer listening on the specified host 202 // (IP or hostname). 203 SpawnedTestServer(Type type, const std::string& host, 204 const base::FilePath& document_root); 205 // Initialize a SpawnedTestServer with a specific set of SSLOptions. 206 SpawnedTestServer(Type type, 207 const SSLOptions& ssl_options, 208 const base::FilePath& document_root); 209 210 %feature("docstring", "Start SpawnedTestServer over an ephemeral port") Start; 211 bool Start(); 212 213 %feature("docstring", "Stop SpawnedTestServer") Stop; 214 bool Stop(); 215 216 %feature("docstring", "Get FilePath to the document root") document_root; 217 const base::FilePath& document_root() const; 218 219 std::string GetScheme() const; 220 221 %feature("docstring", "Get URL for a file path") GetURL; 222 GURL GetURL(const std::string& path) const; 223}; 224 225%extend SpawnedTestServer { 226 %feature("docstring", "Get port number.") GetPort; 227 int GetPort() const { 228 int val = 0; 229 $self->server_data().GetInteger("port", &val); 230 return val; 231 } 232}; 233 234} 235// SSLOptions 236%feature("docstring", 237 "SSLOptions. Sets one of three types of a cert") 238 SSLOptions; 239struct SSLOptions { 240 enum ServerCertificate { 241 CERT_OK, 242 CERT_MISMATCHED_NAME, 243 CERT_EXPIRED, 244 }; 245 246 // Initialize a new SSLOptions that will use the specified certificate. 247 explicit SSLOptions(ServerCertificate cert); 248}; 249 250%{ 251typedef net::SpawnedTestServer::SSLOptions SSLOptions; 252%} 253 254%pointer_class(int, int_ptr); 255%pointer_class(uint32, uint32_ptr); 256