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_UI_UI_TEST_H_ | 5 #ifndef CHROME_TEST_UI_UI_TEST_H_ |
| 6 #define CHROME_TEST_UI_UI_TEST_H_ | 6 #define CHROME_TEST_UI_UI_TEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // This file provides a common base for running UI unit tests, which operate | 9 // This file provides a common base for running UI unit tests, which operate |
| 10 // the entire browser application in a separate process for holistic | 10 // the entire browser application in a separate process for holistic |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
| 25 #include "base/process.h" | 25 #include "base/process.h" |
| 26 #include "base/scoped_ptr.h" | 26 #include "base/scoped_ptr.h" |
| 27 #include "base/test/test_timeouts.h" | 27 #include "base/test/test_timeouts.h" |
| 28 #include "base/time.h" | 28 #include "base/time.h" |
| 29 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 30 // TODO(evanm): we should be able to just forward-declare | 30 // TODO(evanm): we should be able to just forward-declare |
| 31 // AutomationProxy here, but many files that #include this one don't | 31 // AutomationProxy here, but many files that #include this one don't |
| 32 // themselves #include automation_proxy.h. | 32 // themselves #include automation_proxy.h. |
| 33 #include "chrome/test/automation/automation_proxy.h" | 33 #include "chrome/test/automation/automation_proxy.h" |
| 34 #include "chrome/test/automation/proxy_launcher.h" | |
| 34 #include "testing/platform_test.h" | 35 #include "testing/platform_test.h" |
| 35 | 36 |
| 36 class AutomationProxy; | 37 class AutomationProxy; |
| 37 class BrowserProxy; | 38 class BrowserProxy; |
| 38 class DictionaryValue; | 39 class DictionaryValue; |
| 39 class FilePath; | 40 class FilePath; |
| 40 class GURL; | 41 class GURL; |
| 41 class ProxyLauncher; | |
| 42 class ScopedTempDir; | 42 class ScopedTempDir; |
| 43 class TabProxy; | 43 class TabProxy; |
| 44 | 44 |
| 45 // Base class for UI Tests. This implements the core of the functions. | 45 // Base class for UI Tests. This implements the core of the functions. |
| 46 // This base class decouples all automation functionality from testing | 46 // This base class decouples all automation functionality from testing |
| 47 // infrastructure, for use without gtest. | 47 // infrastructure, for use without gtest. |
| 48 // If using gtest, you probably want to inherit from UITest (declared below) | 48 // If using gtest, you probably want to inherit from UITest (declared below) |
| 49 // rather than UITestBase. | 49 // rather than UITestBase. |
| 50 class UITestBase { | 50 class UITestBase { |
| 51 protected: | 51 protected: |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 bool CloseBrowser(BrowserProxy* browser, bool* application_closed) const; | 200 bool CloseBrowser(BrowserProxy* browser, bool* application_closed) const; |
| 201 | 201 |
| 202 // Gets the directory for the currently active profile in the browser. | 202 // Gets the directory for the currently active profile in the browser. |
| 203 FilePath GetDownloadDirectory(); | 203 FilePath GetDownloadDirectory(); |
| 204 | 204 |
| 205 // Get the handle of browser process connected to the automation. This | 205 // Get the handle of browser process connected to the automation. This |
| 206 // function only retruns a reference to the handle so the caller does not | 206 // function only retruns a reference to the handle so the caller does not |
| 207 // own the handle returned. | 207 // own the handle returned. |
| 208 base::ProcessHandle process() { return process_; } | 208 base::ProcessHandle process() { return process_; } |
| 209 | 209 |
| 210 // Get/Set a flag to run the renderer in process when running the | |
| 211 // tests. | |
| 212 static bool in_process_renderer() { return in_process_renderer_; } | |
| 213 static void set_in_process_renderer(bool value) { | |
| 214 in_process_renderer_ = value; | |
| 215 } | |
| 216 | |
| 217 // Get/Set a flag to run the renderer outside the sandbox when running the | |
| 218 // tests | |
| 219 static bool no_sandbox() { return no_sandbox_; } | |
| 220 static void set_no_sandbox(bool value) { | |
| 221 no_sandbox_ = value; | |
| 222 } | |
| 223 | |
| 224 // Get/Set a flag to run with DCHECKs enabled in release. | |
| 225 static bool enable_dcheck() { return enable_dcheck_; } | |
| 226 static void set_enable_dcheck(bool value) { | |
| 227 enable_dcheck_ = value; | |
| 228 } | |
| 229 | |
| 230 // Get/Set a flag to dump the process memory without crashing on DCHECKs. | |
| 231 static bool silent_dump_on_dcheck() { return silent_dump_on_dcheck_; } | |
| 232 static void set_silent_dump_on_dcheck(bool value) { | |
| 233 silent_dump_on_dcheck_ = value; | |
| 234 } | |
| 235 | |
| 236 // Get/Set a flag to disable breakpad handling. | |
| 237 static bool disable_breakpad() { return disable_breakpad_; } | |
| 238 static void set_disable_breakpad(bool value) { | |
| 239 disable_breakpad_ = value; | |
| 240 } | |
| 241 | |
| 242 // Get/Set a flag to run the plugin processes inside the sandbox when running | |
| 243 // the tests | |
| 244 static bool safe_plugins() { return safe_plugins_; } | |
| 245 static void set_safe_plugins(bool value) { | |
| 246 safe_plugins_ = value; | |
| 247 } | |
| 248 | |
| 249 static bool show_error_dialogs() { return show_error_dialogs_; } | |
| 250 static void set_show_error_dialogs(bool value) { | |
| 251 show_error_dialogs_ = value; | |
| 252 } | |
| 253 | |
| 254 static bool full_memory_dump() { return full_memory_dump_; } | |
| 255 static void set_full_memory_dump(bool value) { | |
| 256 full_memory_dump_ = value; | |
| 257 } | |
| 258 | |
| 259 static bool dump_histograms_on_exit() { return dump_histograms_on_exit_; } | |
| 260 static void set_dump_histograms_on_exit(bool value) { | |
| 261 dump_histograms_on_exit_ = value; | |
| 262 } | |
| 263 | |
| 264 static const std::string& js_flags() { return js_flags_; } | |
| 265 static void set_js_flags(const std::string& value) { | |
| 266 js_flags_ = value; | |
| 267 } | |
| 268 | |
| 269 static const std::string& log_level() { return log_level_; } | |
| 270 static void set_log_level(const std::string& value) { | |
| 271 log_level_ = value; | |
| 272 } | |
| 273 | |
| 274 // Profile theme type choices. | |
| 275 typedef enum { | |
| 276 DEFAULT_THEME = 0, | |
| 277 COMPLEX_THEME = 1, | |
| 278 NATIVE_THEME = 2, | |
| 279 CUSTOM_FRAME = 3, | |
| 280 CUSTOM_FRAME_NATIVE_THEME = 4, | |
| 281 } ProfileType; | |
| 282 | |
| 283 // Returns the directory name where the "typical" user data is that we use | 210 // Returns the directory name where the "typical" user data is that we use |
| 284 // for testing. | 211 // for testing. |
| 285 static FilePath ComputeTypicalUserDataSource(ProfileType profile_type); | 212 static FilePath ComputeTypicalUserDataSource( |
| 213 ProxyLauncher::ProfileType profile_type); | |
| 286 | 214 |
| 287 // Rewrite the preferences file to point to the proper image directory. | 215 // Return the user data directory being used by the browser instance in |
| 288 static void RewritePreferencesFile(const FilePath& user_data_dir); | 216 // UITest::SetUp(). |
| 217 FilePath user_data_dir() const { | |
| 218 return launcher_->user_data_dir(); | |
| 219 } | |
| 289 | 220 |
| 290 // Called by some tests that wish to have a base profile to start from. This | 221 // Called by some tests that wish to have a base profile to start from. This |
| 291 // "user data directory" (containing one or more profiles) will be recursively | 222 // "user data directory" (containing one or more profiles) will be recursively |
| 292 // copied into the user data directory for the test and the files will be | 223 // copied into the user data directory for the test and the files will be |
| 293 // evicted from the OS cache. To start with a blank profile, supply an empty | 224 // evicted from the OS cache. To start with a blank profile, supply an empty |
| 294 // string (the default). | 225 // string (the default). |
| 295 const FilePath& template_user_data() const { return template_user_data_; } | 226 const FilePath& template_user_data() const { return template_user_data_; } |
| 296 void set_template_user_data(const FilePath& template_user_data) { | 227 void set_template_user_data(const FilePath& template_user_data) { |
| 297 template_user_data_ = template_user_data; | 228 template_user_data_ = template_user_data; |
| 298 } | 229 } |
| 299 | 230 |
| 300 // Return the user data directory being used by the browser instance in | |
| 301 // UITest::SetUp(). | |
| 302 FilePath user_data_dir() const; | |
| 303 | |
| 304 // Return the process id of the browser process (-1 on error). | 231 // Return the process id of the browser process (-1 on error). |
| 305 base::ProcessId browser_process_id() const { return process_id_; } | 232 base::ProcessId browser_process_id() const { return process_id_; } |
| 306 | 233 |
| 307 // Compatibility timeout accessors. | 234 // Compatibility timeout accessors. |
| 308 // TODO(phajdan.jr): update callers and remove these. | 235 // TODO(phajdan.jr): update callers and remove these. |
| 309 static int command_execution_timeout_ms() { | 236 static int command_execution_timeout_ms() { |
| 310 return TestTimeouts::command_execution_timeout_ms(); | 237 return TestTimeouts::command_execution_timeout_ms(); |
| 311 } | 238 } |
| 312 static int action_timeout_ms() { | 239 static int action_timeout_ms() { |
| 313 return TestTimeouts::action_timeout_ms(); | 240 return TestTimeouts::action_timeout_ms(); |
| 314 } | 241 } |
| 315 static int action_max_timeout_ms() { | 242 static int action_max_timeout_ms() { |
| 316 return TestTimeouts::action_max_timeout_ms(); | 243 return TestTimeouts::action_max_timeout_ms(); |
| 317 } | 244 } |
| 318 static int sleep_timeout_ms() { | 245 static int sleep_timeout_ms() { |
| 319 // TODO(phajdan.jr): Fix all callers and remove sleep_timeout_ms. | 246 // TODO(phajdan.jr): Fix all callers and remove sleep_timeout_ms. |
| 320 return TestTimeouts::action_timeout_ms(); | 247 return TestTimeouts::action_timeout_ms(); |
| 321 } | 248 } |
| 322 static int test_timeout_ms() { | 249 static int test_timeout_ms() { |
| 323 return TestTimeouts::huge_test_timeout_ms(); | 250 return TestTimeouts::huge_test_timeout_ms(); |
| 324 } | 251 } |
| 325 | 252 |
| 326 void set_ui_test_name(const std::string& name) { | 253 void set_ui_test_name(const std::string& name) { |
| 327 ui_test_name_ = name; | 254 launcher_->set_ui_test_name(name); |
| 328 } | 255 } |
| 329 | 256 |
| 330 // Fetch the state which determines whether the profile will be cleared on | 257 // Fetch the state which determines whether the profile will be cleared on |
| 331 // next startup. | 258 // next startup. |
| 332 bool get_clear_profile() const { | 259 bool get_clear_profile() const { |
| 333 return clear_profile_; | 260 return clear_profile_; |
| 334 } | 261 } |
| 335 // Sets clear_profile_. Should be called before launching browser to have | 262 // Sets clear_profile_. Should be called before launching browser to have |
| 336 // any effect. | 263 // any effect. |
| 337 void set_clear_profile(bool clear_profile) { | 264 void set_clear_profile(bool clear_profile) { |
| 338 clear_profile_ = clear_profile; | 265 clear_profile_ = clear_profile; |
| 339 } | 266 } |
| 340 | 267 |
| 341 // Sets homepage_. Should be called before launching browser to have | 268 // Sets homepage_. Should be called before launching browser to have |
| 342 // any effect. | 269 // any effect. |
| 343 void set_homepage(const std::string& homepage) { | 270 void set_homepage(const std::string& homepage) { |
| 344 homepage_ = homepage; | 271 launcher_->set_homepage(homepage); |
| 345 } | 272 } |
| 346 | 273 |
| 347 // Different ways to quit the browser. | |
| 348 typedef enum { | |
| 349 WINDOW_CLOSE, | |
| 350 USER_QUIT, | |
| 351 SESSION_ENDING, | |
| 352 } ShutdownType; | |
| 353 | |
| 354 // Sets the shutdown type, which defaults to WINDOW_CLOSE. | 274 // Sets the shutdown type, which defaults to WINDOW_CLOSE. |
| 355 void set_shutdown_type(ShutdownType value) { | 275 void set_shutdown_type(ProxyLauncher::ShutdownType value) { |
| 356 shutdown_type_ = value; | 276 shutdown_type_ = value; |
| 357 } | 277 } |
| 358 | 278 |
| 359 // Get the number of crash dumps we've logged since the test started. | 279 // Get the number of crash dumps we've logged since the test started. |
| 360 int GetCrashCount(); | 280 int GetCrashCount(); |
| 361 | 281 |
| 362 // Use Chromium binaries from the given directory. | 282 // Use Chromium binaries from the given directory. |
| 363 void SetBrowserDirectory(const FilePath& dir); | 283 void SetBrowserDirectory(const FilePath& dir); |
| 364 | 284 |
| 365 private: | |
| 366 // Check that no processes related to Chrome exist, displaying | |
| 367 // the given message if any do. | |
| 368 void AssertAppNotRunning(const std::wstring& error_message); | |
| 369 | |
| 370 protected: | 285 protected: |
| 371 AutomationProxy* automation() { | 286 AutomationProxy* automation() const { |
| 372 EXPECT_TRUE(automation_proxy_.get()); | 287 return launcher_->automation(); |
| 373 return automation_proxy_.get(); | |
| 374 } | 288 } |
| 375 | 289 |
| 376 virtual bool ShouldFilterInet() { | 290 virtual bool ShouldFilterInet() { |
| 377 return true; | 291 return true; |
| 378 } | 292 } |
| 379 | 293 |
| 294 // Extra command-line switches that need to be passed to the browser are | |
| 295 // added in this function. Add new command-line switches here. | |
| 296 void SetLaunchSwitches(); | |
| 297 | |
| 298 // Helper function for SetLaunchSwitches() that | |
| 299 // adds a switch if it's not already there. | |
| 300 void SetLaunchSwitch(const std::string& switch_string); | |
| 301 | |
| 380 // Wait a certain amount of time for all the app processes to exit, | 302 // Wait a certain amount of time for all the app processes to exit, |
| 381 // forcibly killing them if they haven't exited by then. | 303 // forcibly killing them if they haven't exited by then. |
| 382 // It has the side-effect of killing every browser window opened in your | 304 // It has the side-effect of killing every browser window opened in your |
| 383 // session, even those unrelated in the test. | 305 // session, even those unrelated in the test. |
| 384 void CleanupAppProcesses(); | 306 void CleanupAppProcesses(); |
| 385 | 307 |
| 386 // Returns the proxy for the currently active tab, or NULL if there is no | 308 // Returns the proxy for the currently active tab, or NULL if there is no |
| 387 // tab or there was some kind of error. Only looks at the first window, for | 309 // tab or there was some kind of error. Only looks at the first window, for |
| 388 // backward compatibility. The returned pointer MUST be deleted by the | 310 // backward compatibility. The returned pointer MUST be deleted by the |
| 389 // caller if non-NULL. | 311 // caller if non-NULL. |
| 390 scoped_refptr<TabProxy> GetActiveTab(); | 312 scoped_refptr<TabProxy> GetActiveTab(); |
| 391 | 313 |
| 392 // Like above, but looks at the window at the given index. | 314 // Like above, but looks at the window at the given index. |
| 393 scoped_refptr<TabProxy> GetActiveTab(int window_index); | 315 scoped_refptr<TabProxy> GetActiveTab(int window_index); |
| 394 | 316 |
| 395 // ********* Member variables ********* | 317 // ********* Member variables ********* |
| 396 | 318 |
| 397 FilePath browser_directory_; // Path to the browser executable. | 319 FilePath browser_directory_; // Path to the browser executable. |
| 398 FilePath test_data_directory_; // Path to the unit test data. | 320 FilePath test_data_directory_; // Path to the unit test data. |
| 399 CommandLine launch_arguments_; // Command to launch the browser | 321 CommandLine launch_arguments_; // Command to launch the browser |
| 400 size_t expected_errors_; // The number of errors expected during | 322 size_t expected_errors_; // The number of errors expected during |
| 401 // the run (generally 0). | 323 // the run (generally 0). |
| 402 int expected_crashes_; // The number of crashes expected during | 324 int expected_crashes_; // The number of crashes expected during |
| 403 // the run (generally 0). | 325 // the run (generally 0). |
| 404 std::string homepage_; // Homepage used for testing. | |
| 405 bool wait_for_initial_loads_; // Wait for initial loads to complete | 326 bool wait_for_initial_loads_; // Wait for initial loads to complete |
| 406 // in SetUp() before running test body. | 327 // in SetUp() before running test body. |
| 407 base::TimeTicks browser_launch_time_; // Time when the browser was run. | 328 base::TimeTicks browser_launch_time_; // Time when the browser was run. |
| 408 base::TimeDelta browser_quit_time_; // How long the shutdown took. | 329 base::TimeDelta browser_quit_time_; // How long the shutdown took. |
| 409 bool dom_automation_enabled_; // This can be set to true to have the | 330 bool dom_automation_enabled_; // This can be set to true to have the |
| 410 // test run the dom automation case. | 331 // test run the dom automation case. |
| 411 FilePath template_user_data_; // See set_template_user_data(). | 332 FilePath template_user_data_; // See set_template_user_data(). |
| 412 base::ProcessHandle process_; // Handle to the first Chrome process. | 333 base::ProcessHandle process_; // Handle to the first Chrome process. |
| 413 base::ProcessId process_id_; // PID of |process_| (for debugging). | 334 base::ProcessId process_id_; // PID of |process_| (for debugging). |
| 414 static bool in_process_renderer_; // true if we're in single process mode | |
| 415 bool show_window_; // Determines if the window is shown or | 335 bool show_window_; // Determines if the window is shown or |
| 416 // hidden. Defaults to hidden. | 336 // hidden. Defaults to hidden. |
| 417 bool clear_profile_; // If true the profile is cleared before | 337 bool clear_profile_; // If true the profile is cleared before |
| 418 // launching. Default is true. | 338 // launching. Default is true. |
| 419 bool include_testing_id_; // Should we supply the testing channel | 339 bool include_testing_id_; // Should we supply the testing channel |
| 420 // id on the command line? Default is | 340 // id on the command line? Default is |
| 421 // true. | 341 // true. |
| 422 bool enable_file_cookies_; // Enable file cookies, default is true. | 342 bool enable_file_cookies_; // Enable file cookies, default is true. |
| 423 scoped_ptr<ProxyLauncher> launcher_; // Launches browser and AutomationProxy. | 343 scoped_ptr<ProxyLauncher> launcher_; // Launches browser and AutomationProxy. |
| 424 ProfileType profile_type_; // Are we using a profile with a | 344 ProxyLauncher::ProfileType profile_type_; // Are we using a profile with a |
|
Paweł Hajdan Jr.
2011/01/05 21:47:59
nit: Could you move the comments above the member
dtu
2011/01/06 01:41:13
Done.
| |
| 425 // complex theme? | 345 // complex theme? |
| 426 FilePath websocket_pid_file_; // PID file for websocket server. | 346 FilePath websocket_pid_file_; // PID file for websocket server. |
| 427 ShutdownType shutdown_type_; // The method for shutting down | 347 ProxyLauncher::ShutdownType shutdown_type_; // The method for shutting down |
| 428 // the browser. Used in ShutdownTest. | 348 // the browser. Used in ShutdownTest. |
| 429 | 349 |
| 430 private: | 350 private: |
| 431 void WaitForBrowserLaunch(); | |
| 432 | |
| 433 bool LaunchBrowserHelper(const CommandLine& arguments, | |
| 434 bool wait, | |
| 435 base::ProcessHandle* process); | |
| 436 | |
| 437 // Prepare command line that will be used to launch the child browser process | |
| 438 // with an UI test. | |
| 439 void PrepareTestCommandline(CommandLine* arguments); | |
| 440 | |
| 441 // We want to have a current history database when we start the browser so | |
| 442 // things like the NTP will have thumbnails. This method updates the dates | |
| 443 // in the history to be more recent. | |
| 444 void UpdateHistoryDates(); | |
| 445 | |
| 446 base::Time test_start_time_; // Time the test was started | 351 base::Time test_start_time_; // Time the test was started |
| 447 // (so we can check for new crash dumps) | 352 // (so we can check for new crash dumps) |
| 448 static bool no_sandbox_; | |
| 449 static bool safe_plugins_; | |
| 450 static bool full_memory_dump_; // If true, write full memory dump | |
| 451 // during crash. | |
| 452 static bool show_error_dialogs_; // If true, a user is paying attention | |
| 453 // to the test, so show error dialogs. | |
| 454 static bool dump_histograms_on_exit_; // Include histograms in log on exit. | |
| 455 static bool enable_dcheck_; // Enable dchecks in release mode. | |
| 456 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without | |
| 457 // crashing. | |
| 458 static bool disable_breakpad_; // Disable breakpad on the browser. | |
| 459 static int timeout_ms_; // Timeout in milliseconds to wait | |
| 460 // for an test to finish. | |
| 461 static std::string js_flags_; // Flags passed to the JS engine. | |
| 462 static std::string log_level_; // Logging level. | |
| 463 | |
| 464 scoped_ptr<AutomationProxy> automation_proxy_; | |
| 465 | |
| 466 std::string ui_test_name_; | |
| 467 | |
| 468 // We use a temporary directory for profile to avoid issues with being | |
| 469 // unable to delete some files because they're in use, etc. | |
| 470 scoped_ptr<ScopedTempDir> temp_profile_dir_; | |
| 471 }; | 353 }; |
| 472 | 354 |
| 473 class UITest : public UITestBase, public PlatformTest { | 355 class UITest : public UITestBase, public PlatformTest { |
| 474 protected: | 356 protected: |
| 475 UITest() {} | 357 UITest() {} |
| 476 explicit UITest(MessageLoop::Type msg_loop_type) | 358 explicit UITest(MessageLoop::Type msg_loop_type) |
| 477 : UITestBase(), PlatformTest(), message_loop_(msg_loop_type) { | 359 : UITestBase(), PlatformTest(), message_loop_(msg_loop_type) { |
| 478 } | 360 } |
| 479 virtual void SetUp(); | 361 virtual void SetUp(); |
| 480 virtual void TearDown(); | 362 virtual void TearDown(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 #ifdef UNIT_TEST | 472 #ifdef UNIT_TEST |
| 591 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); | 473 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); |
| 592 | 474 |
| 593 template<typename T> | 475 template<typename T> |
| 594 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { | 476 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { |
| 595 return out << ptr.get(); | 477 return out << ptr.get(); |
| 596 } | 478 } |
| 597 #endif // UNIT_TEST | 479 #endif // UNIT_TEST |
| 598 | 480 |
| 599 #endif // CHROME_TEST_UI_UI_TEST_H_ | 481 #endif // CHROME_TEST_UI_UI_TEST_H_ |
| OLD | NEW |