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 #import "ui/message_center/cocoa/notification_controller.h" | 5 #import "ui/message_center/cocoa/notification_controller.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 }; | 97 }; |
98 | 98 |
99 TEST_F(NotificationControllerTest, BasicLayout) { | 99 TEST_F(NotificationControllerTest, BasicLayout) { |
100 scoped_ptr<message_center::Notification> notification( | 100 scoped_ptr<message_center::Notification> notification( |
101 new message_center::Notification( | 101 new message_center::Notification( |
102 message_center::NOTIFICATION_TYPE_SIMPLE, | 102 message_center::NOTIFICATION_TYPE_SIMPLE, |
103 "", | 103 "", |
104 ASCIIToUTF16("Added to circles"), | 104 ASCIIToUTF16("Added to circles"), |
105 ASCIIToUTF16("Jonathan and 5 others"), | 105 ASCIIToUTF16("Jonathan and 5 others"), |
| 106 gfx::Image(), |
106 string16(), | 107 string16(), |
107 std::string(), | 108 std::string(), |
108 NULL, | 109 NULL, |
109 NULL)); | 110 NULL)); |
110 notification->set_icon(gfx::Image([TestIcon() retain])); | 111 notification->set_icon(gfx::Image([TestIcon() retain])); |
111 | 112 |
112 scoped_nsobject<MCNotificationController> controller( | 113 scoped_nsobject<MCNotificationController> controller( |
113 [[MCNotificationController alloc] initWithNotification:notification.get() | 114 [[MCNotificationController alloc] initWithNotification:notification.get() |
114 messageCenter:NULL]); | 115 messageCenter:NULL]); |
115 [controller view]; | 116 [controller view]; |
116 | 117 |
117 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 118 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
118 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), | 119 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), |
119 notification->title()); | 120 notification->title()); |
120 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), | 121 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), |
121 notification->message()); | 122 notification->message()); |
122 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 123 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
123 } | 124 } |
124 | 125 |
125 TEST_F(NotificationControllerTest, OverflowText) { | 126 TEST_F(NotificationControllerTest, OverflowText) { |
126 scoped_ptr<message_center::Notification> notification( | 127 scoped_ptr<message_center::Notification> notification( |
127 new message_center::Notification( | 128 new message_center::Notification( |
128 message_center::NOTIFICATION_TYPE_SIMPLE, | 129 message_center::NOTIFICATION_TYPE_SIMPLE, |
129 "", | 130 "", |
130 ASCIIToUTF16("This is a much longer title that should wrap " | 131 ASCIIToUTF16("This is a much longer title that should wrap " |
131 "multiple lines."), | 132 "multiple lines."), |
132 ASCIIToUTF16("And even the message is long. This sure is a wordy " | 133 ASCIIToUTF16("And even the message is long. This sure is a wordy " |
133 "notification. Are you really going to read this " | 134 "notification. Are you really going to read this " |
134 "entire thing?"), | 135 "entire thing?"), |
| 136 gfx::Image(), |
135 string16(), | 137 string16(), |
136 std::string(), | 138 std::string(), |
137 NULL, | 139 NULL, |
138 NULL)); | 140 NULL)); |
139 scoped_nsobject<MCNotificationController> controller( | 141 scoped_nsobject<MCNotificationController> controller( |
140 [[MCNotificationController alloc] initWithNotification:notification.get() | 142 [[MCNotificationController alloc] initWithNotification:notification.get() |
141 messageCenter:NULL]); | 143 messageCenter:NULL]); |
142 [controller view]; | 144 [controller view]; |
143 | 145 |
144 EXPECT_GT(NSHeight([[controller view] frame]), | 146 EXPECT_GT(NSHeight([[controller view] frame]), |
145 message_center::kNotificationIconSize); | 147 message_center::kNotificationIconSize); |
146 } | 148 } |
147 | 149 |
148 TEST_F(NotificationControllerTest, Close) { | 150 TEST_F(NotificationControllerTest, Close) { |
149 scoped_ptr<message_center::Notification> notification( | 151 scoped_ptr<message_center::Notification> notification( |
150 new message_center::Notification( | 152 new message_center::Notification( |
151 message_center::NOTIFICATION_TYPE_SIMPLE, | 153 message_center::NOTIFICATION_TYPE_SIMPLE, |
152 "an_id", | 154 "an_id", |
153 string16(), | 155 string16(), |
154 string16(), | 156 string16(), |
| 157 gfx::Image(), |
155 string16(), | 158 string16(), |
156 std::string(), | 159 std::string(), |
157 NULL, | 160 NULL, |
158 NULL)); | 161 NULL)); |
159 MockMessageCenter message_center; | 162 MockMessageCenter message_center; |
160 | 163 |
161 scoped_nsobject<MCNotificationController> controller( | 164 scoped_nsobject<MCNotificationController> controller( |
162 [[MCNotificationController alloc] initWithNotification:notification.get() | 165 [[MCNotificationController alloc] initWithNotification:notification.get() |
163 messageCenter:&message_center]); | 166 messageCenter:&message_center]); |
164 [controller view]; | 167 [controller view]; |
165 | 168 |
166 [[controller closeButton] performClick:nil]; | 169 [[controller closeButton] performClick:nil]; |
167 | 170 |
168 EXPECT_EQ(1, message_center.remove_count()); | 171 EXPECT_EQ(1, message_center.remove_count()); |
169 EXPECT_EQ("an_id", message_center.last_removed_id()); | 172 EXPECT_EQ("an_id", message_center.last_removed_id()); |
170 EXPECT_TRUE(message_center.last_removed_by_user()); | 173 EXPECT_TRUE(message_center.last_removed_by_user()); |
171 } | 174 } |
172 | 175 |
173 TEST_F(NotificationControllerTest, Update) { | 176 TEST_F(NotificationControllerTest, Update) { |
174 scoped_ptr<message_center::Notification> notification( | 177 scoped_ptr<message_center::Notification> notification( |
175 new message_center::Notification( | 178 new message_center::Notification( |
176 message_center::NOTIFICATION_TYPE_SIMPLE, | 179 message_center::NOTIFICATION_TYPE_SIMPLE, |
177 "", | 180 "", |
178 ASCIIToUTF16("A simple title"), | 181 ASCIIToUTF16("A simple title"), |
179 ASCIIToUTF16("This message isn't too long and should fit in the" | 182 ASCIIToUTF16("This message isn't too long and should fit in the" |
180 "default bounds."), | 183 "default bounds."), |
| 184 gfx::Image(), |
181 string16(), | 185 string16(), |
182 std::string(), | 186 std::string(), |
183 NULL, | 187 NULL, |
184 NULL)); | 188 NULL)); |
185 scoped_nsobject<MCNotificationController> controller( | 189 scoped_nsobject<MCNotificationController> controller( |
186 [[MCNotificationController alloc] initWithNotification:notification.get() | 190 [[MCNotificationController alloc] initWithNotification:notification.get() |
187 messageCenter:NULL]); | 191 messageCenter:NULL]); |
188 | 192 |
189 // Set up the default layout. | 193 // Set up the default layout. |
190 [controller view]; | 194 [controller view]; |
(...skipping 13 matching lines...) Expand all Loading... |
204 base::DictionaryValue buttons; | 208 base::DictionaryValue buttons; |
205 buttons.SetString(message_center::kButtonOneTitleKey, "button1"); | 209 buttons.SetString(message_center::kButtonOneTitleKey, "button1"); |
206 buttons.SetString(message_center::kButtonTwoTitleKey, "button2"); | 210 buttons.SetString(message_center::kButtonTwoTitleKey, "button2"); |
207 | 211 |
208 scoped_ptr<message_center::Notification> notification( | 212 scoped_ptr<message_center::Notification> notification( |
209 new message_center::Notification( | 213 new message_center::Notification( |
210 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 214 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
211 "an_id", | 215 "an_id", |
212 string16(), | 216 string16(), |
213 string16(), | 217 string16(), |
| 218 gfx::Image(), |
214 string16(), | 219 string16(), |
215 std::string(), | 220 std::string(), |
216 &buttons, | 221 &buttons, |
217 NULL)); | 222 NULL)); |
218 MockMessageCenter message_center; | 223 MockMessageCenter message_center; |
219 | 224 |
220 scoped_nsobject<MCNotificationController> controller( | 225 scoped_nsobject<MCNotificationController> controller( |
221 [[MCNotificationController alloc] initWithNotification:notification.get() | 226 [[MCNotificationController alloc] initWithNotification:notification.get() |
222 messageCenter:&message_center]); | 227 messageCenter:&message_center]); |
223 [controller view]; | 228 [controller view]; |
224 | 229 |
225 [[controller secondButton] performClick:nil]; | 230 [[controller secondButton] performClick:nil]; |
226 | 231 |
227 EXPECT_EQ("an_id", message_center.last_clicked_id()); | 232 EXPECT_EQ("an_id", message_center.last_clicked_id()); |
228 EXPECT_EQ(1, message_center.last_clicked_index()); | 233 EXPECT_EQ(1, message_center.last_clicked_index()); |
229 } | 234 } |
230 | 235 |
231 TEST_F(NotificationControllerTest, Image) { | 236 TEST_F(NotificationControllerTest, Image) { |
232 scoped_ptr<message_center::Notification> notification( | 237 scoped_ptr<message_center::Notification> notification( |
233 new message_center::Notification( | 238 new message_center::Notification( |
234 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 239 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
235 "an_id", | 240 "an_id", |
236 string16(), | 241 string16(), |
237 string16(), | 242 string16(), |
| 243 gfx::Image(), |
238 string16(), | 244 string16(), |
239 std::string(), | 245 std::string(), |
240 NULL, | 246 NULL, |
241 NULL)); | 247 NULL)); |
242 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; | 248 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; |
243 notification->set_image(gfx::Image([image retain])); | 249 notification->set_image(gfx::Image([image retain])); |
244 | 250 |
245 MockMessageCenter message_center; | 251 MockMessageCenter message_center; |
246 | 252 |
247 scoped_nsobject<MCNotificationController> controller( | 253 scoped_nsobject<MCNotificationController> controller( |
(...skipping 23 matching lines...) Expand all Loading... |
271 | 277 |
272 base::DictionaryValue items; | 278 base::DictionaryValue items; |
273 items.Set(message_center::kItemsKey, list); | 279 items.Set(message_center::kItemsKey, list); |
274 | 280 |
275 scoped_ptr<message_center::Notification> notification( | 281 scoped_ptr<message_center::Notification> notification( |
276 new message_center::Notification( | 282 new message_center::Notification( |
277 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 283 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
278 "an_id", | 284 "an_id", |
279 string16(), | 285 string16(), |
280 string16(), | 286 string16(), |
| 287 gfx::Image(), |
281 string16(), | 288 string16(), |
282 std::string(), | 289 std::string(), |
283 &items, | 290 &items, |
284 NULL)); | 291 NULL)); |
285 | 292 |
286 MockMessageCenter message_center; | 293 MockMessageCenter message_center; |
287 scoped_nsobject<MCNotificationController> controller( | 294 scoped_nsobject<MCNotificationController> controller( |
288 [[MCNotificationController alloc] initWithNotification:notification.get() | 295 [[MCNotificationController alloc] initWithNotification:notification.get() |
289 messageCenter:&message_center]); | 296 messageCenter:&message_center]); |
290 [controller view]; | 297 [controller view]; |
291 | 298 |
292 EXPECT_EQ(2u, [[[controller listItemView] subviews] count]); | 299 EXPECT_EQ(2u, [[[controller listItemView] subviews] count]); |
293 EXPECT_TRUE(NSMaxY([[controller listItemView] frame]) < | 300 EXPECT_TRUE(NSMaxY([[controller listItemView] frame]) < |
294 NSMinY([[controller messageView] frame])); | 301 NSMinY([[controller messageView] frame])); |
295 } | 302 } |
OLD | NEW |