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

Side by Side Diff: chrome/browser/ui/views/message_center/web_notification_tray_win_browsertest.cc

Issue 11819048: Implement message center on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address petewil & stevenjb comments. Move MessageCenterTrayDelegate to its own class. Created 7 years, 11 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 (c) 2013 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
miket_OOO 2013/01/25 17:14:48 remove extra vertical space
dewittj 2013/01/25 19:38:46 Done.
5
6 #include "chrome/browser/ui/views/message_center/web_notification_tray_win.h"
7
8 #include <set>
9
10 #include "ash/root_window_controller.h"
11 #include "ash/system/status_area_widget.h"
12 #include "ash/system/tray/system_tray_item.h"
13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "content/public/test/test_utils.h"
17 #include "ui/message_center/message_center_bubble.h"
18 #include "ui/message_center/message_center_tray.h"
19 #include "ui/message_center/message_popup_bubble.h"
20 #include "ui/message_center/notification_list.h"
21 #include "ui/notifications/notification_types.h"
22 #include "ui/views/controls/label.h"
23 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/view.h"
25 #include "ui/views/widget/widget.h"
26
27 namespace message_center {
28
29 namespace {
30
31 class TestDelegate : public message_center::MessageCenter::Delegate {
32 public:
33 explicit TestDelegate(message_center::MessageCenter* message_center)
34 : message_center_(message_center) {
35 message_center_->SetDelegate(this);
36 }
miket_OOO 2013/01/25 17:14:48 vertical whitespace
dewittj 2013/01/25 19:38:46 Done.
37 virtual ~TestDelegate() {
38 message_center_->SetDelegate(NULL);
39 message_center_->notification_list()->RemoveAllNotifications();
40 }
41
42 // WebNotificationTray::Delegate overrides.
43 virtual void NotificationRemoved(const std::string& notifcation_id) {
miket_OOO 2013/01/25 17:14:48 spelling (and elsewhere)
dewittj 2013/01/25 19:38:46 Notification is one of the hardest words to spell
44 notification_ids_.erase(notifcation_id);
45 }
46
47 virtual void DisableExtension(const std::string& notifcation_id) {
48 }
49
50 virtual void DisableNotificationsFromSource(
51 const std::string& notifcation_id) {
52 }
53
54 virtual void ShowSettings(const std::string& notifcation_id) {
55 }
56
57 virtual void OnClicked(const std::string& notifcation_id) {
58 }
59
60 void AddNotification(const std::string& id) {
61 notification_ids_.insert(id);
62 message_center_->AddNotification(
63 ui::notifications::NOTIFICATION_TYPE_SIMPLE,
64 id,
65 ASCIIToUTF16("Test Web Notification"),
66 ASCIIToUTF16("Notification message body."),
67 ASCIIToUTF16("www.test.org"),
68 "" /* extension id */,
69 NULL /* optional_fields */);
70 }
71
72 void UpdateNotification(const std::string& old_id,
73 const std::string& new_id) {
74 notification_ids_.erase(old_id);
75 notification_ids_.insert(new_id);
76 message_center_->UpdateNotification(
77 old_id, new_id,
78 ASCIIToUTF16("Updated Web Notification"),
79 ASCIIToUTF16("Updated message body."),
80 NULL);
81 }
82
83 void RemoveNotification(const std::string& id) {
84 message_center_->RemoveNotification(id);
85 notification_ids_.erase(id);
86 }
87
88 bool HasNotificationId(const std::string& id) {
89 return notification_ids_.find(id) != notification_ids_.end();
90 }
91
92 private:
93 std::set<std::string> notification_ids_;
94 // Weak pointer.
95 message_center::MessageCenter* message_center_;
96
97 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
98 };
99
100 } // namespace
101
102 typedef InProcessBrowserTest WebNotificationTrayWinTest;
103
104 // TODO(dewittj): More exhaustive testing.
105 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, WebNotifications) {
106 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin());
107 message_center::MessageCenter* message_center = tray->message_center();
108 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center));
109
110 // Add a notification.
111 delegate->AddNotification("test_id1");
112 EXPECT_EQ(1u, message_center->NotificationCount());
113 EXPECT_TRUE(message_center->notification_list()->HasNotification("test_id1"));
114 EXPECT_FALSE(
115 message_center->notification_list()->HasNotification("test_id2"));
116 delegate->AddNotification("test_id2");
117 delegate->AddNotification("test_id2");
118 EXPECT_EQ(2u, message_center->NotificationCount());
119 EXPECT_TRUE(message_center->notification_list()->HasNotification("test_id2"));
120
121 // Ensure that updating a notification does not affect the count.
122 delegate->UpdateNotification("test_id2", "test_id3");
123 delegate->UpdateNotification("test_id3", "test_id3");
124 EXPECT_EQ(2u, message_center->NotificationCount());
125 EXPECT_FALSE(delegate->HasNotificationId("test_id2"));
126 EXPECT_FALSE(message_center->notification_list()->HasNotification(
127 "test_id2"));
128 EXPECT_TRUE(delegate->HasNotificationId("test_id3"));
129
130 // Ensure that Removing the first notification removes it from the tray.
131 delegate->RemoveNotification("test_id1");
132 EXPECT_FALSE(delegate->HasNotificationId("test_id1"));
133 EXPECT_FALSE(message_center->notification_list()->HasNotification(
134 "test_id1"));
135 EXPECT_EQ(1u, message_center->NotificationCount());
136
137 // Remove the remaining notification.
138 delegate->RemoveNotification("test_id3");
139 EXPECT_EQ(0u, message_center->NotificationCount());
140 EXPECT_FALSE(message_center->notification_list()->HasNotification(
141 "test_id3"));
142 }
143
144 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, WebNotificationPopupBubble) {
145 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin());
146 message_center::MessageCenter* message_center = tray->message_center();
147 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center));
148
149 // Adding a notification should show the popup bubble.
150 delegate->AddNotification("test_id1");
151 EXPECT_TRUE(tray->message_center_tray_->popups_visible());
152
153 // Updating a notification should not hide the popup bubble.
154 delegate->AddNotification("test_id2");
155 delegate->UpdateNotification("test_id2", "test_id3");
156 EXPECT_TRUE(tray->message_center_tray_->popups_visible());
157
158 // Removing the first notification should not hide the popup bubble.
159 delegate->RemoveNotification("test_id1");
160 EXPECT_TRUE(tray->message_center_tray_->popups_visible());
161
162 // Removing the visible notification should hide the popup bubble.
163 delegate->RemoveNotification("test_id3");
164 EXPECT_FALSE(tray->message_center_tray_->popups_visible());
165 }
166
167 using message_center::NotificationList;
168
169 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest,
170 ManyMessageCenterNotifications) {
171 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin());
172 message_center::MessageCenter* message_center = tray->message_center();
173 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center));
174
175 // Add the max visible notifications +1, ensure the correct visible number.
176 size_t notifications_to_add =
177 NotificationList::kMaxVisibleMessageCenterNotifications + 1;
178 for (size_t i = 0; i < notifications_to_add; ++i) {
179 std::string id = StringPrintf("test_id%d", static_cast<int>(i));
180 delegate->AddNotification(id);
181 }
182 tray->message_center_tray_->ShowMessageCenterBubble();
183 content::RunAllPendingInMessageLoop();
184 EXPECT_TRUE(tray->message_center_bubble_.get() != NULL);
185 EXPECT_EQ(notifications_to_add,
186 message_center->NotificationCount());
187 EXPECT_EQ(NotificationList::kMaxVisibleMessageCenterNotifications,
188 tray->GetMessageCenterBubbleForTest()->NumMessageViewsForTest());
189 }
190
191 IN_PROC_BROWSER_TEST_F(WebNotificationTrayWinTest, ManyPopupNotifications) {
192 scoped_ptr<WebNotificationTrayWin> tray(new WebNotificationTrayWin());
193 message_center::MessageCenter* message_center = tray->message_center();
194 scoped_ptr<TestDelegate> delegate(new TestDelegate(message_center));
195
196 // Add the max visible popup notifications +1, ensure the correct num visible.
197 size_t notifications_to_add =
198 NotificationList::kMaxVisiblePopupNotifications + 1;
199 for (size_t i = 0; i < notifications_to_add; ++i) {
200 std::string id = StringPrintf("test_id%d", static_cast<int>(i));
201 delegate->AddNotification(id);
202 }
203 // Hide and reshow the bubble so that it is updated immediately, not delayed.
204 tray->message_center_tray_->HidePopupBubble();
205 tray->message_center_tray_->ShowPopupBubble();
206 EXPECT_TRUE(tray->message_center_tray_->popups_visible());
207 EXPECT_EQ(notifications_to_add,
208 message_center->NotificationCount());
209 EXPECT_EQ(NotificationList::kMaxVisiblePopupNotifications,
210 tray->GetPopupBubbleForTest()->NumMessageViewsForTest());
211 message_center->SetDelegate(NULL);
212 message_center->notification_list()->RemoveAllNotifications();
213 }
214
215 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698