This source file includes following definitions.
- SetUp
- TearDown
- UpdateSessionLengthLimitInMin
- GetNotification
- ClearSessionLengthLimit
- RemoveNotification
- tray_session_length_limit
- IsTrayViewVisible
- TEST_F
- TEST_F
- TEST_F
#include "ash/system/chromeos/session/tray_session_length_limit.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_system_tray_delegate.h"
#include "base/time/time.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_types.h"
namespace ash {
namespace test {
class TraySessionLengthLimitTest : public AshTestBase {
public:
TraySessionLengthLimitTest() {}
virtual ~TraySessionLengthLimitTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
SystemTray* system_tray =
Shell::GetPrimaryRootWindowController()->GetSystemTray();
tray_session_length_limit_ = new TraySessionLengthLimit(system_tray);
system_tray->AddTrayItem(tray_session_length_limit_);
}
virtual void TearDown() OVERRIDE {
AshTestBase::TearDown();
}
protected:
void UpdateSessionLengthLimitInMin(int mins) {
GetSystemTrayDelegate()->SetSessionLengthLimitForTest(
base::TimeDelta::FromMinutes(mins));
tray_session_length_limit_->OnSessionLengthLimitChanged();
}
message_center::Notification* GetNotification() {
const message_center::NotificationList::Notifications& notifications =
message_center::MessageCenter::Get()->GetVisibleNotifications();
for (message_center::NotificationList::Notifications::const_iterator iter =
notifications.begin(); iter != notifications.end(); ++iter) {
if ((*iter)->id() == TraySessionLengthLimit::kNotificationId)
return *iter;
}
return NULL;
}
void ClearSessionLengthLimit() {
GetSystemTrayDelegate()->ClearSessionLengthLimit();
tray_session_length_limit_->OnSessionLengthLimitChanged();
}
void RemoveNotification() {
message_center::MessageCenter::Get()->RemoveNotification(
TraySessionLengthLimit::kNotificationId, true );
}
TraySessionLengthLimit* tray_session_length_limit() {
return tray_session_length_limit_;
}
bool IsTrayViewVisible() {
return tray_session_length_limit_->IsTrayViewVisibleForTest();
}
private:
TraySessionLengthLimit* tray_session_length_limit_;
DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest);
};
TEST_F(TraySessionLengthLimitTest, TrayView) {
EXPECT_FALSE(IsTrayViewVisible());
UpdateSessionLengthLimitInMin(15);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_SET,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
UpdateSessionLengthLimitInMin(3);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
UpdateSessionLengthLimitInMin(0);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
UpdateSessionLengthLimitInMin(-5);
EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
tray_session_length_limit()->GetLimitState());
EXPECT_TRUE(IsTrayViewVisible());
ClearSessionLengthLimit();
ASSERT_EQ(TraySessionLengthLimit::LIMIT_NONE,
tray_session_length_limit()->GetLimitState());
EXPECT_FALSE(IsTrayViewVisible());
}
TEST_F(TraySessionLengthLimitTest, Notification) {
EXPECT_FALSE(GetNotification());
UpdateSessionLengthLimitInMin(15);
message_center::Notification* notification = GetNotification();
EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
base::string16 first_content = notification->title();
EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates);
UpdateSessionLengthLimitInMin(10);
notification = GetNotification();
EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
EXPECT_NE(first_content, notification->title());
EXPECT_FALSE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates);
UpdateSessionLengthLimitInMin(3);
notification = GetNotification();
EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
EXPECT_TRUE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates);
UpdateSessionLengthLimitInMin(15);
notification = GetNotification();
EXPECT_TRUE(notification);
EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
EXPECT_FALSE(notification->rich_notification_data().
should_make_spoken_feedback_for_popup_updates);
ClearSessionLengthLimit();
EXPECT_FALSE(GetNotification());
}
TEST_F(TraySessionLengthLimitTest, RemoveNotification) {
UpdateSessionLengthLimitInMin(15);
EXPECT_TRUE(GetNotification());
UpdateSessionLengthLimitInMin(14);
EXPECT_TRUE(GetNotification());
RemoveNotification();
EXPECT_FALSE(GetNotification());
UpdateSessionLengthLimitInMin(13);
EXPECT_FALSE(GetNotification());
UpdateSessionLengthLimitInMin(3);
EXPECT_TRUE(GetNotification());
RemoveNotification();
UpdateSessionLengthLimitInMin(15);
EXPECT_FALSE(GetNotification());
}
}
}