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

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

Issue 262973004: Move session length timer into tray bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 7 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/chromeos/session/tray_session_length_limit.h" 5 #include "ash/system/chromeos/session/tray_session_length_limit.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/tray/system_tray.h" 9 #include "ash/system/tray/system_tray.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return NULL; 52 return NULL;
53 } 53 }
54 54
55 void ClearSessionLengthLimit() { 55 void ClearSessionLengthLimit() {
56 GetSystemTrayDelegate()->ClearSessionLengthLimit(); 56 GetSystemTrayDelegate()->ClearSessionLengthLimit();
57 tray_session_length_limit_->OnSessionLengthLimitChanged(); 57 tray_session_length_limit_->OnSessionLengthLimitChanged();
58 } 58 }
59 59
60 void RemoveNotification() { 60 void RemoveNotification() {
61 message_center::MessageCenter::Get()->RemoveNotification( 61 message_center::MessageCenter::Get()->RemoveNotification(
62 TraySessionLengthLimit::kNotificationId, true /* by_user */); 62 TraySessionLengthLimit::kNotificationId, false /* by_user */);
63 } 63 }
64 64
65 TraySessionLengthLimit* tray_session_length_limit() { 65 TraySessionLengthLimit* tray_session_length_limit() {
66 return tray_session_length_limit_; 66 return tray_session_length_limit_;
67 } 67 }
68 68
69 bool IsTrayViewVisible() {
70 return tray_session_length_limit_->IsTrayViewVisibleForTest();
71 }
72
73 private: 69 private:
74 // Weak reference, owned by the SystemTray. 70 // Weak reference, owned by the SystemTray.
75 TraySessionLengthLimit* tray_session_length_limit_; 71 TraySessionLengthLimit* tray_session_length_limit_;
76 72
77 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest); 73 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest);
78 }; 74 };
79 75
80 TEST_F(TraySessionLengthLimitTest, TrayView) {
81 // No session limit.
82 EXPECT_FALSE(IsTrayViewVisible());
83
84 // Limit is 15 min.
85 UpdateSessionLengthLimitInMin(15);
86 EXPECT_EQ(TraySessionLengthLimit::LIMIT_SET,
87 tray_session_length_limit()->GetLimitState());
88 EXPECT_TRUE(IsTrayViewVisible());
89
90 // Limit is 3 min.
91 UpdateSessionLengthLimitInMin(3);
92 EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
93 tray_session_length_limit()->GetLimitState());
94 EXPECT_TRUE(IsTrayViewVisible());
95
96 // Nothing left.
97 UpdateSessionLengthLimitInMin(0);
98 EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
99 tray_session_length_limit()->GetLimitState());
100 EXPECT_TRUE(IsTrayViewVisible());
101
102 // Checks the behavior in case the limit goes negative.
103 UpdateSessionLengthLimitInMin(-5);
104 EXPECT_EQ(TraySessionLengthLimit::LIMIT_EXPIRING_SOON,
105 tray_session_length_limit()->GetLimitState());
106 EXPECT_TRUE(IsTrayViewVisible());
107
108 // Clears the session length limit, the TrayView should get invisible.
109 ClearSessionLengthLimit();
110 ASSERT_EQ(TraySessionLengthLimit::LIMIT_NONE,
111 tray_session_length_limit()->GetLimitState());
112 EXPECT_FALSE(IsTrayViewVisible());
113 }
114
115 TEST_F(TraySessionLengthLimitTest, Notification) { 76 TEST_F(TraySessionLengthLimitTest, Notification) {
116 // No notifications when no session limit. 77 // No notifications when no session limit.
117 EXPECT_FALSE(GetNotification()); 78 EXPECT_FALSE(GetNotification());
118 79
119 // Limit is 15 min. 80 // Limit is 15 min.
120 UpdateSessionLengthLimitInMin(15); 81 UpdateSessionLengthLimitInMin(15);
121 message_center::Notification* notification = GetNotification(); 82 message_center::Notification* notification = GetNotification();
122 EXPECT_TRUE(notification); 83 EXPECT_TRUE(notification);
123 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); 84 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
124 base::string16 first_content = notification->title(); 85 base::string16 first_content = notification->message();
125 // Should read the content. 86 // Should read the content.
126 EXPECT_TRUE(notification->rich_notification_data(). 87 EXPECT_TRUE(notification->rich_notification_data().
127 should_make_spoken_feedback_for_popup_updates); 88 should_make_spoken_feedback_for_popup_updates);
128 89
129 // Limit is 10 min. 90 // Limit is 10 min.
130 UpdateSessionLengthLimitInMin(10); 91 UpdateSessionLengthLimitInMin(10);
131 notification = GetNotification(); 92 notification = GetNotification();
132 EXPECT_TRUE(notification); 93 EXPECT_TRUE(notification);
133 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); 94 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
134 // The content should be updated. 95 // The content should be updated.
135 EXPECT_NE(first_content, notification->title()); 96 EXPECT_NE(first_content, notification->message());
136 // Should NOT read, because just update the remaining time. 97 // Should NOT read, because just update the remaining time.
137 EXPECT_FALSE(notification->rich_notification_data(). 98 EXPECT_FALSE(notification->rich_notification_data().
138 should_make_spoken_feedback_for_popup_updates); 99 should_make_spoken_feedback_for_popup_updates);
139 100
140 // Limit is 3 min. 101 // Limit is 3 min.
141 UpdateSessionLengthLimitInMin(3); 102 UpdateSessionLengthLimitInMin(3);
142 notification = GetNotification(); 103 notification = GetNotification();
143 EXPECT_TRUE(notification); 104 EXPECT_TRUE(notification);
144 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); 105 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
145 // Should read the content again because the state has changed. 106 // Should read the content again because the state has changed.
146 EXPECT_TRUE(notification->rich_notification_data(). 107 EXPECT_TRUE(notification->rich_notification_data().
147 should_make_spoken_feedback_for_popup_updates); 108 should_make_spoken_feedback_for_popup_updates);
148 109
149 // Session length limit is updated to longer. This should not read the 110 // Session length limit is updated to longer: 15 min.
150 // notification content again.
151 UpdateSessionLengthLimitInMin(15); 111 UpdateSessionLengthLimitInMin(15);
152 notification = GetNotification(); 112 notification = GetNotification();
153 EXPECT_TRUE(notification); 113 EXPECT_TRUE(notification);
154 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); 114 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
155 // Should not read again because the state has changed to longer. 115 // Should read again because an increase of the remaining time is noteworthy.
156 EXPECT_FALSE(notification->rich_notification_data(). 116 EXPECT_TRUE(notification->rich_notification_data().
157 should_make_spoken_feedback_for_popup_updates); 117 should_make_spoken_feedback_for_popup_updates);
158 118
159 // Clears the limit: the notification should be gone. 119 // Clears the limit: the notification should be gone.
160 ClearSessionLengthLimit(); 120 ClearSessionLengthLimit();
161 EXPECT_FALSE(GetNotification()); 121 EXPECT_FALSE(GetNotification());
162 } 122 }
163 123
164 TEST_F(TraySessionLengthLimitTest, RemoveNotification) { 124 TEST_F(TraySessionLengthLimitTest, RemoveNotification) {
125 message_center::Notification* notification;
126
165 // Limit is 15 min. 127 // Limit is 15 min.
166 UpdateSessionLengthLimitInMin(15); 128 UpdateSessionLengthLimitInMin(15);
167 EXPECT_TRUE(GetNotification()); 129 EXPECT_TRUE(GetNotification());
168 130
169 // Limit is 14 min.
170 UpdateSessionLengthLimitInMin(14);
171 EXPECT_TRUE(GetNotification());
172
173 // Removes the notification. 131 // Removes the notification.
174 RemoveNotification(); 132 RemoveNotification();
175 EXPECT_FALSE(GetNotification()); 133 EXPECT_FALSE(GetNotification());
176 134
177 // Limit is 13 min. The notification should not re-appear. 135 // Limit is 10 min. The notification should not re-appear.
178 UpdateSessionLengthLimitInMin(13); 136 UpdateSessionLengthLimitInMin(10);
179 EXPECT_FALSE(GetNotification()); 137 EXPECT_FALSE(GetNotification());
180 138
181 // Limit is 3 min. The notification should re-appear because of state change. 139 // Limit is 3 min. The notification should re-appear and should be re-read
140 // because of state change.
182 UpdateSessionLengthLimitInMin(3); 141 UpdateSessionLengthLimitInMin(3);
183 EXPECT_TRUE(GetNotification()); 142 notification = GetNotification();
143 EXPECT_TRUE(notification);
144 EXPECT_TRUE(notification->rich_notification_data().
145 should_make_spoken_feedback_for_popup_updates);
184 146
185 RemoveNotification(); 147 RemoveNotification();
186 148
187 // Session length limit is updated to longer state. This should not re-appear 149 // Session length limit is updated to longer state. Notification should
188 // the notification. 150 // re-appear and be re-read.
189 UpdateSessionLengthLimitInMin(15); 151 UpdateSessionLengthLimitInMin(15);
190 EXPECT_FALSE(GetNotification()); 152 notification = GetNotification();
153 EXPECT_TRUE(notification);
154 EXPECT_TRUE(notification->rich_notification_data().
155 should_make_spoken_feedback_for_popup_updates);
191 } 156 }
192 157
193 } // namespace test 158 } // namespace test
194 } // namespace ash 159 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/session/tray_session_length_limit.cc ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698