Index: ui/message_center/views/notification_view_unittest.cc |
diff --git a/ui/message_center/views/notification_view_unittest.cc b/ui/message_center/views/notification_view_unittest.cc |
index 88686283f8c2809a41621653b04fc957379066d1..0ca8e0a389044cbd6773de4a8132d47ac596ec51 100644 |
--- a/ui/message_center/views/notification_view_unittest.cc |
+++ b/ui/message_center/views/notification_view_unittest.cc |
@@ -10,68 +10,169 @@ |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/gfx/image/image.h" |
#include "ui/message_center/notification.h" |
+#include "ui/message_center/notification_list.h" |
+#include "ui/message_center/notification_types.h" |
+#include "ui/message_center/views/message_center_controller.h" |
namespace message_center { |
/* Test fixture ***************************************************************/ |
-typedef testing::Test NotificationViewTest; |
+class NotificationViewTest : public testing::Test, |
+ public MessageCenterController { |
+ public: |
+ NotificationViewTest(); |
+ virtual ~NotificationViewTest(); |
-TEST_F(NotificationViewTest, TestLineLimits) { |
- message_center::RichNotificationData data; |
- std::string id("id"); |
- NotifierId notifier_id(NotifierId::APPLICATION, "notifier"); |
- scoped_ptr<Notification> notification( |
- new Notification(NOTIFICATION_TYPE_BASE_FORMAT, |
- id, |
- base::UTF8ToUTF16("test title"), |
- base::UTF8ToUTF16("test message"), |
- gfx::Image(), |
- base::string16() /* display_source */, |
- notifier_id, |
- data, |
- NULL /* delegate */)); |
- scoped_ptr<NotificationView> view(new NotificationView(NULL, *notification)); |
- |
- EXPECT_EQ(5, view->GetMessageLineLimit(0, 360)); |
- EXPECT_EQ(5, view->GetMessageLineLimit(1, 360)); |
- EXPECT_EQ(3, view->GetMessageLineLimit(2, 360)); |
+ virtual void SetUp() OVERRIDE; |
+ virtual void TearDown() OVERRIDE; |
+ |
+ NotificationView* notification_view() { return notification_view_.get(); } |
+ Notification* notification() { return notification_.get(); } |
+ RichNotificationData* data() { return data_.get(); } |
+ |
+ // Overridden from MessageCenterController: |
+ virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE; |
+ virtual void RemoveNotification(const std::string& notification_id, |
+ bool by_user) OVERRIDE; |
+ virtual scoped_ptr<ui::MenuModel> CreateMenuModel( |
+ const NotifierId& notifier_id, |
+ const base::string16& display_source) OVERRIDE; |
+ virtual bool HasClickedListener(const std::string& notification_id) OVERRIDE; |
+ virtual void ClickOnNotificationButton(const std::string& notification_id, |
+ int button_index) OVERRIDE; |
+ |
+ protected: |
+ const gfx::Image CreateTestImage(int width, int height) { |
+ return gfx::Image::CreateFrom1xBitmap(CreateBitmap(width, height)); |
+ } |
+ |
+ const SkBitmap CreateBitmap(int width, int height) { |
+ SkBitmap bitmap; |
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
+ bitmap.allocPixels(); |
+ bitmap.eraseRGB(0, 255, 0); |
+ return bitmap; |
+ } |
+ |
+ private: |
+ scoped_ptr<RichNotificationData> data_; |
+ scoped_ptr<Notification> notification_; |
+ scoped_ptr<NotificationView> notification_view_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); |
+}; |
+ |
+NotificationViewTest::NotificationViewTest() { |
+} |
+NotificationViewTest::~NotificationViewTest() { |
+} |
+ |
+void NotificationViewTest::SetUp() { |
+ // Create a dummy notification. |
SkBitmap bitmap; |
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
- bitmap.allocPixels(); |
- bitmap.eraseColor(SK_ColorGREEN); |
- data.image = gfx::Image::CreateFrom1xBitmap(bitmap); |
- notification.reset(new Notification(NOTIFICATION_TYPE_BASE_FORMAT, |
- id, |
- base::UTF8ToUTF16("test title"), |
- base::UTF8ToUTF16("test message"), |
- gfx::Image(), |
- base::string16() /* display_source */, |
- notifier_id, |
- data, |
- NULL /* delegate */)); |
- view.reset(new NotificationView(NULL, *notification)); |
- |
- EXPECT_EQ(2, view->GetMessageLineLimit(0, 360)); |
- EXPECT_EQ(2, view->GetMessageLineLimit(1, 360)); |
- EXPECT_EQ(1, view->GetMessageLineLimit(2, 360)); |
- |
- data.context_message = base::UTF8ToUTF16("foo"); |
- notification.reset(new Notification(NOTIFICATION_TYPE_BASE_FORMAT, |
- id, |
- base::UTF8ToUTF16("test title"), |
- base::UTF8ToUTF16("test message"), |
- gfx::Image(), |
- base::string16() /* display_source */, |
- notifier_id, |
- data, |
- NULL /* delegate */)); |
- view.reset(new NotificationView(NULL, *notification)); |
- |
- EXPECT_EQ(1, view->GetMessageLineLimit(0, 360)); |
- EXPECT_EQ(1, view->GetMessageLineLimit(1, 360)); |
- EXPECT_EQ(0, view->GetMessageLineLimit(2, 360)); |
+ data_.reset(new RichNotificationData()); |
+ notification_.reset( |
+ new Notification(NOTIFICATION_TYPE_BASE_FORMAT, |
+ std::string("notification id"), |
+ base::UTF8ToUTF16("title"), |
+ base::UTF8ToUTF16("message"), |
+ CreateTestImage(80, 80), |
+ base::UTF8ToUTF16("display source"), |
+ NotifierId(NotifierId::APPLICATION, "extension_id"), |
+ *data_, |
+ NULL)); |
+ notification_->set_small_image(CreateTestImage(16, 16)); |
+ notification_->set_image(CreateTestImage(320, 240)); |
+ |
+ // Then create a new NotificationView with that single notification. |
+ notification_view_.reset( |
+ NotificationView::Create(this, *notification_, true)); |
+} |
+ |
+void NotificationViewTest::TearDown() { |
+ notification_view_.reset(); |
+} |
+ |
+void NotificationViewTest::ClickOnNotification( |
+ const std::string& notification_id) { |
+ // For this test, this method should not be invoked. |
+ NOTREACHED(); |
+} |
+ |
+void NotificationViewTest::RemoveNotification( |
+ const std::string& notification_id, |
+ bool by_user) { |
+ // For this test, this method should not be invoked. |
+ NOTREACHED(); |
+} |
+ |
+scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel( |
+ const NotifierId& notifier_id, |
+ const base::string16& display_source) { |
+ // For this test, this method should not be invoked. |
+ NOTREACHED(); |
+ return scoped_ptr<ui::MenuModel>(); |
+} |
+ |
+bool NotificationViewTest::HasClickedListener( |
+ const std::string& notification_id) { |
+ return true; |
+} |
+ |
+void NotificationViewTest::ClickOnNotificationButton( |
+ const std::string& notification_id, |
+ int button_index) { |
+ // For this test, this method should not be invoked. |
+ NOTREACHED(); |
+} |
+ |
+/* Unit tests *****************************************************************/ |
+ |
+TEST_F(NotificationViewTest, CreateOrUpdateTest) { |
+ EXPECT_TRUE(NULL != notification_view()->title_view_); |
+ EXPECT_TRUE(NULL != notification_view()->message_view_); |
+ EXPECT_TRUE(NULL != notification_view()->icon_view_); |
+ EXPECT_TRUE(NULL != notification_view()->image_view_); |
+ |
+ notification()->set_image(gfx::Image()); |
+ notification()->set_title(base::ASCIIToUTF16("")); |
+ notification()->set_message(base::ASCIIToUTF16("")); |
+ notification()->set_icon(gfx::Image()); |
+ |
+ notification_view()->CreateOrUpdateViews(*notification()); |
+ EXPECT_TRUE(NULL == notification_view()->title_view_); |
+ EXPECT_TRUE(NULL == notification_view()->message_view_); |
+ EXPECT_TRUE(NULL == notification_view()->image_view_); |
+ // We still expect an icon view for all layouts. |
+ EXPECT_TRUE(NULL != notification_view()->icon_view_); |
+} |
+ |
+TEST_F(NotificationViewTest, TestLineLimits) { |
+ notification()->set_image(CreateTestImage(0, 0)); |
+ notification()->set_context_message(base::ASCIIToUTF16("")); |
+ notification_view()->CreateOrUpdateViews(*notification()); |
+ |
+ EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360)); |
+ EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360)); |
+ EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360)); |
+ |
+ notification()->set_image(CreateTestImage(2, 2)); |
+ notification_view()->CreateOrUpdateViews(*notification()); |
+ |
+ EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360)); |
+ EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360)); |
+ EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360)); |
+ |
+ notification()->set_context_message(base::UTF8ToUTF16("foo")); |
+ notification_view()->CreateOrUpdateViews(*notification()); |
+ |
+ EXPECT_TRUE(notification_view()->context_message_view_ != NULL); |
+ |
+ EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360)); |
+ EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360)); |
+ EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360)); |
} |
} // namespace message_center |