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/mac/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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #import "ui/base/cocoa/hover_image_button.h" | 12 #import "ui/base/cocoa/hover_image_button.h" |
13 #import "ui/base/test/ui_cocoa_test_helper.h" | 13 #import "ui/base/test/ui_cocoa_test_helper.h" |
14 #include "ui/message_center/fake_message_center.h" | 14 #include "ui/message_center/fake_message_center.h" |
15 #include "ui/message_center/message_center_style.h" | 15 #include "ui/message_center/message_center_style.h" |
16 #include "ui/message_center/notification.h" | 16 #include "ui/message_center/notification.h" |
17 #include "ui/message_center/notification_types.h" | 17 #include "ui/message_center/notification_types.h" |
18 | 18 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 gfx::Image(), |
107 string16(), | 107 string16(), |
108 std::string(), | 108 std::string(), |
109 message_center::RichNotificationData(), | 109 message_center::RichNotificationData(), |
110 NULL)); | 110 NULL)); |
111 notification->set_icon(gfx::Image([TestIcon() retain])); | 111 notification->set_icon(gfx::Image([TestIcon() retain])); |
112 | 112 |
113 scoped_nsobject<MCNotificationController> controller( | 113 base::scoped_nsobject<MCNotificationController> controller( |
114 [[MCNotificationController alloc] initWithNotification:notification.get() | 114 [[MCNotificationController alloc] initWithNotification:notification.get() |
115 messageCenter:NULL]); | 115 messageCenter:NULL]); |
116 [controller view]; | 116 [controller view]; |
117 | 117 |
118 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 118 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
119 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), | 119 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), |
120 notification->title()); | 120 notification->title()); |
121 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), | 121 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), |
122 notification->message()); | 122 notification->message()); |
123 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 123 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
124 } | 124 } |
125 | 125 |
126 TEST_F(NotificationControllerTest, OverflowText) { | 126 TEST_F(NotificationControllerTest, OverflowText) { |
127 scoped_ptr<message_center::Notification> notification( | 127 scoped_ptr<message_center::Notification> notification( |
128 new message_center::Notification( | 128 new message_center::Notification( |
129 message_center::NOTIFICATION_TYPE_SIMPLE, | 129 message_center::NOTIFICATION_TYPE_SIMPLE, |
130 "", | 130 "", |
131 ASCIIToUTF16("This is a much longer title that should wrap " | 131 ASCIIToUTF16("This is a much longer title that should wrap " |
132 "multiple lines."), | 132 "multiple lines."), |
133 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 " |
134 "notification. Are you really going to read this " | 134 "notification. Are you really going to read this " |
135 "entire thing?"), | 135 "entire thing?"), |
136 gfx::Image(), | 136 gfx::Image(), |
137 string16(), | 137 string16(), |
138 std::string(), | 138 std::string(), |
139 message_center::RichNotificationData(), | 139 message_center::RichNotificationData(), |
140 NULL)); | 140 NULL)); |
141 scoped_nsobject<MCNotificationController> controller( | 141 base::scoped_nsobject<MCNotificationController> controller( |
142 [[MCNotificationController alloc] initWithNotification:notification.get() | 142 [[MCNotificationController alloc] initWithNotification:notification.get() |
143 messageCenter:NULL]); | 143 messageCenter:NULL]); |
144 [controller view]; | 144 [controller view]; |
145 | 145 |
146 EXPECT_GT(NSHeight([[controller view] frame]), | 146 EXPECT_GT(NSHeight([[controller view] frame]), |
147 message_center::kNotificationIconSize); | 147 message_center::kNotificationIconSize); |
148 } | 148 } |
149 | 149 |
150 TEST_F(NotificationControllerTest, Close) { | 150 TEST_F(NotificationControllerTest, Close) { |
151 scoped_ptr<message_center::Notification> notification( | 151 scoped_ptr<message_center::Notification> notification( |
152 new message_center::Notification( | 152 new message_center::Notification( |
153 message_center::NOTIFICATION_TYPE_SIMPLE, | 153 message_center::NOTIFICATION_TYPE_SIMPLE, |
154 "an_id", | 154 "an_id", |
155 string16(), | 155 string16(), |
156 string16(), | 156 string16(), |
157 gfx::Image(), | 157 gfx::Image(), |
158 string16(), | 158 string16(), |
159 std::string(), | 159 std::string(), |
160 message_center::RichNotificationData(), | 160 message_center::RichNotificationData(), |
161 NULL)); | 161 NULL)); |
162 MockMessageCenter message_center; | 162 MockMessageCenter message_center; |
163 | 163 |
164 scoped_nsobject<MCNotificationController> controller( | 164 base::scoped_nsobject<MCNotificationController> controller( |
165 [[MCNotificationController alloc] initWithNotification:notification.get() | 165 [[MCNotificationController alloc] initWithNotification:notification.get() |
166 messageCenter:&message_center]); | 166 messageCenter:&message_center]); |
167 [controller view]; | 167 [controller view]; |
168 | 168 |
169 [[controller closeButton] performClick:nil]; | 169 [[controller closeButton] performClick:nil]; |
170 | 170 |
171 EXPECT_EQ(1, message_center.remove_count()); | 171 EXPECT_EQ(1, message_center.remove_count()); |
172 EXPECT_EQ("an_id", message_center.last_removed_id()); | 172 EXPECT_EQ("an_id", message_center.last_removed_id()); |
173 EXPECT_TRUE(message_center.last_removed_by_user()); | 173 EXPECT_TRUE(message_center.last_removed_by_user()); |
174 } | 174 } |
175 | 175 |
176 TEST_F(NotificationControllerTest, Update) { | 176 TEST_F(NotificationControllerTest, Update) { |
177 scoped_ptr<message_center::Notification> notification( | 177 scoped_ptr<message_center::Notification> notification( |
178 new message_center::Notification( | 178 new message_center::Notification( |
179 message_center::NOTIFICATION_TYPE_SIMPLE, | 179 message_center::NOTIFICATION_TYPE_SIMPLE, |
180 "", | 180 "", |
181 ASCIIToUTF16("A simple title"), | 181 ASCIIToUTF16("A simple title"), |
182 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" |
183 "default bounds."), | 183 "default bounds."), |
184 gfx::Image(), | 184 gfx::Image(), |
185 string16(), | 185 string16(), |
186 std::string(), | 186 std::string(), |
187 message_center::RichNotificationData(), | 187 message_center::RichNotificationData(), |
188 NULL)); | 188 NULL)); |
189 scoped_nsobject<MCNotificationController> controller( | 189 base::scoped_nsobject<MCNotificationController> controller( |
190 [[MCNotificationController alloc] initWithNotification:notification.get() | 190 [[MCNotificationController alloc] initWithNotification:notification.get() |
191 messageCenter:NULL]); | 191 messageCenter:NULL]); |
192 | 192 |
193 // Set up the default layout. | 193 // Set up the default layout. |
194 [controller view]; | 194 [controller view]; |
195 EXPECT_EQ(NSHeight([[controller view] frame]), | 195 EXPECT_EQ(NSHeight([[controller view] frame]), |
196 message_center::kNotificationIconSize); | 196 message_center::kNotificationIconSize); |
197 EXPECT_FALSE([[controller iconView] image]); | 197 EXPECT_FALSE([[controller iconView] image]); |
198 | 198 |
199 // Update the icon. | 199 // Update the icon. |
(...skipping 17 matching lines...) Expand all Loading... |
217 "an_id", | 217 "an_id", |
218 string16(), | 218 string16(), |
219 string16(), | 219 string16(), |
220 gfx::Image(), | 220 gfx::Image(), |
221 string16(), | 221 string16(), |
222 std::string(), | 222 std::string(), |
223 optional, | 223 optional, |
224 NULL)); | 224 NULL)); |
225 MockMessageCenter message_center; | 225 MockMessageCenter message_center; |
226 | 226 |
227 scoped_nsobject<MCNotificationController> controller( | 227 base::scoped_nsobject<MCNotificationController> controller( |
228 [[MCNotificationController alloc] initWithNotification:notification.get() | 228 [[MCNotificationController alloc] initWithNotification:notification.get() |
229 messageCenter:&message_center]); | 229 messageCenter:&message_center]); |
230 [controller view]; | 230 [controller view]; |
231 | 231 |
232 [[controller secondButton] performClick:nil]; | 232 [[controller secondButton] performClick:nil]; |
233 | 233 |
234 EXPECT_EQ("an_id", message_center.last_clicked_id()); | 234 EXPECT_EQ("an_id", message_center.last_clicked_id()); |
235 EXPECT_EQ(1, message_center.last_clicked_index()); | 235 EXPECT_EQ(1, message_center.last_clicked_index()); |
236 } | 236 } |
237 | 237 |
238 TEST_F(NotificationControllerTest, Image) { | 238 TEST_F(NotificationControllerTest, Image) { |
239 scoped_ptr<message_center::Notification> notification( | 239 scoped_ptr<message_center::Notification> notification( |
240 new message_center::Notification( | 240 new message_center::Notification( |
241 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 241 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
242 "an_id", | 242 "an_id", |
243 string16(), | 243 string16(), |
244 string16(), | 244 string16(), |
245 gfx::Image(), | 245 gfx::Image(), |
246 string16(), | 246 string16(), |
247 std::string(), | 247 std::string(), |
248 message_center::RichNotificationData(), | 248 message_center::RichNotificationData(), |
249 NULL)); | 249 NULL)); |
250 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; | 250 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; |
251 notification->set_image(gfx::Image([image retain])); | 251 notification->set_image(gfx::Image([image retain])); |
252 | 252 |
253 MockMessageCenter message_center; | 253 MockMessageCenter message_center; |
254 | 254 |
255 scoped_nsobject<MCNotificationController> controller( | 255 base::scoped_nsobject<MCNotificationController> controller( |
256 [[MCNotificationController alloc] initWithNotification:notification.get() | 256 [[MCNotificationController alloc] initWithNotification:notification.get() |
257 messageCenter:&message_center]); | 257 messageCenter:&message_center]); |
258 [controller view]; | 258 [controller view]; |
259 | 259 |
260 ASSERT_EQ(1u, [[controller bottomSubviews] count]); | 260 ASSERT_EQ(1u, [[controller bottomSubviews] count]); |
261 ASSERT_TRUE([[[controller bottomSubviews] lastObject] | 261 ASSERT_TRUE([[[controller bottomSubviews] lastObject] |
262 isKindOfClass:[NSImageView class]]); | 262 isKindOfClass:[NSImageView class]]); |
263 EXPECT_EQ(image, [[[controller bottomSubviews] lastObject] image]); | 263 EXPECT_EQ(image, [[[controller bottomSubviews] lastObject] image]); |
264 } | 264 } |
265 | 265 |
(...skipping 13 matching lines...) Expand all Loading... |
279 "an_id", | 279 "an_id", |
280 string16(), | 280 string16(), |
281 string16(), | 281 string16(), |
282 gfx::Image(), | 282 gfx::Image(), |
283 string16(), | 283 string16(), |
284 std::string(), | 284 std::string(), |
285 optional, | 285 optional, |
286 NULL)); | 286 NULL)); |
287 | 287 |
288 MockMessageCenter message_center; | 288 MockMessageCenter message_center; |
289 scoped_nsobject<MCNotificationController> controller( | 289 base::scoped_nsobject<MCNotificationController> controller( |
290 [[MCNotificationController alloc] initWithNotification:notification.get() | 290 [[MCNotificationController alloc] initWithNotification:notification.get() |
291 messageCenter:&message_center]); | 291 messageCenter:&message_center]); |
292 [controller view]; | 292 [controller view]; |
293 | 293 |
294 EXPECT_EQ(2u, [[[controller listItemView] subviews] count]); | 294 EXPECT_EQ(2u, [[[controller listItemView] subviews] count]); |
295 EXPECT_TRUE(NSMaxY([[controller listItemView] frame]) < | 295 EXPECT_TRUE(NSMaxY([[controller listItemView] frame]) < |
296 NSMinY([[controller messageView] frame])); | 296 NSMinY([[controller messageView] frame])); |
297 } | 297 } |
OLD | NEW |