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