Chromium Code Reviews| Index: ash/system/session/tray_session_length_limit_unittest.cc |
| diff --git a/ash/system/session/tray_session_length_limit_unittest.cc b/ash/system/session/tray_session_length_limit_unittest.cc |
| index 19df0ccc214ecaf60fc6238a69b007635605ea3d..463fae99c45cba3e15117e0353ff50237a88808d 100644 |
| --- a/ash/system/session/tray_session_length_limit_unittest.cc |
| +++ b/ash/system/session/tray_session_length_limit_unittest.cc |
| @@ -4,9 +4,11 @@ |
| #include "ash/system/session/tray_session_length_limit.h" |
| +#include "ash/session/session_controller.h" |
| +#include "ash/shell.h" |
| +#include "ash/system/tray/label_tray_view.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/memory/ptr_util.h" |
| #include "base/time/time.h" |
| #include "ui/message_center/message_center.h" |
| @@ -18,26 +20,19 @@ namespace test { |
| class TraySessionLengthLimitTest : public AshTestBase { |
| public: |
| - TraySessionLengthLimitTest() {} |
| - ~TraySessionLengthLimitTest() override {} |
| - |
| - void SetUp() override { |
| - AshTestBase::SetUp(); |
| - SystemTray* system_tray = GetPrimarySystemTray(); |
| - tray_session_length_limit_ = new TraySessionLengthLimit(system_tray); |
| - system_tray->AddTrayItem(base::WrapUnique(tray_session_length_limit_)); |
| - } |
| + TraySessionLengthLimitTest() = default; |
| + ~TraySessionLengthLimitTest() override = default; |
| - void TearDown() override { |
| - ClearSessionLengthLimit(); |
| - AshTestBase::TearDown(); |
| + protected: |
| + LabelTrayView* GetTrayBubbleView() { |
|
msw
2017/06/06 19:01:04
nit: maybe add some session length limit context t
James Cook
2017/06/07 00:48:13
Done.
|
| + return GetPrimarySystemTray() |
| + ->GetTraySessionLengthLimitForTesting() |
| + ->tray_bubble_view_; |
| } |
| - protected: |
| void UpdateSessionLengthLimitInMin(int mins) { |
| - GetSystemTrayDelegate()->SetSessionLengthLimitForTest( |
| - base::TimeDelta::FromMinutes(mins)); |
| - tray_session_length_limit_->OnSessionLengthLimitChanged(); |
| + Shell::Get()->session_controller()->SetSessionLengthLimit( |
| + base::TimeDelta::FromMinutes(mins), base::TimeTicks::Now()); |
| } |
| message_center::Notification* GetNotification() { |
| @@ -53,8 +48,8 @@ class TraySessionLengthLimitTest : public AshTestBase { |
| } |
| void ClearSessionLengthLimit() { |
| - GetSystemTrayDelegate()->ClearSessionLengthLimit(); |
| - tray_session_length_limit_->OnSessionLengthLimitChanged(); |
| + Shell::Get()->session_controller()->SetSessionLengthLimit( |
| + base::TimeDelta(), base::TimeTicks()); |
| } |
| void RemoveNotification() { |
| @@ -62,17 +57,32 @@ class TraySessionLengthLimitTest : public AshTestBase { |
| TraySessionLengthLimit::kNotificationId, false /* by_user */); |
| } |
| - TraySessionLengthLimit* tray_session_length_limit() { |
| - return tray_session_length_limit_; |
| - } |
| - |
| private: |
| - // Weak reference, owned by the SystemTray. |
| - TraySessionLengthLimit* tray_session_length_limit_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest); |
| }; |
| +TEST_F(TraySessionLengthLimitTest, Visibility) { |
| + SystemTray* system_tray = GetPrimarySystemTray(); |
| + |
| + // By default there is no session length limit item. |
| + system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + EXPECT_FALSE(GetTrayBubbleView()); |
| + system_tray->CloseSystemBubble(); |
| + |
| + // Setting a length limit shows an item in the system tray menu. |
| + UpdateSessionLengthLimitInMin(10); |
| + system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + ASSERT_TRUE(GetTrayBubbleView()); |
| + EXPECT_TRUE(GetTrayBubbleView()->visible()); |
| + system_tray->CloseSystemBubble(); |
| + |
| + // Removing the session length limit removes the tray menu item. |
| + UpdateSessionLengthLimitInMin(0); |
| + system_tray->ShowDefaultView(BUBBLE_CREATE_NEW); |
| + EXPECT_FALSE(GetTrayBubbleView()); |
| + system_tray->CloseSystemBubble(); |
| +} |
| + |
| TEST_F(TraySessionLengthLimitTest, Notification) { |
| // No notifications when no session limit. |
| EXPECT_FALSE(GetNotification()); |