Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(838)

Side by Side Diff: ash/system/session/tray_session_length_limit_unittest.cc

Issue 2923083002: chromeos: Convert system tray session length limit to mojo (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/session/tray_session_length_limit.h" 5 #include "ash/system/session/tray_session_length_limit.h"
6 6
7 #include "ash/session/session_controller.h"
8 #include "ash/shell.h"
9 #include "ash/system/tray/label_tray_view.h"
7 #include "ash/system/tray/system_tray.h" 10 #include "ash/system/tray/system_tray.h"
8 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
9 #include "ash/test/test_system_tray_delegate.h"
10 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
11 #include "base/time/time.h" 13 #include "base/time/time.h"
12 #include "ui/message_center/message_center.h" 14 #include "ui/message_center/message_center.h"
13 #include "ui/message_center/notification.h" 15 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_types.h" 16 #include "ui/message_center/notification_types.h"
15 17
16 namespace ash { 18 namespace ash {
17 namespace test { 19 namespace test {
18 20
19 class TraySessionLengthLimitTest : public AshTestBase { 21 class TraySessionLengthLimitTest : public AshTestBase {
20 public: 22 public:
21 TraySessionLengthLimitTest() {} 23 TraySessionLengthLimitTest() = default;
22 ~TraySessionLengthLimitTest() override {} 24 ~TraySessionLengthLimitTest() override = default;
23 25
24 void SetUp() override { 26 protected:
25 AshTestBase::SetUp(); 27 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.
26 SystemTray* system_tray = GetPrimarySystemTray(); 28 return GetPrimarySystemTray()
27 tray_session_length_limit_ = new TraySessionLengthLimit(system_tray); 29 ->GetTraySessionLengthLimitForTesting()
28 system_tray->AddTrayItem(base::WrapUnique(tray_session_length_limit_)); 30 ->tray_bubble_view_;
29 } 31 }
30 32
31 void TearDown() override {
32 ClearSessionLengthLimit();
33 AshTestBase::TearDown();
34 }
35
36 protected:
37 void UpdateSessionLengthLimitInMin(int mins) { 33 void UpdateSessionLengthLimitInMin(int mins) {
38 GetSystemTrayDelegate()->SetSessionLengthLimitForTest( 34 Shell::Get()->session_controller()->SetSessionLengthLimit(
39 base::TimeDelta::FromMinutes(mins)); 35 base::TimeDelta::FromMinutes(mins), base::TimeTicks::Now());
40 tray_session_length_limit_->OnSessionLengthLimitChanged();
41 } 36 }
42 37
43 message_center::Notification* GetNotification() { 38 message_center::Notification* GetNotification() {
44 const message_center::NotificationList::Notifications& notifications = 39 const message_center::NotificationList::Notifications& notifications =
45 message_center::MessageCenter::Get()->GetVisibleNotifications(); 40 message_center::MessageCenter::Get()->GetVisibleNotifications();
46 for (message_center::NotificationList::Notifications::const_iterator iter = 41 for (message_center::NotificationList::Notifications::const_iterator iter =
47 notifications.begin(); 42 notifications.begin();
48 iter != notifications.end(); ++iter) { 43 iter != notifications.end(); ++iter) {
49 if ((*iter)->id() == TraySessionLengthLimit::kNotificationId) 44 if ((*iter)->id() == TraySessionLengthLimit::kNotificationId)
50 return *iter; 45 return *iter;
51 } 46 }
52 return nullptr; 47 return nullptr;
53 } 48 }
54 49
55 void ClearSessionLengthLimit() { 50 void ClearSessionLengthLimit() {
56 GetSystemTrayDelegate()->ClearSessionLengthLimit(); 51 Shell::Get()->session_controller()->SetSessionLengthLimit(
57 tray_session_length_limit_->OnSessionLengthLimitChanged(); 52 base::TimeDelta(), base::TimeTicks());
58 } 53 }
59 54
60 void RemoveNotification() { 55 void RemoveNotification() {
61 message_center::MessageCenter::Get()->RemoveNotification( 56 message_center::MessageCenter::Get()->RemoveNotification(
62 TraySessionLengthLimit::kNotificationId, false /* by_user */); 57 TraySessionLengthLimit::kNotificationId, false /* by_user */);
63 } 58 }
64 59
65 TraySessionLengthLimit* tray_session_length_limit() {
66 return tray_session_length_limit_;
67 }
68
69 private: 60 private:
70 // Weak reference, owned by the SystemTray.
71 TraySessionLengthLimit* tray_session_length_limit_;
72
73 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest); 61 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest);
74 }; 62 };
75 63
64 TEST_F(TraySessionLengthLimitTest, Visibility) {
65 SystemTray* system_tray = GetPrimarySystemTray();
66
67 // By default there is no session length limit item.
68 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW);
69 EXPECT_FALSE(GetTrayBubbleView());
70 system_tray->CloseSystemBubble();
71
72 // Setting a length limit shows an item in the system tray menu.
73 UpdateSessionLengthLimitInMin(10);
74 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW);
75 ASSERT_TRUE(GetTrayBubbleView());
76 EXPECT_TRUE(GetTrayBubbleView()->visible());
77 system_tray->CloseSystemBubble();
78
79 // Removing the session length limit removes the tray menu item.
80 UpdateSessionLengthLimitInMin(0);
81 system_tray->ShowDefaultView(BUBBLE_CREATE_NEW);
82 EXPECT_FALSE(GetTrayBubbleView());
83 system_tray->CloseSystemBubble();
84 }
85
76 TEST_F(TraySessionLengthLimitTest, Notification) { 86 TEST_F(TraySessionLengthLimitTest, Notification) {
77 // No notifications when no session limit. 87 // No notifications when no session limit.
78 EXPECT_FALSE(GetNotification()); 88 EXPECT_FALSE(GetNotification());
79 89
80 // Limit is 15 min. 90 // Limit is 15 min.
81 UpdateSessionLengthLimitInMin(15); 91 UpdateSessionLengthLimitInMin(15);
82 message_center::Notification* notification = GetNotification(); 92 message_center::Notification* notification = GetNotification();
83 EXPECT_TRUE(notification); 93 EXPECT_TRUE(notification);
84 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); 94 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
85 base::string16 first_content = notification->message(); 95 base::string16 first_content = notification->message();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // re-appear and be re-read. 158 // re-appear and be re-read.
149 UpdateSessionLengthLimitInMin(15); 159 UpdateSessionLengthLimitInMin(15);
150 notification = GetNotification(); 160 notification = GetNotification();
151 EXPECT_TRUE(notification); 161 EXPECT_TRUE(notification);
152 EXPECT_TRUE(notification->rich_notification_data() 162 EXPECT_TRUE(notification->rich_notification_data()
153 .should_make_spoken_feedback_for_popup_updates); 163 .should_make_spoken_feedback_for_popup_updates);
154 } 164 }
155 165
156 } // namespace test 166 } // namespace test
157 } // namespace ash 167 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698