 Chromium Code Reviews
 Chromium Code Reviews Issue 5967003:
  Refactor UITestBase/ProxyLauncher.  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk
    
  
    Issue 5967003:
  Refactor UITestBase/ProxyLauncher.  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ | 
| 6 #define CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ | 6 #define CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" | 
| 11 #include "base/command_line.h" | |
| 12 #include "base/process.h" | |
| 13 #include "base/scoped_ptr.h" | |
| 14 #include "base/scoped_temp_dir.h" | |
| 15 #include "base/time.h" | |
| 11 | 16 | 
| 12 class AutomationProxy; | 17 class AutomationProxy; | 
| 13 class UITestBase; | 18 class UITestBase; | 
| 14 | 19 | 
| 15 // Subclass from this class to use a different implementation of AutomationProxy | 20 // Subclass from this class to use a different implementation of AutomationProxy | 
| 16 // or to use different channel IDs inside a class that derives from UITest. | 21 // or to use different channel IDs inside a class that derives from UITest. | 
| 17 class ProxyLauncher { | 22 class ProxyLauncher { | 
| 18 public: | 23 public: | 
| 19 ProxyLauncher() {} | 24 // Profile theme type choices. | 
| 20 virtual ~ProxyLauncher() {} | 25 typedef enum { | 
| 
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: Is the typedef needed? Just enum should be su
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 26 DEFAULT_THEME = 0, | |
| 27 COMPLEX_THEME = 1, | |
| 28 NATIVE_THEME = 2, | |
| 29 CUSTOM_FRAME = 3, | |
| 30 CUSTOM_FRAME_NATIVE_THEME = 4, | |
| 31 } ProfileType; | |
| 32 | |
| 33 // Different ways to quit the browser. | |
| 34 typedef enum { | |
| 35 WINDOW_CLOSE, | |
| 36 USER_QUIT, | |
| 37 SESSION_ENDING, | |
| 38 } ShutdownType; | |
| 39 | |
| 40 ProxyLauncher(); | |
| 41 | |
| 42 virtual ~ProxyLauncher(); | |
| 21 | 43 | 
| 22 // Creates an automation proxy. | 44 // Creates an automation proxy. | 
| 23 virtual AutomationProxy* CreateAutomationProxy( | 45 virtual AutomationProxy* CreateAutomationProxy( | 
| 24 int execution_timeout) = 0; | 46 int execution_timeout) = 0; | 
| 25 | 47 | 
| 26 // Launches the browser if needed and establishes a connection | 48 // Launches the browser if needed and establishes a connection | 
| 27 // connection with it using the specified UITestBase. | 49 // connection with it using the specified UITestBase. | 
| 
Nirnimesh
2011/01/06 22:56:45
Fix this comment. Don't need UITestBase here
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 28 virtual void InitializeConnection(UITestBase* ui_test_base) const = 0; | 50 virtual void InitializeConnection(const CommandLine& arguments, | 
| 51 bool include_testing_id, | |
| 52 bool clear_profile, | |
| 53 FilePath& template_user_data, | |
| 54 ProfileType profile_type, | |
| 55 FilePath browser_directory, | |
| 56 bool show_window, | |
| 57 bool wait_for_initial_loads, | |
| 58 base::TimeTicks* launch_time, | |
| 59 base::ProcessHandle* process, | |
| 60 base::ProcessId* process_id) = 0; | |
| 29 | 61 | 
| 30 // Returns the automation proxy's channel with any prefixes prepended, | 62 // Returns the automation proxy's channel with any prefixes prepended, | 
| 31 // for passing as a command line parameter over to the browser. | 63 // for passing as a command line parameter over to the browser. | 
| 32 virtual std::string PrefixedChannelID() const = 0; | 64 virtual std::string PrefixedChannelID() const = 0; | 
| 33 | 65 | 
| 66 // Launches the browser and IPC testing connection in server mode. | |
| 67 void LaunchBrowserAndServer(const CommandLine& arguments, | |
| 68 bool include_testing_id, | |
| 69 bool clear_profile, | |
| 70 FilePath& template_user_data, | |
| 71 ProfileType profile_type, | |
| 72 FilePath browser_directory, | |
| 73 bool show_window, | |
| 74 bool wait_for_initial_loads, | |
| 75 base::TimeTicks* launch_time, | |
| 76 base::ProcessHandle* process, | |
| 77 base::ProcessId* process_id); | |
| 78 | |
| 79 // Launches the IPC testing connection in client mode, | |
| 80 // which then attempts to connect to a browser. | |
| 81 void ConnectToRunningBrowser(bool wait_for_initial_loads); | |
| 82 | |
| 83 // Only for pyauto. | |
| 84 void set_command_execution_timeout_ms(int timeout); | |
| 85 | |
| 86 // Closes the browser and IPC testing server. | |
| 87 void CloseBrowserAndServer(ShutdownType shutdown_type, | |
| 88 base::TimeDelta* quit_time, | |
| 89 base::ProcessHandle* process, | |
| 90 base::ProcessId* process_id); | |
| 91 | |
| 92 // Launches the browser with the given command line. | |
| 93 // TODO(phajdan.jr): Make LaunchBrowser private. Tests should use | |
| 94 // LaunchAnotherBrowserBlockUntilClosed. | |
| 95 void LaunchBrowser(const CommandLine& arguments, | |
| 96 bool include_testing_id, | |
| 97 bool clear_profile, | |
| 98 FilePath& template_user_data, | |
| 99 ProfileType profile_type, | |
| 100 FilePath browser_directory, | |
| 101 bool show_window, | |
| 102 base::TimeTicks* launch_time, | |
| 103 base::ProcessHandle* process, | |
| 104 base::ProcessId* process_id); | |
| 105 | |
| 106 #if !defined(OS_MACOSX) | |
| 107 // This function is deliberately not defined on the Mac because re-using an | |
| 108 // existing browser process when launching from the command line isn't a | |
| 109 // concept that we support on the Mac; AppleEvents are the Mac solution for | |
| 110 // the same need. Any test based on this function doesn't apply to the Mac. | |
| 111 | |
| 112 // Launches an another browser process and waits for it to finish. Returns | |
| 113 // true on success. | |
| 114 bool LaunchAnotherBrowserBlockUntilClosed(const CommandLine& cmdline, | |
| 115 bool include_testing_id, | |
| 116 FilePath browser_directory, | |
| 117 bool show_window, | |
| 118 base::TimeTicks* launch_time); | |
| 119 #endif | |
| 120 | |
| 121 // Exits out browser instance. | |
| 
Nirnimesh
2011/01/06 22:56:45
s/out/our/
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 122 void QuitBrowser(ShutdownType shutdown_type, | |
| 123 base::TimeDelta* quit_time, | |
| 124 base::ProcessHandle* process, | |
| 125 base::ProcessId* process_id); | |
| 126 | |
| 127 // Terminates the browser, simulates end of session. | |
| 128 void TerminateBrowser(base::TimeDelta* quit_time, | |
| 129 base::ProcessHandle* process, | |
| 130 base::ProcessId* process_id); | |
| 131 | |
| 132 // Check that no processes related to Chrome exist, displaying | |
| 133 // the given message if any do. | |
| 134 void AssertAppNotRunning(const std::wstring& error_message, | |
| 135 base::ProcessId process_id); | |
| 136 | |
| 137 // Returns true when the browser process is running, independent if any | |
| 138 // renderer process exists or not. It will returns false if an user closed the | |
| 139 // window or if the browser process died by itself. | |
| 140 bool IsBrowserRunning(base::ProcessHandle process); | |
| 141 | |
| 142 // Returns true when timeout_ms milliseconds have elapsed. | |
| 143 // Returns false if the browser process died while waiting. | |
| 144 bool CrashAwareSleep(base::ProcessHandle process, int timeout_ms); | |
| 145 | |
| 146 // Wait for the browser process to shut down on its own (i.e. as a result of | |
| 147 // some action that your test has taken). | |
| 148 bool WaitForBrowserProcessToQuit(base::ProcessHandle process); | |
| 149 | |
| 150 AutomationProxy* automation() const; | |
| 151 | |
| 152 // Return the user data directory being used by the browser instance in | |
| 153 // UITest::SetUp(). | |
| 
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: Don't mention UITest::SetUp here. I think it
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 154 FilePath user_data_dir() const; | |
| 155 | |
| 156 void set_test_name(const std::string& name) { | |
| 157 test_name_ = name; | |
| 158 } | |
| 159 | |
| 160 // Sets homepage_. Should be called before launching browser to have | |
| 161 // any effect. | |
| 162 void set_homepage(const std::string& homepage) { | |
| 163 homepage_ = homepage; | |
| 164 } | |
| 165 | |
| 166 // Get/Set a flag to run the renderer in process when running the | |
| 167 // tests. | |
| 168 static bool in_process_renderer() { return in_process_renderer_; } | |
| 169 static void set_in_process_renderer(bool value) { | |
| 170 in_process_renderer_ = value; | |
| 171 } | |
| 172 | |
| 173 // Get/Set a flag to run the renderer outside the sandbox when running the | |
| 174 // tests | |
| 175 static bool no_sandbox() { return no_sandbox_; } | |
| 176 static void set_no_sandbox(bool value) { | |
| 177 no_sandbox_ = value; | |
| 178 } | |
| 179 | |
| 180 // Get/Set a flag to run with DCHECKs enabled in release. | |
| 181 static bool enable_dcheck() { return enable_dcheck_; } | |
| 182 static void set_enable_dcheck(bool value) { | |
| 183 enable_dcheck_ = value; | |
| 184 } | |
| 185 | |
| 186 // Get/Set a flag to dump the process memory without crashing on DCHECKs. | |
| 187 static bool silent_dump_on_dcheck() { return silent_dump_on_dcheck_; } | |
| 188 static void set_silent_dump_on_dcheck(bool value) { | |
| 189 silent_dump_on_dcheck_ = value; | |
| 190 } | |
| 191 | |
| 192 // Get/Set a flag to disable breakpad handling. | |
| 193 static bool disable_breakpad() { return disable_breakpad_; } | |
| 194 static void set_disable_breakpad(bool value) { | |
| 195 disable_breakpad_ = value; | |
| 196 } | |
| 197 | |
| 198 // Get/Set a flag to run the plugin processes inside the sandbox when running | |
| 199 // the tests | |
| 200 static bool safe_plugins() { return safe_plugins_; } | |
| 201 static void set_safe_plugins(bool value) { | |
| 202 safe_plugins_ = value; | |
| 203 } | |
| 204 | |
| 205 static bool show_error_dialogs() { return show_error_dialogs_; } | |
| 206 static void set_show_error_dialogs(bool value) { | |
| 207 show_error_dialogs_ = value; | |
| 208 } | |
| 209 | |
| 210 static bool full_memory_dump() { return full_memory_dump_; } | |
| 211 static void set_full_memory_dump(bool value) { | |
| 212 full_memory_dump_ = value; | |
| 213 } | |
| 214 | |
| 215 static bool dump_histograms_on_exit() { return dump_histograms_on_exit_; } | |
| 216 static void set_dump_histograms_on_exit(bool value) { | |
| 217 dump_histograms_on_exit_ = value; | |
| 218 } | |
| 219 | |
| 220 static const std::string& js_flags() { return js_flags_; } | |
| 221 static void set_js_flags(const std::string& value) { | |
| 222 js_flags_ = value; | |
| 223 } | |
| 224 | |
| 225 static const std::string& log_level() { return log_level_; } | |
| 226 static void set_log_level(const std::string& value) { | |
| 227 log_level_ = value; | |
| 228 } | |
| 229 | |
| 230 protected: | |
| 231 virtual bool ShouldFilterInet() { | |
| 232 return true; | |
| 233 } | |
| 234 | |
| 34 private: | 235 private: | 
| 236 void WaitForBrowserLaunch(bool wait_for_initial_loads); | |
| 237 | |
| 238 // Prepare command line that will be used to launch the child browser process | |
| 239 // with an UI test. | |
| 
Nirnimesh
2011/01/06 22:56:45
s/an/a/
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 240 void PrepareTestCommandline(CommandLine* command_line, | |
| 241 bool include_testing_id); | |
| 242 | |
| 243 bool LaunchBrowserHelper(const CommandLine& arguments, | |
| 244 bool include_testing_id, | |
| 245 FilePath browser_directory, | |
| 246 bool wait, | |
| 247 bool show_window, | |
| 248 base::TimeTicks* launch_time, | |
| 249 base::ProcessHandle* process); | |
| 250 | |
| 251 // Wait a certain amount of time for all the app processes to exit, | |
| 252 // forcibly killing them if they haven't exited by then. | |
| 253 // It has the side-effect of killing every browser window opened in your | |
| 254 // session, even those unrelated in the test. | |
| 255 void CleanupAppProcesses(base::ProcessId process_id); | |
| 256 | |
| 257 scoped_ptr<AutomationProxy> automation_proxy_; | |
| 258 | |
| 259 // We use a temporary directory for profile to avoid issues with being | |
| 260 // unable to delete some files because they're in use, etc. | |
| 261 ScopedTempDir temp_profile_dir_; | |
| 262 | |
| 263 // Name of currently running automeated test passed to Chrome process. | |
| 264 std::string test_name_; | |
| 
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: Add empty line below.
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 265 // Homepage used for testing. | |
| 266 std::string homepage_; | |
| 267 | |
| 268 // True if we're in single process mode. | |
| 269 static bool in_process_renderer_; | |
| 
Paweł Hajdan Jr.
2011/01/06 20:37:14
nit: Similarly here, separate the variables by emp
 
dtu
2011/01/07 01:46:17
Done.
 | |
| 270 // If true, runs the renderer outside the sandbox. | |
| 271 static bool no_sandbox_; | |
| 272 // If true, runs plugin processes inside the sandbox. | |
| 273 static bool safe_plugins_; | |
| 274 // If true, write full memory dump during crash. | |
| 275 static bool full_memory_dump_; | |
| 276 // If true, a user is paying attention to the test, so show error dialogs. | |
| 277 static bool show_error_dialogs_; | |
| 278 // Include histograms in log on exit. | |
| 279 static bool dump_histograms_on_exit_; | |
| 280 // Enable dchecks in release mode. | |
| 281 static bool enable_dcheck_; | |
| 282 // Dump process memory on dcheck without crashing. | |
| 283 static bool silent_dump_on_dcheck_; | |
| 284 // Disable breakpad on the browser. | |
| 285 static bool disable_breakpad_; | |
| 286 // Flags passed to the JS engine. | |
| 287 static std::string js_flags_; | |
| 288 // Logging level. | |
| 289 static std::string log_level_; | |
| 290 | |
| 35 DISALLOW_COPY_AND_ASSIGN(ProxyLauncher); | 291 DISALLOW_COPY_AND_ASSIGN(ProxyLauncher); | 
| 36 }; | 292 }; | 
| 37 | 293 | 
| 38 // Uses an automation proxy that communicates over a named socket. | 294 // Uses an automation proxy that communicates over a named socket. | 
| 39 // This is used if you want to connect an AutomationProxy | 295 // This is used if you want to connect an AutomationProxy | 
| 40 // to a browser process that is already running. | 296 // to a browser process that is already running. | 
| 41 // The channel id of the proxy is a constant specified by kInterfacePath. | 297 // The channel id of the proxy is a constant specified by kInterfacePath. | 
| 42 class NamedProxyLauncher : public ProxyLauncher { | 298 class NamedProxyLauncher : public ProxyLauncher { | 
| 43 public: | 299 public: | 
| 44 // If launch_browser is true, launches Chrome with named interface enabled. | 300 // If launch_browser is true, launches Chrome with named interface enabled. | 
| 45 // Otherwise, there should be an existing instance the proxy can connect to. | 301 // Otherwise, there should be an existing instance the proxy can connect to. | 
| 46 NamedProxyLauncher(bool launch_browser, bool disconnect_on_failure); | 302 NamedProxyLauncher(bool launch_browser, bool disconnect_on_failure); | 
| 47 | 303 | 
| 48 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | 304 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | 
| 49 virtual void InitializeConnection(UITestBase* ui_test_base) const; | 305 virtual void InitializeConnection(const CommandLine& arguments, | 
| 306 bool include_testing_id, | |
| 307 bool clear_profile, | |
| 308 FilePath& template_user_data, | |
| 309 ProfileType profile_type, | |
| 310 FilePath browser_directory, | |
| 311 bool show_window, | |
| 312 bool wait_for_initial_loads, | |
| 313 base::TimeTicks* launch_time, | |
| 314 base::ProcessHandle* process, | |
| 315 base::ProcessId* process_id); | |
| 50 virtual std::string PrefixedChannelID() const; | 316 virtual std::string PrefixedChannelID() const; | 
| 51 | 317 | 
| 52 protected: | 318 protected: | 
| 53 std::string channel_id_; // Channel id of automation proxy. | 319 std::string channel_id_; // Channel id of automation proxy. | 
| 54 bool launch_browser_; // True if we should launch the browser too. | 320 bool launch_browser_; // True if we should launch the browser too. | 
| 55 bool disconnect_on_failure_; // True if we disconnect on IPC channel failure. | 321 bool disconnect_on_failure_; // True if we disconnect on IPC channel failure. | 
| 56 | 322 | 
| 57 private: | 323 private: | 
| 58 DISALLOW_COPY_AND_ASSIGN(NamedProxyLauncher); | 324 DISALLOW_COPY_AND_ASSIGN(NamedProxyLauncher); | 
| 59 }; | 325 }; | 
| 60 | 326 | 
| 61 // Uses an automation proxy that communicates over an anonymous socket. | 327 // Uses an automation proxy that communicates over an anonymous socket. | 
| 62 class AnonymousProxyLauncher : public ProxyLauncher { | 328 class AnonymousProxyLauncher : public ProxyLauncher { | 
| 63 public: | 329 public: | 
| 64 explicit AnonymousProxyLauncher(bool disconnect_on_failure); | 330 explicit AnonymousProxyLauncher(bool disconnect_on_failure); | 
| 65 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | 331 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | 
| 66 virtual void InitializeConnection(UITestBase* ui_test_base) const; | 332 virtual void InitializeConnection(const CommandLine& arguments, | 
| 333 bool include_testing_id, | |
| 334 bool clear_profile, | |
| 335 FilePath& template_user_data, | |
| 336 ProfileType profile_type, | |
| 337 FilePath browser_directory, | |
| 338 bool show_window, | |
| 339 bool wait_for_initial_loads, | |
| 340 base::TimeTicks* launch_time, | |
| 341 base::ProcessHandle* process, | |
| 342 base::ProcessId* process_id); | |
| 67 virtual std::string PrefixedChannelID() const; | 343 virtual std::string PrefixedChannelID() const; | 
| 68 | 344 | 
| 69 protected: | 345 protected: | 
| 70 std::string channel_id_; // Channel id of automation proxy. | 346 std::string channel_id_; // Channel id of automation proxy. | 
| 71 bool disconnect_on_failure_; // True if we disconnect on IPC channel failure. | 347 bool disconnect_on_failure_; // True if we disconnect on IPC channel failure. | 
| 72 | 348 | 
| 73 private: | 349 private: | 
| 74 DISALLOW_COPY_AND_ASSIGN(AnonymousProxyLauncher); | 350 DISALLOW_COPY_AND_ASSIGN(AnonymousProxyLauncher); | 
| 75 }; | 351 }; | 
| 76 | 352 | 
| 77 #endif // CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ | 353 #endif // CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ | 
| 78 | |
| OLD | NEW |