| 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 20 matching lines...) Expand all Loading... |
| 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 "testing/platform_test.h" | 34 #include "testing/platform_test.h" |
| 35 | 35 |
| 36 class AutomationProxy; | 36 class AutomationProxy; |
| 37 class BrowserProxy; | 37 class BrowserProxy; |
| 38 class DictionaryValue; | 38 class DictionaryValue; |
| 39 class FilePath; | 39 class FilePath; |
| 40 class GURL; | 40 class GURL; |
| 41 class ProxyLauncher; |
| 41 class ScopedTempDir; | 42 class ScopedTempDir; |
| 42 class TabProxy; | 43 class TabProxy; |
| 43 | 44 |
| 44 // 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. |
| 45 // This base class decouples all automation functionality from testing | 46 // This base class decouples all automation functionality from testing |
| 46 // infrastructure, for use without gtest. | 47 // infrastructure, for use without gtest. |
| 47 // 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) |
| 48 // rather than UITestBase. | 49 // rather than UITestBase. |
| 49 class UITestBase { | 50 class UITestBase { |
| 50 protected: | 51 protected: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 // Starts the browser using the arguments in launch_arguments_, and | 62 // Starts the browser using the arguments in launch_arguments_, and |
| 62 // sets up member variables. | 63 // sets up member variables. |
| 63 virtual void SetUp(); | 64 virtual void SetUp(); |
| 64 | 65 |
| 65 // Closes the browser window. | 66 // Closes the browser window. |
| 66 virtual void TearDown(); | 67 virtual void TearDown(); |
| 67 | 68 |
| 68 public: | 69 public: |
| 69 // ********* Utility functions ********* | 70 // ********* Utility functions ********* |
| 70 | 71 |
| 71 // Launches the browser and IPC testing server. | 72 // Launches the browser and IPC testing connection in server mode. |
| 72 void LaunchBrowserAndServer(); | 73 void LaunchBrowserAndServer(); |
| 73 | 74 |
| 75 // Launches the IPC testing connection in client mode, |
| 76 // which then attempts to connect to a browser. |
| 77 void ConnectToRunningBrowser(); |
| 78 |
| 74 // Only for pyauto. | 79 // Only for pyauto. |
| 75 void set_command_execution_timeout_ms(int timeout); | 80 void set_command_execution_timeout_ms(int timeout); |
| 76 | 81 |
| 77 // Overridable so that derived classes can provide their own AutomationProxy. | 82 // Overridable so that derived classes can provide their own ProxyLauncher. |
| 78 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | 83 virtual ProxyLauncher* CreateProxyLauncher(); |
| 79 | 84 |
| 80 // Closes the browser and IPC testing server. | 85 // Closes the browser and IPC testing server. |
| 81 void CloseBrowserAndServer(); | 86 void CloseBrowserAndServer(); |
| 82 | 87 |
| 83 // Launches the browser with the given command line. | 88 // Launches the browser with the given command line. |
| 84 // TODO(phajdan.jr): Make LaunchBrowser private. Tests should use | 89 // TODO(phajdan.jr): Make LaunchBrowser private. Tests should use |
| 85 // LaunchAnotherBrowserBlockUntilClosed. | 90 // LaunchAnotherBrowserBlockUntilClosed. |
| 86 void LaunchBrowser(const CommandLine& cmdline, bool clear_profile); | 91 void LaunchBrowser(const CommandLine& cmdline, bool clear_profile); |
| 87 | 92 |
| 88 #if !defined(OS_MACOSX) | 93 #if !defined(OS_MACOSX) |
| 89 // This function is deliberately not defined on the Mac because re-using an | 94 // This function is deliberately not defined on the Mac because re-using an |
| 90 // existing browser process when launching from the command line isn't a | 95 // existing browser process when launching from the command line isn't a |
| 91 // concept that we support on the Mac; AppleEvents are the Mac solution for | 96 // concept that we support on the Mac; AppleEvents are the Mac solution for |
| 92 // the same need. Any test based on this function doesn't apply to the Mac. | 97 // the same need. Any test based on this function doesn't apply to the Mac. |
| 93 | 98 |
| 94 // Launches an another browser process and waits for it to finish. Returns | 99 // Launches an another browser process and waits for it to finish. Returns |
| 95 // true on success. | 100 // true on success. |
| 96 bool LaunchAnotherBrowserBlockUntilClosed(const CommandLine& cmdline); | 101 bool LaunchAnotherBrowserBlockUntilClosed(const CommandLine& cmdline); |
| 97 #endif | 102 #endif |
| 98 | 103 |
| 99 // Exits out browser instance. | 104 // Exits out browser instance. |
| 100 void QuitBrowser(); | 105 void QuitBrowser(); |
| 101 | 106 |
| 102 // Terminates the browser, simulates end of session. | 107 // Terminates the browser, simulates end of session. |
| 103 void TerminateBrowser(); | 108 void TerminateBrowser(); |
| 104 | 109 |
| 105 // Tells the browser to navigato to the givne URL in the active tab | 110 // Tells the browser to navigate to the given URL in the active tab |
| 106 // of the first app window. | 111 // of the first app window. |
| 107 // Does not wait for the navigation to complete to return. | 112 // Does not wait for the navigation to complete to return. |
| 108 void NavigateToURLAsync(const GURL& url); | 113 void NavigateToURLAsync(const GURL& url); |
| 109 | 114 |
| 110 // Tells the browser to navigate to the given URL in the active tab | 115 // Tells the browser to navigate to the given URL in the active tab |
| 111 // of the first app window. | 116 // of the first app window. |
| 112 // This method doesn't return until the navigation is complete. | 117 // This method doesn't return until the navigation is complete. |
| 113 void NavigateToURL(const GURL& url); | 118 void NavigateToURL(const GURL& url); |
| 114 | 119 |
| 115 // Same as above, except in the given tab and window. | 120 // Same as above, except in the given tab and window. |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // Use Chromium binaries from the given directory. | 359 // Use Chromium binaries from the given directory. |
| 355 void SetBrowserDirectory(const FilePath& dir); | 360 void SetBrowserDirectory(const FilePath& dir); |
| 356 | 361 |
| 357 private: | 362 private: |
| 358 // Check that no processes related to Chrome exist, displaying | 363 // Check that no processes related to Chrome exist, displaying |
| 359 // the given message if any do. | 364 // the given message if any do. |
| 360 void AssertAppNotRunning(const std::wstring& error_message); | 365 void AssertAppNotRunning(const std::wstring& error_message); |
| 361 | 366 |
| 362 protected: | 367 protected: |
| 363 AutomationProxy* automation() { | 368 AutomationProxy* automation() { |
| 364 EXPECT_TRUE(server_.get()); | 369 EXPECT_TRUE(automation_proxy_.get()); |
| 365 return server_.get(); | 370 return automation_proxy_.get(); |
| 366 } | 371 } |
| 367 | 372 |
| 368 virtual bool ShouldFilterInet() { | 373 virtual bool ShouldFilterInet() { |
| 369 return true; | 374 return true; |
| 370 } | 375 } |
| 371 | 376 |
| 372 // Wait a certain amount of time for all the app processes to exit, | 377 // Wait a certain amount of time for all the app processes to exit, |
| 373 // forcibly killing them if they haven't exited by then. | 378 // forcibly killing them if they haven't exited by then. |
| 374 // It has the side-effect of killing every browser window opened in your | 379 // It has the side-effect of killing every browser window opened in your |
| 375 // session, even those unrelated in the test. | 380 // session, even those unrelated in the test. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 405 base::ProcessId process_id_; // PID of |process_| (for debugging). | 410 base::ProcessId process_id_; // PID of |process_| (for debugging). |
| 406 static bool in_process_renderer_; // true if we're in single process mode | 411 static bool in_process_renderer_; // true if we're in single process mode |
| 407 bool show_window_; // Determines if the window is shown or | 412 bool show_window_; // Determines if the window is shown or |
| 408 // hidden. Defaults to hidden. | 413 // hidden. Defaults to hidden. |
| 409 bool clear_profile_; // If true the profile is cleared before | 414 bool clear_profile_; // If true the profile is cleared before |
| 410 // launching. Default is true. | 415 // launching. Default is true. |
| 411 bool include_testing_id_; // Should we supply the testing channel | 416 bool include_testing_id_; // Should we supply the testing channel |
| 412 // id on the command line? Default is | 417 // id on the command line? Default is |
| 413 // true. | 418 // true. |
| 414 bool enable_file_cookies_; // Enable file cookies, default is true. | 419 bool enable_file_cookies_; // Enable file cookies, default is true. |
| 420 scoped_ptr<ProxyLauncher> launcher_; // Launches browser and AutomationProxy. |
| 415 ProfileType profile_type_; // Are we using a profile with a | 421 ProfileType profile_type_; // Are we using a profile with a |
| 416 // complex theme? | 422 // complex theme? |
| 417 FilePath websocket_pid_file_; // PID file for websocket server. | 423 FilePath websocket_pid_file_; // PID file for websocket server. |
| 418 ShutdownType shutdown_type_; // The method for shutting down | 424 ShutdownType shutdown_type_; // The method for shutting down |
| 419 // the browser. Used in ShutdownTest. | 425 // the browser. Used in ShutdownTest. |
| 420 | 426 |
| 421 private: | 427 private: |
| 428 void WaitForBrowserLaunch(); |
| 429 |
| 422 bool LaunchBrowserHelper(const CommandLine& arguments, | 430 bool LaunchBrowserHelper(const CommandLine& arguments, |
| 423 bool wait, | 431 bool wait, |
| 424 base::ProcessHandle* process); | 432 base::ProcessHandle* process); |
| 425 | 433 |
| 426 // We want to have a current history database when we start the browser so | 434 // We want to have a current history database when we start the browser so |
| 427 // things like the NTP will have thumbnails. This method updates the dates | 435 // things like the NTP will have thumbnails. This method updates the dates |
| 428 // in the history to be more recent. | 436 // in the history to be more recent. |
| 429 void UpdateHistoryDates(); | 437 void UpdateHistoryDates(); |
| 430 | 438 |
| 431 base::Time test_start_time_; // Time the test was started | 439 base::Time test_start_time_; // Time the test was started |
| 432 // (so we can check for new crash dumps) | 440 // (so we can check for new crash dumps) |
| 433 static bool no_sandbox_; | 441 static bool no_sandbox_; |
| 434 static bool safe_plugins_; | 442 static bool safe_plugins_; |
| 435 static bool full_memory_dump_; // If true, write full memory dump | 443 static bool full_memory_dump_; // If true, write full memory dump |
| 436 // during crash. | 444 // during crash. |
| 437 static bool show_error_dialogs_; // If true, a user is paying attention | 445 static bool show_error_dialogs_; // If true, a user is paying attention |
| 438 // to the test, so show error dialogs. | 446 // to the test, so show error dialogs. |
| 439 static bool dump_histograms_on_exit_; // Include histograms in log on exit. | 447 static bool dump_histograms_on_exit_; // Include histograms in log on exit. |
| 440 static bool enable_dcheck_; // Enable dchecks in release mode. | 448 static bool enable_dcheck_; // Enable dchecks in release mode. |
| 441 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without | 449 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without |
| 442 // crashing. | 450 // crashing. |
| 443 static bool disable_breakpad_; // Disable breakpad on the browser. | 451 static bool disable_breakpad_; // Disable breakpad on the browser. |
| 444 static int timeout_ms_; // Timeout in milliseconds to wait | 452 static int timeout_ms_; // Timeout in milliseconds to wait |
| 445 // for an test to finish. | 453 // for an test to finish. |
| 446 static std::string js_flags_; // Flags passed to the JS engine. | 454 static std::string js_flags_; // Flags passed to the JS engine. |
| 447 static std::string log_level_; // Logging level. | 455 static std::string log_level_; // Logging level. |
| 448 | 456 |
| 449 scoped_ptr<AutomationProxy> server_; | 457 scoped_ptr<AutomationProxy> automation_proxy_; |
| 450 | 458 |
| 451 std::string ui_test_name_; | 459 std::string ui_test_name_; |
| 452 | 460 |
| 453 // We use a temporary directory for profile to avoid issues with being | 461 // We use a temporary directory for profile to avoid issues with being |
| 454 // unable to delete some files because they're in use, etc. | 462 // unable to delete some files because they're in use, etc. |
| 455 scoped_ptr<ScopedTempDir> temp_profile_dir_; | 463 scoped_ptr<ScopedTempDir> temp_profile_dir_; |
| 456 }; | 464 }; |
| 457 | 465 |
| 458 class UITest : public UITestBase, public PlatformTest { | 466 class UITest : public UITestBase, public PlatformTest { |
| 459 protected: | 467 protected: |
| 460 UITest() {} | 468 UITest() {} |
| 461 explicit UITest(MessageLoop::Type msg_loop_type) | 469 explicit UITest(MessageLoop::Type msg_loop_type) |
| 462 : UITestBase(), PlatformTest(), message_loop_(msg_loop_type) { | 470 : UITestBase(), PlatformTest(), message_loop_(msg_loop_type) { |
| 463 } | 471 } |
| 464 virtual void SetUp(); | 472 virtual void SetUp(); |
| 465 virtual void TearDown(); | 473 virtual void TearDown(); |
| 466 | 474 |
| 467 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | 475 virtual ProxyLauncher* CreateProxyLauncher(); |
| 468 | 476 |
| 469 // Synchronously launches local http server normally used to run LayoutTests. | 477 // Synchronously launches local http server normally used to run LayoutTests. |
| 470 void StartHttpServer(const FilePath& root_directory); | 478 void StartHttpServer(const FilePath& root_directory); |
| 471 | 479 |
| 472 // Launches local http server on the specified port. | 480 // Launches local http server on the specified port. |
| 473 void StartHttpServerWithPort(const FilePath& root_directory, int port); | 481 void StartHttpServerWithPort(const FilePath& root_directory, int port); |
| 474 | 482 |
| 475 void StopHttpServer(); | 483 void StopHttpServer(); |
| 476 | 484 |
| 477 // Count the number of active browser processes launched by this test. | 485 // Count the number of active browser processes launched by this test. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 #ifdef UNIT_TEST | 583 #ifdef UNIT_TEST |
| 576 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); | 584 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); |
| 577 | 585 |
| 578 template<typename T> | 586 template<typename T> |
| 579 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { | 587 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { |
| 580 return out << ptr.get(); | 588 return out << ptr.get(); |
| 581 } | 589 } |
| 582 #endif // UNIT_TEST | 590 #endif // UNIT_TEST |
| 583 | 591 |
| 584 #endif // CHROME_TEST_UI_UI_TEST_H_ | 592 #endif // CHROME_TEST_UI_UI_TEST_H_ |
| OLD | NEW |