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/ui/ash/session_state_delegate_chromeos.h"
10 #include "chrome/browser/chromeos/login/fake_user_manager.h"
11 #include "chrome/test/base/testing_profile_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
15 class SessionStateDelegateChromeOSTest
: public testing::Test
{
17 SessionStateDelegateChromeOSTest() : user_manager_(NULL
) {
20 virtual ~SessionStateDelegateChromeOSTest() {
23 virtual void SetUp() OVERRIDE
{
24 // Initialize the UserManager singleton to a fresh FakeUserManager instance.
25 user_manager_
= new chromeos::FakeUserManager
;
26 user_manager_enabler_
.reset(
27 new chromeos::ScopedUserManagerEnabler(user_manager_
));
29 // Create our SessionStateDelegate to experiment with.
30 session_state_delegate_
.reset(new SessionStateDelegateChromeos());
31 testing::Test::SetUp();
34 virtual void TearDown() OVERRIDE
{
35 testing::Test::TearDown();
36 session_state_delegate_
.reset();
37 user_manager_enabler_
.reset();
41 // Add and log in a user to the session.
42 void UserAddedToSession(std::string user
) {
43 user_manager()->AddUser(user
);
44 user_manager()->LoginUser(user
);
47 // Get the active user.
48 const std::string
& GetActiveUser() {
49 return chromeos::UserManager::Get()->GetActiveUser()->email();
52 chromeos::FakeUserManager
* user_manager() { return user_manager_
; }
53 SessionStateDelegateChromeos
* session_state_delegate() {
54 return session_state_delegate_
.get();
58 scoped_ptr
<chromeos::ScopedUserManagerEnabler
> user_manager_enabler_
;
59 scoped_ptr
<SessionStateDelegateChromeos
> session_state_delegate_
;
62 chromeos::FakeUserManager
* user_manager_
;
64 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateChromeOSTest
);
67 // Make sure that cycling one user does not cause any harm.
68 TEST_F(SessionStateDelegateChromeOSTest
, CyclingOneUser
) {
69 UserAddedToSession("firstuser@test.com");
71 EXPECT_EQ("firstuser@test.com", GetActiveUser());
72 session_state_delegate()->CycleActiveUser(
73 ash::SessionStateDelegate::CYCLE_TO_NEXT_USER
);
74 EXPECT_EQ("firstuser@test.com", GetActiveUser());
75 session_state_delegate()->CycleActiveUser(
76 ash::SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
);
77 EXPECT_EQ("firstuser@test.com", GetActiveUser());
80 // Cycle three users forwards and backwards to see that it works.
81 TEST_F(SessionStateDelegateChromeOSTest
, CyclingThreeUsers
) {
82 UserAddedToSession("firstuser@test.com");
83 UserAddedToSession("seconduser@test.com");
84 UserAddedToSession("thirduser@test.com");
85 const ash::SessionStateDelegate::CycleUser forward
=
86 ash::SessionStateDelegate::CYCLE_TO_NEXT_USER
;
89 EXPECT_EQ("firstuser@test.com", GetActiveUser());
90 session_state_delegate()->CycleActiveUser(forward
);
91 EXPECT_EQ("seconduser@test.com", GetActiveUser());
92 session_state_delegate()->CycleActiveUser(forward
);
93 EXPECT_EQ("thirduser@test.com", GetActiveUser());
94 session_state_delegate()->CycleActiveUser(forward
);
95 EXPECT_EQ("firstuser@test.com", GetActiveUser());
98 const ash::SessionStateDelegate::CycleUser backward
=
99 ash::SessionStateDelegate::CYCLE_TO_PREVIOUS_USER
;
100 session_state_delegate()->CycleActiveUser(backward
);
101 EXPECT_EQ("thirduser@test.com", GetActiveUser());
102 session_state_delegate()->CycleActiveUser(backward
);
103 EXPECT_EQ("seconduser@test.com", GetActiveUser());
104 session_state_delegate()->CycleActiveUser(backward
);
105 EXPECT_EQ("firstuser@test.com", GetActiveUser());