Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/test/ui/ui_test.h

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

Powered by Google App Engine
This is Rietveld 408576698