| 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_PERF_TEST_H_ |
| 6 #define CHROME_TEST_UI_UI_TEST_H_ | 6 #define CHROME_TEST_UI_UI_PERF_TEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 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 | |
| 11 // functional testing. | |
| 12 // | |
| 13 // Tests should #include this file, subclass UITest, and use the TEST_F macro | |
| 14 // to declare individual test cases. This provides a running browser window | |
| 15 // during the test, accessible through the window_ member variable. The window | |
| 16 // will close when the test ends, regardless of whether the test passed. | |
| 17 // | |
| 18 // Tests which need to launch the browser with a particular set of command-line | |
| 19 // arguments should set the value of launch_arguments_ in their constructors. | |
| 20 | |
| 21 #include <string> | 9 #include <string> |
| 22 | 10 |
| 23 #include "base/command_line.h" | 11 #include "chrome/test/ui/ui_test.h" |
| 24 #include "base/message_loop.h" | |
| 25 #include "base/process.h" | |
| 26 #include "base/scoped_ptr.h" | |
| 27 #include "base/time.h" | |
| 28 #include "build/build_config.h" | |
| 29 // TODO(evanm): we should be able to just forward-declare | |
| 30 // AutomationProxy here, but many files that #include this one don't | |
| 31 // themselves #include automation_proxy.h. | |
| 32 #include "chrome/test/automation/automation_proxy.h" | |
| 33 #include "testing/platform_test.h" | |
| 34 | 12 |
| 35 class AutomationProxy; | 13 class UIPerfTest : public UITest { |
| 36 class BrowserProxy; | |
| 37 class DictionaryValue; | |
| 38 class FilePath; | |
| 39 class GURL; | |
| 40 class ScopedTempDir; | |
| 41 class TabProxy; | |
| 42 | |
| 43 // Base class for UI Tests. This implements the core of the functions. | |
| 44 // This base class decouples all automation functionality from testing | |
| 45 // infrastructure, for use without gtest. | |
| 46 // If using gtest, you probably want to inherit from UITest (declared below) | |
| 47 // rather than UITestBase. | |
| 48 class UITestBase { | |
| 49 protected: | 14 protected: |
| 50 // String to display when a test fails because the crash service isn't | |
| 51 // running. | |
| 52 static const wchar_t kFailedNoCrashService[]; | |
| 53 | |
| 54 // Constructor | |
| 55 UITestBase(); | |
| 56 explicit UITestBase(MessageLoop::Type msg_loop_type); | |
| 57 | |
| 58 virtual ~UITestBase(); | |
| 59 | |
| 60 // Starts the browser using the arguments in launch_arguments_, and | |
| 61 // sets up member variables. | |
| 62 virtual void SetUp(); | |
| 63 | |
| 64 // Closes the browser window. | |
| 65 virtual void TearDown(); | |
| 66 | |
| 67 // Set up the test time out values. | |
| 68 virtual void InitializeTimeouts(); | |
| 69 | |
| 70 public: | |
| 71 // ********* Utility functions ********* | |
| 72 | |
| 73 // Launches the browser and IPC testing server. | |
| 74 void LaunchBrowserAndServer(); | |
| 75 | |
| 76 // Overridable so that derived classes can provide their own AutomationProxy. | |
| 77 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | |
| 78 | |
| 79 // Closes the browser and IPC testing server. | |
| 80 void CloseBrowserAndServer(); | |
| 81 | |
| 82 // Launches the browser with the given command line. | |
| 83 // TODO(phajdan.jr): Make LaunchBrowser private. Tests should use | |
| 84 // LaunchAnotherBrowserBlockUntilClosed. | |
| 85 void LaunchBrowser(const CommandLine& cmdline, bool clear_profile); | |
| 86 | |
| 87 // Launches an another browser process and waits for it to finish. Returns | |
| 88 // true on success. | |
| 89 bool LaunchAnotherBrowserBlockUntilClosed(const CommandLine& cmdline); | |
| 90 | |
| 91 // Exits out browser instance. | |
| 92 void QuitBrowser(); | |
| 93 | |
| 94 // Terminates the browser, simulates end of session. | |
| 95 void TerminateBrowser(); | |
| 96 | |
| 97 // Tells the browser to navigato to the givne URL in the active tab | |
| 98 // of the first app window. | |
| 99 // Does not wait for the navigation to complete to return. | |
| 100 void NavigateToURLAsync(const GURL& url); | |
| 101 | |
| 102 // Tells the browser to navigate to the given URL in the active tab | |
| 103 // of the first app window. | |
| 104 // This method doesn't return until the navigation is complete. | |
| 105 void NavigateToURL(const GURL& url); | |
| 106 | |
| 107 // Same as above, except in the given tab and window. | |
| 108 void NavigateToURL(const GURL& url, int window_index, int tab_index); | |
| 109 | |
| 110 // Tells the browser to navigate to the given URL in the active tab | |
| 111 // of the first app window. | |
| 112 // This method doesn't return until the |number_of_navigations| navigations | |
| 113 // complete. | |
| 114 void NavigateToURLBlockUntilNavigationsComplete(const GURL& url, | |
| 115 int number_of_navigations); | |
| 116 | |
| 117 // Same as above, except in the given tab and window. | |
| 118 void NavigateToURLBlockUntilNavigationsComplete(const GURL& url, | |
| 119 int number_of_navigations, int tab_index, int window_index); | |
| 120 | |
| 121 // Returns the URL of the currently active tab. Only looks in the first | |
| 122 // window, for backward compatibility. If there is no active tab, or some | |
| 123 // other error, the returned URL will be empty. | |
| 124 GURL GetActiveTabURL() { return GetActiveTabURL(0); } | |
| 125 | |
| 126 // Like above, but looks at the window at the given index. | |
| 127 GURL GetActiveTabURL(int window_index); | |
| 128 | |
| 129 // Returns the title of the currently active tab. Only looks in the first | |
| 130 // window, for backward compatibility. | |
| 131 std::wstring GetActiveTabTitle() { return GetActiveTabTitle(0); } | |
| 132 | |
| 133 // Like above, but looks at the window at the given index. | |
| 134 std::wstring GetActiveTabTitle(int window_index); | |
| 135 | |
| 136 // Returns the tabstrip index of the currently active tab in the window at | |
| 137 // the given index, or -1 on error. Only looks in the first window, for | |
| 138 // backward compatibility. | |
| 139 int GetActiveTabIndex() { return GetActiveTabIndex(0); } | |
| 140 | |
| 141 // Like above, but looks at the window at the given index. | |
| 142 int GetActiveTabIndex(int window_index); | |
| 143 | |
| 144 // Returns true when the browser process is running, independent if any | |
| 145 // renderer process exists or not. It will returns false if an user closed the | |
| 146 // window or if the browser process died by itself. | |
| 147 bool IsBrowserRunning(); | |
| 148 | |
| 149 // Returns true when time_out_ms milliseconds have elapsed. | |
| 150 // Returns false if the browser process died while waiting. | |
| 151 bool CrashAwareSleep(int time_out_ms); | |
| 152 | |
| 153 // Returns the number of tabs in the first window. If no windows exist, | |
| 154 // causes a test failure and returns 0. | |
| 155 int GetTabCount(); | |
| 156 | |
| 157 // Same as GetTabCount(), except with the window at the given index. | |
| 158 int GetTabCount(int window_index); | |
| 159 | |
| 160 // Polls the tab for the cookie_name cookie and returns once one of the | |
| 161 // following conditions hold true: | |
| 162 // - The cookie is of expected_value. | |
| 163 // - The browser process died. | |
| 164 // - The time_out value has been exceeded. | |
| 165 bool WaitUntilCookieValue(TabProxy* tab, const GURL& url, | |
| 166 const char* cookie_name, | |
| 167 int time_out_ms, | |
| 168 const char* expected_value); | |
| 169 // Polls the tab for the cookie_name cookie and returns once one of the | |
| 170 // following conditions hold true: | |
| 171 // - The cookie is set to any value. | |
| 172 // - The browser process died. | |
| 173 // - The time_out value has been exceeded. | |
| 174 std::string WaitUntilCookieNonEmpty(TabProxy* tab, | |
| 175 const GURL& url, | |
| 176 const char* cookie_name, | |
| 177 int time_out_ms); | |
| 178 | |
| 179 // Polls the tab for a JavaScript condition and returns once one of the | |
| 180 // following conditions hold true: | |
| 181 // - The JavaScript condition evaluates to true (return true). | |
| 182 // - The browser process died (return false). | |
| 183 // - The time_out value has been exceeded (return false). | |
| 184 // | |
| 185 // The JavaScript expression is executed in the context of the frame that | |
| 186 // matches the provided xpath. | |
| 187 bool WaitUntilJavaScriptCondition(TabProxy* tab, | |
| 188 const std::wstring& frame_xpath, | |
| 189 const std::wstring& jscript, | |
| 190 int time_out_ms); | |
| 191 | |
| 192 // Polls up to kWaitForActionMaxMsec ms to attain a specific tab count. Will | |
| 193 // assert that the tab count is valid at the end of the wait. | |
| 194 void WaitUntilTabCount(int tab_count); | |
| 195 | |
| 196 // Checks whether the download shelf is visible in the current browser, giving | |
| 197 // it a chance to appear (we don't know the exact timing) while finishing as | |
| 198 // soon as possible. | |
| 199 bool WaitForDownloadShelfVisible(BrowserProxy* browser); | |
| 200 | |
| 201 // Checks whether the download shelf is invisible in the current browser, | |
| 202 // giving it a chance to appear (we don't know the exact timing) while | |
| 203 // finishing as soon as possible. | |
| 204 bool WaitForDownloadShelfInvisible(BrowserProxy* browser); | |
| 205 | |
| 206 private: | |
| 207 // Waits for download shelf visibility or invisibility. | |
| 208 bool WaitForDownloadShelfVisibilityChange(BrowserProxy* browser, | |
| 209 bool wait_for_open); | |
| 210 | |
| 211 public: | |
| 212 | |
| 213 // Waits until the Find window has become fully visible (if |wait_for_open| is | |
| 214 // true) or fully hidden (if |wait_for_open| is false). This function can time | |
| 215 // out (return false) if the window doesn't appear within a specific time. | |
| 216 bool WaitForFindWindowVisibilityChange(BrowserProxy* browser, | |
| 217 bool wait_for_open); | |
| 218 | |
| 219 // Waits until the Bookmark bar has stopped animating and become fully visible | |
| 220 // (if |wait_for_open| is true) or fully hidden (if |wait_for_open| is false). | |
| 221 // This function can time out (in which case it returns false). | |
| 222 bool WaitForBookmarkBarVisibilityChange(BrowserProxy* browser, | |
| 223 bool wait_for_open); | |
| 224 | |
| 225 // Sends the request to close the browser without blocking. | |
| 226 // This is so we can interact with dialogs opened on browser close, | |
| 227 // e.g. the beforeunload confirm dialog. | |
| 228 void CloseBrowserAsync(BrowserProxy* browser) const; | |
| 229 | |
| 230 // Closes the specified browser. Returns true if the browser was closed. | |
| 231 // This call is blocking. |application_closed| is set to true if this was | |
| 232 // the last browser window (and therefore as a result of it closing the | |
| 233 // browser process terminated). Note that in that case this method returns | |
| 234 // after the browser process has terminated. | |
| 235 bool CloseBrowser(BrowserProxy* browser, bool* application_closed) const; | |
| 236 | |
| 237 // Prints numerical information to stdout in a controlled format, for | 15 // Prints numerical information to stdout in a controlled format, for |
| 238 // post-processing. |measurement| is a description of the quantity being | 16 // post-processing. |measurement| is a description of the quantity being |
| 239 // measured, e.g. "vm_peak"; |modifier| is provided as a convenience and | 17 // measured, e.g. "vm_peak"; |modifier| is provided as a convenience and |
| 240 // will be appended directly to the name of the |measurement|, e.g. | 18 // will be appended directly to the name of the |measurement|, e.g. |
| 241 // "_browser"; |trace| is a description of the particular data point, e.g. | 19 // "_browser"; |trace| is a description of the particular data point, e.g. |
| 242 // "reference"; |value| is the measured value; and |units| is a description | 20 // "reference"; |value| is the measured value; and |units| is a description |
| 243 // of the units of measure, e.g. "bytes". If |important| is true, the output | 21 // of the units of measure, e.g. "bytes". If |important| is true, the output |
| 244 // line will be specially marked, to notify the post-processor. The strings | 22 // line will be specially marked, to notify the post-processor. The strings |
| 245 // may be empty. They should not contain any colons (:) or equals signs (=). | 23 // may be empty. They should not contain any colons (:) or equals signs (=). |
| 246 // A typical post-processing step would be to produce graphs of the data | 24 // A typical post-processing step would be to produce graphs of the data |
| (...skipping 30 matching lines...) Expand all Loading... |
| 277 // will generally be a list of comma-separated numbers. A typical | 55 // will generally be a list of comma-separated numbers. A typical |
| 278 // post-processing step might produce plots of their mean and standard | 56 // post-processing step might produce plots of their mean and standard |
| 279 // deviation. | 57 // deviation. |
| 280 void PrintResultList(const std::string& measurement, | 58 void PrintResultList(const std::string& measurement, |
| 281 const std::string& modifier, | 59 const std::string& modifier, |
| 282 const std::string& trace, | 60 const std::string& trace, |
| 283 const std::string& values, | 61 const std::string& values, |
| 284 const std::string& units, | 62 const std::string& units, |
| 285 bool important); | 63 bool important); |
| 286 | 64 |
| 287 // Gets the directory for the currently active profile in the browser. | |
| 288 FilePath GetDownloadDirectory(); | |
| 289 | |
| 290 // Get the handle of browser process connected to the automation. This | |
| 291 // function only retruns a reference to the handle so the caller does not | |
| 292 // own the handle returned. | |
| 293 base::ProcessHandle process() { return process_; } | |
| 294 | |
| 295 // Wait for |generated_file| to be ready and then compare it with | |
| 296 // |original_file| to see if they're identical or not if |compare_file| is | |
| 297 // true. If |need_equal| is true, they need to be identical. Otherwise, | |
| 298 // they should be different. This function will delete the generated file if | |
| 299 // the parameter |delete_generated_file| is true. | |
| 300 void WaitForGeneratedFileAndCheck(const FilePath& generated_file, | |
| 301 const FilePath& original_file, | |
| 302 bool compare_files, | |
| 303 bool need_equal, | |
| 304 bool delete_generated_file); | |
| 305 | |
| 306 // Get/Set a flag to run the renderer in process when running the | |
| 307 // tests. | |
| 308 static bool in_process_renderer() { return in_process_renderer_; } | |
| 309 static void set_in_process_renderer(bool value) { | |
| 310 in_process_renderer_ = value; | |
| 311 } | |
| 312 | |
| 313 // Get/Set a flag to run the renderer outside the sandbox when running the | |
| 314 // tests | |
| 315 static bool no_sandbox() { return no_sandbox_; } | |
| 316 static void set_no_sandbox(bool value) { | |
| 317 no_sandbox_ = value; | |
| 318 } | |
| 319 | |
| 320 // Get/Set a flag to run with DCHECKs enabled in release. | |
| 321 static bool enable_dcheck() { return enable_dcheck_; } | |
| 322 static void set_enable_dcheck(bool value) { | |
| 323 enable_dcheck_ = value; | |
| 324 } | |
| 325 | |
| 326 // Get/Set a flag to dump the process memory without crashing on DCHECKs. | |
| 327 static bool silent_dump_on_dcheck() { return silent_dump_on_dcheck_; } | |
| 328 static void set_silent_dump_on_dcheck(bool value) { | |
| 329 silent_dump_on_dcheck_ = value; | |
| 330 } | |
| 331 | |
| 332 // Get/Set a flag to disable breakpad handling. | |
| 333 static bool disable_breakpad() { return disable_breakpad_; } | |
| 334 static void set_disable_breakpad(bool value) { | |
| 335 disable_breakpad_ = value; | |
| 336 } | |
| 337 | |
| 338 // Get/Set a flag to run the plugin processes inside the sandbox when running | |
| 339 // the tests | |
| 340 static bool safe_plugins() { return safe_plugins_; } | |
| 341 static void set_safe_plugins(bool value) { | |
| 342 safe_plugins_ = value; | |
| 343 } | |
| 344 | |
| 345 static bool show_error_dialogs() { return show_error_dialogs_; } | |
| 346 static void set_show_error_dialogs(bool value) { | |
| 347 show_error_dialogs_ = value; | |
| 348 } | |
| 349 | |
| 350 static bool full_memory_dump() { return full_memory_dump_; } | |
| 351 static void set_full_memory_dump(bool value) { | |
| 352 full_memory_dump_ = value; | |
| 353 } | |
| 354 | |
| 355 static bool dump_histograms_on_exit() { return dump_histograms_on_exit_; } | |
| 356 static void set_dump_histograms_on_exit(bool value) { | |
| 357 dump_histograms_on_exit_ = value; | |
| 358 } | |
| 359 | |
| 360 static int test_timeout_ms() { return timeout_ms_; } | |
| 361 static void set_test_timeout_ms(int value) { | |
| 362 timeout_ms_ = value; | |
| 363 } | |
| 364 | |
| 365 static const std::string& js_flags() { return js_flags_; } | |
| 366 static void set_js_flags(const std::string& value) { | |
| 367 js_flags_ = value; | |
| 368 } | |
| 369 | |
| 370 static const std::string& log_level() { return log_level_; } | |
| 371 static void set_log_level(const std::string& value) { | |
| 372 log_level_ = value; | |
| 373 } | |
| 374 | |
| 375 // Profile theme type choices. | |
| 376 typedef enum { | |
| 377 DEFAULT_THEME = 0, | |
| 378 COMPLEX_THEME = 1, | |
| 379 NATIVE_THEME = 2, | |
| 380 CUSTOM_FRAME = 3, | |
| 381 CUSTOM_FRAME_NATIVE_THEME = 4, | |
| 382 } ProfileType; | |
| 383 | |
| 384 // Returns the directory name where the "typical" user data is that we use | |
| 385 // for testing. | |
| 386 static FilePath ComputeTypicalUserDataSource(ProfileType profile_type); | |
| 387 | |
| 388 // Rewrite the preferences file to point to the proper image directory. | |
| 389 static void RewritePreferencesFile(const FilePath& user_data_dir); | |
| 390 | |
| 391 // Called by some tests that wish to have a base profile to start from. This | |
| 392 // "user data directory" (containing one or more profiles) will be recursively | |
| 393 // copied into the user data directory for the test and the files will be | |
| 394 // evicted from the OS cache. To start with a blank profile, supply an empty | |
| 395 // string (the default). | |
| 396 const FilePath& template_user_data() const { return template_user_data_; } | |
| 397 void set_template_user_data(const FilePath& template_user_data) { | |
| 398 template_user_data_ = template_user_data; | |
| 399 } | |
| 400 | |
| 401 // Return the user data directory being used by the browser instance in | |
| 402 // UITest::SetUp(). | |
| 403 FilePath user_data_dir() const; | |
| 404 | |
| 405 // Return the process id of the browser process (-1 on error). | |
| 406 base::ProcessId browser_process_id() const { return process_id_; } | |
| 407 | |
| 408 // Timeout accessors. | |
| 409 void set_command_execution_timeout_ms(int timeout); | |
| 410 | |
| 411 int command_execution_timeout_ms() const { | |
| 412 return command_execution_timeout_ms_; | |
| 413 } | |
| 414 | |
| 415 int action_timeout_ms() const { return action_timeout_ms_; } | |
| 416 | |
| 417 void set_action_timeout_ms(int timeout) { | |
| 418 action_timeout_ms_ = timeout; | |
| 419 } | |
| 420 | |
| 421 int action_max_timeout_ms() const { return action_max_timeout_ms_; } | |
| 422 | |
| 423 int sleep_timeout_ms() const { return sleep_timeout_ms_; } | |
| 424 | |
| 425 void set_ui_test_name(const std::string& name) { | |
| 426 ui_test_name_ = name; | |
| 427 } | |
| 428 | |
| 429 // Fetch the state which determines whether the profile will be cleared on | |
| 430 // next startup. | |
| 431 bool get_clear_profile() const { | |
| 432 return clear_profile_; | |
| 433 } | |
| 434 // Sets clear_profile_. Should be called before launching browser to have | |
| 435 // any effect. | |
| 436 void set_clear_profile(bool clear_profile) { | |
| 437 clear_profile_ = clear_profile; | |
| 438 } | |
| 439 | |
| 440 // Sets homepage_. Should be called before launching browser to have | |
| 441 // any effect. | |
| 442 void set_homepage(const std::string& homepage) { | |
| 443 homepage_ = homepage; | |
| 444 } | |
| 445 | |
| 446 // Different ways to quit the browser. | |
| 447 typedef enum { | |
| 448 WINDOW_CLOSE, | |
| 449 USER_QUIT, | |
| 450 SESSION_ENDING, | |
| 451 } ShutdownType; | |
| 452 | |
| 453 // Sets the shutdown type, which defaults to WINDOW_CLOSE. | |
| 454 void set_shutdown_type(ShutdownType value) { | |
| 455 shutdown_type_ = value; | |
| 456 } | |
| 457 | |
| 458 // Count the number of active browser processes launched by this test. | |
| 459 // The count includes browser sub-processes. | |
| 460 int GetBrowserProcessCount(); | |
| 461 | |
| 462 // Returns a copy of local state preferences. The caller is responsible for | |
| 463 // deleting the returned object. Returns NULL if there is an error. | |
| 464 DictionaryValue* GetLocalState(); | |
| 465 | |
| 466 // Returns a copy of the default profile preferences. The caller is | |
| 467 // responsible for deleting the returned object. Returns NULL if there is an | |
| 468 // error. | |
| 469 DictionaryValue* GetDefaultProfilePreferences(); | |
| 470 | |
| 471 // Waits for the test case to finish. | |
| 472 // ASSERTS if there are test failures. | |
| 473 void WaitForFinish(const std::string &name, | |
| 474 const std::string &id, const GURL &url, | |
| 475 const std::string& test_complete_cookie, | |
| 476 const std::string& expected_cookie_value, | |
| 477 const int wait_time); | |
| 478 | |
| 479 // Wrapper around EvictFileFromSystemCache to retry 10 times in case of | |
| 480 // error. | |
| 481 // Apparently needed for Windows buildbots (to workaround an error when | |
| 482 // file is in use). | |
| 483 // TODO(phajdan.jr): Move to test_file_util if we need it in more places. | |
| 484 bool EvictFileFromSystemCacheWrapper(const FilePath& path); | |
| 485 | |
| 486 // Synchronously launches local http server normally used to run LayoutTests. | |
| 487 void StartHttpServer(const FilePath& root_directory); | |
| 488 | |
| 489 // Launches local http server on the specified port. | |
| 490 void StartHttpServerWithPort(const FilePath& root_directory, int port); | |
| 491 | |
| 492 void StopHttpServer(); | |
| 493 | |
| 494 // Prints IO performance data for use by perf graphs. | 65 // Prints IO performance data for use by perf graphs. |
| 495 void PrintIOPerfInfo(const char* test_name); | 66 void PrintIOPerfInfo(const char* test_name); |
| 496 | 67 |
| 497 // Prints memory usage data for use by perf graphs. | 68 // Prints memory usage data for use by perf graphs. |
| 498 void PrintMemoryUsageInfo(const char* test_name); | 69 void PrintMemoryUsageInfo(const char* test_name); |
| 499 | 70 |
| 500 // Prints memory commit charge stats for use by perf graphs. | 71 // Prints memory commit charge stats for use by perf graphs. |
| 501 void PrintSystemCommitCharge(const char* test_name, | 72 void PrintSystemCommitCharge(const char* test_name, |
| 502 size_t charge, | 73 size_t charge, |
| 503 bool important); | 74 bool important); |
| 504 | 75 |
| 505 // Configures the test to use the reference build. | 76 // Configures the test to use the reference build. |
| 506 void UseReferenceBuild(); | 77 void UseReferenceBuild(); |
| 507 | 78 |
| 508 // Use Chromium binaries from the given directory. | |
| 509 void SetBrowserDirectory(const FilePath& dir); | |
| 510 | |
| 511 private: | 79 private: |
| 512 // Check that no processes related to Chrome exist, displaying | |
| 513 // the given message if any do. | |
| 514 void AssertAppNotRunning(const std::wstring& error_message); | |
| 515 | |
| 516 // Common functionality for the public PrintResults methods. | 80 // Common functionality for the public PrintResults methods. |
| 517 void PrintResultsImpl(const std::string& measurement, | 81 void PrintResultsImpl(const std::string& measurement, |
| 518 const std::string& modifier, | 82 const std::string& modifier, |
| 519 const std::string& trace, | 83 const std::string& trace, |
| 520 const std::string& values, | 84 const std::string& values, |
| 521 const std::string& prefix, | 85 const std::string& prefix, |
| 522 const std::string& suffix, | 86 const std::string& suffix, |
| 523 const std::string& units, | 87 const std::string& units, |
| 524 bool important); | 88 bool important); |
| 525 | |
| 526 protected: | |
| 527 AutomationProxy* automation() { | |
| 528 EXPECT_TRUE(server_.get()); | |
| 529 return server_.get(); | |
| 530 } | |
| 531 | |
| 532 virtual bool ShouldFilterInet() { | |
| 533 return true; | |
| 534 } | |
| 535 | |
| 536 // Wait a certain amount of time for all the app processes to exit, | |
| 537 // forcibly killing them if they haven't exited by then. | |
| 538 // It has the side-effect of killing every browser window opened in your | |
| 539 // session, even those unrelated in the test. | |
| 540 void CleanupAppProcesses(); | |
| 541 | |
| 542 // Returns the proxy for the currently active tab, or NULL if there is no | |
| 543 // tab or there was some kind of error. Only looks at the first window, for | |
| 544 // backward compatibility. The returned pointer MUST be deleted by the | |
| 545 // caller if non-NULL. | |
| 546 scoped_refptr<TabProxy> GetActiveTab(); | |
| 547 | |
| 548 // Like above, but looks at the window at the given index. | |
| 549 scoped_refptr<TabProxy> GetActiveTab(int window_index); | |
| 550 | |
| 551 // ********* Member variables ********* | |
| 552 | |
| 553 FilePath browser_directory_; // Path to the browser executable. | |
| 554 FilePath test_data_directory_; // Path to the unit test data. | |
| 555 CommandLine launch_arguments_; // Command to launch the browser | |
| 556 size_t expected_errors_; // The number of errors expected during | |
| 557 // the run (generally 0). | |
| 558 int expected_crashes_; // The number of crashes expected during | |
| 559 // the run (generally 0). | |
| 560 std::string homepage_; // Homepage used for testing. | |
| 561 bool wait_for_initial_loads_; // Wait for initial loads to complete | |
| 562 // in SetUp() before running test body. | |
| 563 base::TimeTicks browser_launch_time_; // Time when the browser was run. | |
| 564 base::TimeDelta browser_quit_time_; // How long the shutdown took. | |
| 565 bool dom_automation_enabled_; // This can be set to true to have the | |
| 566 // test run the dom automation case. | |
| 567 FilePath template_user_data_; // See set_template_user_data(). | |
| 568 base::ProcessHandle process_; // Handle to the first Chrome process. | |
| 569 base::ProcessId process_id_; // PID of |process_| (for debugging). | |
| 570 static bool in_process_renderer_; // true if we're in single process mode | |
| 571 bool show_window_; // Determines if the window is shown or | |
| 572 // hidden. Defaults to hidden. | |
| 573 bool clear_profile_; // If true the profile is cleared before | |
| 574 // launching. Default is true. | |
| 575 bool include_testing_id_; // Should we supply the testing channel | |
| 576 // id on the command line? Default is | |
| 577 // true. | |
| 578 bool enable_file_cookies_; // Enable file cookies, default is true. | |
| 579 ProfileType profile_type_; // Are we using a profile with a | |
| 580 // complex theme? | |
| 581 FilePath websocket_pid_file_; // PID file for websocket server. | |
| 582 ShutdownType shutdown_type_; // The method for shutting down | |
| 583 // the browser. Used in ShutdownTest. | |
| 584 | |
| 585 private: | |
| 586 bool LaunchBrowserHelper(const CommandLine& arguments, | |
| 587 bool wait, | |
| 588 base::ProcessHandle* process); | |
| 589 | |
| 590 // We want to have a current history database when we start the browser so | |
| 591 // things like the NTP will have thumbnails. This method updates the dates | |
| 592 // in the history to be more recent. | |
| 593 void UpdateHistoryDates(); | |
| 594 | |
| 595 base::Time test_start_time_; // Time the test was started | |
| 596 // (so we can check for new crash dumps) | |
| 597 static bool no_sandbox_; | |
| 598 static bool safe_plugins_; | |
| 599 static bool full_memory_dump_; // If true, write full memory dump | |
| 600 // during crash. | |
| 601 static bool show_error_dialogs_; // If true, a user is paying attention | |
| 602 // to the test, so show error dialogs. | |
| 603 static bool dump_histograms_on_exit_; // Include histograms in log on exit. | |
| 604 static bool enable_dcheck_; // Enable dchecks in release mode. | |
| 605 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without | |
| 606 // crashing. | |
| 607 static bool disable_breakpad_; // Disable breakpad on the browser. | |
| 608 static int timeout_ms_; // Timeout in milliseconds to wait | |
| 609 // for an test to finish. | |
| 610 static std::string js_flags_; // Flags passed to the JS engine. | |
| 611 static std::string log_level_; // Logging level. | |
| 612 | |
| 613 scoped_ptr<AutomationProxy> server_; | |
| 614 | |
| 615 int command_execution_timeout_ms_; | |
| 616 int action_timeout_ms_; | |
| 617 int action_max_timeout_ms_; | |
| 618 int sleep_timeout_ms_; | |
| 619 int terminate_timeout_ms_; | |
| 620 | |
| 621 std::string ui_test_name_; | |
| 622 | |
| 623 // We use a temporary directory for profile to avoid issues with being | |
| 624 // unable to delete some files because they're in use, etc. | |
| 625 scoped_ptr<ScopedTempDir> temp_profile_dir_; | |
| 626 }; | 89 }; |
| 627 | 90 |
| 628 class UITest : public UITestBase, public PlatformTest { | 91 #endif // CHROME_TEST_UI_UI_PERF_TEST_H_ |
| 629 protected: | |
| 630 UITest() {} | |
| 631 explicit UITest(MessageLoop::Type msg_loop_type) | |
| 632 : UITestBase(), PlatformTest(), message_loop_(msg_loop_type) { | |
| 633 } | |
| 634 virtual void SetUp(); | |
| 635 virtual void TearDown(); | |
| 636 | |
| 637 virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); | |
| 638 | |
| 639 private: | |
| 640 MessageLoop message_loop_; // Enables PostTask to main thread. | |
| 641 }; | |
| 642 | |
| 643 // These exist only to support the gTest assertion macros, and | |
| 644 // shouldn't be used in normal program code. | |
| 645 #ifdef UNIT_TEST | |
| 646 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); | |
| 647 | |
| 648 template<typename T> | |
| 649 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { | |
| 650 return out << ptr.get(); | |
| 651 } | |
| 652 #endif // UNIT_TEST | |
| 653 | |
| 654 #endif // CHROME_TEST_UI_UI_TEST_H_ | |
| OLD | NEW |