| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, true /* 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. This should not read the |
| 150 // notification content again. | 111 // notification content again. |
| 151 UpdateSessionLengthLimitInMin(15); | 112 UpdateSessionLengthLimitInMin(15); |
| 152 notification = GetNotification(); | 113 notification = GetNotification(); |
| 153 EXPECT_TRUE(notification); | 114 EXPECT_TRUE(notification); |
| 154 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); | 115 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority()); |
| 155 // Should not read again because the state has changed to longer. | 116 // Should read again because an increase of the remaining time is noteworthy. |
| 156 EXPECT_FALSE(notification->rich_notification_data(). | 117 EXPECT_TRUE(notification->rich_notification_data(). |
| 157 should_make_spoken_feedback_for_popup_updates); | 118 should_make_spoken_feedback_for_popup_updates); |
| 158 | 119 |
| 159 // Clears the limit: the notification should be gone. | 120 // Clears the limit: the notification should be gone. |
| 160 ClearSessionLengthLimit(); | 121 ClearSessionLengthLimit(); |
| 161 EXPECT_FALSE(GetNotification()); | 122 EXPECT_FALSE(GetNotification()); |
| 162 } | 123 } |
| 163 | 124 |
| 164 TEST_F(TraySessionLengthLimitTest, RemoveNotification) { | 125 TEST_F(TraySessionLengthLimitTest, RemoveNotification) { |
| 126 message_center::Notification* notification; |
| 127 |
| 165 // Limit is 15 min. | 128 // Limit is 15 min. |
| 166 UpdateSessionLengthLimitInMin(15); | 129 UpdateSessionLengthLimitInMin(15); |
| 167 EXPECT_TRUE(GetNotification()); | 130 EXPECT_TRUE(GetNotification()); |
| 168 | 131 |
| 169 // Limit is 14 min. | |
| 170 UpdateSessionLengthLimitInMin(14); | |
| 171 EXPECT_TRUE(GetNotification()); | |
| 172 | |
| 173 // Removes the notification. | 132 // Removes the notification. |
| 174 RemoveNotification(); | 133 RemoveNotification(); |
| 175 EXPECT_FALSE(GetNotification()); | 134 EXPECT_FALSE(GetNotification()); |
| 176 | 135 |
| 177 // Limit is 13 min. The notification should not re-appear. | 136 // Limit is 10 min. The notification should not re-appear. |
| 178 UpdateSessionLengthLimitInMin(13); | 137 UpdateSessionLengthLimitInMin(10); |
| 179 EXPECT_FALSE(GetNotification()); | 138 EXPECT_FALSE(GetNotification()); |
| 180 | 139 |
| 181 // Limit is 3 min. The notification should re-appear because of state change. | 140 // Limit is 3 min. The notification should re-appear and should be re-read |
| 141 // because of state change. |
| 182 UpdateSessionLengthLimitInMin(3); | 142 UpdateSessionLengthLimitInMin(3); |
| 183 EXPECT_TRUE(GetNotification()); | 143 notification = GetNotification(); |
| 144 EXPECT_TRUE(notification); |
| 145 EXPECT_TRUE(notification->rich_notification_data(). |
| 146 should_make_spoken_feedback_for_popup_updates); |
| 184 | 147 |
| 185 RemoveNotification(); | 148 RemoveNotification(); |
| 186 | 149 |
| 187 // Session length limit is updated to longer state. This should not re-appear | 150 // Session length limit is updated to longer state. Notification should |
| 188 // the notification. | 151 // re-appear and be re-read. |
| 189 UpdateSessionLengthLimitInMin(15); | 152 UpdateSessionLengthLimitInMin(15); |
| 190 EXPECT_FALSE(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 |
| OLD | NEW |