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 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. |
| 25 typedef enum { | |
| 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 | |
| 20 virtual ~ProxyLauncher() {} | 42 virtual ~ProxyLauncher() {} |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: Move the dtor's impl to the .cc file.
dtu
2011/01/06 01:41:13
Done.
| |
| 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. |
| 28 virtual void InitializeConnection(UITestBase* ui_test_base) const = 0; | 50 virtual void InitializeConnection(const CommandLine& arguments, |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
This has definitely too many parameters. Can we st
dtu
2011/01/08 01:54:51
Done.
| |
| 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 virtual void SetUp(base::ProcessId process_id); | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: SetUp in context of ProxyLauncher is very vag
dtu
2011/01/06 01:41:13
Done. Moved back into UITestBase::SetUp().
| |
| 67 | |
| 68 // Launches the browser and IPC testing connection in server mode. | |
| 69 void LaunchBrowserAndServer(const CommandLine& arguments, | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
This has definitely too many parameters. Can we st
dtu
2011/01/08 01:54:51
Done.
| |
| 70 bool include_testing_id, | |
| 71 bool clear_profile, | |
| 72 FilePath& template_user_data, | |
| 73 ProfileType profile_type, | |
| 74 FilePath browser_directory, | |
| 75 bool show_window, | |
| 76 bool wait_for_initial_loads, | |
| 77 base::TimeTicks* launch_time, | |
| 78 base::ProcessHandle* process, | |
| 79 base::ProcessId* process_id); | |
| 80 | |
| 81 // Launches the IPC testing connection in client mode, | |
| 82 // which then attempts to connect to a browser. | |
| 83 void ConnectToRunningBrowser(bool wait_for_initial_loads); | |
| 84 | |
| 85 // Only for pyauto. | |
| 86 void set_command_execution_timeout_ms(int timeout); | |
| 87 | |
| 88 // Closes the browser and IPC testing server. | |
| 89 void CloseBrowserAndServer(ShutdownType shutdown_type, | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
This has too many parameters. Can we store quit_ti
dtu
2011/01/08 01:54:51
Done.
| |
| 90 base::TimeDelta* quit_time, | |
| 91 base::ProcessHandle* process, | |
| 92 base::ProcessId* process_id); | |
| 93 | |
| 94 // Launches the browser with the given command line. | |
| 95 // TODO(phajdan.jr): Make LaunchBrowser private. Tests should use | |
| 96 // LaunchAnotherBrowserBlockUntilClosed. | |
| 97 void LaunchBrowser(const CommandLine& arguments, | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
This has definitely too many parameters. Can we st
dtu
2011/01/08 01:54:51
Done.
| |
| 98 bool include_testing_id, | |
| 99 bool clear_profile, | |
| 100 FilePath& template_user_data, | |
| 101 ProfileType profile_type, | |
| 102 FilePath browser_directory, | |
| 103 bool show_window, | |
| 104 base::TimeTicks* launch_time, | |
| 105 base::ProcessHandle* process, | |
| 106 base::ProcessId* process_id); | |
| 107 | |
| 108 #if !defined(OS_MACOSX) | |
| 109 // This function is deliberately not defined on the Mac because re-using an | |
| 110 // existing browser process when launching from the command line isn't a | |
| 111 // concept that we support on the Mac; AppleEvents are the Mac solution for | |
| 112 // the same need. Any test based on this function doesn't apply to the Mac. | |
| 113 | |
| 114 // Launches an another browser process and waits for it to finish. Returns | |
| 115 // true on success. | |
| 116 bool LaunchAnotherBrowserBlockUntilClosed(const CommandLine& cmdline, | |
| 117 bool include_testing_id, | |
| 118 FilePath browser_directory, | |
| 119 bool show_window, | |
| 120 base::TimeTicks* launch_time); | |
| 121 #endif | |
| 122 | |
| 123 // Exits out browser instance. | |
| 124 void QuitBrowser(ShutdownType shutdown_type, | |
| 125 base::TimeDelta* quit_time, | |
| 126 base::ProcessHandle* process, | |
| 127 base::ProcessId* process_id); | |
| 128 | |
| 129 // Terminates the browser, simulates end of session. | |
| 130 void TerminateBrowser(base::TimeDelta* quit_time, | |
| 131 base::ProcessHandle* process, | |
| 132 base::ProcessId* process_id); | |
| 133 | |
| 134 // Returns true when the browser process is running, independent if any | |
| 135 // renderer process exists or not. It will returns false if an user closed the | |
| 136 // window or if the browser process died by itself. | |
| 137 bool IsBrowserRunning(base::ProcessHandle process); | |
| 138 | |
| 139 // Returns true when time_out_ms milliseconds have elapsed. | |
| 140 // Returns false if the browser process died while waiting. | |
| 141 bool CrashAwareSleep(base::ProcessHandle process, int time_out_ms); | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: time_out_ms -> timeout_ms
dtu
2011/01/06 01:41:13
Done. All instances in ProxyLauncher and UITest.
| |
| 142 | |
| 143 // Wait for the browser process to shut down on its own (i.e. as a result of | |
| 144 // some action that your test has taken). | |
| 145 bool WaitForBrowserProcessToQuit(base::ProcessHandle process); | |
| 146 | |
| 147 AutomationProxy* automation() const; | |
| 148 | |
| 149 // Return the user data directory being used by the browser instance in | |
| 150 // UITest::SetUp(). | |
| 151 FilePath user_data_dir() const; | |
| 152 | |
| 153 void set_ui_test_name(const std::string& name) { | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: set_ui_test_name -> set_test_name (ProxyLaunc
dtu
2011/01/06 01:41:13
Done.
| |
| 154 ui_test_name_ = name; | |
| 155 } | |
| 156 | |
| 157 // Sets homepage_. Should be called before launching browser to have | |
| 158 // any effect. | |
| 159 void set_homepage(const std::string& homepage) { | |
| 160 homepage_ = homepage; | |
| 161 } | |
| 162 | |
| 163 // Get/Set a flag to run the renderer in process when running the | |
| 164 // tests. | |
| 165 static bool in_process_renderer() { return in_process_renderer_; } | |
| 166 static void set_in_process_renderer(bool value) { | |
| 167 in_process_renderer_ = value; | |
| 168 } | |
| 169 | |
| 170 // Get/Set a flag to run the renderer outside the sandbox when running the | |
| 171 // tests | |
| 172 static bool no_sandbox() { return no_sandbox_; } | |
| 173 static void set_no_sandbox(bool value) { | |
| 174 no_sandbox_ = value; | |
| 175 } | |
| 176 | |
| 177 // Get/Set a flag to run with DCHECKs enabled in release. | |
| 178 static bool enable_dcheck() { return enable_dcheck_; } | |
| 179 static void set_enable_dcheck(bool value) { | |
| 180 enable_dcheck_ = value; | |
| 181 } | |
| 182 | |
| 183 // Get/Set a flag to dump the process memory without crashing on DCHECKs. | |
| 184 static bool silent_dump_on_dcheck() { return silent_dump_on_dcheck_; } | |
| 185 static void set_silent_dump_on_dcheck(bool value) { | |
| 186 silent_dump_on_dcheck_ = value; | |
| 187 } | |
| 188 | |
| 189 // Get/Set a flag to disable breakpad handling. | |
| 190 static bool disable_breakpad() { return disable_breakpad_; } | |
| 191 static void set_disable_breakpad(bool value) { | |
| 192 disable_breakpad_ = value; | |
| 193 } | |
| 194 | |
| 195 // Get/Set a flag to run the plugin processes inside the sandbox when running | |
| 196 // the tests | |
| 197 static bool safe_plugins() { return safe_plugins_; } | |
| 198 static void set_safe_plugins(bool value) { | |
| 199 safe_plugins_ = value; | |
| 200 } | |
| 201 | |
| 202 static bool show_error_dialogs() { return show_error_dialogs_; } | |
| 203 static void set_show_error_dialogs(bool value) { | |
| 204 show_error_dialogs_ = value; | |
| 205 } | |
| 206 | |
| 207 static bool full_memory_dump() { return full_memory_dump_; } | |
| 208 static void set_full_memory_dump(bool value) { | |
| 209 full_memory_dump_ = value; | |
| 210 } | |
| 211 | |
| 212 static bool dump_histograms_on_exit() { return dump_histograms_on_exit_; } | |
| 213 static void set_dump_histograms_on_exit(bool value) { | |
| 214 dump_histograms_on_exit_ = value; | |
| 215 } | |
| 216 | |
| 217 static const std::string& js_flags() { return js_flags_; } | |
| 218 static void set_js_flags(const std::string& value) { | |
| 219 js_flags_ = value; | |
| 220 } | |
| 221 | |
| 222 static const std::string& log_level() { return log_level_; } | |
| 223 static void set_log_level(const std::string& value) { | |
| 224 log_level_ = value; | |
| 225 } | |
| 226 | |
| 227 protected: | |
| 228 virtual bool ShouldFilterInet() { | |
| 229 return true; | |
| 230 } | |
| 231 | |
| 34 private: | 232 private: |
| 233 void WaitForBrowserLaunch(bool wait_for_initial_loads); | |
| 234 | |
| 235 // Prepare command line that will be used to launch the child browser process | |
| 236 // with an UI test. | |
| 237 void PrepareTestCommandline(CommandLine* command_line, | |
| 238 bool include_testing_id); | |
| 239 | |
| 240 bool LaunchBrowserHelper(const CommandLine& arguments, | |
| 241 bool include_testing_id, | |
| 242 FilePath browser_directory, | |
| 243 bool wait, | |
| 244 bool show_window, | |
| 245 base::TimeTicks* launch_time, | |
| 246 base::ProcessHandle* process); | |
| 247 | |
| 248 // Check that no processes related to Chrome exist, displaying | |
| 249 // the given message if any do. | |
| 250 void AssertAppNotRunning(const std::wstring& error_message, | |
| 251 base::ProcessId process_id); | |
| 252 | |
| 253 // Wait a certain amount of time for all the app processes to exit, | |
| 254 // forcibly killing them if they haven't exited by then. | |
| 255 // It has the side-effect of killing every browser window opened in your | |
| 256 // session, even those unrelated in the test. | |
| 257 void CleanupAppProcesses(base::ProcessId process_id); | |
| 258 | |
| 259 // Rewrite the preferences file to point to the proper image directory. | |
| 260 static void RewritePreferencesFile(const FilePath& user_data_dir); | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: Can we move those private static functions to
dtu
2011/01/06 01:41:13
Done.
| |
| 261 | |
| 262 // We want to have a current history database when we start the browser so | |
| 263 // things like the NTP will have thumbnails. This method updates the dates | |
| 264 // in the history to be more recent. | |
| 265 static void UpdateHistoryDates(const FilePath& user_data_dir); | |
| 266 | |
| 267 scoped_ptr<AutomationProxy> automation_proxy_; | |
| 268 | |
| 269 // We use a temporary directory for profile to avoid issues with being | |
| 270 // unable to delete some files because they're in use, etc. | |
| 271 scoped_ptr<ScopedTempDir> temp_profile_dir_; | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: Can we stack-allocate this?
dtu
2011/01/06 01:41:13
Done.
| |
| 272 | |
| 273 std::string ui_test_name_; | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: ui_test_name_ -> test_name_ + add a comment.
dtu
2011/01/06 01:41:13
Done.
| |
| 274 std::string homepage_; // Homepage used for testing. | |
| 275 | |
| 276 static bool in_process_renderer_; // true if we're in single process mode | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: dot at the end of comment, start with a capit
dtu
2011/01/06 01:41:13
Done.
| |
| 277 static bool no_sandbox_; | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: comment those two.
dtu
2011/01/06 01:41:13
Done.
| |
| 278 static bool safe_plugins_; | |
| 279 static bool full_memory_dump_; // If true, write full memory dump | |
| 280 // during crash. | |
| 281 static bool show_error_dialogs_; // If true, a user is paying attention | |
| 282 // to the test, so show error dialogs. | |
| 283 static bool dump_histograms_on_exit_; // Include histograms in log on exit. | |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: This comment is misaligned. It looks weird, s
dtu
2011/01/06 01:41:13
Done.
| |
| 284 static bool enable_dcheck_; // Enable dchecks in release mode. | |
| 285 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without | |
| 286 // crashing. | |
| 287 static bool disable_breakpad_; // Disable breakpad on the browser. | |
| 288 static std::string js_flags_; // Flags passed to the JS engine. | |
| 289 static std::string log_level_; // Logging 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, |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
This has definitely too many parameters. Can we st
dtu
2011/01/08 01:54:51
Done.
| |
| 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, |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
This has definitely too many parameters. Can we st
dtu
2011/01/08 01:54:51
Done.
| |
| 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 |