OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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. |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
25 #include "base/process.h" | 25 #include "base/process.h" |
26 #include "base/time.h" | 26 #include "base/time.h" |
27 #include "chrome/test/automation/proxy_launcher.h" | 27 #include "chrome/test/automation/proxy_launcher.h" |
28 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
29 #include "testing/platform_test.h" | 29 #include "testing/platform_test.h" |
30 | 30 |
31 class AutomationProxy; | 31 class AutomationProxy; |
32 class BrowserProxy; | 32 class BrowserProxy; |
33 class FilePath; | |
34 class GURL; | 33 class GURL; |
35 class TabProxy; | 34 class TabProxy; |
36 | 35 |
37 namespace base { | 36 namespace base { |
38 class DictionaryValue; | 37 class DictionaryValue; |
| 38 class FilePath; |
39 } | 39 } |
40 | 40 |
41 // Base class for UI Tests. This implements the core of the functions. | 41 // Base class for UI Tests. This implements the core of the functions. |
42 // This base class decouples all automation functionality from testing | 42 // This base class decouples all automation functionality from testing |
43 // infrastructure, for use without gtest. | 43 // infrastructure, for use without gtest. |
44 // If using gtest, you probably want to inherit from UITest (declared below) | 44 // If using gtest, you probably want to inherit from UITest (declared below) |
45 // rather than UITestBase. | 45 // rather than UITestBase. |
46 class UITestBase { | 46 class UITestBase { |
47 public: | 47 public: |
48 // Profile theme type choices. | 48 // Profile theme type choices. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 void WaitUntilTabCount(int tab_count); | 139 void WaitUntilTabCount(int tab_count); |
140 | 140 |
141 // Closes the specified browser. Returns true if the browser was closed. | 141 // Closes the specified browser. Returns true if the browser was closed. |
142 // This call is blocking. |application_closed| is set to true if this was | 142 // This call is blocking. |application_closed| is set to true if this was |
143 // the last browser window (and therefore as a result of it closing the | 143 // the last browser window (and therefore as a result of it closing the |
144 // browser process terminated). Note that in that case this method returns | 144 // browser process terminated). Note that in that case this method returns |
145 // after the browser process has terminated. | 145 // after the browser process has terminated. |
146 bool CloseBrowser(BrowserProxy* browser, bool* application_closed) const; | 146 bool CloseBrowser(BrowserProxy* browser, bool* application_closed) const; |
147 | 147 |
148 // Gets the executable file path of the Chrome browser process. | 148 // Gets the executable file path of the Chrome browser process. |
149 const FilePath::CharType* GetExecutablePath(); | 149 const base::FilePath::CharType* GetExecutablePath(); |
150 | 150 |
151 // Returns the directory name where the "typical" user data is that we use | 151 // Returns the directory name where the "typical" user data is that we use |
152 // for testing. | 152 // for testing. |
153 static FilePath ComputeTypicalUserDataSource(ProfileType profile_type); | 153 static base::FilePath ComputeTypicalUserDataSource(ProfileType profile_type); |
154 | 154 |
155 // Return the user data directory being used by the browser instance in | 155 // Return the user data directory being used by the browser instance in |
156 // UITest::SetUp(). | 156 // UITest::SetUp(). |
157 FilePath user_data_dir() const { | 157 base::FilePath user_data_dir() const { |
158 return launcher_->user_data_dir(); | 158 return launcher_->user_data_dir(); |
159 } | 159 } |
160 | 160 |
161 // Called by some tests that wish to have a base profile to start from. This | 161 // Called by some tests that wish to have a base profile to start from. This |
162 // "user data directory" (containing one or more profiles) will be recursively | 162 // "user data directory" (containing one or more profiles) will be recursively |
163 // copied into the user data directory for the test and the files will be | 163 // copied into the user data directory for the test and the files will be |
164 // evicted from the OS cache. To start with a blank profile, supply an empty | 164 // evicted from the OS cache. To start with a blank profile, supply an empty |
165 // string (the default). | 165 // string (the default). |
166 const FilePath& template_user_data() const { return template_user_data_; } | 166 const base::FilePath& template_user_data() const { return template_user_data_;
} |
167 void set_template_user_data(const FilePath& template_user_data) { | 167 void set_template_user_data(const base::FilePath& template_user_data) { |
168 template_user_data_ = template_user_data; | 168 template_user_data_ = template_user_data; |
169 } | 169 } |
170 | 170 |
171 // Get the handle of browser process connected to the automation. This | 171 // Get the handle of browser process connected to the automation. This |
172 // function only returns a reference to the handle so the caller does not | 172 // function only returns a reference to the handle so the caller does not |
173 // own the handle returned. | 173 // own the handle returned. |
174 base::ProcessHandle process() const { return launcher_->process(); } | 174 base::ProcessHandle process() const { return launcher_->process(); } |
175 | 175 |
176 // Return the process id of the browser process (-1 on error). | 176 // Return the process id of the browser process (-1 on error). |
177 base::ProcessId browser_process_id() const { return launcher_->process_id(); } | 177 base::ProcessId browser_process_id() const { return launcher_->process_id(); } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 219 |
220 // Get the number of crash dumps we've logged since the test started. | 220 // Get the number of crash dumps we've logged since the test started. |
221 int GetCrashCount() const; | 221 int GetCrashCount() const; |
222 | 222 |
223 // Returns empty string if there were no unexpected Chrome asserts or crashes, | 223 // Returns empty string if there were no unexpected Chrome asserts or crashes, |
224 // a string describing the failures otherwise. As a side effect, it will fail | 224 // a string describing the failures otherwise. As a side effect, it will fail |
225 // with EXPECT_EQ macros if this code runs within a gtest harness. | 225 // with EXPECT_EQ macros if this code runs within a gtest harness. |
226 std::string CheckErrorsAndCrashes() const; | 226 std::string CheckErrorsAndCrashes() const; |
227 | 227 |
228 // Use Chromium binaries from the given directory. | 228 // Use Chromium binaries from the given directory. |
229 void SetBrowserDirectory(const FilePath& dir); | 229 void SetBrowserDirectory(const base::FilePath& dir); |
230 | 230 |
231 // Appends a command-line switch (no associated value) to be passed to the | 231 // Appends a command-line switch (no associated value) to be passed to the |
232 // browser when launched. | 232 // browser when launched. |
233 void AppendBrowserLaunchSwitch(const char* name); | 233 void AppendBrowserLaunchSwitch(const char* name); |
234 | 234 |
235 // Appends a command-line switch with associated value to be passed to the | 235 // Appends a command-line switch with associated value to be passed to the |
236 // browser when launched. | 236 // browser when launched. |
237 void AppendBrowserLaunchSwitch(const char* name, const char* value); | 237 void AppendBrowserLaunchSwitch(const char* name, const char* value); |
238 | 238 |
239 // Pass-through to AutomationProxy::BeginTracing. | 239 // Pass-through to AutomationProxy::BeginTracing. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // backward compatibility. The returned pointer MUST be deleted by the | 276 // backward compatibility. The returned pointer MUST be deleted by the |
277 // caller if non-NULL. | 277 // caller if non-NULL. |
278 scoped_refptr<TabProxy> GetActiveTab(); | 278 scoped_refptr<TabProxy> GetActiveTab(); |
279 | 279 |
280 // Like above, but looks at the window at the given index. | 280 // Like above, but looks at the window at the given index. |
281 scoped_refptr<TabProxy> GetActiveTab(int window_index); | 281 scoped_refptr<TabProxy> GetActiveTab(int window_index); |
282 | 282 |
283 // ********* Member variables ********* | 283 // ********* Member variables ********* |
284 | 284 |
285 // Path to the browser executable. | 285 // Path to the browser executable. |
286 FilePath browser_directory_; | 286 base::FilePath browser_directory_; |
287 | 287 |
288 // Path to the unit test data. | 288 // Path to the unit test data. |
289 FilePath test_data_directory_; | 289 base::FilePath test_data_directory_; |
290 | 290 |
291 // Command to launch the browser | 291 // Command to launch the browser |
292 CommandLine launch_arguments_; | 292 CommandLine launch_arguments_; |
293 | 293 |
294 // The number of errors expected during the run (generally 0). | 294 // The number of errors expected during the run (generally 0). |
295 size_t expected_errors_; | 295 size_t expected_errors_; |
296 | 296 |
297 // The number of crashes expected during the run (generally 0). | 297 // The number of crashes expected during the run (generally 0). |
298 int expected_crashes_; | 298 int expected_crashes_; |
299 | 299 |
300 // Homepage used for testing. | 300 // Homepage used for testing. |
301 std::string homepage_; | 301 std::string homepage_; |
302 | 302 |
303 // Name of currently running automated test passed to Chrome process. | 303 // Name of currently running automated test passed to Chrome process. |
304 std::string test_name_; | 304 std::string test_name_; |
305 | 305 |
306 // Wait for initial loads to complete in SetUp() before running test body. | 306 // Wait for initial loads to complete in SetUp() before running test body. |
307 bool wait_for_initial_loads_; | 307 bool wait_for_initial_loads_; |
308 | 308 |
309 // This can be set to true to have the test run the dom automation case. | 309 // This can be set to true to have the test run the dom automation case. |
310 bool dom_automation_enabled_; | 310 bool dom_automation_enabled_; |
311 | 311 |
312 // See set_template_user_data(). | 312 // See set_template_user_data(). |
313 FilePath template_user_data_; | 313 base::FilePath template_user_data_; |
314 | 314 |
315 // Determines if the window is shown or hidden. Defaults to hidden. | 315 // Determines if the window is shown or hidden. Defaults to hidden. |
316 bool show_window_; | 316 bool show_window_; |
317 | 317 |
318 // If true the profile is cleared before launching. Default is true. | 318 // If true the profile is cleared before launching. Default is true. |
319 bool clear_profile_; | 319 bool clear_profile_; |
320 | 320 |
321 // Should we supply the testing channel id | 321 // Should we supply the testing channel id |
322 // on the command line? Default is true. | 322 // on the command line? Default is true. |
323 bool include_testing_id_; | 323 bool include_testing_id_; |
324 | 324 |
325 // Enable file cookies, default is true. | 325 // Enable file cookies, default is true. |
326 bool enable_file_cookies_; | 326 bool enable_file_cookies_; |
327 | 327 |
328 // Launches browser and AutomationProxy. | 328 // Launches browser and AutomationProxy. |
329 scoped_ptr<ProxyLauncher> launcher_; | 329 scoped_ptr<ProxyLauncher> launcher_; |
330 | 330 |
331 // Are we using a profile with a complex theme? | 331 // Are we using a profile with a complex theme? |
332 ProfileType profile_type_; | 332 ProfileType profile_type_; |
333 | 333 |
334 // PID file for websocket server. | 334 // PID file for websocket server. |
335 FilePath websocket_pid_file_; | 335 base::FilePath websocket_pid_file_; |
336 | 336 |
337 private: | 337 private: |
338 // Time the test was started (so we can check for new crash dumps) | 338 // Time the test was started (so we can check for new crash dumps) |
339 base::Time test_start_time_; | 339 base::Time test_start_time_; |
340 }; | 340 }; |
341 | 341 |
342 class UITest : public UITestBase, public PlatformTest { | 342 class UITest : public UITestBase, public PlatformTest { |
343 protected: | 343 protected: |
344 UITest() {} | 344 UITest() {} |
345 explicit UITest(MessageLoop::Type msg_loop_type) | 345 explicit UITest(MessageLoop::Type msg_loop_type) |
(...skipping 24 matching lines...) Expand all Loading... |
370 const std::string &id, const GURL &url, | 370 const std::string &id, const GURL &url, |
371 const std::string& test_complete_cookie, | 371 const std::string& test_complete_cookie, |
372 const std::string& expected_cookie_value, | 372 const std::string& expected_cookie_value, |
373 const base::TimeDelta wait_time); | 373 const base::TimeDelta wait_time); |
374 | 374 |
375 // Wrapper around EvictFileFromSystemCache to retry 10 times in case of | 375 // Wrapper around EvictFileFromSystemCache to retry 10 times in case of |
376 // error. | 376 // error. |
377 // Apparently needed for Windows buildbots (to workaround an error when | 377 // Apparently needed for Windows buildbots (to workaround an error when |
378 // file is in use). | 378 // file is in use). |
379 // TODO(phajdan.jr): Move to test_file_util if we need it in more places. | 379 // TODO(phajdan.jr): Move to test_file_util if we need it in more places. |
380 bool EvictFileFromSystemCacheWrapper(const FilePath& path); | 380 bool EvictFileFromSystemCacheWrapper(const base::FilePath& path); |
381 | 381 |
382 // Polls the tab for a JavaScript condition and returns once one of the | 382 // Polls the tab for a JavaScript condition and returns once one of the |
383 // following conditions hold true: | 383 // following conditions hold true: |
384 // - The JavaScript condition evaluates to true (return true). | 384 // - The JavaScript condition evaluates to true (return true). |
385 // - The browser process died (return false). | 385 // - The browser process died (return false). |
386 // - The timeout value has been exceeded (return false). | 386 // - The timeout value has been exceeded (return false). |
387 // | 387 // |
388 // The JavaScript expression is executed in the context of the frame that | 388 // The JavaScript expression is executed in the context of the frame that |
389 // matches the provided xpath. | 389 // matches the provided xpath. |
390 bool WaitUntilJavaScriptCondition(TabProxy* tab, | 390 bool WaitUntilJavaScriptCondition(TabProxy* tab, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 #ifdef UNIT_TEST | 437 #ifdef UNIT_TEST |
438 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); | 438 std::ostream& operator<<(std::ostream& out, const std::wstring& wstr); |
439 | 439 |
440 template<typename T> | 440 template<typename T> |
441 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { | 441 std::ostream& operator<<(std::ostream& out, const ::scoped_ptr<T>& ptr) { |
442 return out << ptr.get(); | 442 return out << ptr.get(); |
443 } | 443 } |
444 #endif // UNIT_TEST | 444 #endif // UNIT_TEST |
445 | 445 |
446 #endif // CHROME_TEST_UI_UI_TEST_H_ | 446 #endif // CHROME_TEST_UI_UI_TEST_H_ |
OLD | NEW |