OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/message_center/web_notification_tray.h" | 5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 EXPECT_FALSE(HasNotification(message_center, "test_id1")); | 138 EXPECT_FALSE(HasNotification(message_center, "test_id1")); |
139 EXPECT_EQ(1u, message_center->NotificationCount()); | 139 EXPECT_EQ(1u, message_center->NotificationCount()); |
140 | 140 |
141 // Remove the remaining notification. | 141 // Remove the remaining notification. |
142 RemoveNotification("test_id3"); | 142 RemoveNotification("test_id3"); |
143 EXPECT_EQ(0u, message_center->NotificationCount()); | 143 EXPECT_EQ(0u, message_center->NotificationCount()); |
144 EXPECT_FALSE(HasNotification(message_center, "test_id1")); | 144 EXPECT_FALSE(HasNotification(message_center, "test_id1")); |
145 } | 145 } |
146 | 146 |
147 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) { | 147 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, WebNotificationPopupBubble) { |
148 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray(NULL)); | 148 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray()); |
149 tray->message_center(); | 149 tray->message_center(); |
150 | 150 |
151 // Adding a notification should show the popup bubble. | 151 // Adding a notification should show the popup bubble. |
152 AddNotification("test_id1", "replace_id1"); | 152 AddNotification("test_id1", "replace_id1"); |
153 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); | 153 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); |
154 | 154 |
155 // Updating a notification should not hide the popup bubble. | 155 // Updating a notification should not hide the popup bubble. |
156 AddNotification("test_id2", "replace_id2"); | 156 AddNotification("test_id2", "replace_id2"); |
157 UpdateNotification("replace_id2", "test_id3"); | 157 UpdateNotification("replace_id2", "test_id3"); |
158 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); | 158 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); |
159 | 159 |
160 // Removing the first notification should not hide the popup bubble. | 160 // Removing the first notification should not hide the popup bubble. |
161 RemoveNotification("test_id1"); | 161 RemoveNotification("test_id1"); |
162 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); | 162 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); |
163 | 163 |
164 // Removing the visible notification should hide the popup bubble. | 164 // Removing the visible notification should hide the popup bubble. |
165 RemoveNotification("test_id3"); | 165 RemoveNotification("test_id3"); |
166 EXPECT_FALSE(tray->message_center_tray_->popups_visible()); | 166 EXPECT_FALSE(tray->message_center_tray_->popups_visible()); |
167 } | 167 } |
168 | 168 |
169 using message_center::NotificationList; | 169 using message_center::NotificationList; |
170 | 170 |
171 // Flaky, see http://crbug.com/222500 . | |
172 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, | |
173 DISABLED_ManyMessageCenterNotifications) { | |
174 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray(NULL)); | |
175 message_center::MessageCenter* message_center = tray->message_center(); | |
176 | |
177 // Add the max visible notifications +1, ensure the correct visible number. | |
178 size_t notifications_to_add = kMaxVisibleMessageCenterNotifications + 1; | |
179 for (size_t i = 0; i < notifications_to_add; ++i) { | |
180 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); | |
181 std::string replace_id = | |
182 base::StringPrintf("replace_id%d", static_cast<int>(i)); | |
183 AddNotification(id, replace_id); | |
184 } | |
185 bool shown = tray->message_center_tray_->ShowMessageCenterBubble(); | |
186 EXPECT_TRUE(shown); | |
187 content::RunAllPendingInMessageLoop(); | |
188 EXPECT_TRUE(tray->message_center_delegate_ != NULL); | |
189 EXPECT_EQ(notifications_to_add, message_center->NotificationCount()); | |
190 EXPECT_EQ(kMaxVisibleMessageCenterNotifications, | |
191 tray->message_center_delegate_->NumMessageViewsForTest()); | |
192 } | |
193 | |
194 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, ManyPopupNotifications) { | 171 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, ManyPopupNotifications) { |
195 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray(NULL)); | 172 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray()); |
196 message_center::MessageCenter* message_center = tray->message_center(); | 173 message_center::MessageCenter* message_center = tray->message_center(); |
197 | 174 |
198 // Add the max visible popup notifications +1, ensure the correct num visible. | 175 // Add the max visible popup notifications +1, ensure the correct num visible. |
199 size_t notifications_to_add = kMaxVisiblePopupNotifications + 1; | 176 size_t notifications_to_add = kMaxVisiblePopupNotifications + 1; |
200 for (size_t i = 0; i < notifications_to_add; ++i) { | 177 for (size_t i = 0; i < notifications_to_add; ++i) { |
201 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); | 178 std::string id = base::StringPrintf("test_id%d", static_cast<int>(i)); |
202 std::string replace_id = | 179 std::string replace_id = |
203 base::StringPrintf("replace_id%d", static_cast<int>(i)); | 180 base::StringPrintf("replace_id%d", static_cast<int>(i)); |
204 AddNotification(id, replace_id); | 181 AddNotification(id, replace_id); |
205 } | 182 } |
206 // Hide and reshow the bubble so that it is updated immediately, not delayed. | 183 // Hide and reshow the bubble so that it is updated immediately, not delayed. |
207 tray->message_center_tray_->HidePopupBubble(); | 184 tray->message_center_tray_->HidePopupBubble(); |
208 tray->message_center_tray_->ShowPopupBubble(); | 185 tray->message_center_tray_->ShowPopupBubble(); |
209 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); | 186 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); |
210 EXPECT_EQ(notifications_to_add, message_center->NotificationCount()); | 187 EXPECT_EQ(notifications_to_add, message_center->NotificationCount()); |
211 NotificationList::PopupNotifications popups = | 188 NotificationList::PopupNotifications popups = |
212 message_center->GetPopupNotifications(); | 189 message_center->GetPopupNotifications(); |
213 EXPECT_EQ(kMaxVisiblePopupNotifications, popups.size()); | 190 EXPECT_EQ(kMaxVisiblePopupNotifications, popups.size()); |
214 } | 191 } |
215 | 192 |
216 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, | |
217 ManuallyCloseMessageCenter) { | |
218 NotificationUIManager* manager = g_browser_process->notification_ui_manager(); | |
219 MessageCenterNotificationManager* mc_manager = | |
220 static_cast<MessageCenterNotificationManager*>(manager); | |
221 | |
222 WebNotificationTray* tray = | |
223 static_cast<WebNotificationTray*>(mc_manager->tray_.get()); | |
224 ASSERT_TRUE(NULL != tray); | |
225 | |
226 message_center::MessageCenter* message_center = tray->message_center(); | |
227 | |
228 bool shown = tray->message_center_tray_->ShowMessageCenterBubble(); | |
229 EXPECT_TRUE(shown); | |
230 EXPECT_TRUE(message_center->IsMessageCenterVisible()); | |
231 | |
232 mc_manager->EnsureMessageCenterClosed(); | |
233 | |
234 EXPECT_FALSE(message_center->IsMessageCenterVisible()); | |
235 if (NULL != tray->message_center_delegate_) | |
236 EXPECT_TRUE(tray->message_center_delegate_->GetWidget()->IsClosed()); | |
237 } | |
238 | |
239 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
240 #define MAYBE_StatusIconBehavior DISABLED_StatusIconBehavior | |
241 #else | |
242 #define MAYBE_StatusIconBehavior StatusIconBehavior | |
243 #endif | |
244 IN_PROC_BROWSER_TEST_F(WebNotificationTrayTest, MAYBE_StatusIconBehavior) { | |
245 scoped_ptr<WebNotificationTray> tray(new WebNotificationTray(NULL)); | |
246 | |
247 EXPECT_TRUE(tray->status_icon_ == NULL); | |
248 tray->OnMessageCenterTrayChanged(); | |
249 base::RunLoop().RunUntilIdle(); | |
250 EXPECT_TRUE(tray->status_icon_ == NULL); | |
251 AddNotification("test_id", "replace_id"); | |
252 base::RunLoop().RunUntilIdle(); | |
253 EXPECT_TRUE(tray->status_icon_ != NULL); | |
254 RemoveNotification("test_id"); | |
255 base::RunLoop().RunUntilIdle(); | |
256 EXPECT_TRUE(tray->status_icon_ == NULL); | |
257 } | |
258 } // namespace message_center | 193 } // namespace message_center |
OLD | NEW |