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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 TEST_F(NotificationControllerTest, BasicLayout) { | 95 TEST_F(NotificationControllerTest, BasicLayout) { |
96 scoped_ptr<message_center::Notification> notification( | 96 scoped_ptr<message_center::Notification> notification( |
97 new message_center::Notification( | 97 new message_center::Notification( |
98 message_center::NOTIFICATION_TYPE_SIMPLE, | 98 message_center::NOTIFICATION_TYPE_SIMPLE, |
99 "", | 99 "", |
100 ASCIIToUTF16("Added to circles"), | 100 ASCIIToUTF16("Added to circles"), |
101 ASCIIToUTF16("Jonathan and 5 others"), | 101 ASCIIToUTF16("Jonathan and 5 others"), |
102 string16(), | 102 string16(), |
103 std::string(), | 103 std::string(), |
| 104 NULL, |
104 NULL)); | 105 NULL)); |
105 notification->set_icon(gfx::Image([TestIcon() retain])); | 106 notification->set_icon(gfx::Image([TestIcon() retain])); |
106 | 107 |
107 scoped_nsobject<MCNotificationController> controller( | 108 scoped_nsobject<MCNotificationController> controller( |
108 [[MCNotificationController alloc] initWithNotification:notification.get() | 109 [[MCNotificationController alloc] initWithNotification:notification.get() |
109 messageCenter:NULL]); | 110 messageCenter:NULL]); |
110 [controller view]; | 111 [controller view]; |
111 | 112 |
112 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 113 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
113 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), | 114 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] stringValue]), |
114 notification->title()); | 115 notification->title()); |
115 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), | 116 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] stringValue]), |
116 notification->message()); | 117 notification->message()); |
117 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 118 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
118 } | 119 } |
119 | 120 |
120 TEST_F(NotificationControllerTest, OverflowText) { | 121 TEST_F(NotificationControllerTest, OverflowText) { |
121 scoped_ptr<message_center::Notification> notification( | 122 scoped_ptr<message_center::Notification> notification( |
122 new message_center::Notification( | 123 new message_center::Notification( |
123 message_center::NOTIFICATION_TYPE_SIMPLE, | 124 message_center::NOTIFICATION_TYPE_SIMPLE, |
124 "", | 125 "", |
125 ASCIIToUTF16("This is a much longer title that should wrap " | 126 ASCIIToUTF16("This is a much longer title that should wrap " |
126 "multiple lines."), | 127 "multiple lines."), |
127 ASCIIToUTF16("And even the message is long. This sure is a wordy " | 128 ASCIIToUTF16("And even the message is long. This sure is a wordy " |
128 "notification. Are you really going to read this " | 129 "notification. Are you really going to read this " |
129 "entire thing?"), | 130 "entire thing?"), |
130 string16(), | 131 string16(), |
131 std::string(), | 132 std::string(), |
| 133 NULL, |
132 NULL)); | 134 NULL)); |
133 scoped_nsobject<MCNotificationController> controller( | 135 scoped_nsobject<MCNotificationController> controller( |
134 [[MCNotificationController alloc] initWithNotification:notification.get() | 136 [[MCNotificationController alloc] initWithNotification:notification.get() |
135 messageCenter:NULL]); | 137 messageCenter:NULL]); |
136 [controller view]; | 138 [controller view]; |
137 | 139 |
138 EXPECT_GT(NSHeight([[controller view] frame]), | 140 EXPECT_GT(NSHeight([[controller view] frame]), |
139 message_center::kNotificationIconSize); | 141 message_center::kNotificationIconSize); |
140 } | 142 } |
141 | 143 |
142 TEST_F(NotificationControllerTest, Close) { | 144 TEST_F(NotificationControllerTest, Close) { |
143 scoped_ptr<message_center::Notification> notification( | 145 scoped_ptr<message_center::Notification> notification( |
144 new message_center::Notification( | 146 new message_center::Notification( |
145 message_center::NOTIFICATION_TYPE_SIMPLE, | 147 message_center::NOTIFICATION_TYPE_SIMPLE, |
146 "an_id", | 148 "an_id", |
147 string16(), | 149 string16(), |
148 string16(), | 150 string16(), |
149 string16(), | 151 string16(), |
150 std::string(), | 152 std::string(), |
| 153 NULL, |
151 NULL)); | 154 NULL)); |
152 MockMessageCenter message_center; | 155 MockMessageCenter message_center; |
153 | 156 |
154 scoped_nsobject<MCNotificationController> controller( | 157 scoped_nsobject<MCNotificationController> controller( |
155 [[MCNotificationController alloc] initWithNotification:notification.get() | 158 [[MCNotificationController alloc] initWithNotification:notification.get() |
156 messageCenter:&message_center]); | 159 messageCenter:&message_center]); |
157 [controller view]; | 160 [controller view]; |
158 | 161 |
159 [[controller closeButton] performClick:nil]; | 162 [[controller closeButton] performClick:nil]; |
160 | 163 |
161 EXPECT_EQ(1, message_center.remove_count()); | 164 EXPECT_EQ(1, message_center.remove_count()); |
162 EXPECT_EQ("an_id", message_center.last_removed_id()); | 165 EXPECT_EQ("an_id", message_center.last_removed_id()); |
163 EXPECT_TRUE(message_center.last_removed_by_user()); | 166 EXPECT_TRUE(message_center.last_removed_by_user()); |
164 } | 167 } |
165 | 168 |
166 TEST_F(NotificationControllerTest, Update) { | 169 TEST_F(NotificationControllerTest, Update) { |
167 scoped_ptr<message_center::Notification> notification( | 170 scoped_ptr<message_center::Notification> notification( |
168 new message_center::Notification( | 171 new message_center::Notification( |
169 message_center::NOTIFICATION_TYPE_SIMPLE, | 172 message_center::NOTIFICATION_TYPE_SIMPLE, |
170 "", | 173 "", |
171 ASCIIToUTF16("A simple title"), | 174 ASCIIToUTF16("A simple title"), |
172 ASCIIToUTF16("This message isn't too long and should fit in the" | 175 ASCIIToUTF16("This message isn't too long and should fit in the" |
173 "default bounds."), | 176 "default bounds."), |
174 string16(), | 177 string16(), |
175 std::string(), | 178 std::string(), |
| 179 NULL, |
176 NULL)); | 180 NULL)); |
177 scoped_nsobject<MCNotificationController> controller( | 181 scoped_nsobject<MCNotificationController> controller( |
178 [[MCNotificationController alloc] initWithNotification:notification.get() | 182 [[MCNotificationController alloc] initWithNotification:notification.get() |
179 messageCenter:NULL]); | 183 messageCenter:NULL]); |
180 | 184 |
181 // Set up the default layout. | 185 // Set up the default layout. |
182 [controller view]; | 186 [controller view]; |
183 EXPECT_EQ(NSHeight([[controller view] frame]), | 187 EXPECT_EQ(NSHeight([[controller view] frame]), |
184 message_center::kNotificationIconSize); | 188 message_center::kNotificationIconSize); |
185 EXPECT_FALSE([[controller iconView] image]); | 189 EXPECT_FALSE([[controller iconView] image]); |
(...skipping 12 matching lines...) Expand all Loading... |
198 buttons.SetString(message_center::kButtonTwoTitleKey, "button2"); | 202 buttons.SetString(message_center::kButtonTwoTitleKey, "button2"); |
199 | 203 |
200 scoped_ptr<message_center::Notification> notification( | 204 scoped_ptr<message_center::Notification> notification( |
201 new message_center::Notification( | 205 new message_center::Notification( |
202 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 206 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
203 "an_id", | 207 "an_id", |
204 string16(), | 208 string16(), |
205 string16(), | 209 string16(), |
206 string16(), | 210 string16(), |
207 std::string(), | 211 std::string(), |
208 &buttons)); | 212 &buttons, |
| 213 NULL)); |
209 MockMessageCenter message_center; | 214 MockMessageCenter message_center; |
210 | 215 |
211 scoped_nsobject<MCNotificationController> controller( | 216 scoped_nsobject<MCNotificationController> controller( |
212 [[MCNotificationController alloc] initWithNotification:notification.get() | 217 [[MCNotificationController alloc] initWithNotification:notification.get() |
213 messageCenter:&message_center]); | 218 messageCenter:&message_center]); |
214 [controller view]; | 219 [controller view]; |
215 | 220 |
216 [[controller secondButton] performClick:nil]; | 221 [[controller secondButton] performClick:nil]; |
217 | 222 |
218 EXPECT_EQ("an_id", message_center.last_clicked_id()); | 223 EXPECT_EQ("an_id", message_center.last_clicked_id()); |
219 EXPECT_EQ(1, message_center.last_clicked_index()); | 224 EXPECT_EQ(1, message_center.last_clicked_index()); |
220 } | 225 } |
221 | 226 |
222 TEST_F(NotificationControllerTest, Image) { | 227 TEST_F(NotificationControllerTest, Image) { |
223 scoped_ptr<message_center::Notification> notification( | 228 scoped_ptr<message_center::Notification> notification( |
224 new message_center::Notification( | 229 new message_center::Notification( |
225 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 230 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
226 "an_id", | 231 "an_id", |
227 string16(), | 232 string16(), |
228 string16(), | 233 string16(), |
229 string16(), | 234 string16(), |
230 std::string(), | 235 std::string(), |
| 236 NULL, |
231 NULL)); | 237 NULL)); |
232 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; | 238 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; |
233 notification->set_image(gfx::Image([image retain])); | 239 notification->set_image(gfx::Image([image retain])); |
234 | 240 |
235 MockMessageCenter message_center; | 241 MockMessageCenter message_center; |
236 | 242 |
237 scoped_nsobject<MCNotificationController> controller( | 243 scoped_nsobject<MCNotificationController> controller( |
238 [[MCNotificationController alloc] initWithNotification:notification.get() | 244 [[MCNotificationController alloc] initWithNotification:notification.get() |
239 messageCenter:&message_center]); | 245 messageCenter:&message_center]); |
240 [controller view]; | 246 [controller view]; |
241 | 247 |
242 ASSERT_EQ(1u, [[controller bottomSubviews] count]); | 248 ASSERT_EQ(1u, [[controller bottomSubviews] count]); |
243 ASSERT_TRUE([[[controller bottomSubviews] lastObject] | 249 ASSERT_TRUE([[[controller bottomSubviews] lastObject] |
244 isKindOfClass:[NSImageView class]]); | 250 isKindOfClass:[NSImageView class]]); |
245 EXPECT_EQ(image, [[[controller bottomSubviews] lastObject] image]); | 251 EXPECT_EQ(image, [[[controller bottomSubviews] lastObject] image]); |
246 } | 252 } |
OLD | NEW |