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

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

Issue 108213009: Adds TraySessionLengthLimitTest to ash_unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ash/system/session_length_limit/tray_session_length_limit.h"
6
7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h"
9 #include "ash/system/tray/system_tray.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_system_tray_delegate.h"
12 #include "base/time/time.h"
13 #include "ui/message_center/message_center.h"
14 #include "ui/message_center/notification.h"
15 #include "ui/message_center/notification_types.h"
16
17 namespace ash {
18 namespace test {
19
20 class TraySessionLengthLimitTest : public AshTestBase {
21 public:
22 TraySessionLengthLimitTest() {}
23 virtual ~TraySessionLengthLimitTest() {}
24
25 virtual void SetUp() OVERRIDE {
26 AshTestBase::SetUp();
27 SystemTray* system_tray =
28 Shell::GetPrimaryRootWindowController()->GetSystemTray();
29 tray_session_length_limit_ = new internal::TraySessionLengthLimit(
30 system_tray);
31 system_tray->AddTrayItem(tray_session_length_limit_);
32 }
33
34 virtual void TearDown() OVERRIDE {
35 AshTestBase::TearDown();
36 }
37
38 protected:
39 void UpdateSessionLengthLimitInMin(int mins) {
40 GetTestSystemTrayDelegate()->SetSessionLengthLimitForTest(
41 base::TimeDelta::FromMinutes(mins));
42 tray_session_length_limit_->OnSessionLengthLimitChanged();
43 }
44
45 message_center::Notification* GetNotification() {
46 const message_center::NotificationList::Notifications& notifications =
47 message_center::MessageCenter::Get()->GetVisibleNotifications();
48 for (message_center::NotificationList::Notifications::const_iterator iter =
49 notifications.begin(); iter != notifications.end(); ++iter) {
50 if ((*iter)->id() == internal::TraySessionLengthLimit::kNotificationId)
51 return *iter;
52 }
stevenjb 2013/12/12 23:30:32 Another place where MessageCenter::GetNotification
Jun Mukai 2013/12/13 00:15:44 Can I do that in another CL? Several other tests u
stevenjb 2013/12/13 01:20:09 Sure, just a suggestion.
53 return NULL;
54 }
55
56 void ClearSessionLengthLimit() {
57 GetTestSystemTrayDelegate()->ClearSessionLengthLimit();
58 tray_session_length_limit_->OnSessionLengthLimitChanged();
59 }
60
61 void RemoveNotification() {
62 message_center::MessageCenter::Get()->RemoveNotification(
63 internal::TraySessionLengthLimit::kNotificationId, true /* by_user */);
64 }
65
66 internal::TraySessionLengthLimit* tray_session_length_limit() {
67 return tray_session_length_limit_;
68 }
69
70 bool IsTrayViewVisible() {
71 return tray_session_length_limit_->IsTrayViewVisibleForTest();
72 }
73
74 private:
75 TestSystemTrayDelegate* GetTestSystemTrayDelegate() {
76 return static_cast<TestSystemTrayDelegate*>(
77 Shell::GetInstance()->system_tray_delegate());
78 }
stevenjb 2013/12/12 23:30:32 This should probably be a protected member of AshT
Jun Mukai 2013/12/13 00:15:44 Done.
79
80 // Weak reference, owned by the SystemTray.
81 internal::TraySessionLengthLimit* tray_session_length_limit_;
82
83 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest);
84 };
85
86 TEST_F(TraySessionLengthLimitTest, TrayView) {
87 // No session limit.
88 EXPECT_FALSE(IsTrayViewVisible());
89
90 // Limit is 15 min.
91 UpdateSessionLengthLimitInMin(15);
92 EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_SET,
93 tray_session_length_limit()->GetLimitState());
94 EXPECT_TRUE(IsTrayViewVisible());
95
96 // Limit is 3 min.
97 UpdateSessionLengthLimitInMin(3);
98 EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
99 tray_session_length_limit()->GetLimitState());
100 EXPECT_TRUE(IsTrayViewVisible());
101
102 // Nothing left.
103 UpdateSessionLengthLimitInMin(0);
104 EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
105 tray_session_length_limit()->GetLimitState());
106 EXPECT_TRUE(IsTrayViewVisible());
107
108 // Checks the behavior in case the limit goes negative.
109 UpdateSessionLengthLimitInMin(-5);
110 EXPECT_EQ(internal::TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
111 tray_session_length_limit()->GetLimitState());
112 EXPECT_TRUE(IsTrayViewVisible());
113
114 // Clears the session length limit, the TrayView should get invisible.
115 ClearSessionLengthLimit();
116 ASSERT_EQ(internal::TraySessionLengthLimit::LIMIT_NONE,
117 tray_session_length_limit()->GetLimitState());
118 EXPECT_FALSE(IsTrayViewVisible());
119 }
120
121 TEST_F(TraySessionLengthLimitTest, Notification) {
122 // No notifications when no session limit.
123 EXPECT_FALSE(GetNotification());
124
125 // Limit is 15 min.
126 UpdateSessionLengthLimitInMin(15);
127 message_center::Notification* notification = GetNotification();
128 EXPECT_TRUE(notification);
129 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
130 base::string16 first_content = notification->title();
131 // Should read the content.
132 EXPECT_TRUE(notification->rich_notification_data().
133 should_make_spoken_feedback_for_popup_updates);
134
135 // Limit is 10 min.
136 UpdateSessionLengthLimitInMin(10);
137 notification = GetNotification();
138 EXPECT_TRUE(notification);
139 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
140 // The content should be updated.
141 EXPECT_NE(first_content, notification->title());
142 // Should NOT read, because just update the remaining time.
143 EXPECT_FALSE(notification->rich_notification_data().
144 should_make_spoken_feedback_for_popup_updates);
145
146 // Limit is 3 min.
147 UpdateSessionLengthLimitInMin(3);
148 notification = GetNotification();
149 EXPECT_TRUE(notification);
150 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
151 // Should read the content again because the state has changed.
152 EXPECT_TRUE(notification->rich_notification_data().
153 should_make_spoken_feedback_for_popup_updates);
154
155 // Session length limit is updated to longer. This should not read the
156 // notification content again.
157 UpdateSessionLengthLimitInMin(15);
158 notification = GetNotification();
159 EXPECT_TRUE(notification);
160 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
161 // Should not read again because the state has changed to longer.
162 EXPECT_FALSE(notification->rich_notification_data().
163 should_make_spoken_feedback_for_popup_updates);
164
165 // Clears the limit: the notification should be gone.
166 ClearSessionLengthLimit();
167 EXPECT_FALSE(GetNotification());
168 }
169
170 TEST_F(TraySessionLengthLimitTest, RemoveNotification) {
171 // Limit is 15 min.
172 UpdateSessionLengthLimitInMin(15);
173 EXPECT_TRUE(GetNotification());
174
175 // Limit is 14 min.
176 UpdateSessionLengthLimitInMin(14);
177 EXPECT_TRUE(GetNotification());
178
179 // Removes the notification.
180 RemoveNotification();
181 EXPECT_FALSE(GetNotification());
182
183 // Limit is 13 min. The notification should not re-appear.
184 UpdateSessionLengthLimitInMin(13);
185 EXPECT_FALSE(GetNotification());
186
187 // Limit is 3 min. The notification should re-appear because of state change.
188 UpdateSessionLengthLimitInMin(3);
189 EXPECT_TRUE(GetNotification());
190
191 RemoveNotification();
192
193 // Session length limit is updated to longer state. This should not re-appear
194 // the notification.
195 UpdateSessionLengthLimitInMin(15);
196 EXPECT_FALSE(GetNotification());
197 }
198
199 } // namespace test
200 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/session_length_limit/tray_session_length_limit.cc ('k') | ash/test/test_system_tray_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698