- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / login_manager_test.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_
7
8 #include "chrome/browser/chromeos/login/mock_login_utils.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10
11 namespace content {
12 class WebContents;
13 }  // namespace content
14
15 namespace chromeos {
16
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 {
24  public:
25   explicit LoginManagerTest(bool should_launch_browser);
26
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;
32
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);
37
38   // Set expected credentials for next login attempt.
39   void SetExpectedCredentials(const std::string& username,
40                               const std::string& password);
41
42   // Tries to login with |username| and |password|. Returns false if attempt
43   // has failed.
44   bool TryToLogin(const std::string& username, const std::string& password);
45
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);
51
52   // Login user with |username|. User should be registered using RegisterUser().
53   void LoginUser(const std::string& username);
54
55   // Add user with |username| to session.
56   void AddUser(const std::string& username);
57
58   // Executes given JS |expression| in |web_contents_| and checks
59   // that it is true.
60   void JSExpect(const std::string& expression);
61
62   MockLoginUtils& login_utils() { return *mock_login_utils_; }
63
64   content::WebContents* web_contents() { return web_contents_; }
65
66  private:
67   void InitializeWebContents();
68
69   void set_web_contents(content::WebContents* web_contents) {
70     web_contents_ = web_contents;
71   }
72
73   MockLoginUtils* mock_login_utils_;
74   bool should_launch_browser_;
75   content::WebContents* web_contents_;
76
77   DISALLOW_COPY_AND_ASSIGN(LoginManagerTest);
78 };
79
80 }  // namespace chromeos
81
82 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_TEST_H_