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