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 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
6 #include "chrome/browser/chromeos/login/login_manager_test.h"
7 #include "chrome/browser/chromeos/login/startup_utils.h"
8 #include "chrome/browser/chromeos/login/user_adding_screen.h"
9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "content/public/test/test_utils.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 using namespace testing
;
19 const char* kTestUsers
[] = {"test-user@gmail.com",
20 "test-user1@gmail.com",
21 "test-user2@gmail.com"};
23 } // anonymous namespace
27 class UserAddingScreenTest
: public LoginManagerTest
,
28 public UserAddingScreen::Observer
{
30 UserAddingScreenTest() : LoginManagerTest(false),
31 user_adding_started_(0),
32 user_adding_finished_(0) {
35 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
36 LoginManagerTest::SetUpCommandLine(command_line
);
37 command_line
->AppendSwitch(::switches::kMultiProfiles
);
40 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
41 LoginManagerTest::SetUpInProcessBrowserTestFixture();
42 UserAddingScreen::Get()->AddObserver(this);
45 virtual void OnUserAddingFinished() OVERRIDE
{ ++user_adding_finished_
; }
47 virtual void OnUserAddingStarted() OVERRIDE
{ ++user_adding_started_
; }
49 int user_adding_started() { return user_adding_started_
; }
51 int user_adding_finished() { return user_adding_finished_
; }
54 int user_adding_started_
;
55 int user_adding_finished_
;
57 DISALLOW_COPY_AND_ASSIGN(UserAddingScreenTest
);
60 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest
, PRE_CancelAdding
) {
61 RegisterUser(kTestUsers
[0]);
62 RegisterUser(kTestUsers
[1]);
63 RegisterUser(kTestUsers
[2]);
64 StartupUtils::MarkOobeCompleted();
67 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest
, CancelAdding
) {
68 EXPECT_CALL(login_utils(), DoBrowserLaunch(_
, _
)).Times(1);
69 EXPECT_EQ(UserManager::Get()->GetUsers().size(), 3u);
70 EXPECT_EQ(UserManager::Get()->GetLoggedInUsers().size(), 0u);
72 LoginUser(kTestUsers
[0]);
73 EXPECT_EQ(UserManager::Get()->GetLoggedInUsers().size(), 1u);
75 UserAddingScreen::Get()->Start();
76 content::RunAllPendingInMessageLoop();
77 EXPECT_EQ(user_adding_started(), 1);
79 UserAddingScreen::Get()->Cancel();
80 content::RunAllPendingInMessageLoop();
81 EXPECT_EQ(user_adding_finished(), 1);
83 EXPECT_TRUE(LoginDisplayHostImpl::default_host() == NULL
);
84 EXPECT_EQ(UserManager::Get()->GetLoggedInUsers().size(), 1u);
85 EXPECT_EQ(UserManager::Get()->GetActiveUser()->email(), kTestUsers
[0]);
88 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest
, PRE_AddingSeveralUsers
) {
89 RegisterUser(kTestUsers
[0]);
90 RegisterUser(kTestUsers
[1]);
91 RegisterUser(kTestUsers
[2]);
92 StartupUtils::MarkOobeCompleted();
95 // Does not correctly enable multi-users. See http://crbug.com/326832.
96 IN_PROC_BROWSER_TEST_F(UserAddingScreenTest
, DISABLED_AddingSeveralUsers
) {
97 EXPECT_CALL(login_utils(), DoBrowserLaunch(_
, _
)).Times(3);
98 LoginUser(kTestUsers
[0]);
99 for (int i
= 1; i
< 3; ++i
) {
100 UserAddingScreen::Get()->Start();
101 content::RunAllPendingInMessageLoop();
102 EXPECT_EQ(user_adding_started(), i
);
103 AddUser(kTestUsers
[i
]);
104 EXPECT_EQ(user_adding_finished(), i
);
105 EXPECT_TRUE(LoginDisplayHostImpl::default_host() == NULL
);
106 EXPECT_EQ(UserManager::Get()->GetLoggedInUsers().size(), unsigned(i
+ 1));
110 } // namespace chromeos