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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_
8 #include "chrome/browser/chromeos/login/mock_login_utils.h"
9 #include "chrome/test/base/in_process_browser_test.h"
13 } // namespace content
17 // Base class for Chrome OS out-of-box/login WebUI tests.
18 // If no special configuration is done launches out-of-box WebUI.
19 // To launch login UI use PRE_* test that will register user(s) and mark
20 // out-of-box as completed.
21 // Guarantees that WebUI has been initialized by waiting for
22 // NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE notification.
23 class LoginManagerTest : public InProcessBrowserTest {
25 explicit LoginManagerTest(bool should_launch_browser);
27 // Overriden from InProcessBrowserTest.
28 virtual void CleanUpOnMainThread() OVERRIDE;
29 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
30 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
31 virtual void SetUpOnMainThread() OVERRIDE;
33 // Registers user with given |username| on device.
34 // Should be called in PRE_* test.
35 // TODO(dzhioev): add ability to register users without PRE_* test.
36 void RegisterUser(const std::string& username);
38 // Set expected credentials for next login attempt.
39 void SetExpectedCredentials(const std::string& username,
40 const std::string& password);
42 // Tries to login with |username| and |password|. Returns false if attempt
44 bool TryToLogin(const std::string& username, const std::string& password);
46 // Tries to add user to session with |username| and |password|. Returns false
47 // if attempt has failed. this function does the same as TryToLogin but
48 // doesn't check that new user become active user.
49 bool AddUserTosession(const std::string& username,
50 const std::string& password);
52 // Login user with |username|. User should be registered using RegisterUser().
53 void LoginUser(const std::string& username);
55 // Add user with |username| to session.
56 void AddUser(const std::string& username);
58 // Executes given JS |expression| in |web_contents_| and checks
60 void JSExpect(const std::string& expression);
62 MockLoginUtils& login_utils() { return *mock_login_utils_; }
64 content::WebContents* web_contents() { return web_contents_; }
67 void InitializeWebContents();
69 void set_web_contents(content::WebContents* web_contents) {
70 web_contents_ = web_contents;
73 MockLoginUtils* mock_login_utils_;
74 bool should_launch_browser_;
75 content::WebContents* web_contents_;
77 DISALLOW_COPY_AND_ASSIGN(LoginManagerTest);
80 } // namespace chromeos
82 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_