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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
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 383d1989dda44c642e7fa1be08fe081f929e0093..aa76e4aeb4e23502f60d38ceca540409bab2c765 100644
--- a/ui/message_center/views/notification_view_unittest.cc
+++ b/ui/message_center/views/notification_view_unittest.cc
@@ -31,6 +31,24 @@
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget_delegate.h"
+namespace {
+
+scoped_ptr<ui::GestureEvent> GenerateGestureEvent(ui::EventType type) {
+ ui::GestureEventDetails detail(type);
+ scoped_ptr<ui::GestureEvent> event(
+ new ui::GestureEvent(0, 0, 0, base::TimeDelta(), detail));
+ return event;
+}
+
+scoped_ptr<ui::GestureEvent> GenerateGestureVerticalScrollUpdateEvent(int dx) {
+ ui::GestureEventDetails detail(ui::ET_GESTURE_SCROLL_UPDATE, dx, 0);
+ scoped_ptr<ui::GestureEvent> event(
+ new ui::GestureEvent(0, 0, 0, base::TimeDelta(), detail));
+ return event;
+}
+
+} // anonymouse namespace
+
namespace message_center {
// A test delegate used for tests that deal with the notification settings
@@ -54,7 +72,9 @@ class NotificationViewTest : public views::ViewsTestBase,
void TearDown() override;
views::Widget* widget() { return notification_view_->GetWidget(); }
- NotificationView* notification_view() { return notification_view_.get(); }
+ NotificationView* notification_view() const {
+ return notification_view_.get();
+ }
Notification* notification() { return notification_.get(); }
RichNotificationData* data() { return data_.get(); }
@@ -155,12 +175,30 @@ class NotificationViewTest : public views::ViewsTestBase,
}
}
+ views::ImageButton* GetCloseButton() {
+ return notification_view()->close_button_.get();
+ }
+
void UpdateNotificationViews() {
notification_view()->CreateOrUpdateViews(*notification());
notification_view()->Layout();
}
+ float GetNotificationScrollAmount() const {
+ return notification_view()->GetTransform().To2dTranslation().x();
+ }
+
+ bool IsRemoved(const std::string& notification_id) const {
+ return (removed_ids_.find(notification_id) != removed_ids_.end());
+ }
+
+ void RemoveNotificationView() {
+ notification_view_.reset();
+ }
+
private:
+ std::set<std::string> removed_ids_;
+
scoped_ptr<RichNotificationData> data_;
scoped_ptr<Notification> notification_;
scoped_ptr<NotificationView> notification_view_;
@@ -216,8 +254,7 @@ void NotificationViewTest::ClickOnNotification(
void NotificationViewTest::RemoveNotification(
const std::string& notification_id,
bool by_user) {
- // For this test, this method should not be invoked.
- NOTREACHED();
+ removed_ids_.insert(notification_id);
}
scoped_ptr<ui::MenuModel> NotificationViewTest::CreateMenuModel(
@@ -258,6 +295,7 @@ TEST_F(NotificationViewTest, CreateOrUpdateTest) {
notification()->set_title(base::ASCIIToUTF16(""));
notification()->set_message(base::ASCIIToUTF16(""));
notification()->set_icon(gfx::Image());
+ notification()->set_icon(gfx::Image());
notification_view()->CreateOrUpdateViews(*notification());
EXPECT_TRUE(NULL == notification_view()->title_view_);
@@ -618,4 +656,57 @@ TEST_F(NotificationViewTest, FormatContextMessageTest) {
EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
}
+TEST_F(NotificationViewTest, SlideOut) {
+ views::SlideOutView::DisableAnimationsForTesting();
+
+ UpdateNotificationViews();
+ std::string notification_id = notification()->id();
+
+ auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
+ auto event_scroll10 = GenerateGestureVerticalScrollUpdateEvent(-10);
+ auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
+ auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll10.get());
+ EXPECT_FALSE(IsRemoved(notification_id));
+ EXPECT_EQ(-10.f, GetNotificationScrollAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_FALSE(IsRemoved(notification_id));
+ EXPECT_EQ(0.f, GetNotificationScrollAmount());
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll500.get());
+ EXPECT_FALSE(IsRemoved(notification_id));
+ EXPECT_EQ(-500.f, GetNotificationScrollAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_TRUE(IsRemoved(notification_id));
+}
+
+TEST_F(NotificationViewTest, SlideOutNonClosable) {
+ views::SlideOutView::DisableAnimationsForTesting();
+
+ notification()->set_closable(false);
+ UpdateNotificationViews();
+ std::string notification_id = notification()->id();
+
+ auto event_begin = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN);
+ auto event_scroll500 = GenerateGestureVerticalScrollUpdateEvent(-500);
+ auto event_end = GenerateGestureEvent(ui::ET_GESTURE_SCROLL_END);
+
+ notification_view()->OnGestureEvent(event_begin.get());
+ notification_view()->OnGestureEvent(event_scroll500.get());
+ EXPECT_FALSE(IsRemoved(notification_id));
+ EXPECT_LT(-500.f, GetNotificationScrollAmount());
+ notification_view()->OnGestureEvent(event_end.get());
+ EXPECT_FALSE(IsRemoved(notification_id));
+}
+
+TEST_F(NotificationViewTest, NonClosable) {
+ notification()->set_closable(false);
+
+ UpdateNotificationViews();
+ EXPECT_EQ(NULL, GetCloseButton());
+}
+
} // namespace message_center

Powered by Google App Engine
This is Rietveld 408576698