OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_win.h" | 5 #include "chrome/browser/ui/views/message_center/web_notification_tray_win.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" |
11 #include "ash/system/tray/system_tray_item.h" | 11 #include "ash/system/tray/system_tray_item.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
16 #include "ui/message_center/message_center_tray.h" | 16 #include "ui/message_center/message_center_tray.h" |
17 #include "ui/message_center/notification_list.h" | 17 #include "ui/message_center/notification_list.h" |
18 #include "ui/message_center/notification_types.h" | 18 #include "ui/message_center/notification_types.h" |
19 #include "ui/message_center/views/message_center_bubble.h" | 19 #include "ui/message_center/views/message_center_bubble.h" |
20 #include "ui/message_center/views/message_popup_bubble.h" | 20 #include "ui/message_center/views/message_popup_collection.h" |
21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
22 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
23 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
25 | 25 |
26 namespace message_center { | 26 namespace message_center { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 class TestDelegate : public message_center::MessageCenter::Delegate { | 30 class TestDelegate : public message_center::MessageCenter::Delegate { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 97 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
98 }; | 98 }; |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 typedef InProcessBrowserTest WebNotificationTrayWinTest; | 102 typedef InProcessBrowserTest WebNotificationTrayWinTest; |
103 | 103 |
104 // TODO(dewittj): More exhaustive testing. | 104 // TODO(dewittj): More exhaustive testing. |
105 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, WebNotifications) { | 105 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, WebNotifications) { |
106 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin()); | 106 message_center::MessageCenter* message_center = |
107 message_center::MessageCenter* message_center = tray->message_center(); | 107 message_center::MessageCenter::Get(); |
108 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center)); | 108 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center)); |
109 | 109 |
110 // Add a notification. | 110 // Add a notification. |
111 delegate->AddNotification("test_id1"); | 111 delegate->AddNotification("test_id1"); |
112 EXPECT_EQ(1u, message_center->NotificationCount()); | 112 EXPECT_EQ(1u, message_center->NotificationCount()); |
113 EXPECT_TRUE(message_center->notification_list()->HasNotification("test_id1")); | 113 EXPECT_TRUE(message_center->notification_list()->HasNotification("test_id1")); |
114 EXPECT_FALSE( | 114 EXPECT_FALSE( |
115 message_center->notification_list()->HasNotification("test_id2")); | 115 message_center->notification_list()->HasNotification("test_id2")); |
116 delegate->AddNotification("test_id2"); | 116 delegate->AddNotification("test_id2"); |
117 delegate->AddNotification("test_id2"); | 117 delegate->AddNotification("test_id2"); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 delegate->AddNotification(id); | 180 delegate->AddNotification(id); |
181 } | 181 } |
182 bool shown = tray->message_center_tray_->ShowMessageCenterBubble(); | 182 bool shown = tray->message_center_tray_->ShowMessageCenterBubble(); |
183 EXPECT_TRUE(shown); | 183 EXPECT_TRUE(shown); |
184 content::RunAllPendingInMessageLoop(); | 184 content::RunAllPendingInMessageLoop(); |
185 EXPECT_TRUE(tray->message_center_bubble_.get() != NULL); | 185 EXPECT_TRUE(tray->message_center_bubble_.get() != NULL); |
186 EXPECT_EQ(notifications_to_add, | 186 EXPECT_EQ(notifications_to_add, |
187 message_center->NotificationCount()); | 187 message_center->NotificationCount()); |
188 EXPECT_EQ(NotificationList::kMaxVisibleMessageCenterNotifications, | 188 EXPECT_EQ(NotificationList::kMaxVisibleMessageCenterNotifications, |
189 tray->GetMessageCenterBubbleForTest()->NumMessageViewsForTest()); | 189 tray->GetMessageCenterBubbleForTest()->NumMessageViewsForTest()); |
| 190 message_center->notification_list()->RemoveAllNotifications(); |
| 191 message_center->NotifyMessageCenterChanged(false); |
190 } | 192 } |
191 | 193 |
192 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, ManyPopupNotifications) { | 194 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, ManyPopupNotifications) { |
193 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin()); | 195 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin()); |
194 message_center::MessageCenter* message_center = tray->message_center(); | 196 message_center::MessageCenter* message_center = tray->message_center(); |
195 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center)); | 197 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center)); |
196 | 198 |
197 // Add the max visible popup notifications +1, ensure the correct num visible. | 199 // Add the max visible popup notifications +1, ensure the correct num visible. |
198 size_t notifications_to_add = | 200 size_t notifications_to_add = |
199 NotificationList::kMaxVisiblePopupNotifications + 1; | 201 NotificationList::kMaxVisiblePopupNotifications + 1; |
200 for (size_t i = 0; i < notifications_to_add; ++i) { | 202 for (size_t i = 0; i < notifications_to_add; ++i) { |
201 std::string id = StringPrintf("test_id%d", static_cast<int>(i)); | 203 std::string id = StringPrintf("test_id%d", static_cast<int>(i)); |
202 delegate->AddNotification(id); | 204 delegate->AddNotification(id); |
203 } | 205 } |
204 // Hide and reshow the bubble so that it is updated immediately, not delayed. | 206 // Hide and reshow the bubble so that it is updated immediately, not delayed. |
205 tray->message_center_tray_->HidePopupBubble(); | 207 tray->message_center_tray_->HidePopupBubble(); |
206 tray->message_center_tray_->ShowPopupBubble(); | 208 tray->message_center_tray_->ShowPopupBubble(); |
207 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); | 209 EXPECT_TRUE(tray->message_center_tray_->popups_visible()); |
208 EXPECT_EQ(notifications_to_add, | 210 EXPECT_EQ(notifications_to_add, |
209 message_center->NotificationCount()); | 211 message_center->NotificationCount()); |
210 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, | 212 NotificationList::PopupNotifications popups = |
211 tray->GetPopupBubbleForTest()->NumMessageViewsForTest()); | 213 message_center->notification_list()->GetPopupNotifications(); |
212 message_center->SetDelegate(NULL); | 214 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications, popups.size()); |
213 message_center->notification_list()->RemoveAllNotifications(); | 215 message_center->notification_list()->RemoveAllNotifications(); |
| 216 message_center->NotifyMessageCenterChanged(false); |
214 } | 217 } |
215 | 218 |
216 } // namespace message_center | 219 } // namespace message_center |
OLD | NEW |