Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_HELPER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_HELPER_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/chromeos/login/mock_login_utils.h" | 8 #include "chrome/browser/chromeos/login/mock_login_utils.h" |
| 9 #include "chrome/browser/chromeos/login/test/js_checker.h" | 9 #include "chrome/browser/chromeos/login/test/js_checker.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 class WebContents; | 12 class WebContents; |
| 14 } // namespace content | 13 } // namespace content |
| 15 | 14 |
| 16 namespace chromeos { | 15 namespace chromeos { |
| 17 | 16 |
| 18 // Base class for Chrome OS out-of-box/login WebUI tests. | 17 // Helper class for Chrome OS out-of-box/login WebUI tests. |
| 19 // If no special configuration is done launches out-of-box WebUI. | 18 // If no special configuration is done launches out-of-box WebUI. |
| 20 // To launch login UI use PRE_* test that will register user(s) and mark | 19 // To launch login UI use PRE_* test that will register user(s) and mark |
| 21 // out-of-box as completed. | 20 // out-of-box as completed. |
| 22 // Guarantees that WebUI has been initialized by waiting for | 21 class LoginManagerTestHelper { |
| 23 // NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE notification. | |
| 24 class LoginManagerTest : public InProcessBrowserTest { | |
| 25 public: | 22 public: |
| 26 explicit LoginManagerTest(bool should_launch_browser); | 23 LoginManagerTestHelper(); |
| 27 | 24 |
| 28 // Overriden from InProcessBrowserTest. | 25 // Sets up web contents. Guarantees that WebUI has been initialized by |
| 29 virtual void CleanUpOnMainThread() OVERRIDE; | 26 // waiting for NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE notification. |
| 30 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; | 27 void SetUp(); |
|
Nikita (slow)
2014/05/12 15:23:53
nit: Should this be named SetUpOnMainThread() to b
| |
| 31 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; | 28 void SetUpCommandLine(CommandLine* command_line); |
| 32 virtual void SetUpOnMainThread() OVERRIDE; | 29 void SetUpLoginUtils(bool should_launch_browser); |
| 30 void CleanUp(); | |
|
Nikita (slow)
2014/05/12 15:23:53
nit: CleanUpOnMainThread()?
| |
| 33 | 31 |
| 34 // Registers user with given |username| on device. | 32 // Registers user with given |username| on device. |
| 35 // Should be called in PRE_* test. | 33 // Should be called in PRE_* test. |
| 36 // TODO(dzhioev): add ability to register users without PRE_* test. | 34 // TODO(dzhioev): add ability to register users without PRE_* test. |
| 37 void RegisterUser(const std::string& username); | 35 void RegisterUser(const std::string& username); |
| 38 | 36 |
| 39 // Set expected credentials for next login attempt. | 37 // Set expected credentials for next login attempt. |
| 40 void SetExpectedCredentials(const std::string& username, | 38 void SetExpectedCredentials(const std::string& username, |
| 41 const std::string& password); | 39 const std::string& password); |
| 42 | 40 |
| 43 // Tries to login with |username| and |password|. Returns false if attempt | 41 // Tries to log in with |username| and |password|. Returns false if attempt |
| 44 // has failed. | 42 // has failed. |
| 45 bool TryToLogin(const std::string& username, const std::string& password); | 43 bool TryToLogIn(const std::string& username, const std::string& password); |
| 46 | 44 |
| 47 // Tries to add user to session with |username| and |password|. Returns false | 45 // Tries to add user to session with |username| and |password|. Returns false |
| 48 // if attempt has failed. this function does the same as TryToLogin but | 46 // if attempt has failed. this function does the same as TryToLogin but |
| 49 // doesn't check that new user become active user. | 47 // doesn't check that new user become active user. |
| 50 bool AddUserTosession(const std::string& username, | 48 bool AddUserToSession(const std::string& username, |
| 51 const std::string& password); | 49 const std::string& password); |
| 52 | 50 |
| 53 // Login user with |username|. User should be registered using RegisterUser(). | 51 // Log in user with |username|. User should be registered using |
| 54 void LoginUser(const std::string& username); | 52 // RegisterUser(). |
| 53 void LogInUser(const std::string& username); | |
| 55 | 54 |
| 56 // Add user with |username| to session. | 55 // Add user with |username| to session. |
| 57 void AddUser(const std::string& username); | 56 void AddUser(const std::string& username); |
| 58 | 57 |
| 59 // Executes given JS |expression| in |web_contents_| and checks | 58 // Executes given JS |expression| in |web_contents_| and checks |
| 60 // that it is true. | 59 // that it is true. |
| 61 void JSExpect(const std::string& expression); | 60 void JSExpect(const std::string& expression); |
| 62 | 61 |
| 63 MockLoginUtils& login_utils() { return *mock_login_utils_; } | 62 MockLoginUtils& login_utils() { return *mock_login_utils_; } |
| 64 | 63 |
| 65 content::WebContents* web_contents() { return web_contents_; } | 64 content::WebContents* web_contents() { return web_contents_; } |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 void InitializeWebContents(); | 67 void InitializeWebContents(); |
| 69 | 68 |
| 70 void set_web_contents(content::WebContents* web_contents) { | 69 void set_web_contents(content::WebContents* web_contents) { |
| 71 web_contents_ = web_contents; | 70 web_contents_ = web_contents; |
| 72 } | 71 } |
| 73 | 72 |
| 74 MockLoginUtils* mock_login_utils_; | 73 MockLoginUtils* mock_login_utils_; |
| 75 bool should_launch_browser_; | |
| 76 content::WebContents* web_contents_; | 74 content::WebContents* web_contents_; |
| 77 test::JSChecker js_checker_; | 75 test::JSChecker js_checker_; |
| 78 | 76 |
| 79 DISALLOW_COPY_AND_ASSIGN(LoginManagerTest); | 77 DISALLOW_COPY_AND_ASSIGN(LoginManagerTestHelper); |
| 80 }; | 78 }; |
| 81 | 79 |
| 82 } // namespace chromeos | 80 } // namespace chromeos |
| 83 | 81 |
| 84 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_ | 82 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_HELPER_H_ |
| OLD | NEW |