ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_browsertest.cc
bloba66cd30fc5d0c7c3e71e4344486b2e22e7d33432
1 // Copyright (c) 2012 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 #include "ash/shell.h"
6 #include "ash/system/tray/system_tray.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/login/login_manager_test.h"
11 #include "chrome/browser/chromeos/login/login_wizard.h"
12 #include "chrome/browser/chromeos/login/startup_utils.h"
13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/wizard_controller.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/profiles/profiles_state.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/interactive_test_utils.h"
23 #include "chrome/test/base/tracing.h"
24 #include "chrome/test/base/ui_test_utils.h"
25 #include "chromeos/chromeos_switches.h"
26 #include "chromeos/login/user_names.h"
27 #include "chromeos/settings/cros_settings_names.h"
28 #include "content/public/browser/render_frame_host.h"
29 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/test_utils.h"
31 #include "extensions/browser/extension_system.h"
32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h"
35 using ::testing::_;
36 using ::testing::AnyNumber;
37 using ::testing::Return;
39 namespace {
41 const char kTestUser[] = "test-user@gmail.com";
42 const char kPassword[] = "password";
44 void FilterFrameByName(std::set<content::RenderFrameHost*>* frame_set,
45 const std::string& frame_name,
46 content::RenderFrameHost* frame) {
47 if (frame->GetFrameName() == frame_name)
48 frame_set->insert(frame);
51 class LoginUserTest : public InProcessBrowserTest {
52 protected:
53 void SetUpCommandLine(base::CommandLine* command_line) override {
54 command_line->AppendSwitchASCII(
55 chromeos::switches::kLoginUser, "TestUser@gmail.com");
56 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
57 "hash");
61 class LoginGuestTest : public InProcessBrowserTest {
62 protected:
63 void SetUpCommandLine(base::CommandLine* command_line) override {
64 command_line->AppendSwitch(chromeos::switches::kGuestSession);
65 command_line->AppendSwitch(::switches::kIncognito);
66 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
67 "hash");
68 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
69 chromeos::login::kGuestUserName);
73 class LoginCursorTest : public InProcessBrowserTest {
74 protected:
75 void SetUpCommandLine(base::CommandLine* command_line) override {
76 command_line->AppendSwitch(chromeos::switches::kLoginManager);
80 class LoginSigninTest : public InProcessBrowserTest {
81 protected:
82 void SetUpCommandLine(base::CommandLine* command_line) override {
83 command_line->AppendSwitch(chromeos::switches::kLoginManager);
84 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
87 void SetUpOnMainThread() override {
88 ASSERT_TRUE(tracing::BeginTracingWithWatch(
89 "ui", "ui", "ShowLoginWebUI", 1));
93 class LoginTest : public chromeos::LoginManagerTest {
94 public:
95 LoginTest() : LoginManagerTest(true) {}
96 ~LoginTest() override {}
98 content::RenderFrameHost* GetNamedFrame(const std::string& frame_name) {
99 std::set<content::RenderFrameHost*> frame_set;
100 web_contents()->ForEachFrame(
101 base::Bind(&FilterFrameByName, &frame_set, frame_name));
102 return frame_set.empty() ? NULL : *frame_set.begin();
105 void ExecuteJsInGaiaAuthFrame(const std::string& js) {
106 content::RenderFrameHost* frame = GetNamedFrame("signin-frame");
107 ASSERT_TRUE(frame);
108 ASSERT_TRUE(content::ExecuteScript(frame, js));
111 void StartGaiaAuthOffline() {
112 content::DOMMessageQueue message_queue;
113 const std::string js = "(function() {"
114 "var frame = $('signin-frame');"
115 "var onload= function() {"
116 "frame.removeEventListener('load', onload);"
117 "window.domAutomationController.setAutomationId(0);"
118 "window.domAutomationController.send('frameLoaded');"
119 "};"
120 "frame.addEventListener('load', onload);"
121 "$('error-offline-login-link').onclick();"
122 "})();";
123 ASSERT_TRUE(content::ExecuteScript(web_contents(), js));
125 std::string message;
126 do {
127 ASSERT_TRUE(message_queue.WaitForMessage(&message));
128 } while (message != "\"frameLoaded\"");
131 void SubmitGaiaAuthOfflineForm(const std::string& user_email,
132 const std::string& password) {
133 // Note the input elements must match gaia_auth/offline.html.
134 std::string js =
135 "(function(){"
136 "document.getElementsByName('email')[0].value = '$Email';"
137 "document.getElementsByName('password')[0].value = '$Password';"
138 "document.getElementById('submit-button').click();"
139 "})();";
140 ReplaceSubstringsAfterOffset(&js, 0, "$Email", user_email);
141 ReplaceSubstringsAfterOffset(&js, 0, "$Password", password);
142 ExecuteJsInGaiaAuthFrame(js);
146 // Used to make sure that the system tray is visible and within the screen
147 // bounds after login.
148 void TestSystemTrayIsVisible() {
149 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
150 aura::Window* primary_win = ash::Shell::GetPrimaryRootWindow();
151 EXPECT_TRUE(tray->visible());
152 EXPECT_TRUE(primary_win->bounds().Contains(tray->GetBoundsInScreen()));
155 // After a chrome crash, the session manager will restart chrome with
156 // the -login-user flag indicating that the user is already logged in.
157 // This profile should NOT be an OTR profile.
158 IN_PROC_BROWSER_TEST_F(LoginUserTest, UserPassed) {
159 Profile* profile = browser()->profile();
160 std::string profile_base_path("hash");
161 profile_base_path.insert(0, chrome::kProfileDirPrefix);
162 EXPECT_EQ(profile_base_path, profile->GetPath().BaseName().value());
163 EXPECT_FALSE(profile->IsOffTheRecord());
165 TestSystemTrayIsVisible();
168 // Verifies the cursor is not hidden at startup when user is logged in.
169 IN_PROC_BROWSER_TEST_F(LoginUserTest, CursorShown) {
170 EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
172 TestSystemTrayIsVisible();
175 // After a guest login, we should get the OTR default profile.
176 IN_PROC_BROWSER_TEST_F(LoginGuestTest, GuestIsOTR) {
177 Profile* profile = browser()->profile();
178 EXPECT_TRUE(profile->IsOffTheRecord());
179 // Ensure there's extension service for this profile.
180 EXPECT_TRUE(extensions::ExtensionSystem::Get(profile)->extension_service());
182 TestSystemTrayIsVisible();
185 // Verifies the cursor is not hidden at startup when running guest session.
186 IN_PROC_BROWSER_TEST_F(LoginGuestTest, CursorShown) {
187 EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
189 TestSystemTrayIsVisible();
192 // Verifies the cursor is hidden at startup on login screen.
193 IN_PROC_BROWSER_TEST_F(LoginCursorTest, CursorHidden) {
194 // Login screen needs to be shown explicitly when running test.
195 chromeos::ShowLoginWizard(chromeos::WizardController::kLoginScreenName);
197 // Cursor should be hidden at startup
198 EXPECT_FALSE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
200 // Cursor should be shown after cursor is moved.
201 EXPECT_TRUE(ui_test_utils::SendMouseMoveSync(gfx::Point()));
202 EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
204 base::MessageLoop::current()->DeleteSoon(
205 FROM_HERE, chromeos::LoginDisplayHostImpl::default_host());
207 TestSystemTrayIsVisible();
210 // Verifies that the webui for login comes up successfully.
211 IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) {
212 base::TimeDelta no_timeout;
213 EXPECT_TRUE(tracing::WaitForWatchEvent(no_timeout));
214 std::string json_events;
215 ASSERT_TRUE(tracing::EndTracing(&json_events));
218 IN_PROC_BROWSER_TEST_F(LoginTest, PRE_GaiaAuthOffline) {
219 RegisterUser(kTestUser);
220 chromeos::StartupUtils::MarkOobeCompleted();
221 chromeos::CrosSettings::Get()->SetBoolean(
222 chromeos::kAccountsPrefShowUserNamesOnSignIn, false);
225 IN_PROC_BROWSER_TEST_F(LoginTest, GaiaAuthOffline) {
226 bool show_user;
227 ASSERT_TRUE(chromeos::CrosSettings::Get()->GetBoolean(
228 chromeos::kAccountsPrefShowUserNamesOnSignIn, &show_user));
229 ASSERT_FALSE(show_user);
231 StartGaiaAuthOffline();
233 chromeos::UserContext user_context(kTestUser);
234 user_context.SetKey(chromeos::Key(kPassword));
235 SetExpectedCredentials(user_context);
237 SubmitGaiaAuthOfflineForm(kTestUser, kPassword);
239 content::WindowedNotificationObserver(
240 chrome::NOTIFICATION_SESSION_STARTED,
241 content::NotificationService::AllSources()).Wait();
243 TestSystemTrayIsVisible();
246 } // namespace