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

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

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/system/chromeos/session/tray_session_length_limit.h"
6
7 #include "ash/common/system/tray/system_tray.h"
8 #include "ash/common/test/test_system_tray_delegate.h"
9 #include "ash/test/ash_test_base.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/time/time.h"
12 #include "ui/message_center/message_center.h"
13 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_types.h"
15
16 namespace ash {
17 namespace test {
18
19 class TraySessionLengthLimitTest : public AshTestBase {
20 public:
21 TraySessionLengthLimitTest() {}
22 ~TraySessionLengthLimitTest() override {}
23
24 void SetUp() override {
25 AshTestBase::SetUp();
26 SystemTray* system_tray = GetPrimarySystemTray();
27 tray_session_length_limit_ = new TraySessionLengthLimit(system_tray);
28 system_tray->AddTrayItem(base::WrapUnique(tray_session_length_limit_));
29 }
30
31 void TearDown() override {
32 ClearSessionLengthLimit();
33 AshTestBase::TearDown();
34 }
35
36 protected:
37 void UpdateSessionLengthLimitInMin(int mins) {
38 GetSystemTrayDelegate()->SetSessionLengthLimitForTest(
39 base::TimeDelta::FromMinutes(mins));
40 tray_session_length_limit_->OnSessionLengthLimitChanged();
41 }
42
43 message_center::Notification* GetNotification() {
44 const message_center::NotificationList::Notifications& notifications =
45 message_center::MessageCenter::Get()->GetVisibleNotifications();
46 for (message_center::NotificationList::Notifications::const_iterator iter =
47 notifications.begin();
48 iter != notifications.end(); ++iter) {
49 if ((*iter)->id() == TraySessionLengthLimit::kNotificationId)
50 return *iter;
51 }
52 return nullptr;
53 }
54
55 void ClearSessionLengthLimit() {
56 GetSystemTrayDelegate()->ClearSessionLengthLimit();
57 tray_session_length_limit_->OnSessionLengthLimitChanged();
58 }
59
60 void RemoveNotification() {
61 message_center::MessageCenter::Get()->RemoveNotification(
62 TraySessionLengthLimit::kNotificationId, false /* by_user */);
63 }
64
65 TraySessionLengthLimit* tray_session_length_limit() {
66 return tray_session_length_limit_;
67 }
68
69 private:
70 // Weak reference, owned by the SystemTray.
71 TraySessionLengthLimit* tray_session_length_limit_;
72
73 DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimitTest);
74 };
75
76 TEST_F(TraySessionLengthLimitTest, Notification) {
77 // No notifications when no session limit.
78 EXPECT_FALSE(GetNotification());
79
80 // Limit is 15 min.
81 UpdateSessionLengthLimitInMin(15);
82 message_center::Notification* notification = GetNotification();
83 EXPECT_TRUE(notification);
84 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
85 base::string16 first_content = notification->message();
86 // Should read the content.
87 EXPECT_TRUE(notification->rich_notification_data()
88 .should_make_spoken_feedback_for_popup_updates);
89
90 // Limit is 10 min.
91 UpdateSessionLengthLimitInMin(10);
92 notification = GetNotification();
93 EXPECT_TRUE(notification);
94 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
95 // The content should be updated.
96 EXPECT_NE(first_content, notification->message());
97 // Should NOT read, because just update the remaining time.
98 EXPECT_FALSE(notification->rich_notification_data()
99 .should_make_spoken_feedback_for_popup_updates);
100
101 // Limit is 3 min.
102 UpdateSessionLengthLimitInMin(3);
103 notification = GetNotification();
104 EXPECT_TRUE(notification);
105 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
106 // Should read the content again because the state has changed.
107 EXPECT_TRUE(notification->rich_notification_data()
108 .should_make_spoken_feedback_for_popup_updates);
109
110 // Session length limit is updated to longer: 15 min.
111 UpdateSessionLengthLimitInMin(15);
112 notification = GetNotification();
113 EXPECT_TRUE(notification);
114 EXPECT_EQ(message_center::SYSTEM_PRIORITY, notification->priority());
115 // Should read again because an increase of the remaining time is noteworthy.
116 EXPECT_TRUE(notification->rich_notification_data()
117 .should_make_spoken_feedback_for_popup_updates);
118
119 // Clears the limit: the notification should be gone.
120 ClearSessionLengthLimit();
121 EXPECT_FALSE(GetNotification());
122 }
123
124 TEST_F(TraySessionLengthLimitTest, RemoveNotification) {
125 // Limit is 15 min.
126 UpdateSessionLengthLimitInMin(15);
127 EXPECT_TRUE(GetNotification());
128
129 // Removes the notification.
130 RemoveNotification();
131 EXPECT_FALSE(GetNotification());
132
133 // Limit is 10 min. The notification should not re-appear.
134 UpdateSessionLengthLimitInMin(10);
135 EXPECT_FALSE(GetNotification());
136
137 // Limit is 3 min. The notification should re-appear and should be re-read
138 // because of state change.
139 UpdateSessionLengthLimitInMin(3);
140 message_center::Notification* notification = GetNotification();
141 EXPECT_TRUE(notification);
142 EXPECT_TRUE(notification->rich_notification_data()
143 .should_make_spoken_feedback_for_popup_updates);
144
145 RemoveNotification();
146
147 // Session length limit is updated to longer state. Notification should
148 // re-appear and be re-read.
149 UpdateSessionLengthLimitInMin(15);
150 notification = GetNotification();
151 EXPECT_TRUE(notification);
152 EXPECT_TRUE(notification->rich_notification_data()
153 .should_make_spoken_feedback_for_popup_updates);
154 }
155
156 } // namespace test
157 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/session/tray_session_length_limit.cc ('k') | ash/common/system/chromeos/settings/tray_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698