| 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/mac/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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 std::string last_removed_id_; | 48 std::string last_removed_id_; |
| 49 bool last_removed_by_user_; | 49 bool last_removed_by_user_; |
| 50 int remove_count_; | 50 int remove_count_; |
| 51 | 51 |
| 52 std::string last_clicked_id_; | 52 std::string last_clicked_id_; |
| 53 int last_clicked_index_; | 53 int last_clicked_index_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 55 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } | 58 } // namespace |
| 59 | 59 |
| 60 @implementation MCNotificationController (TestingInterface) | 60 @implementation MCNotificationController (TestingInterface) |
| 61 - (NSButton*)closeButton { | 61 - (NSButton*)closeButton { |
| 62 return closeButton_.get(); | 62 return closeButton_.get(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 - (NSButton*)secondButton { | 65 - (NSButton*)secondButton { |
| 66 // The buttons are in Cocoa-y-order, so the 2nd button is first. | 66 // The buttons are in Cocoa-y-order, so the 2nd button is first. |
| 67 NSView* view = [[bottomView_ subviews] objectAtIndex:0]; | 67 NSView* view = [[bottomView_ subviews] objectAtIndex:0]; |
| 68 return base::mac::ObjCCastStrict<NSButton>(view); | 68 return base::mac::ObjCCastStrict<NSButton>(view); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 | 86 |
| 87 - (NSTextView*)contextMessageView { | 87 - (NSTextView*)contextMessageView { |
| 88 return contextMessage_.get(); | 88 return contextMessage_.get(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 - (NSView*)listView { | 91 - (NSView*)listView { |
| 92 return listView_.get(); | 92 return listView_.get(); |
| 93 } | 93 } |
| 94 @end | 94 @end |
| 95 | 95 |
| 96 namespace message_center { |
| 97 |
| 96 class NotificationControllerTest : public ui::CocoaTest { | 98 class NotificationControllerTest : public ui::CocoaTest { |
| 97 public: | 99 public: |
| 98 NSImage* TestIcon() { | 100 NSImage* TestIcon() { |
| 99 return [NSImage imageNamed:NSImageNameUser]; | 101 return [NSImage imageNamed:NSImageNameUser]; |
| 100 } | 102 } |
| 103 |
| 104 protected: |
| 105 message_center::NotifierId DummyNotifierId() { |
| 106 return message_center::NotifierId(); |
| 107 } |
| 101 }; | 108 }; |
| 102 | 109 |
| 103 TEST_F(NotificationControllerTest, BasicLayout) { | 110 TEST_F(NotificationControllerTest, BasicLayout) { |
| 104 scoped_ptr<message_center::Notification> notification( | 111 scoped_ptr<message_center::Notification> notification( |
| 105 new message_center::Notification( | 112 new message_center::Notification( |
| 106 message_center::NOTIFICATION_TYPE_SIMPLE, | 113 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 107 "", | 114 "", |
| 108 ASCIIToUTF16("Added to circles"), | 115 ASCIIToUTF16("Added to circles"), |
| 109 ASCIIToUTF16("Jonathan and 5 others"), | 116 ASCIIToUTF16("Jonathan and 5 others"), |
| 110 gfx::Image(), | 117 gfx::Image(), |
| 111 string16(), | 118 string16(), |
| 112 message_center::NotifierId(), | 119 DummyNotifierId(), |
| 113 message_center::RichNotificationData(), | 120 message_center::RichNotificationData(), |
| 114 NULL)); | 121 NULL)); |
| 115 notification->set_icon(gfx::Image([TestIcon() retain])); | 122 notification->set_icon(gfx::Image([TestIcon() retain])); |
| 116 | 123 |
| 117 base::scoped_nsobject<MCNotificationController> controller( | 124 base::scoped_nsobject<MCNotificationController> controller( |
| 118 [[MCNotificationController alloc] initWithNotification:notification.get() | 125 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 119 messageCenter:NULL]); | 126 messageCenter:NULL]); |
| 120 [controller view]; | 127 [controller view]; |
| 121 | 128 |
| 122 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 129 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
| 123 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]), | 130 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]), |
| 124 notification->title()); | 131 notification->title()); |
| 125 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]), | 132 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]), |
| 126 notification->message()); | 133 notification->message()); |
| 127 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 134 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
| 128 } | 135 } |
| 129 | 136 |
| 130 TEST_F(NotificationControllerTest, OverflowText) { | 137 TEST_F(NotificationControllerTest, OverflowText) { |
| 131 scoped_ptr<message_center::Notification> notification( | 138 scoped_ptr<message_center::Notification> notification( |
| 132 new message_center::Notification( | 139 new message_center::Notification( |
| 133 message_center::NOTIFICATION_TYPE_SIMPLE, | 140 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 134 "", | 141 "", |
| 135 ASCIIToUTF16("This is a much longer title that should wrap " | 142 ASCIIToUTF16("This is a much longer title that should wrap " |
| 136 "multiple lines."), | 143 "multiple lines."), |
| 137 ASCIIToUTF16("And even the message is long. This sure is a wordy " | 144 ASCIIToUTF16("And even the message is long. This sure is a wordy " |
| 138 "notification. Are you really going to read this " | 145 "notification. Are you really going to read this " |
| 139 "entire thing?"), | 146 "entire thing?"), |
| 140 gfx::Image(), | 147 gfx::Image(), |
| 141 string16(), | 148 string16(), |
| 142 message_center::NotifierId(), | 149 DummyNotifierId(), |
| 143 message_center::RichNotificationData(), | 150 message_center::RichNotificationData(), |
| 144 NULL)); | 151 NULL)); |
| 145 base::scoped_nsobject<MCNotificationController> controller( | 152 base::scoped_nsobject<MCNotificationController> controller( |
| 146 [[MCNotificationController alloc] initWithNotification:notification.get() | 153 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 147 messageCenter:NULL]); | 154 messageCenter:NULL]); |
| 148 [controller view]; | 155 [controller view]; |
| 149 | 156 |
| 150 EXPECT_GT(NSHeight([[controller view] frame]), | 157 EXPECT_GT(NSHeight([[controller view] frame]), |
| 151 message_center::kNotificationIconSize); | 158 message_center::kNotificationIconSize); |
| 152 } | 159 } |
| 153 | 160 |
| 154 TEST_F(NotificationControllerTest, Close) { | 161 TEST_F(NotificationControllerTest, Close) { |
| 155 scoped_ptr<message_center::Notification> notification( | 162 scoped_ptr<message_center::Notification> notification( |
| 156 new message_center::Notification( | 163 new message_center::Notification( |
| 157 message_center::NOTIFICATION_TYPE_SIMPLE, | 164 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 158 "an_id", | 165 "an_id", |
| 159 string16(), | 166 string16(), |
| 160 string16(), | 167 string16(), |
| 161 gfx::Image(), | 168 gfx::Image(), |
| 162 string16(), | 169 string16(), |
| 163 message_center::NotifierId(), | 170 DummyNotifierId(), |
| 164 message_center::RichNotificationData(), | 171 message_center::RichNotificationData(), |
| 165 NULL)); | 172 NULL)); |
| 166 MockMessageCenter message_center; | 173 MockMessageCenter message_center; |
| 167 | 174 |
| 168 base::scoped_nsobject<MCNotificationController> controller( | 175 base::scoped_nsobject<MCNotificationController> controller( |
| 169 [[MCNotificationController alloc] initWithNotification:notification.get() | 176 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 170 messageCenter:&message_center]); | 177 messageCenter:&message_center]); |
| 171 [controller view]; | 178 [controller view]; |
| 172 | 179 |
| 173 [[controller closeButton] performClick:nil]; | 180 [[controller closeButton] performClick:nil]; |
| 174 | 181 |
| 175 EXPECT_EQ(1, message_center.remove_count()); | 182 EXPECT_EQ(1, message_center.remove_count()); |
| 176 EXPECT_EQ("an_id", message_center.last_removed_id()); | 183 EXPECT_EQ("an_id", message_center.last_removed_id()); |
| 177 EXPECT_TRUE(message_center.last_removed_by_user()); | 184 EXPECT_TRUE(message_center.last_removed_by_user()); |
| 178 } | 185 } |
| 179 | 186 |
| 180 TEST_F(NotificationControllerTest, Update) { | 187 TEST_F(NotificationControllerTest, Update) { |
| 181 scoped_ptr<message_center::Notification> notification( | 188 scoped_ptr<message_center::Notification> notification( |
| 182 new message_center::Notification( | 189 new message_center::Notification( |
| 183 message_center::NOTIFICATION_TYPE_SIMPLE, | 190 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 184 "", | 191 "", |
| 185 ASCIIToUTF16("A simple title"), | 192 ASCIIToUTF16("A simple title"), |
| 186 ASCIIToUTF16("This message isn't too long and should fit in the" | 193 ASCIIToUTF16("This message isn't too long and should fit in the" |
| 187 "default bounds."), | 194 "default bounds."), |
| 188 gfx::Image(), | 195 gfx::Image(), |
| 189 string16(), | 196 string16(), |
| 190 message_center::NotifierId(), | 197 DummyNotifierId(), |
| 191 message_center::RichNotificationData(), | 198 message_center::RichNotificationData(), |
| 192 NULL)); | 199 NULL)); |
| 193 base::scoped_nsobject<MCNotificationController> controller( | 200 base::scoped_nsobject<MCNotificationController> controller( |
| 194 [[MCNotificationController alloc] initWithNotification:notification.get() | 201 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 195 messageCenter:NULL]); | 202 messageCenter:NULL]); |
| 196 | 203 |
| 197 // Set up the default layout. | 204 // Set up the default layout. |
| 198 [controller view]; | 205 [controller view]; |
| 199 EXPECT_EQ(NSHeight([[controller view] frame]), | 206 EXPECT_EQ(NSHeight([[controller view] frame]), |
| 200 message_center::kNotificationIconSize); | 207 message_center::kNotificationIconSize); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 216 optional.buttons.push_back(button2); | 223 optional.buttons.push_back(button2); |
| 217 | 224 |
| 218 scoped_ptr<message_center::Notification> notification( | 225 scoped_ptr<message_center::Notification> notification( |
| 219 new message_center::Notification( | 226 new message_center::Notification( |
| 220 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 227 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
| 221 "an_id", | 228 "an_id", |
| 222 string16(), | 229 string16(), |
| 223 string16(), | 230 string16(), |
| 224 gfx::Image(), | 231 gfx::Image(), |
| 225 string16(), | 232 string16(), |
| 226 message_center::NotifierId(), | 233 DummyNotifierId(), |
| 227 optional, | 234 optional, |
| 228 NULL)); | 235 NULL)); |
| 229 MockMessageCenter message_center; | 236 MockMessageCenter message_center; |
| 230 | 237 |
| 231 base::scoped_nsobject<MCNotificationController> controller( | 238 base::scoped_nsobject<MCNotificationController> controller( |
| 232 [[MCNotificationController alloc] initWithNotification:notification.get() | 239 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 233 messageCenter:&message_center]); | 240 messageCenter:&message_center]); |
| 234 [controller view]; | 241 [controller view]; |
| 235 | 242 |
| 236 [[controller secondButton] performClick:nil]; | 243 [[controller secondButton] performClick:nil]; |
| 237 | 244 |
| 238 EXPECT_EQ("an_id", message_center.last_clicked_id()); | 245 EXPECT_EQ("an_id", message_center.last_clicked_id()); |
| 239 EXPECT_EQ(1, message_center.last_clicked_index()); | 246 EXPECT_EQ(1, message_center.last_clicked_index()); |
| 240 } | 247 } |
| 241 | 248 |
| 242 TEST_F(NotificationControllerTest, Image) { | 249 TEST_F(NotificationControllerTest, Image) { |
| 243 scoped_ptr<message_center::Notification> notification( | 250 scoped_ptr<message_center::Notification> notification( |
| 244 new message_center::Notification( | 251 new message_center::Notification( |
| 245 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 252 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
| 246 "an_id", | 253 "an_id", |
| 247 string16(), | 254 string16(), |
| 248 string16(), | 255 string16(), |
| 249 gfx::Image(), | 256 gfx::Image(), |
| 250 string16(), | 257 string16(), |
| 251 message_center::NotifierId(), | 258 DummyNotifierId(), |
| 252 message_center::RichNotificationData(), | 259 message_center::RichNotificationData(), |
| 253 NULL)); | 260 NULL)); |
| 254 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; | 261 NSImage* image = [NSImage imageNamed:NSImageNameFolder]; |
| 255 notification->set_image(gfx::Image([image retain])); | 262 notification->set_image(gfx::Image([image retain])); |
| 256 | 263 |
| 257 MockMessageCenter message_center; | 264 MockMessageCenter message_center; |
| 258 | 265 |
| 259 base::scoped_nsobject<MCNotificationController> controller( | 266 base::scoped_nsobject<MCNotificationController> controller( |
| 260 [[MCNotificationController alloc] initWithNotification:notification.get() | 267 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 261 messageCenter:&message_center]); | 268 messageCenter:&message_center]); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 283 optional.context_message = UTF8ToUTF16("Context Message"); | 290 optional.context_message = UTF8ToUTF16("Context Message"); |
| 284 | 291 |
| 285 scoped_ptr<message_center::Notification> notification( | 292 scoped_ptr<message_center::Notification> notification( |
| 286 new message_center::Notification( | 293 new message_center::Notification( |
| 287 message_center::NOTIFICATION_TYPE_BASE_FORMAT, | 294 message_center::NOTIFICATION_TYPE_BASE_FORMAT, |
| 288 "an_id", | 295 "an_id", |
| 289 UTF8ToUTF16("Notification Title"), | 296 UTF8ToUTF16("Notification Title"), |
| 290 UTF8ToUTF16("Notification Message - should be hidden"), | 297 UTF8ToUTF16("Notification Message - should be hidden"), |
| 291 gfx::Image(), | 298 gfx::Image(), |
| 292 string16(), | 299 string16(), |
| 293 message_center::NotifierId(), | 300 DummyNotifierId(), |
| 294 optional, | 301 optional, |
| 295 NULL)); | 302 NULL)); |
| 296 | 303 |
| 297 MockMessageCenter message_center; | 304 MockMessageCenter message_center; |
| 298 base::scoped_nsobject<MCNotificationController> controller( | 305 base::scoped_nsobject<MCNotificationController> controller( |
| 299 [[MCNotificationController alloc] initWithNotification:notification.get() | 306 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 300 messageCenter:&message_center]); | 307 messageCenter:&message_center]); |
| 301 [controller view]; | 308 [controller view]; |
| 302 | 309 |
| 303 EXPECT_FALSE([[controller titleView] isHidden]); | 310 EXPECT_FALSE([[controller titleView] isHidden]); |
| 304 EXPECT_TRUE([[controller messageView] isHidden]); | 311 EXPECT_TRUE([[controller messageView] isHidden]); |
| 305 EXPECT_FALSE([[controller contextMessageView] isHidden]); | 312 EXPECT_FALSE([[controller contextMessageView] isHidden]); |
| 306 | 313 |
| 307 EXPECT_EQ(3u, [[[controller listView] subviews] count]); | 314 EXPECT_EQ(3u, [[[controller listView] subviews] count]); |
| 308 EXPECT_LT(NSMaxY([[controller listView] frame]), | 315 EXPECT_LT(NSMaxY([[controller listView] frame]), |
| 309 NSMinY([[controller titleView] frame])); | 316 NSMinY([[controller titleView] frame])); |
| 310 } | 317 } |
| 318 |
| 319 } // namespace message_center |
| OLD | NEW |