#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "ui/base/cocoa/hover_image_button.h"
-#import "ui/base/test/ui_cocoa_test_helper.h"
+#import "ui/gfx/test/ui_cocoa_test_helper.h"
#include "ui/message_center/fake_message_center.h"
#include "ui/message_center/message_center_style.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_types.h"
+using base::ASCIIToUTF16;
+using base::UTF8ToUTF16;
+
namespace {
class MockMessageCenter : public message_center::FakeMessageCenter {
DISALLOW_COPY_AND_ASSIGN(MockMessageCenter);
};
-}
+} // namespace
@implementation MCNotificationController (TestingInterface)
- (NSButton*)closeButton {
return closeButton_.get();
}
+- (NSImageView*)smallImageView {
+ return smallImage_.get();
+}
+
- (NSButton*)secondButton {
// The buttons are in Cocoa-y-order, so the 2nd button is first.
NSView* view = [[bottomView_ subviews] objectAtIndex:0];
}
@end
+namespace message_center {
+
class NotificationControllerTest : public ui::CocoaTest {
public:
NSImage* TestIcon() {
return [NSImage imageNamed:NSImageNameUser];
}
+
+ protected:
+ message_center::NotifierId DummyNotifierId() {
+ return message_center::NotifierId();
+ }
};
TEST_F(NotificationControllerTest, BasicLayout) {
ASCIIToUTF16("Added to circles"),
ASCIIToUTF16("Jonathan and 5 others"),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
message_center::RichNotificationData(),
NULL));
- notification->set_icon(gfx::Image([TestIcon() retain]));
+ gfx::Image testIcon([TestIcon() retain]);
+ notification->set_icon(testIcon);
+ notification->set_small_image(testIcon);
base::scoped_nsobject<MCNotificationController> controller(
[[MCNotificationController alloc] initWithNotification:notification.get()
[controller view];
EXPECT_EQ(TestIcon(), [[controller iconView] image]);
+ EXPECT_EQ(TestIcon(), [[controller smallImageView] image]);
EXPECT_EQ(base::SysNSStringToUTF16([[controller titleView] string]),
notification->title());
EXPECT_EQ(base::SysNSStringToUTF16([[controller messageView] string]),
"notification. Are you really going to read this "
"entire thing?"),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
message_center::RichNotificationData(),
NULL));
base::scoped_nsobject<MCNotificationController> controller(
new message_center::Notification(
message_center::NOTIFICATION_TYPE_SIMPLE,
"an_id",
- string16(),
- string16(),
+ base::string16(),
+ base::string16(),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
message_center::RichNotificationData(),
NULL));
MockMessageCenter message_center;
ASCIIToUTF16("This message isn't too long and should fit in the"
"default bounds."),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
message_center::RichNotificationData(),
NULL));
base::scoped_nsobject<MCNotificationController> controller(
EXPECT_EQ(NSHeight([[controller view] frame]),
message_center::kNotificationIconSize);
EXPECT_FALSE([[controller iconView] image]);
+ EXPECT_FALSE([[controller smallImageView] image]);
// Update the icon.
- notification->set_icon(gfx::Image([TestIcon() retain]));
+ gfx::Image testIcon([TestIcon() retain]);
+ notification->set_icon(testIcon);
+ notification->set_small_image(testIcon);
[controller updateNotification:notification.get()];
EXPECT_EQ(TestIcon(), [[controller iconView] image]);
+ EXPECT_EQ(TestIcon(), [[controller smallImageView] image]);
EXPECT_EQ(NSHeight([[controller view] frame]),
message_center::kNotificationIconSize);
}
new message_center::Notification(
message_center::NOTIFICATION_TYPE_BASE_FORMAT,
"an_id",
- string16(),
- string16(),
+ base::string16(),
+ base::string16(),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
optional,
NULL));
MockMessageCenter message_center;
new message_center::Notification(
message_center::NOTIFICATION_TYPE_BASE_FORMAT,
"an_id",
- string16(),
- string16(),
+ base::string16(),
+ base::string16(),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
message_center::RichNotificationData(),
NULL));
NSImage* image = [NSImage imageNamed:NSImageNameFolder];
[controller view];
ASSERT_EQ(1u, [[controller bottomSubviews] count]);
- ASSERT_TRUE([[[controller bottomSubviews] lastObject]
+ ASSERT_TRUE([[[[controller bottomSubviews] lastObject] contentView]
isKindOfClass:[NSImageView class]]);
- EXPECT_EQ(image, [[[controller bottomSubviews] lastObject] image]);
+ EXPECT_EQ(image,
+ [[[[controller bottomSubviews] lastObject] contentView] image]);
}
TEST_F(NotificationControllerTest, List) {
UTF8ToUTF16("Notification Title"),
UTF8ToUTF16("Notification Message - should be hidden"),
gfx::Image(),
- string16(),
- message_center::NotifierId(),
+ base::string16(),
+ DummyNotifierId(),
optional,
NULL));
EXPECT_LT(NSMaxY([[controller listView] frame]),
NSMinY([[controller titleView] frame]));
}
+
+} // namespace message_center