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

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

Issue 1645843003: Implement Non-Closable Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed the comments Created 4 years, 10 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
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/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/message_center/views/constants.h" 24 #include "ui/message_center/views/constants.h"
25 #include "ui/message_center/views/message_center_controller.h" 25 #include "ui/message_center/views/message_center_controller.h"
26 #include "ui/message_center/views/notification_button.h" 26 #include "ui/message_center/views/notification_button.h"
27 #include "ui/message_center/views/proportional_image_view.h" 27 #include "ui/message_center/views/proportional_image_view.h"
28 #include "ui/views/controls/button/image_button.h" 28 #include "ui/views/controls/button/image_button.h"
29 #include "ui/views/layout/fill_layout.h" 29 #include "ui/views/layout/fill_layout.h"
30 #include "ui/views/test/views_test_base.h" 30 #include "ui/views/test/views_test_base.h"
31 #include "ui/views/test/widget_test.h" 31 #include "ui/views/test/widget_test.h"
32 #include "ui/views/widget/widget_delegate.h" 32 #include "ui/views/widget/widget_delegate.h"
33 33
34 namespace {
35
36 scoped_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) {
37 ui::GestureEventDetails detail(type);
38 scoped_ptr<ui::GestureEvent> event(
39 new ui::GestureEvent(0, 0, 0, base::TimeDelta(), detail));
40 return event;
41 }
42
43 scoped_ptr<ui::GestureEvent> GenerateGestureVerticalScrollUpdateEvent(int dx) {
44 ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0);
45 scoped_ptr<ui::GestureEvent> event(
46 new ui::GestureEvent(0, 0, 0, base::TimeDelta(), detail));
47 return event;
48 }
49
50 } // anonymouse namespace
51
34 namespace message_center { 52 namespace message_center {
35 53
36 // A test delegate used for tests that deal with the notification settings 54 // A test delegate used for tests that deal with the notification settings
37 // button. 55 // button.
38 class NotificationSettingsDelegate : public NotificationDelegate { 56 class NotificationSettingsDelegate : public NotificationDelegate {
39 bool ShouldDisplaySettingsButton() override { return true; } 57 bool ShouldDisplaySettingsButton() override { return true; }
40 58
41 private: 59 private:
42 ~NotificationSettingsDelegate() override {} 60 ~NotificationSettingsDelegate() override {}
43 }; 61 };
44 62
45 /* Test fixture ***************************************************************/ 63 /* Test fixture ***************************************************************/
46 64
47 class NotificationViewTest : public views::ViewsTestBase, 65 class NotificationViewTest : public views::ViewsTestBase,
48 public MessageCenterController { 66 public MessageCenterController {
49 public: 67 public:
50 NotificationViewTest(); 68 NotificationViewTest();
51 ~NotificationViewTest() override; 69 ~NotificationViewTest() override;
52 70
53 void SetUp() override; 71 void SetUp() override;
54 void TearDown() override; 72 void TearDown() override;
55 73
56 views::Widget* widget() { return notification_view_->GetWidget(); } 74 views::Widget* widget() { return notification_view_->GetWidget(); }
57 NotificationView* notification_view() { return notification_view_.get(); } 75 NotificationView* notification_view() const {
76 return notification_view_.get();
77 }
58 Notification* notification() { return notification_.get(); } 78 Notification* notification() { return notification_.get(); }
59 RichNotificationData* data() { return data_.get(); } 79 RichNotificationData* data() { return data_.get(); }
60 80
61 // Overridden from MessageCenterController: 81 // Overridden from MessageCenterController:
62 void ClickOnNotification(const std::string& notification_id) override; 82 void ClickOnNotification(const std::string& notification_id) override;
63 void RemoveNotification(const std::string& notification_id, 83 void RemoveNotification(const std::string& notification_id,
64 bool by_user) override; 84 bool by_user) override;
65 scoped_ptr<ui::MenuModel> CreateMenuModel( 85 scoped_ptr<ui::MenuModel> CreateMenuModel(
66 const NotifierId& notifier_id, 86 const NotifierId& notifier_id,
67 const base::string16& display_source) override; 87 const base::string16& display_source) override;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 168
149 gfx::Point current_point = (*current)->bounds().origin(); 169 gfx::Point current_point = (*current)->bounds().origin();
150 views::View::ConvertPointToTarget( 170 views::View::ConvertPointToTarget(
151 (*current), notification_view(), &current_point); 171 (*current), notification_view(), &current_point);
152 172
153 EXPECT_LT(last_point.y(), current_point.y()); 173 EXPECT_LT(last_point.y(), current_point.y());
154 last = current++; 174 last = current++;
155 } 175 }
156 } 176 }
157 177
178 views::ImageButton* GetCloseButton() {
179 return notification_view()->close_button_.get();
180 }
181
158 void UpdateNotificationViews() { 182 void UpdateNotificationViews() {
159 notification_view()->CreateOrUpdateViews(*notification()); 183 notification_view()->CreateOrUpdateViews(*notification());
160 notification_view()->Layout(); 184 notification_view()->Layout();
161 } 185 }
162 186
187 float GetNotificationScrollAmount() const {
188 return notification_view()->GetTransform().To2dTranslation().x();
189 }
190
191 bool IsRemoved(const std::string& notification_id) const {
192 return (removed_ids_.find(notification_id) != removed_ids_.end());
193 }
194
195 void RemoveNotificationView() { notification_view_.reset(); }
196
163 private: 197 private:
198 std::set<std::string> removed_ids_;
199
164 scoped_ptr<RichNotificationData> data_; 200 scoped_ptr<RichNotificationData> data_;
165 scoped_ptr<Notification> notification_; 201 scoped_ptr<Notification> notification_;
166 scoped_ptr<NotificationView> notification_view_; 202 scoped_ptr<NotificationView> notification_view_;
167 203
168 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); 204 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest);
169 }; 205 };
170 206
171 NotificationViewTest::NotificationViewTest() { 207 NotificationViewTest::NotificationViewTest() {
172 } 208 }
173 209
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 245
210 void NotificationViewTest::ClickOnNotification( 246 void NotificationViewTest::ClickOnNotification(
211 const std::string& notification_id) { 247 const std::string& notification_id) {
212 // For this test, this method should not be invoked. 248 // For this test, this method should not be invoked.
213 NOTREACHED(); 249 NOTREACHED();
214 } 250 }
215 251
216 void NotificationViewTest::RemoveNotification( 252 void NotificationViewTest::RemoveNotification(
217 const std::string& notification_id, 253 const std::string& notification_id,
218 bool by_user) { 254 bool by_user) {
219 // For this test, this method should not be invoked. 255 removed_ids_.insert(notification_id);
220 NOTREACHED();
221 } 256 }
222 257
223 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel( 258 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel(
224 const NotifierId& notifier_id, 259 const NotifierId& notifier_id,
225 const base::string16& display_source) { 260 const base::string16& display_source) {
226 // For this test, this method should not be invoked. 261 // For this test, this method should not be invoked.
227 NOTREACHED(); 262 NOTREACHED();
228 return nullptr; 263 return nullptr;
229 } 264 }
230 265
(...skipping 20 matching lines...) Expand all
251 TEST_F(NotificationViewTest, CreateOrUpdateTest) { 286 TEST_F(NotificationViewTest, CreateOrUpdateTest) {
252 EXPECT_TRUE(NULL != notification_view()->title_view_); 287 EXPECT_TRUE(NULL != notification_view()->title_view_);
253 EXPECT_TRUE(NULL != notification_view()->message_view_); 288 EXPECT_TRUE(NULL != notification_view()->message_view_);
254 EXPECT_TRUE(NULL != notification_view()->icon_view_); 289 EXPECT_TRUE(NULL != notification_view()->icon_view_);
255 EXPECT_TRUE(NULL != notification_view()->image_view_); 290 EXPECT_TRUE(NULL != notification_view()->image_view_);
256 291
257 notification()->set_image(gfx::Image()); 292 notification()->set_image(gfx::Image());
258 notification()->set_title(base::ASCIIToUTF16("")); 293 notification()->set_title(base::ASCIIToUTF16(""));
259 notification()->set_message(base::ASCIIToUTF16("")); 294 notification()->set_message(base::ASCIIToUTF16(""));
260 notification()->set_icon(gfx::Image()); 295 notification()->set_icon(gfx::Image());
296 notification()->set_icon(gfx::Image());
261 297
262 notification_view()->CreateOrUpdateViews(*notification()); 298 notification_view()->CreateOrUpdateViews(*notification());
263 EXPECT_TRUE(NULL == notification_view()->title_view_); 299 EXPECT_TRUE(NULL == notification_view()->title_view_);
264 EXPECT_TRUE(NULL == notification_view()->message_view_); 300 EXPECT_TRUE(NULL == notification_view()->message_view_);
265 EXPECT_TRUE(NULL == notification_view()->image_view_); 301 EXPECT_TRUE(NULL == notification_view()->image_view_);
266 EXPECT_TRUE(NULL == notification_view()->settings_button_view_); 302 EXPECT_TRUE(NULL == notification_view()->settings_button_view_);
267 // We still expect an icon view for all layouts. 303 // We still expect an icon view for all layouts.
268 EXPECT_TRUE(NULL != notification_view()->icon_view_); 304 EXPECT_TRUE(NULL != notification_view()->icon_view_);
269 } 305 }
270 306
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // some generic checking here. 647 // some generic checking here.
612 // The url has been elided (it starts with an ellipsis) 648 // The url has been elided (it starts with an ellipsis)
613 // The end of the domainsuffix is shown 649 // The end of the domainsuffix is shown
614 // the url piece is not shown 650 // the url piece is not shown
615 EXPECT_TRUE(base::UTF16ToUTF8(result).find( 651 EXPECT_TRUE(base::UTF16ToUTF8(result).find(
616 ".veryveryveyrylong.chromium.org") != std::string::npos); 652 ".veryveryveyrylong.chromium.org") != std::string::npos);
617 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0); 653 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0);
618 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos); 654 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
619 } 655 }
620 656
657 TEST_F(NotificationViewTest, SlideOut) {
658 views::SlideOutView::DisableAnimationsForTesting();
659
660 UpdateNotificationViews();
661 std::string notification_id = notification()->id();
662
663 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
664 auto event_scroll10 = GenerateGestureVerticalScrollUpdateEvent(-10);
665 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
666 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
667
668 notification_view()->OnGestureEvent(event_begin.get());
669 notification_view()->OnGestureEvent(event_scroll10.get());
670 EXPECT_FALSE(IsRemoved(notification_id));
671 EXPECT_EQ(-10.f, GetNotificationScrollAmount());
672 notification_view()->OnGestureEvent(event_end.get());
673 EXPECT_FALSE(IsRemoved(notification_id));
674 EXPECT_EQ(0.f, GetNotificationScrollAmount());
675
676 notification_view()->OnGestureEvent(event_begin.get());
677 notification_view()->OnGestureEvent(event_scroll500.get());
678 EXPECT_FALSE(IsRemoved(notification_id));
679 EXPECT_EQ(-500.f, GetNotificationScrollAmount());
680 notification_view()->OnGestureEvent(event_end.get());
681 EXPECT_TRUE(IsRemoved(notification_id));
682 }
683
684 TEST_F(NotificationViewTest, SlideOutNonClosable) {
685 views::SlideOutView::DisableAnimationsForTesting();
686
687 notification()->set_closable(false);
688 UpdateNotificationViews();
689 std::string notification_id = notification()->id();
690
691 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
692 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
693 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
694
695 notification_view()->OnGestureEvent(event_begin.get());
696 notification_view()->OnGestureEvent(event_scroll500.get());
697 EXPECT_FALSE(IsRemoved(notification_id));
698 EXPECT_LT(-500.f, GetNotificationScrollAmount());
699 notification_view()->OnGestureEvent(event_end.get());
700 EXPECT_FALSE(IsRemoved(notification_id));
701 }
702
703 TEST_F(NotificationViewTest, NonClosable) {
704 notification()->set_closable(false);
705
706 UpdateNotificationViews();
707 EXPECT_EQ(NULL, GetCloseButton());
708 }
709
621 } // namespace message_center 710 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698