Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_manager_test.h
blob9e23abec7da650e08c500e90e4d2ae2cdd517563
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 <string>
10 #include "chrome/browser/chromeos/login/mixin_based_browser_test.h"
11 #include "chrome/browser/chromeos/login/test/https_forwarder.h"
12 #include "chrome/browser/chromeos/login/test/js_checker.h"
13 #include "google_apis/gaia/fake_gaia.h"
15 namespace content {
16 class WebContents;
17 } // namespace content
19 namespace chromeos {
21 class UserContext;
23 // Base class for Chrome OS out-of-box/login WebUI tests.
24 // If no special configuration is done launches out-of-box WebUI.
25 // To launch login UI use PRE_* test that will register user(s) and mark
26 // out-of-box as completed.
27 // Guarantees that WebUI has been initialized by waiting for
28 // NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE notification.
29 class LoginManagerTest : public MixinBasedBrowserTest {
30 public:
31 explicit LoginManagerTest(bool should_launch_browser);
32 ~LoginManagerTest() override;
34 // Overridden from InProcessBrowserTest.
35 void TearDownOnMainThread() override;
36 void SetUpCommandLine(base::CommandLine* command_line) override;
37 void SetUpInProcessBrowserTestFixture() override;
38 void SetUpOnMainThread() override;
39 void SetUp() override;
41 // Registers the user with the given |user_id| on the device.
42 // This method should be called in PRE_* test.
43 // TODO(dzhioev): Add the ability to register users without a PRE_* test.
44 void RegisterUser(const std::string& user_id);
46 // Set expected credentials for next login attempt.
47 void SetExpectedCredentials(const UserContext& user_context);
49 // Tries to login with the credentials in |user_context|. The return value
50 // indicates whether the login attempt succeeded.
51 bool TryToLogin(const UserContext& user_context);
53 // Tries to add the user identified and authenticated by |user_context| to the
54 // session. The return value indicates whether the attempt succeeded. This
55 // method does the same as TryToLogin() but doesn't verify that the new user
56 // has become the active user.
57 bool AddUserToSession(const UserContext& user_context);
59 // Log in user with |user_id|. User should be registered using RegisterUser().
60 void LoginUser(const std::string& user_id);
62 // Add user with |user_id| to session.
63 void AddUser(const std::string& user_id);
65 // Executes given JS |expression| in |web_contents_| and checks
66 // that it is true.
67 void JSExpect(const std::string& expression);
69 content::WebContents* web_contents() { return web_contents_; }
71 test::JSChecker& js_checker() { return js_checker_; }
73 static std::string GetGaiaIDForUserID(const std::string& user_id);
75 // For obviously consumer users (that have e.g. @gmail.com e-mail) policy
76 // fetching code is skipped. This code is executed only for users that may be
77 // enterprise users. Thus if you derive from this class and don't need
78 // policies, please use @gmail.com e-mail for login. But if you need policies
79 // for your test, you must use e-mail addresses that a) have a potentially
80 // enterprise domain and b) have been registered with |fake_gaia_|.
81 // For your convenience, the e-mail addresses for users that have been set up
82 // in this way are provided below.
83 static const char kEnterpriseUser1[];
84 static const char kEnterpriseUser2[];
86 protected:
87 FakeGaia fake_gaia_;
88 HTTPSForwarder gaia_https_forwarder_;
90 private:
91 void InitializeWebContents();
93 void set_web_contents(content::WebContents* web_contents) {
94 web_contents_ = web_contents;
97 bool should_launch_browser_;
98 content::WebContents* web_contents_;
99 test::JSChecker js_checker_;
101 DISALLOW_COPY_AND_ASSIGN(LoginManagerTest);
104 } // namespace chromeos
106 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_