Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / login_browsertest.cc
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.
4
5 #include "ash/shell.h"
6 #include "base/command_line.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/chromeos/login/login_wizard.h"
9 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
10 #include "chrome/browser/chromeos/login/wizard_controller.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profiles_state.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/interactive_test_utils.h"
18 #include "chrome/test/base/tracing.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "chromeos/chromeos_switches.h"
21 #include "chromeos/login/user_names.h"
22 #include "content/public/test/test_utils.h"
23 #include "extensions/browser/extension_system.h"
24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26
27 using ::testing::_;
28 using ::testing::AnyNumber;
29 using ::testing::Return;
30
31 namespace {
32
33 class LoginUserTest : public InProcessBrowserTest {
34  protected:
35   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36     command_line->AppendSwitchASCII(
37         chromeos::switches::kLoginUser, "TestUser@gmail.com");
38     command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
39                                     "hash");
40   }
41 };
42
43 class LoginGuestTest : public InProcessBrowserTest {
44  protected:
45   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
46     command_line->AppendSwitch(chromeos::switches::kGuestSession);
47     command_line->AppendSwitch(::switches::kIncognito);
48     command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
49                                     "hash");
50     command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
51                                     chromeos::login::kGuestUserName);
52   }
53 };
54
55 class LoginCursorTest : public InProcessBrowserTest {
56  protected:
57   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
58     command_line->AppendSwitch(chromeos::switches::kLoginManager);
59   }
60 };
61
62 class LoginSigninTest : public InProcessBrowserTest {
63  protected:
64   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
65     command_line->AppendSwitch(chromeos::switches::kLoginManager);
66     command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
67   }
68
69   virtual void SetUpOnMainThread() OVERRIDE {
70     ASSERT_TRUE(tracing::BeginTracingWithWatch(
71         "ui", "ui", "ShowLoginWebUI", 1));
72   }
73 };
74
75 // After a chrome crash, the session manager will restart chrome with
76 // the -login-user flag indicating that the user is already logged in.
77 // This profile should NOT be an OTR profile.
78 IN_PROC_BROWSER_TEST_F(LoginUserTest, UserPassed) {
79   Profile* profile = browser()->profile();
80   std::string profile_base_path("hash");
81   profile_base_path.insert(0, chrome::kProfileDirPrefix);
82   EXPECT_EQ(profile_base_path, profile->GetPath().BaseName().value());
83   EXPECT_FALSE(profile->IsOffTheRecord());
84 }
85
86 // Verifies the cursor is not hidden at startup when user is logged in.
87 IN_PROC_BROWSER_TEST_F(LoginUserTest, CursorShown) {
88   EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
89 }
90
91 // After a guest login, we should get the OTR default profile.
92 IN_PROC_BROWSER_TEST_F(LoginGuestTest, GuestIsOTR) {
93   Profile* profile = browser()->profile();
94   EXPECT_TRUE(profile->IsOffTheRecord());
95   // Ensure there's extension service for this profile.
96   EXPECT_TRUE(extensions::ExtensionSystem::Get(profile)->extension_service());
97 }
98
99 // Verifies the cursor is not hidden at startup when running guest session.
100 IN_PROC_BROWSER_TEST_F(LoginGuestTest, CursorShown) {
101   EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
102 }
103
104 // Verifies the cursor is hidden at startup on login screen.
105 IN_PROC_BROWSER_TEST_F(LoginCursorTest, CursorHidden) {
106   // Login screen needs to be shown explicitly when running test.
107   chromeos::ShowLoginWizard(chromeos::WizardController::kLoginScreenName);
108
109   // Cursor should be hidden at startup
110   EXPECT_FALSE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
111
112   // Cursor should be shown after cursor is moved.
113   EXPECT_TRUE(ui_test_utils::SendMouseMoveSync(gfx::Point()));
114   EXPECT_TRUE(ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible());
115
116   base::MessageLoop::current()->DeleteSoon(
117       FROM_HERE, chromeos::LoginDisplayHostImpl::default_host());
118 }
119
120 // Verifies that the webui for login comes up successfully.
121 IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) {
122   base::TimeDelta no_timeout;
123   EXPECT_TRUE(tracing::WaitForWatchEvent(no_timeout));
124   std::string json_events;
125   ASSERT_TRUE(tracing::EndTracing(&json_events));
126 }
127
128 }  // namespace