OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 7 |
8 // This file provides a common base for running UI unit tests, which operate | 8 // This file provides a common base for running UI unit tests, which operate |
9 // the entire browser application in a separate process for holistic | 9 // the entire browser application in a separate process for holistic |
10 // functional testing. | 10 // functional testing. |
11 // | 11 // |
12 // Tests should #include this file, subclass UITest, and use the TEST_F macro | 12 // Tests should #include this file, subclass UITest, and use the TEST_F macro |
13 // to declare individual test cases. This provides a running browser window | 13 // to declare individual test cases. This provides a running browser window |
14 // during the test, accessible through the window_ member variable. The window | 14 // during the test, accessible through the window_ member variable. The window |
15 // will close when the test ends, regardless of whether the test passed. | 15 // will close when the test ends, regardless of whether the test passed. |
16 // | 16 // |
17 // Tests which need to launch the browser with a particular set of command-line | 17 // Tests which need to launch the browser with a particular set of command-line |
18 // arguments should set the value of launch_arguments_ in their constructors. | 18 // arguments should set the value of launch_arguments_ in their constructors. |
19 | 19 |
| 20 #include "build/build_config.h" |
| 21 |
| 22 #if defined(OS_WIN) |
20 #include <windows.h> | 23 #include <windows.h> |
| 24 #endif |
21 #include <string> | 25 #include <string> |
22 | 26 |
| 27 #include "base/message_loop.h" |
23 #include "base/path_service.h" | 28 #include "base/path_service.h" |
| 29 #include "base/process.h" |
24 #include "base/scoped_ptr.h" | 30 #include "base/scoped_ptr.h" |
25 #include "base/time.h" | 31 #include "base/time.h" |
| 32 #if defined(OS_WIN) |
| 33 // TODO(evanm): we should be able to just forward-declare |
| 34 // AutomationProxy here, but many files that #include this one don't |
| 35 // themselves #include automation_proxy.h. |
26 #include "chrome/test/automation/automation_proxy.h" | 36 #include "chrome/test/automation/automation_proxy.h" |
| 37 #endif |
27 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
28 | 39 |
| 40 class AutomationProxy; |
| 41 class BrowserProxy; |
29 class DictionaryValue; | 42 class DictionaryValue; |
30 class GURL; | 43 class GURL; |
31 class TabProxy; | 44 class TabProxy; |
32 | 45 |
33 class UITest : public testing::Test { | 46 class UITest : public testing::Test { |
34 protected: | 47 protected: |
35 // Delay to let browser complete a requested action. | 48 // Delay to let browser complete a requested action. |
36 static const int kWaitForActionMsec = 2000; | 49 static const int kWaitForActionMsec; |
37 static const int kWaitForActionMaxMsec = 10000; | 50 static const int kWaitForActionMaxMsec; |
38 // Delay to let the browser complete the test. | 51 // Delay to let the browser complete the test. |
39 static const int kMaxTestExecutionTime = 30000; | 52 static const int kMaxTestExecutionTime; |
40 | 53 |
41 // String to display when a test fails because the crash service isn't | 54 // String to display when a test fails because the crash service isn't |
42 // running. | 55 // running. |
43 static const wchar_t kFailedNoCrashService[]; | 56 static const wchar_t kFailedNoCrashService[]; |
44 | 57 |
45 // Tries to delete the specified file/directory returning true on success. | 58 // Tries to delete the specified file/directory returning true on success. |
46 // This differs from file_util::Delete in that it repeatedly invokes Delete | 59 // This differs from file_util::Delete in that it repeatedly invokes Delete |
47 // until successful, or a timeout is reached. Returns true on success. | 60 // until successful, or a timeout is reached. Returns true on success. |
48 static bool DieFileDie(const std::wstring& file, bool recurse); | 61 static bool DieFileDie(const std::wstring& file, bool recurse); |
49 | 62 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 const std::wstring& values, | 211 const std::wstring& values, |
199 const std::wstring& units, | 212 const std::wstring& units, |
200 bool important); | 213 bool important); |
201 | 214 |
202 // Gets the directory for the currently active profile in the browser. | 215 // Gets the directory for the currently active profile in the browser. |
203 std::wstring GetDownloadDirectory(); | 216 std::wstring GetDownloadDirectory(); |
204 | 217 |
205 // Get the handle of browser process connected to the automation. This | 218 // 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 | 219 // function only retruns a reference to the handle so the caller does not |
207 // own the handle returned. | 220 // own the handle returned. |
208 HANDLE process() { return process_; } | 221 base::ProcessHandle process() { return process_; } |
209 | 222 |
210 public: | 223 public: |
211 // Get/Set a flag to run the renderer in process when running the | 224 // Get/Set a flag to run the renderer in process when running the |
212 // tests. | 225 // tests. |
213 static bool in_process_renderer() { return in_process_renderer_; } | 226 static bool in_process_renderer() { return in_process_renderer_; } |
214 static void set_in_process_renderer(bool value) { | 227 static void set_in_process_renderer(bool value) { |
215 in_process_renderer_ = value; | 228 in_process_renderer_ = value; |
216 } | 229 } |
217 | 230 |
218 // Get/Set a flag to run the plugins in the renderer process when running the | 231 // Get/Set a flag to run the plugins in the renderer process when running the |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 const std::wstring& modifier, | 357 const std::wstring& modifier, |
345 const std::wstring& trace, | 358 const std::wstring& trace, |
346 const std::wstring& values, | 359 const std::wstring& values, |
347 const std::wstring& prefix, | 360 const std::wstring& prefix, |
348 const std::wstring& suffix, | 361 const std::wstring& suffix, |
349 const std::wstring& units, | 362 const std::wstring& units, |
350 bool important); | 363 bool important); |
351 | 364 |
352 protected: | 365 protected: |
353 AutomationProxy* automation() { | 366 AutomationProxy* automation() { |
| 367 #if defined(OS_WIN) |
354 EXPECT_TRUE(server_.get()); | 368 EXPECT_TRUE(server_.get()); |
355 return server_.get(); | 369 return server_.get(); |
| 370 #else |
| 371 // TODO(port): restore when AutomationProxy bits work. |
| 372 NOTIMPLEMENTED(); |
| 373 return NULL; |
| 374 #endif |
356 } | 375 } |
357 | 376 |
358 // 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, |
359 // forcibly killing them if they haven't exited by then. | 378 // forcibly killing them if they haven't exited by then. |
360 // 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 |
361 // session, even those unrelated in the test. | 380 // session, even those unrelated in the test. |
362 void CleanupAppProcesses(); | 381 void CleanupAppProcesses(); |
363 | 382 |
364 // Returns the proxy for the currently active tab, or NULL if there is no | 383 // Returns the proxy for the currently active tab, or NULL if there is no |
365 // tab or there was some kind of error. The returned pointer MUST be | 384 // tab or there was some kind of error. The returned pointer MUST be |
366 // deleted by the caller if non-NULL. | 385 // deleted by the caller if non-NULL. |
367 TabProxy* GetActiveTab(); | 386 TabProxy* GetActiveTab(); |
368 | 387 |
369 // ********* Member variables ********* | 388 // ********* Member variables ********* |
370 | 389 |
371 std::wstring browser_directory_; // Path to the browser executable, | 390 std::wstring browser_directory_; // Path to the browser executable, |
372 // with no trailing slash | 391 // with no trailing slash |
373 std::wstring test_data_directory_; // Path to the unit test data, | 392 std::wstring test_data_directory_; // Path to the unit test data, |
374 // with no trailing slash | 393 // with no trailing slash |
375 std::wstring launch_arguments_; // Arguments to the browser on launch. | 394 std::wstring launch_arguments_; // Arguments to the browser on launch. |
376 int expected_errors_; // The number of errors expected during | 395 size_t expected_errors_; // The number of errors expected during |
377 // the run (generally 0). | 396 // the run (generally 0). |
378 int expected_crashes_; // The number of crashes expected during | 397 int expected_crashes_; // The number of crashes expected during |
379 // the run (generally 0). | 398 // the run (generally 0). |
380 std::wstring homepage_; // Homepage used for testing. | 399 std::wstring homepage_; // Homepage used for testing. |
381 bool wait_for_initial_loads_; // Wait for initial loads to complete | 400 bool wait_for_initial_loads_; // Wait for initial loads to complete |
382 // in SetUp() before running test body. | 401 // in SetUp() before running test body. |
383 base::TimeTicks browser_launch_time_; // Time when the browser was run. | 402 base::TimeTicks browser_launch_time_; // Time when the browser was run. |
384 bool dom_automation_enabled_; // This can be set to true to have the | 403 bool dom_automation_enabled_; // This can be set to true to have the |
385 // test run the dom automation case. | 404 // test run the dom automation case. |
386 std::wstring template_user_data_; // See set_template_user_data(). | 405 std::wstring template_user_data_; // See set_template_user_data(). |
387 HANDLE process_; // Handle the the first Chrome process. | 406 base::ProcessHandle process_; // Handle to the first Chrome process. |
388 std::wstring user_data_dir_; // User data directory used for the test | 407 std::wstring user_data_dir_; // User data directory used for the test |
389 static bool in_process_renderer_; // true if we're in single process mode | 408 static bool in_process_renderer_; // true if we're in single process mode |
390 bool show_window_; // Determines if the window is shown or | 409 bool show_window_; // Determines if the window is shown or |
391 // hidden. Defaults to hidden. | 410 // hidden. Defaults to hidden. |
392 bool clear_profile_; // If true the profile is cleared before | 411 bool clear_profile_; // If true the profile is cleared before |
393 // launching. Default is true. | 412 // launching. Default is true. |
394 bool include_testing_id_; // Should we supply the testing channel | 413 bool include_testing_id_; // Should we supply the testing channel |
395 // id on the command line? Default is | 414 // id on the command line? Default is |
396 // true. | 415 // true. |
397 bool use_existing_browser_; // Duplicate of the static version. | 416 bool use_existing_browser_; // Duplicate of the static version. |
398 // Default value comes from static. | 417 // Default value comes from static. |
399 | 418 |
400 private: | 419 private: |
| 420 #if defined(OS_WIN) |
| 421 // TODO(port): make this use base::Time instead. It would seem easy, but |
| 422 // the code also depends on file_util::CountFilesCreatedAfter which hasn't |
| 423 // yet been made portable. |
401 FILETIME test_start_time_; // Time the test was started | 424 FILETIME test_start_time_; // Time the test was started |
402 // (so we can check for new crash dumps) | 425 // (so we can check for new crash dumps) |
| 426 #endif |
403 static bool in_process_plugins_; | 427 static bool in_process_plugins_; |
404 static bool no_sandbox_; | 428 static bool no_sandbox_; |
405 static bool safe_plugins_; | 429 static bool safe_plugins_; |
406 static bool full_memory_dump_; // If true, write full memory dump | 430 static bool full_memory_dump_; // If true, write full memory dump |
407 // during crash. | 431 // during crash. |
408 static bool show_error_dialogs_; // If true, a user is paying attention | 432 static bool show_error_dialogs_; // If true, a user is paying attention |
409 // to the test, so show error dialogs. | 433 // to the test, so show error dialogs. |
410 static bool default_use_existing_browser_; // The test connects to an already | 434 static bool default_use_existing_browser_; // The test connects to an already |
411 // running browser instance. | 435 // running browser instance. |
412 static bool dump_histograms_on_exit_; // Include histograms in log on exit. | 436 static bool dump_histograms_on_exit_; // Include histograms in log on exit. |
413 static bool enable_dcheck_; // Enable dchecks in release mode. | 437 static bool enable_dcheck_; // Enable dchecks in release mode. |
414 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without | 438 static bool silent_dump_on_dcheck_; // Dump process memory on dcheck without |
415 // crashing. | 439 // crashing. |
416 static bool disable_breakpad_; // Disable breakpad on the browser. | 440 static bool disable_breakpad_; // Disable breakpad on the browser. |
417 static int timeout_ms_; // Timeout in milliseconds to wait | 441 static int timeout_ms_; // Timeout in milliseconds to wait |
418 // for an test to finish. | 442 // for an test to finish. |
419 static std::wstring js_flags_; // Flags passed to the JS engine. | 443 static std::wstring js_flags_; // Flags passed to the JS engine. |
420 ::scoped_ptr<AutomationProxy> server_; | 444 #if defined(OS_WIN) |
| 445 // TODO(port): restore me after AutomationProxy works. |
| 446 scoped_ptr<AutomationProxy> server_; |
| 447 #endif |
421 | 448 |
422 MessageLoop message_loop_; // Enables PostTask to main thread. | 449 MessageLoop message_loop_; // Enables PostTask to main thread. |
423 | 450 |
424 int command_execution_timeout_ms_; | 451 int command_execution_timeout_ms_; |
425 int action_timeout_ms_; | 452 int action_timeout_ms_; |
426 int action_max_timeout_ms_; | 453 int action_max_timeout_ms_; |
427 }; | 454 }; |
428 | 455 |
429 // These exist only to support the gTest assertion macros, and | 456 // These exist only to support the gTest assertion macros, and |
430 // shouldn't be used in normal program code. | 457 // shouldn't be used in normal program code. |
431 #ifdef UNIT_TEST | 458 #ifdef UNIT_TEST |
432 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); | 459 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); |
433 | 460 |
434 template<typename T> | 461 template<typename T> |
435 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { | 462 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { |
436 return out << ptr.get(); | 463 return out << ptr.get(); |
437 } | 464 } |
438 #endif // UNIT_TEST | 465 #endif // UNIT_TEST |
439 | 466 |
440 #endif // CHROME_TEST_UI_UI_TEST_H_ | 467 #endif // CHROME_TEST_UI_UI_TEST_H_ |
OLD | NEW |