| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 58 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 @implementation MCNotificationController (TestingInterface) | 63 @implementation MCNotificationController (TestingInterface) |
| 64 - (NSButton*)closeButton { | 64 - (NSButton*)closeButton { |
| 65 return closeButton_.get(); | 65 return closeButton_.get(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 - (NSImageView*)smallImageView { |
| 69 return smallImage_.get(); |
| 70 } |
| 71 |
| 68 - (NSButton*)secondButton { | 72 - (NSButton*)secondButton { |
| 69 // The buttons are in Cocoa-y-order, so the 2nd button is first. | 73 // The buttons are in Cocoa-y-order, so the 2nd button is first. |
| 70 NSView* view = [[bottomView_ subviews] objectAtIndex:0]; | 74 NSView* view = [[bottomView_ subviews] objectAtIndex:0]; |
| 71 return base::mac::ObjCCastStrict<NSButton>(view); | 75 return base::mac::ObjCCastStrict<NSButton>(view); |
| 72 } | 76 } |
| 73 | 77 |
| 74 - (NSArray*)bottomSubviews { | 78 - (NSArray*)bottomSubviews { |
| 75 return [bottomView_ subviews]; | 79 return [bottomView_ subviews]; |
| 76 } | 80 } |
| 77 | 81 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 new message_center::Notification( | 119 new message_center::Notification( |
| 116 message_center::NOTIFICATION_TYPE_SIMPLE, | 120 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 117 "", | 121 "", |
| 118 ASCIIToUTF16("Added to circles"), | 122 ASCIIToUTF16("Added to circles"), |
| 119 ASCIIToUTF16("Jonathan and 5 others"), | 123 ASCIIToUTF16("Jonathan and 5 others"), |
| 120 gfx::Image(), | 124 gfx::Image(), |
| 121 base::string16(), | 125 base::string16(), |
| 122 DummyNotifierId(), | 126 DummyNotifierId(), |
| 123 message_center::RichNotificationData(), | 127 message_center::RichNotificationData(), |
| 124 NULL)); | 128 NULL)); |
| 125 notification->set_icon(gfx::Image([TestIcon() retain])); | 129 gfx::Image testIcon([TestIcon() retain]); |
| 130 notification->set_icon(testIcon); |
| 131 notification->set_small_image(testIcon); |
| 126 | 132 |
| 127 base::scoped_nsobject<MCNotificationController> controller( | 133 base::scoped_nsobject<MCNotificationController> controller( |
| 128 [[MCNotificationController alloc] initWithNotification:notification.get() | 134 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 129 messageCenter:NULL]); | 135 messageCenter:NULL]); |
| 130 [controller view]; | 136 [controller view]; |
| 131 | 137 |
| 132 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 138 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
| 139 EXPECT_EQ(TestIcon(), [[controller smallImageView] image]); |
| 133 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]), | 140 EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]), |
| 134 notification->title()); | 141 notification->title()); |
| 135 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]), | 142 EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]), |
| 136 notification->message()); | 143 notification->message()); |
| 137 EXPECT_EQ(controller.get(), [[controller closeButton] target]); | 144 EXPECT_EQ(controller.get(), [[controller closeButton] target]); |
| 138 } | 145 } |
| 139 | 146 |
| 140 TEST_F(NotificationControllerTest, OverflowText) { | 147 TEST_F(NotificationControllerTest, OverflowText) { |
| 141 scoped_ptr<message_center::Notification> notification( | 148 scoped_ptr<message_center::Notification> notification( |
| 142 new message_center::Notification( | 149 new message_center::Notification( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 NULL)); | 209 NULL)); |
| 203 base::scoped_nsobject<MCNotificationController> controller( | 210 base::scoped_nsobject<MCNotificationController> controller( |
| 204 [[MCNotificationController alloc] initWithNotification:notification.get() | 211 [[MCNotificationController alloc] initWithNotification:notification.get() |
| 205 messageCenter:NULL]); | 212 messageCenter:NULL]); |
| 206 | 213 |
| 207 // Set up the default layout. | 214 // Set up the default layout. |
| 208 [controller view]; | 215 [controller view]; |
| 209 EXPECT_EQ(NSHeight([[controller view] frame]), | 216 EXPECT_EQ(NSHeight([[controller view] frame]), |
| 210 message_center::kNotificationIconSize); | 217 message_center::kNotificationIconSize); |
| 211 EXPECT_FALSE([[controller iconView] image]); | 218 EXPECT_FALSE([[controller iconView] image]); |
| 219 EXPECT_FALSE([[controller smallImageView] image]); |
| 212 | 220 |
| 213 // Update the icon. | 221 // Update the icon. |
| 214 notification->set_icon(gfx::Image([TestIcon() retain])); | 222 gfx::Image testIcon([TestIcon() retain]); |
| 223 notification->set_icon(testIcon); |
| 224 notification->set_small_image(testIcon); |
| 215 [controller updateNotification:notification.get()]; | 225 [controller updateNotification:notification.get()]; |
| 216 EXPECT_EQ(TestIcon(), [[controller iconView] image]); | 226 EXPECT_EQ(TestIcon(), [[controller iconView] image]); |
| 227 EXPECT_EQ(TestIcon(), [[controller smallImageView] image]); |
| 217 EXPECT_EQ(NSHeight([[controller view] frame]), | 228 EXPECT_EQ(NSHeight([[controller view] frame]), |
| 218 message_center::kNotificationIconSize); | 229 message_center::kNotificationIconSize); |
| 219 } | 230 } |
| 220 | 231 |
| 221 TEST_F(NotificationControllerTest, Buttons) { | 232 TEST_F(NotificationControllerTest, Buttons) { |
| 222 message_center::RichNotificationData optional; | 233 message_center::RichNotificationData optional; |
| 223 message_center::ButtonInfo button1(UTF8ToUTF16("button1")); | 234 message_center::ButtonInfo button1(UTF8ToUTF16("button1")); |
| 224 optional.buttons.push_back(button1); | 235 optional.buttons.push_back(button1); |
| 225 message_center::ButtonInfo button2(UTF8ToUTF16("button2")); | 236 message_center::ButtonInfo button2(UTF8ToUTF16("button2")); |
| 226 optional.buttons.push_back(button2); | 237 optional.buttons.push_back(button2); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 EXPECT_FALSE([[controller titleView] isHidden]); | 325 EXPECT_FALSE([[controller titleView] isHidden]); |
| 315 EXPECT_TRUE([[controller messageView] isHidden]); | 326 EXPECT_TRUE([[controller messageView] isHidden]); |
| 316 EXPECT_FALSE([[controller contextMessageView] isHidden]); | 327 EXPECT_FALSE([[controller contextMessageView] isHidden]); |
| 317 | 328 |
| 318 EXPECT_EQ(3u, [[[controller listView] subviews] count]); | 329 EXPECT_EQ(3u, [[[controller listView] subviews] count]); |
| 319 EXPECT_LT(NSMaxY([[controller listView] frame]), | 330 EXPECT_LT(NSMaxY([[controller listView] frame]), |
| 320 NSMinY([[controller titleView] frame])); | 331 NSMinY([[controller titleView] frame])); |
| 321 } | 332 } |
| 322 | 333 |
| 323 } // namespace message_center | 334 } // namespace message_center |
| OLD | NEW |