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

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: 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() {
196 notification_view_.reset();
197 }
198
163 private: 199 private:
200 std::set<std::string> removed_ids_;
201
164 scoped_ptr<RichNotificationData> data_; 202 scoped_ptr<RichNotificationData> data_;
165 scoped_ptr<Notification> notification_; 203 scoped_ptr<Notification> notification_;
166 scoped_ptr<NotificationView> notification_view_; 204 scoped_ptr<NotificationView> notification_view_;
167 205
168 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest); 206 DISALLOW_COPY_AND_ASSIGN(NotificationViewTest);
169 }; 207 };
170 208
171 NotificationViewTest::NotificationViewTest() { 209 NotificationViewTest::NotificationViewTest() {
172 } 210 }
173 211
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 247
210 void NotificationViewTest::ClickOnNotification( 248 void NotificationViewTest::ClickOnNotification(
211 const std::string& notification_id) { 249 const std::string& notification_id) {
212 // For this test, this method should not be invoked. 250 // For this test, this method should not be invoked.
213 NOTREACHED(); 251 NOTREACHED();
214 } 252 }
215 253
216 void NotificationViewTest::RemoveNotification( 254 void NotificationViewTest::RemoveNotification(
217 const std::string& notification_id, 255 const std::string& notification_id,
218 bool by_user) { 256 bool by_user) {
219 // For this test, this method should not be invoked. 257 removed_ids_.insert(notification_id);
220 NOTREACHED();
221 } 258 }
222 259
223 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel( 260 scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel(
224 const NotifierId& notifier_id, 261 const NotifierId& notifier_id,
225 const base::string16& display_source) { 262 const base::string16& display_source) {
226 // For this test, this method should not be invoked. 263 // For this test, this method should not be invoked.
227 NOTREACHED(); 264 NOTREACHED();
228 return nullptr; 265 return nullptr;
229 } 266 }
230 267
(...skipping 20 matching lines...) Expand all
251 TEST_F(NotificationViewTest, CreateOrUpdateTest) { 288 TEST_F(NotificationViewTest, CreateOrUpdateTest) {
252 EXPECT_TRUE(NULL != notification_view()->title_view_); 289 EXPECT_TRUE(NULL != notification_view()->title_view_);
253 EXPECT_TRUE(NULL != notification_view()->message_view_); 290 EXPECT_TRUE(NULL != notification_view()->message_view_);
254 EXPECT_TRUE(NULL != notification_view()->icon_view_); 291 EXPECT_TRUE(NULL != notification_view()->icon_view_);
255 EXPECT_TRUE(NULL != notification_view()->image_view_); 292 EXPECT_TRUE(NULL != notification_view()->image_view_);
256 293
257 notification()->set_image(gfx::Image()); 294 notification()->set_image(gfx::Image());
258 notification()->set_title(base::ASCIIToUTF16("")); 295 notification()->set_title(base::ASCIIToUTF16(""));
259 notification()->set_message(base::ASCIIToUTF16("")); 296 notification()->set_message(base::ASCIIToUTF16(""));
260 notification()->set_icon(gfx::Image()); 297 notification()->set_icon(gfx::Image());
298 notification()->set_icon(gfx::Image());
261 299
262 notification_view()->CreateOrUpdateViews(*notification()); 300 notification_view()->CreateOrUpdateViews(*notification());
263 EXPECT_TRUE(NULL == notification_view()->title_view_); 301 EXPECT_TRUE(NULL == notification_view()->title_view_);
264 EXPECT_TRUE(NULL == notification_view()->message_view_); 302 EXPECT_TRUE(NULL == notification_view()->message_view_);
265 EXPECT_TRUE(NULL == notification_view()->image_view_); 303 EXPECT_TRUE(NULL == notification_view()->image_view_);
266 EXPECT_TRUE(NULL == notification_view()->settings_button_view_); 304 EXPECT_TRUE(NULL == notification_view()->settings_button_view_);
267 // We still expect an icon view for all layouts. 305 // We still expect an icon view for all layouts.
268 EXPECT_TRUE(NULL != notification_view()->icon_view_); 306 EXPECT_TRUE(NULL != notification_view()->icon_view_);
269 } 307 }
270 308
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // some generic checking here. 649 // some generic checking here.
612 // The url has been elided (it starts with an ellipsis) 650 // The url has been elided (it starts with an ellipsis)
613 // The end of the domainsuffix is shown 651 // The end of the domainsuffix is shown
614 // the url piece is not shown 652 // the url piece is not shown
615 EXPECT_TRUE(base::UTF16ToUTF8(result).find( 653 EXPECT_TRUE(base::UTF16ToUTF8(result).find(
616 ".veryveryveyrylong.chromium.org") != std::string::npos); 654 ".veryveryveyrylong.chromium.org") != std::string::npos);
617 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0); 655 EXPECT_TRUE(base::UTF16ToUTF8(result).find("\xE2\x80\xA6") == 0);
618 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos); 656 EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
619 } 657 }
620 658
659 TEST_F(NotificationViewTest, SlideOut) {
660 views::SlideOutView::DisableAnimationsForTesting();
661
662 UpdateNotificationViews();
663 std::string notification_id = notification()->id();
664
665 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
666 auto event_scroll10 = GenerateGestureVerticalScrollUpdateEvent(-10);
667 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
668 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
669
670 notification_view()->OnGestureEvent(event_begin.get());
671 notification_view()->OnGestureEvent(event_scroll10.get());
672 EXPECT_FALSE(IsRemoved(notification_id));
673 EXPECT_EQ(-10.f, GetNotificationScrollAmount());
674 notification_view()->OnGestureEvent(event_end.get());
675 EXPECT_FALSE(IsRemoved(notification_id));
676 EXPECT_EQ(0.f, GetNotificationScrollAmount());
677
678 notification_view()->OnGestureEvent(event_begin.get());
679 notification_view()->OnGestureEvent(event_scroll500.get());
680 EXPECT_FALSE(IsRemoved(notification_id));
681 EXPECT_EQ(-500.f, GetNotificationScrollAmount());
682 notification_view()->OnGestureEvent(event_end.get());
683 EXPECT_TRUE(IsRemoved(notification_id));
684 }
685
686 TEST_F(NotificationViewTest, SlideOutNonClosable) {
687 views::SlideOutView::DisableAnimationsForTesting();
688
689 notification()->set_closable(false);
690 UpdateNotificationViews();
691 std::string notification_id = notification()->id();
692
693 auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
694 auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
695 auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
696
697 notification_view()->OnGestureEvent(event_begin.get());
698 notification_view()->OnGestureEvent(event_scroll500.get());
699 EXPECT_FALSE(IsRemoved(notification_id));
700 EXPECT_LT(-500.f, GetNotificationScrollAmount());
701 notification_view()->OnGestureEvent(event_end.get());
702 EXPECT_FALSE(IsRemoved(notification_id));
703 }
704
705 TEST_F(NotificationViewTest, NonClosable) {
706 notification()->set_closable(false);
707
708 UpdateNotificationViews();
709 EXPECT_EQ(NULL, GetCloseButton());
710 }
711
621 } // namespace message_center 712 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698