Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: ui/message_center/views/notification_view_unittest.cc

Issue 271773002: Retain popup bubble mouse status even through updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/message_center/views/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/image/image.h" 11 #include "ui/gfx/image/image.h"
12 #include "ui/message_center/notification.h" 12 #include "ui/message_center/notification.h"
13 #include "ui/message_center/notification_list.h"
14 #include "ui/message_center/notification_types.h"
15 #include "ui/message_center/views/message_center_controller.h"
13 16
14 namespace message_center { 17 namespace message_center {
15 18
16 /* Test fixture ***************************************************************/ 19 /* Test fixture ***************************************************************/
17 20
18 typedef testing::Test NotificationViewTest; 21 class NotificationViewTest : public testing::Test,
22 public MessageCenterController {
23 public:
24 NotificationViewTest();
25 virtual ~NotificationViewTest();
26
27 virtual void SetUp() OVERRIDE;
28 virtual void TearDown() OVERRIDE;
29
30 NotificationView* notification_view() { return notification_view_.get(); }
31 Notification* notification() { return notification_.get(); }
32 RichNotificationData* data() { return data_.get(); }
33
34 // Overridden from MessageCenterController:
35 virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE;
36 virtual void RemoveNotification(const std::string& notification_id,
37 bool by_user) OVERRIDE;
38 virtual scoped_ptr<ui::MenuModel> CreateMenuModel(
39 const NotifierId& notifier_id,
40 const base::string16& display_source) OVERRIDE;
41 virtual bool HasClickedListener(const std::string& notification_id) OVERRIDE;
42 virtual void ClickOnNotificationButton(const std::string& notification_id,
43 int button_index) OVERRIDE;
44
45 protected:
46 const gfx::Image CreateTestImage(int width, int height) {
47 return gfx::Image::CreateFrom1xBitmap(CreateBitmap(width, height));
48 }
49
50 const SkBitmap CreateBitmap(int width, int height) {
51 SkBitmap bitmap;
52 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
53 bitmap.allocPixels();
54 bitmap.eraseRGB(0, 255, 0);
55 return bitmap;
56 }
57
58 private:
59 scoped_ptr<RichNotificationData> data_;
60 scoped_ptr<Notification> notification_;
61 scoped_ptr<NotificationView> notification_view_;
62
63 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest);
64 };
65
66 NotificationViewTest::NotificationViewTest() {
67 }
68
69 NotificationViewTest::~NotificationViewTest() {
70 }
71
72 void NotificationViewTest::SetUp() {
73 // Create a dummy notification.
74 SkBitmap bitmap;
75 data_.reset(new RichNotificationData());
76 notification_.reset(
77 new Notification(NOTIFICATION_TYPE_BASE_FORMAT,
78 std::string("notification id"),
79 base::UTF8ToUTF16("title"),
80 base::UTF8ToUTF16("message"),
81 CreateTestImage(80, 80),
82 base::UTF8ToUTF16("display source"),
83 NotifierId(NotifierId::APPLICATION, "extension_id"),
84 *data_,
85 NULL));
86 notification_->set_small_image(CreateTestImage(16, 16));
87 notification_->set_image(CreateTestImage(320, 240));
88
89 // Then create a new NotificationView with that single notification.
90 notification_view_.reset(
91 NotificationView::Create(this, *notification_, true));
92 }
93
94 void NotificationViewTest::TearDown() {
95 notification_view_.reset();
96 }
97
98 void NotificationViewTest::ClickOnNotification(
99 const std::string& notification_id) {
100 // For this test, this method should not be invoked.
101 NOTREACHED();
102 }
103
104 void NotificationViewTest::RemoveNotification(
105 const std::string& notification_id,
106 bool by_user) {
107 // For this test, this method should not be invoked.
108 NOTREACHED();
109 }
110
111 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel(
112 const NotifierId& notifier_id,
113 const base::string16& display_source) {
114 // For this test, this method should not be invoked.
115 NOTREACHED();
116 return scoped_ptr<ui::MenuModel>();
117 }
118
119 bool NotificationViewTest::HasClickedListener(
120 const std::string& notification_id) {
121 return true;
122 }
123
124 void NotificationViewTest::ClickOnNotificationButton(
125 const std::string& notification_id,
126 int button_index) {
127 // For this test, this method should not be invoked.
128 NOTREACHED();
129 }
130
131 /* Unit tests *****************************************************************/
132
133 TEST_F(NotificationViewTest, CreateOrUpdateTest) {
134 EXPECT_TRUE(NULL != notification_view()->title_view_);
135 EXPECT_TRUE(NULL != notification_view()->message_view_);
136 EXPECT_TRUE(NULL != notification_view()->icon_view_);
137 EXPECT_TRUE(NULL != notification_view()->image_view_);
138
139 notification()->set_image(gfx::Image());
140 notification()->set_title(base::ASCIIToUTF16(""));
141 notification()->set_message(base::ASCIIToUTF16(""));
142 notification()->set_icon(gfx::Image());
143
144 notification_view()->CreateOrUpdateViews(*notification());
145 EXPECT_TRUE(NULL == notification_view()->title_view_);
146 EXPECT_TRUE(NULL == notification_view()->message_view_);
147 EXPECT_TRUE(NULL == notification_view()->image_view_);
148 // We still expect an icon view for all layouts.
149 EXPECT_TRUE(NULL != notification_view()->icon_view_);
150 }
19 151
20 TEST_F(NotificationViewTest, TestLineLimits) { 152 TEST_F(NotificationViewTest, TestLineLimits) {
21 message_center::RichNotificationData data; 153 notification()->set_image(CreateTestImage(0, 0));
22 std::string id("id"); 154 notification()->set_context_message(base::ASCIIToUTF16(""));
23 NotifierId notifier_id(NotifierId::APPLICATION, "notifier"); 155 notification_view()->CreateOrUpdateViews(*notification());
24 scoped_ptr<Notification> notification(
25 new Notification(NOTIFICATION_TYPE_BASE_FORMAT,
26 id,
27 base::UTF8ToUTF16("test title"),
28 base::UTF8ToUTF16("test message"),
29 gfx::Image(),
30 base::string16() /* display_source */,
31 notifier_id,
32 data,
33 NULL /* delegate */));
34 scoped_ptr<NotificationView> view(new NotificationView(NULL, *notification));
35 156
36 EXPECT_EQ(5, view->GetMessageLineLimit(0, 360)); 157 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(0, 360));
37 EXPECT_EQ(5, view->GetMessageLineLimit(1, 360)); 158 EXPECT_EQ(5, notification_view()->GetMessageLineLimit(1, 360));
38 EXPECT_EQ(3, view->GetMessageLineLimit(2, 360)); 159 EXPECT_EQ(3, notification_view()->GetMessageLineLimit(2, 360));
39 160
40 SkBitmap bitmap; 161 notification()->set_image(CreateTestImage(2, 2));
41 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); 162 notification_view()->CreateOrUpdateViews(*notification());
42 bitmap.allocPixels();
43 bitmap.eraseColor(SK_ColorGREEN);
44 data.image = gfx::Image::CreateFrom1xBitmap(bitmap);
45 notification.reset(new Notification(NOTIFICATION_TYPE_BASE_FORMAT,
46 id,
47 base::UTF8ToUTF16("test title"),
48 base::UTF8ToUTF16("test message"),
49 gfx::Image(),
50 base::string16() /* display_source */,
51 notifier_id,
52 data,
53 NULL /* delegate */));
54 view.reset(new NotificationView(NULL, *notification));
55 163
56 EXPECT_EQ(2, view->GetMessageLineLimit(0, 360)); 164 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(0, 360));
57 EXPECT_EQ(2, view->GetMessageLineLimit(1, 360)); 165 EXPECT_EQ(2, notification_view()->GetMessageLineLimit(1, 360));
58 EXPECT_EQ(1, view->GetMessageLineLimit(2, 360)); 166 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(2, 360));
59 167
60 data.context_message = base::UTF8ToUTF16("foo"); 168 notification()->set_context_message(base::UTF8ToUTF16("foo"));
61 notification.reset(new Notification(NOTIFICATION_TYPE_BASE_FORMAT, 169 notification_view()->CreateOrUpdateViews(*notification());
62 id,
63 base::UTF8ToUTF16("test title"),
64 base::UTF8ToUTF16("test message"),
65 gfx::Image(),
66 base::string16() /* display_source */,
67 notifier_id,
68 data,
69 NULL /* delegate */));
70 view.reset(new NotificationView(NULL, *notification));
71 170
72 EXPECT_EQ(1, view->GetMessageLineLimit(0, 360)); 171 EXPECT_TRUE(notification_view()->context_message_view_ != NULL);
73 EXPECT_EQ(1, view->GetMessageLineLimit(1, 360)); 172
74 EXPECT_EQ(0, view->GetMessageLineLimit(2, 360)); 173 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(0, 360));
174 EXPECT_EQ(1, notification_view()->GetMessageLineLimit(1, 360));
175 EXPECT_EQ(0, notification_view()->GetMessageLineLimit(2, 360));
75 } 176 }
76 177
77 } // namespace message_center 178 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view.cc ('k') | ui/message_center/views/toast_contents_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698