OLD | NEW |
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 28 matching lines...) Expand all Loading... |
39 void UpdateSessionLengthLimitInMin(int mins) { | 39 void UpdateSessionLengthLimitInMin(int mins) { |
40 GetSystemTrayDelegate()->SetSessionLengthLimitForTest( | 40 GetSystemTrayDelegate()->SetSessionLengthLimitForTest( |
41 base::TimeDelta::FromMinutes(mins)); | 41 base::TimeDelta::FromMinutes(mins)); |
42 tray_session_length_limit_->OnSessionLengthLimitChanged(); | 42 tray_session_length_limit_->OnSessionLengthLimitChanged(); |
43 } | 43 } |
44 | 44 |
45 message_center::Notification* GetNotification() { | 45 message_center::Notification* GetNotification() { |
46 const message_center::NotificationList::Notifications& notifications = | 46 const message_center::NotificationList::Notifications& notifications = |
47 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 47 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
48 for (message_center::NotificationList::Notifications::const_iterator iter = | 48 for (message_center::NotificationList::Notifications::const_iterator iter = |
49 notifications.begin(); iter != notifications.end(); ++iter) { | 49 notifications.begin(); |
| 50 iter != notifications.end(); ++iter) { |
50 if ((*iter)->id() == TraySessionLengthLimit::kNotificationId) | 51 if ((*iter)->id() == TraySessionLengthLimit::kNotificationId) |
51 return *iter; | 52 return *iter; |
52 } | 53 } |
53 return nullptr; | 54 return nullptr; |
54 } | 55 } |
55 | 56 |
56 void ClearSessionLengthLimit() { | 57 void ClearSessionLengthLimit() { |
57 GetSystemTrayDelegate()->ClearSessionLengthLimit(); | 58 GetSystemTrayDelegate()->ClearSessionLengthLimit(); |
58 tray_session_length_limit_->OnSessionLengthLimitChanged(); | 59 tray_session_length_limit_->OnSessionLengthLimitChanged(); |
59 } | 60 } |
(...skipping 18 matching lines...) Expand all Loading... |
78 // No notifications when no session limit. | 79 // No notifications when no session limit. |
79 EXPECT_FALSE(GetNotification()); | 80 EXPECT_FALSE(GetNotification()); |
80 | 81 |
81 // Limit is 15 min. | 82 // Limit is 15 min. |
82 UpdateSessionLengthLimitInMin(15); | 83 UpdateSessionLengthLimitInMin(15); |
83 message_center::Notification* notification = GetNotification(); | 84 message_center::Notification* notification = GetNotification(); |
84 EXPECT_TRUE(notification); | 85 EXPECT_TRUE(notification); |
85 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); | 86 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); |
86 base::string16 first_content = notification->message(); | 87 base::string16 first_content = notification->message(); |
87 // Should read the content. | 88 // Should read the content. |
88 EXPECT_TRUE(notification->rich_notification_data(). | 89 EXPECT_TRUE(notification->rich_notification_data() |
89 should_make_spoken_feedback_for_popup_updates); | 90 .should_make_spoken_feedback_for_popup_updates); |
90 | 91 |
91 // Limit is 10 min. | 92 // Limit is 10 min. |
92 UpdateSessionLengthLimitInMin(10); | 93 UpdateSessionLengthLimitInMin(10); |
93 notification = GetNotification(); | 94 notification = GetNotification(); |
94 EXPECT_TRUE(notification); | 95 EXPECT_TRUE(notification); |
95 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); | 96 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); |
96 // The content should be updated. | 97 // The content should be updated. |
97 EXPECT_NE(first_content, notification->message()); | 98 EXPECT_NE(first_content, notification->message()); |
98 // Should NOT read, because just update the remaining time. | 99 // Should NOT read, because just update the remaining time. |
99 EXPECT_FALSE(notification->rich_notification_data(). | 100 EXPECT_FALSE(notification->rich_notification_data() |
100 should_make_spoken_feedback_for_popup_updates); | 101 .should_make_spoken_feedback_for_popup_updates); |
101 | 102 |
102 // Limit is 3 min. | 103 // Limit is 3 min. |
103 UpdateSessionLengthLimitInMin(3); | 104 UpdateSessionLengthLimitInMin(3); |
104 notification = GetNotification(); | 105 notification = GetNotification(); |
105 EXPECT_TRUE(notification); | 106 EXPECT_TRUE(notification); |
106 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); | 107 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); |
107 // Should read the content again because the state has changed. | 108 // Should read the content again because the state has changed. |
108 EXPECT_TRUE(notification->rich_notification_data(). | 109 EXPECT_TRUE(notification->rich_notification_data() |
109 should_make_spoken_feedback_for_popup_updates); | 110 .should_make_spoken_feedback_for_popup_updates); |
110 | 111 |
111 // Session length limit is updated to longer: 15 min. | 112 // Session length limit is updated to longer: 15 min. |
112 UpdateSessionLengthLimitInMin(15); | 113 UpdateSessionLengthLimitInMin(15); |
113 notification = GetNotification(); | 114 notification = GetNotification(); |
114 EXPECT_TRUE(notification); | 115 EXPECT_TRUE(notification); |
115 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); | 116 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); |
116 // Should read again because an increase of the remaining time is noteworthy. | 117 // Should read again because an increase of the remaining time is noteworthy. |
117 EXPECT_TRUE(notification->rich_notification_data(). | 118 EXPECT_TRUE(notification->rich_notification_data() |
118 should_make_spoken_feedback_for_popup_updates); | 119 .should_make_spoken_feedback_for_popup_updates); |
119 | 120 |
120 // Clears the limit: the notification should be gone. | 121 // Clears the limit: the notification should be gone. |
121 ClearSessionLengthLimit(); | 122 ClearSessionLengthLimit(); |
122 EXPECT_FALSE(GetNotification()); | 123 EXPECT_FALSE(GetNotification()); |
123 } | 124 } |
124 | 125 |
125 TEST_F(TraySessionLengthLimitTest, RemoveNotification) { | 126 TEST_F(TraySessionLengthLimitTest, RemoveNotification) { |
126 // Limit is 15 min. | 127 // Limit is 15 min. |
127 UpdateSessionLengthLimitInMin(15); | 128 UpdateSessionLengthLimitInMin(15); |
128 EXPECT_TRUE(GetNotification()); | 129 EXPECT_TRUE(GetNotification()); |
129 | 130 |
130 // Removes the notification. | 131 // Removes the notification. |
131 RemoveNotification(); | 132 RemoveNotification(); |
132 EXPECT_FALSE(GetNotification()); | 133 EXPECT_FALSE(GetNotification()); |
133 | 134 |
134 // Limit is 10 min. The notification should not re-appear. | 135 // Limit is 10 min. The notification should not re-appear. |
135 UpdateSessionLengthLimitInMin(10); | 136 UpdateSessionLengthLimitInMin(10); |
136 EXPECT_FALSE(GetNotification()); | 137 EXPECT_FALSE(GetNotification()); |
137 | 138 |
138 // Limit is 3 min. The notification should re-appear and should be re-read | 139 // Limit is 3 min. The notification should re-appear and should be re-read |
139 // because of state change. | 140 // because of state change. |
140 UpdateSessionLengthLimitInMin(3); | 141 UpdateSessionLengthLimitInMin(3); |
141 message_center::Notification* notification = GetNotification(); | 142 message_center::Notification* notification = GetNotification(); |
142 EXPECT_TRUE(notification); | 143 EXPECT_TRUE(notification); |
143 EXPECT_TRUE(notification->rich_notification_data(). | 144 EXPECT_TRUE(notification->rich_notification_data() |
144 should_make_spoken_feedback_for_popup_updates); | 145 .should_make_spoken_feedback_for_popup_updates); |
145 | 146 |
146 RemoveNotification(); | 147 RemoveNotification(); |
147 | 148 |
148 // Session length limit is updated to longer state. Notification should | 149 // Session length limit is updated to longer state. Notification should |
149 // re-appear and be re-read. | 150 // re-appear and be re-read. |
150 UpdateSessionLengthLimitInMin(15); | 151 UpdateSessionLengthLimitInMin(15); |
151 notification = GetNotification(); | 152 notification = GetNotification(); |
152 EXPECT_TRUE(notification); | 153 EXPECT_TRUE(notification); |
153 EXPECT_TRUE(notification->rich_notification_data(). | 154 EXPECT_TRUE(notification->rich_notification_data() |
154 should_make_spoken_feedback_for_popup_updates); | 155 .should_make_spoken_feedback_for_popup_updates); |
155 } | 156 } |
156 | 157 |
157 } // namespace test | 158 } // namespace test |
158 } // namespace ash | 159 } // namespace ash |
OLD | NEW |