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

Unified Diff: ui/message_center/views/message_popup_collection_unittest.cc

Issue 1913433004: Supporting shrinking/enlarging for notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review, test for many notifications Created 4 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 side-by-side diff with in-line comments
Download patch
Index: ui/message_center/views/message_popup_collection_unittest.cc
diff --git a/ui/message_center/views/message_popup_collection_unittest.cc b/ui/message_center/views/message_popup_collection_unittest.cc
index 75fc26968ed8a140247929e28844fb179dea5213..64697d617544be74df17244fb5210526706604e0 100644
--- a/ui/message_center/views/message_popup_collection_unittest.cc
+++ b/ui/message_center/views/message_popup_collection_unittest.cc
@@ -26,6 +26,22 @@
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
+namespace {
+
+std::unique_ptr<message_center::Notification> CreateTestNotification(
+ std::string id,
+ std::string text) {
+ return base::WrapUnique(new message_center::Notification(
+ message_center::NOTIFICATION_TYPE_BASE_FORMAT, id,
+ base::UTF8ToUTF16("test title"), base::ASCIIToUTF16(text), gfx::Image(),
+ base::string16() /* display_source */, GURL(),
+ message_center::NotifierId(message_center::NotifierId::APPLICATION, id),
+ message_center::RichNotificationData(),
+ new message_center::NotificationDelegate()));
+}
+
+} // namespace
+
namespace message_center {
namespace test {
@@ -266,11 +282,6 @@ TEST_F(MessagePopupCollectionTest, DefaultPositioningWithRightTaskbar) {
CloseAllToasts();
EXPECT_EQ(0u, GetToastCounts());
-
- // Restore simulated taskbar position to bottom.
- SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area.
- gfx::Rect(0, 0, 600, 400)); // Display-bounds.
-
WaitForTransitionsDone();
}
@@ -297,10 +308,6 @@ TEST_F(MessagePopupCollectionTest, TopDownPositioningWithTopTaskbar) {
CloseAllToasts();
EXPECT_EQ(0u, GetToastCounts());
WaitForTransitionsDone();
-
- // Restore simulated taskbar position to bottom.
- SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area.
- gfx::Rect(0, 0, 600, 400)); // Display-bounds.
}
TEST_F(MessagePopupCollectionTest, TopDownPositioningWithLeftAndTopTaskbar) {
@@ -329,10 +336,6 @@ TEST_F(MessagePopupCollectionTest, TopDownPositioningWithLeftAndTopTaskbar) {
CloseAllToasts();
EXPECT_EQ(0u, GetToastCounts());
WaitForTransitionsDone();
-
- // Restore simulated taskbar position to bottom.
- SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area.
- gfx::Rect(0, 0, 600, 400)); // Display-bounds.
}
TEST_F(MessagePopupCollectionTest, TopDownPositioningWithBottomAndTopTaskbar) {
@@ -361,10 +364,6 @@ TEST_F(MessagePopupCollectionTest, TopDownPositioningWithBottomAndTopTaskbar) {
CloseAllToasts();
EXPECT_EQ(0u, GetToastCounts());
WaitForTransitionsDone();
-
- // Restore simulated taskbar position to bottom.
- SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area.
- gfx::Rect(0, 0, 600, 400)); // Display-bounds.
}
TEST_F(MessagePopupCollectionTest, LeftPositioningWithLeftTaskbar) {
@@ -393,10 +392,6 @@ TEST_F(MessagePopupCollectionTest, LeftPositioningWithLeftTaskbar) {
CloseAllToasts();
EXPECT_EQ(0u, GetToastCounts());
WaitForTransitionsDone();
-
- // Restore simulated taskbar position to bottom.
- SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area.
- gfx::Rect(0, 0, 600, 400)); // Display-bounds.
}
TEST_F(MessagePopupCollectionTest, DetectMouseHover) {
@@ -520,5 +515,76 @@ TEST_F(MessagePopupCollectionTest, CloseNonClosableNotifications) {
#endif // defined(OS_CHROMEOS)
+// When notifications were displayed on top, change of notification
+// size didn't affect corresponding widget.
+TEST_F(MessagePopupCollectionTest, ChangingNotificationSize) {
+ // Simulate a taskbar at the top.
+ SetDisplayInfo(gfx::Rect(0, 10, 600, 390), // Work-area.
+ gfx::Rect(0, 0, 600, 400)); // Display-bounds.
+
+ struct {
+ std::string name;
+ std::string text;
+ } updates[] = {
+ {"shrinking", ""},
+ {"enlarging", "abc\ndef\nghk\n"},
+ {"restoring", "abc\n"},
+ };
+
+ std::vector<std::string> notification_ids;
+ // adding notifications
+ {
+ constexpr int max_visible_popup_notifications = 3;
+ notification_ids.reserve(max_visible_popup_notifications);
+ std::generate_n(std::back_inserter(notification_ids),
+ max_visible_popup_notifications,
+ [this] { return AddNotification(); });
+ }
+
+ // helper to check, that notifications borders have the same size
+ // as their widgets at any time
+ auto check_notifications = [this, &notification_ids](const std::string& msg) {
+ for (const std::string& id : notification_ids) {
+ auto* toast = GetToast(id);
+ ASSERT_TRUE(toast) << "no toast for: " << id << "\ntest case: " << msg;
+ auto* widget = GetWidget(id);
+ ASSERT_TRUE(widget) << "no widget for: " << id << "\ntest case: " << msg;
+ EXPECT_TRUE(toast->bounds().height() ==
+ widget->GetWindowBoundsInScreen().height() &&
+ toast->bounds().width() ==
+ widget->GetWindowBoundsInScreen().width())
Jun Mukai 2016/05/05 18:01:51 nit: EXPECT_EQ(toast->bounds().size(), widget->Get
+ << "size of toast contents doesn't match widget's size"
+ << "\nfor id: " << id << "\ntest case: " << msg
+ << "\ntoast width: " << toast->bounds().width()
+ << "\nwidget width: " << widget->GetWindowBoundsInScreen().width()
+ << "\ntoast height: " << toast->bounds().height()
+ << "\nwidget height: " << widget->GetWindowBoundsInScreen().height();
Jun Mukai 2016/05/05 18:01:51 In case you have to keep EXPECT_TRUE, you may want
+ }
+ };
+
+ // checks not updated notifications
+ {
+ WaitForTransitionsDone();
+ ASSERT_NO_FATAL_FAILURE(
+ check_notifications("before updating, animation is done"));
+ }
+
+ // updating notifications one by one
+ for (const std::string& id : notification_ids) {
+ for (const auto& update : updates) {
+ MessageCenter::Get()->UpdateNotification(
+ id, CreateTestNotification(id, update.text));
+ ASSERT_NO_FATAL_FAILURE(check_notifications(id + " " + update.name +
+ " animation in progress"));
+ WaitForTransitionsDone();
+ ASSERT_NO_FATAL_FAILURE(
+ check_notifications(id + " " + update.name + " animation is done"));
+ }
+ }
+
+ CloseAllToasts();
+ WaitForTransitionsDone();
+}
+
} // namespace test
} // namespace message_center
« no previous file with comments | « no previous file | ui/message_center/views/toast_contents_view.h » ('j') | ui/message_center/views/toast_contents_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698