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_
10 #include "chrome/browser/chromeos/login/mixin_based_browser_test.h"
11 #include "chrome/browser/chromeos/login/test/js_checker.h"
15 } // namespace content
21 // Base class for Chrome OS out-of-box/login WebUI tests.
22 // If no special configuration is done launches out-of-box WebUI.
23 // To launch login UI use PRE_* test that will register user(s) and mark
24 // out-of-box as completed.
25 // Guarantees that WebUI has been initialized by waiting for
26 // NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE notification.
27 class LoginManagerTest
: public MixinBasedBrowserTest
{
29 explicit LoginManagerTest(bool should_launch_browser
);
31 // Overridden from InProcessBrowserTest.
32 void TearDownOnMainThread() override
;
33 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
34 void SetUpInProcessBrowserTestFixture() override
;
35 void SetUpOnMainThread() override
;
37 // Registers the user with the given |user_id| on the device.
38 // This method should be called in PRE_* test.
39 // TODO(dzhioev): Add the ability to register users without a PRE_* test.
40 void RegisterUser(const std::string
& user_id
);
42 // Set expected credentials for next login attempt.
43 void SetExpectedCredentials(const UserContext
& user_context
);
45 // Tries to login with the credentials in |user_context|. The return value
46 // indicates whether the login attempt succeeded.
47 bool TryToLogin(const UserContext
& user_context
);
49 // Tries to add the user identified and authenticated by |user_context| to the
50 // session. The return value indicates whether the attempt succeeded. This
51 // method does the same as TryToLogin() but doesn't verify that the new user
52 // has become the active user.
53 bool AddUserToSession(const UserContext
& user_context
);
55 // Log in user with |user_id|. User should be registered using RegisterUser().
56 void LoginUser(const std::string
& user_id
);
58 // Add user with |user_id| to session.
59 void AddUser(const std::string
& user_id
);
61 // Executes given JS |expression| in |web_contents_| and checks
63 void JSExpect(const std::string
& expression
);
65 content::WebContents
* web_contents() { return web_contents_
; }
67 test::JSChecker
& js_checker() { return js_checker_
; }
69 static std::string
GetGaiaIDForUserID(const std::string
& user_id
);
72 void InitializeWebContents();
74 void set_web_contents(content::WebContents
* web_contents
) {
75 web_contents_
= web_contents
;
78 bool should_launch_browser_
;
79 content::WebContents
* web_contents_
;
80 test::JSChecker js_checker_
;
82 DISALLOW_COPY_AND_ASSIGN(LoginManagerTest
);
85 } // namespace chromeos
87 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_