This source file includes following definitions.
- shelf
- tray
- delegate
- tray_user
- tray_user_separator
- tray_user_separator_
- SetUp
- InitializeParameters
- ShowTrayMenu
- MoveOverUserItem
- ClickUserItem
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include <vector>
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/user/tray_user.h"
#include "ash/system/user/tray_user_separator.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#include "base/command_line.h"
#include "ui/aura/test/event_generator.h"
#include "ui/gfx/animation/animation_container_element.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace ash {
class TrayUserTest : public ash::test::AshTestBase {
public:
TrayUserTest();
virtual void SetUp() OVERRIDE;
void InitializeParameters(int users_logged_in, bool multiprofile);
void ShowTrayMenu(aura::test::EventGenerator* generator);
void MoveOverUserItem(aura::test::EventGenerator* generator, int index);
void ClickUserItem(aura::test::EventGenerator* generator, int index);
ShelfLayoutManager* shelf() { return shelf_; }
SystemTray* tray() { return tray_; }
ash::test::TestSessionStateDelegate* delegate() { return delegate_; }
ash::TrayUser* tray_user(int index) { return tray_user_[index]; }
ash::TrayUserSeparator* tray_user_separator() { return tray_user_separator_; }
private:
ShelfLayoutManager* shelf_;
SystemTray* tray_;
ash::test::TestSessionStateDelegate* delegate_;
std::vector<ash::TrayUser*> tray_user_;
TrayUserSeparator* tray_user_separator_;
DISALLOW_COPY_AND_ASSIGN(TrayUserTest);
};
TrayUserTest::TrayUserTest()
: shelf_(NULL),
tray_(NULL),
delegate_(NULL),
tray_user_separator_(NULL) {
}
void TrayUserTest::SetUp() {
ash::test::AshTestBase::SetUp();
shelf_ = Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray();
delegate_ = static_cast<ash::test::TestSessionStateDelegate*>(
ash::Shell::GetInstance()->session_state_delegate());
}
void TrayUserTest::InitializeParameters(int users_logged_in,
bool multiprofile) {
shelf()->LayoutShelf();
shelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
delegate_->set_logged_in_users(users_logged_in);
ash::test::TestShellDelegate* shell_delegate =
static_cast<ash::test::TestShellDelegate*>(
ash::Shell::GetInstance()->delegate());
shell_delegate->set_multi_profiles_enabled(multiprofile);
for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) {
tray_user_.push_back(new ash::TrayUser(tray_, i));
tray_->AddTrayItem(tray_user_[i]);
}
tray_user_separator_ = new ash::TrayUserSeparator(tray_);
tray_->AddTrayItem(tray_user_separator_);
}
void TrayUserTest::ShowTrayMenu(aura::test::EventGenerator* generator) {
gfx::Point center = tray()->GetBoundsInScreen().CenterPoint();
generator->MoveMouseTo(center.x(), center.y());
EXPECT_FALSE(tray()->IsAnyBubbleVisible());
generator->ClickLeftButton();
}
void TrayUserTest::MoveOverUserItem(aura::test::EventGenerator* generator,
int index) {
gfx::Point center =
tray_user(index)->GetUserPanelBoundsInScreenForTest().CenterPoint();
generator->MoveMouseTo(center.x(), center.y());
}
void TrayUserTest::ClickUserItem(aura::test::EventGenerator* generator,
int index) {
MoveOverUserItem(generator, index);
generator->ClickLeftButton();
}
TEST_F(TrayUserTest, CheckTrayItemSize) {
InitializeParameters(1, false);
tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_GUEST);
gfx::Size size = tray_user(0)->GetLayoutSizeForTest();
EXPECT_EQ(kTrayItemSize, size.height());
tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_USER);
size = tray_user(0)->GetLayoutSizeForTest();
EXPECT_EQ(kTrayItemSize, size.height());
}
TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) {
InitializeParameters(1, false);
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
EXPECT_FALSE(tray()->IsAnyBubbleVisible());
for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
EXPECT_FALSE(tray_user_separator()->separator_shown());
ShowTrayMenu(&generator);
EXPECT_TRUE(tray()->HasSystemBubble());
EXPECT_TRUE(tray()->IsAnyBubbleVisible());
for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
EXPECT_EQ(i == 0 ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN,
tray_user(i)->GetStateForTest());
EXPECT_FALSE(tray_user_separator()->separator_shown());
tray()->CloseSystemBubble();
}
#if defined(OS_CHROMEOS)
TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) {
InitializeParameters(1, true);
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
generator.set_async(false);
int max_users = delegate()->GetMaximumNumberOfLoggedInUsers();
for (int j = 1; j < max_users; j++) {
delegate()->set_logged_in_users(j);
EXPECT_FALSE(tray()->IsAnyBubbleVisible());
for (int i = 0; i < max_users; i++)
EXPECT_FALSE(tray_user(i)->GetStateForTest());
EXPECT_FALSE(tray_user_separator()->separator_shown());
ShowTrayMenu(&generator);
EXPECT_TRUE(tray()->HasSystemBubble());
EXPECT_TRUE(tray()->IsAnyBubbleVisible());
for (int i = 0; i < max_users; i++) {
EXPECT_EQ(i < j ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN,
tray_user(i)->GetStateForTest());
}
EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown());
MoveOverUserItem(&generator, 0);
EXPECT_EQ(ash::TrayUser::HOVERED, tray_user(0)->GetStateForTest());
for (int i = 1; i < max_users; i++) {
EXPECT_EQ(i < j ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN,
tray_user(i)->GetStateForTest());
}
ClickUserItem(&generator, 0);
EXPECT_EQ(j == max_users ? ash::TrayUser::ACTIVE_BUT_DISABLED
: ash::TrayUser::ACTIVE,
tray_user(0)->GetStateForTest());
ClickUserItem(&generator, 0);
EXPECT_EQ(ash::TrayUser::HOVERED, tray_user(0)->GetStateForTest());
tray()->CloseSystemBubble();
EXPECT_FALSE(tray()->IsAnyBubbleVisible());
for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
}
}
TEST_F(TrayUserTest, MutiUserModeButtonClicks) {
InitializeParameters(2, true);
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
ShowTrayMenu(&generator);
ClickUserItem(&generator, 1);
EXPECT_EQ(delegate()->get_activated_user(), delegate()->GetUserID(1));
EXPECT_NE(delegate()->get_activated_user(), delegate()->GetUserEmail(1));
tray()->CloseSystemBubble();
}
#endif
}