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

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: Remove unnecessary property. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/notification_view.cc ('k') | ui/views/controls/slide_out_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..bcaf4217ae2be8dea976e38a9407fd00cdd85632 100644
--- a/ui/message_center/views/notification_view_unittest.cc
+++ b/ui/message_center/views/notification_view_unittest.cc
@@ -11,6 +11,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/canvas.h"
@@ -31,6 +32,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 +73,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 +176,28 @@ 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 +253,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(
@@ -618,4 +654,64 @@ TEST_F(NotificationViewTest, FormatContextMessageTest) {
EXPECT_TRUE(base::UTF16ToUTF8(result).find("hello") == std::string::npos);
}
+TEST_F(NotificationViewTest, SlideOut) {
+ ui::ScopedAnimationDurationScaleMode zero_duration_scope(
+ ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
+
+ 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));
+}
+
+// Pinning notification is ChromeOS only feature.
+#if defined(OS_CHROMEOS)
+
+TEST_F(NotificationViewTest, SlideOutPinned) {
+ ui::ScopedAnimationDurationScaleMode zero_duration_scope(
+ ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
+
+ notification()->set_pinned(true);
+ 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, Pinned) {
+ notification()->set_pinned(true);
+
+ UpdateNotificationViews();
+ EXPECT_EQ(NULL, GetCloseButton());
+}
+
+#endif // defined(OS_CHROMEOS)
+
} // namespace message_center
« no previous file with comments | « ui/message_center/views/notification_view.cc ('k') | ui/views/controls/slide_out_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698