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