| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/message_popup_collection.h" | 5 #include "ui/message_center/views/message_popup_collection.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> |
| 9 #include <list> | 10 #include <list> |
| 11 #include <numeric> |
| 10 #include <utility> | 12 #include <utility> |
| 11 | 13 |
| 12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/optional.h" |
| 13 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/display/display.h" | 20 #include "ui/display/display.h" |
| 18 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 19 #include "ui/events/event_constants.h" | 22 #include "ui/events/event_constants.h" |
| 20 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
| 24 #include "ui/gfx/animation/animation_delegate.h" |
| 25 #include "ui/gfx/animation/slide_animation.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/message_center/fake_message_center.h" | 27 #include "ui/message_center/fake_message_center.h" |
| 28 #include "ui/message_center/message_center_style.h" |
| 23 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" | 29 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" |
| 24 #include "ui/message_center/views/toast_contents_view.h" | 30 #include "ui/message_center/views/toast_contents_view.h" |
| 25 #include "ui/views/test/views_test_base.h" | 31 #include "ui/views/test/views_test_base.h" |
| 26 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/widget/widget_delegate.h" | 33 #include "ui/views/widget/widget_delegate.h" |
| 28 | 34 |
| 35 namespace { |
| 36 |
| 37 std::unique_ptr<message_center::Notification> CreateTestNotification( |
| 38 std::string id, |
| 39 std::string text) { |
| 40 return base::WrapUnique(new message_center::Notification( |
| 41 message_center::NOTIFICATION_TYPE_BASE_FORMAT, id, |
| 42 base::UTF8ToUTF16("test title"), base::ASCIIToUTF16(text), gfx::Image(), |
| 43 base::string16() /* display_source */, GURL(), |
| 44 message_center::NotifierId(message_center::NotifierId::APPLICATION, id), |
| 45 message_center::RichNotificationData(), |
| 46 new message_center::NotificationDelegate())); |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 29 namespace message_center { | 51 namespace message_center { |
| 30 namespace test { | 52 namespace test { |
| 31 | 53 |
| 32 class MessagePopupCollectionTest : public views::ViewsTestBase { | 54 class MessagePopupCollectionTest : public views::ViewsTestBase { |
| 33 public: | 55 public: |
| 34 void SetUp() override { | 56 void SetUp() override { |
| 35 views::ViewsTestBase::SetUp(); | 57 views::ViewsTestBase::SetUp(); |
| 36 MessageCenter::Initialize(); | 58 MessageCenter::Initialize(); |
| 37 MessageCenter::Get()->DisableTimersForTest(); | 59 MessageCenter::Get()->DisableTimersForTest(); |
| 38 alignment_delegate_.reset(new DesktopPopupAlignmentDelegate); | 60 alignment_delegate_.reset(new DesktopPopupAlignmentDelegate); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Assumes there is at least one toast to close. | 141 // Assumes there is at least one toast to close. |
| 120 EXPECT_TRUE(GetToastCounts() > 0); | 142 EXPECT_TRUE(GetToastCounts() > 0); |
| 121 MessageCenter::Get()->RemoveAllNotifications( | 143 MessageCenter::Get()->RemoveAllNotifications( |
| 122 false /* by_user */, MessageCenter::RemoveType::ALL); | 144 false /* by_user */, MessageCenter::RemoveType::ALL); |
| 123 } | 145 } |
| 124 | 146 |
| 125 gfx::Rect GetToastRectAt(size_t index) { | 147 gfx::Rect GetToastRectAt(size_t index) { |
| 126 return collection_->GetToastRectAt(index); | 148 return collection_->GetToastRectAt(index); |
| 127 } | 149 } |
| 128 | 150 |
| 151 // Checks: |
| 152 // 1) sizes of toast and corresponding widget are equal; |
| 153 // 2) widgets do not owerlap; |
| 154 // 3) after animation is done, aligment is propper; |
| 155 class CheckedAnimationDelegate : public gfx::AnimationDelegate { |
| 156 public: |
| 157 explicit CheckedAnimationDelegate(MessagePopupCollectionTest* test); |
| 158 |
| 159 // returns first encountered error |
| 160 const base::Optional<std::string>& error_msg() const { return error_msg_; } |
| 161 |
| 162 // gfx::AnimationDelegate overrides |
| 163 void AnimationEnded(const gfx::Animation* animation) override; |
| 164 void AnimationProgressed(const gfx::Animation* animation) override; |
| 165 void AnimationCanceled(const gfx::Animation* animation) override; |
| 166 |
| 167 private: |
| 168 // we attach ourselves to the last toast, because we accept |
| 169 // invalidation of invariants during intermidiate |
| 170 // notification updates. |
| 171 ToastContentsView& animation_delegate() { return *toasts_->back(); } |
| 172 const ToastContentsView& animation_delegate() const { |
| 173 return *toasts_->back(); |
| 174 } |
| 175 |
| 176 void CheckWidgetLEView(const std::string& calling_func); |
| 177 void CheckToastsAreAligned(const std::string& calling_func); |
| 178 void CheckToastsDontOverlap(const std::string& calling_func); |
| 179 |
| 180 static int ComputeYDistance(const ToastContentsView& top, |
| 181 const ToastContentsView& bottom); |
| 182 |
| 183 MessagePopupCollection::Toasts* toasts_; |
| 184 |
| 185 // first encountered error |
| 186 base::Optional<std::string> error_msg_; |
| 187 |
| 188 DISALLOW_COPY_AND_ASSIGN(CheckedAnimationDelegate); |
| 189 }; |
| 190 |
| 191 static std::string YPositionsToString( |
| 192 const MessagePopupCollection::Toasts& toasts); |
| 193 |
| 129 private: | 194 private: |
| 130 std::unique_ptr<MessagePopupCollection> collection_; | 195 std::unique_ptr<MessagePopupCollection> collection_; |
| 131 std::unique_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; | 196 std::unique_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; |
| 132 int id_; | 197 int id_; |
| 133 }; | 198 }; |
| 134 | 199 |
| 200 MessagePopupCollectionTest::CheckedAnimationDelegate::CheckedAnimationDelegate( |
| 201 MessagePopupCollectionTest* test) |
| 202 : toasts_(&test->collection_->toasts_) { |
| 203 DCHECK(!toasts_->empty()); |
| 204 animation_delegate().bounds_animation_->set_delegate(this); |
| 205 } |
| 206 |
| 207 void MessagePopupCollectionTest::CheckedAnimationDelegate::AnimationEnded( |
| 208 const gfx::Animation* animation) { |
| 209 animation_delegate().AnimationEnded(animation); |
| 210 CheckWidgetLEView("AnimationEnded"); |
| 211 CheckToastsAreAligned("AnimationEnded"); |
| 212 } |
| 213 |
| 214 void MessagePopupCollectionTest::CheckedAnimationDelegate::AnimationProgressed( |
| 215 const gfx::Animation* animation) { |
| 216 animation_delegate().AnimationProgressed(animation); |
| 217 CheckWidgetLEView("AnimationProgressed"); |
| 218 CheckToastsDontOverlap("AnimationProgressed"); |
| 219 } |
| 220 |
| 221 void MessagePopupCollectionTest::CheckedAnimationDelegate::AnimationCanceled( |
| 222 const gfx::Animation* animation) { |
| 223 animation_delegate().AnimationCanceled(animation); |
| 224 CheckWidgetLEView("AnimationCanceled"); |
| 225 CheckToastsDontOverlap("AnimationCanceled"); |
| 226 } |
| 227 |
| 228 void MessagePopupCollectionTest::CheckedAnimationDelegate::CheckWidgetLEView( |
| 229 const std::string& calling_func) { |
| 230 if (error_msg_) |
| 231 return; |
| 232 for (ToastContentsView* toast : *toasts_) { |
| 233 auto* widget = toast->GetWidget(); |
| 234 DCHECK(widget) << "no widget for: " << toast->id(); |
| 235 if (toast->bounds().height() < widget->GetWindowBoundsInScreen().height()) { |
| 236 error_msg_ = calling_func + " CheckWidgetSizeLEView: id: " + toast->id() + |
| 237 "\ntoast size: " + toast->bounds().size().ToString() + |
| 238 "\nwidget size: " + |
| 239 widget->GetWindowBoundsInScreen().size().ToString(); |
| 240 return; |
| 241 } |
| 242 } |
| 243 }; |
| 244 |
| 245 void MessagePopupCollectionTest::CheckedAnimationDelegate:: |
| 246 CheckToastsAreAligned(const std::string& calling_func) { |
| 247 if (error_msg_) |
| 248 return; |
| 249 auto poorly_aligned = std::adjacent_find( |
| 250 toasts_->begin(), toasts_->end(), |
| 251 [this](ToastContentsView* top, ToastContentsView* bottom) { |
| 252 return ComputeYDistance(*top, *bottom) != kMarginBetweenItems; |
| 253 }); |
| 254 if (poorly_aligned != toasts_->end()) |
| 255 error_msg_ = calling_func + " CheckToastsAreAligned: distance between: " + |
| 256 (*poorly_aligned)->id() + ' ' + |
| 257 (*std::next(poorly_aligned))->id() + ": " + |
| 258 std::to_string(ComputeYDistance(**poorly_aligned, |
| 259 **std::next(poorly_aligned))) + |
| 260 " expected: " + std::to_string(kMarginBetweenItems) + |
| 261 "\nLayout:\n" + YPositionsToString(*toasts_); |
| 262 } |
| 263 |
| 264 void MessagePopupCollectionTest::CheckedAnimationDelegate:: |
| 265 CheckToastsDontOverlap(const std::string& calling_func) { |
| 266 if (error_msg_) |
| 267 return; |
| 268 auto poorly_aligned = std::adjacent_find( |
| 269 toasts_->begin(), toasts_->end(), |
| 270 [this](ToastContentsView* top, ToastContentsView* bottom) { |
| 271 return ComputeYDistance(*top, *bottom) < 0; |
| 272 }); |
| 273 if (poorly_aligned != toasts_->end()) |
| 274 error_msg_ = calling_func + " CheckToastsDontOverlap: distance between: " + |
| 275 (*poorly_aligned)->id() + ' ' + |
| 276 (*std::next(poorly_aligned))->id() + ": " + |
| 277 std::to_string(ComputeYDistance(**poorly_aligned, |
| 278 **std::next(poorly_aligned))) + |
| 279 "\nLayout:\n" + YPositionsToString(*toasts_); |
| 280 } |
| 281 |
| 282 // static |
| 283 std::string MessagePopupCollectionTest::YPositionsToString( |
| 284 const MessagePopupCollection::Toasts& toasts) { |
| 285 return std::accumulate(toasts.begin(), toasts.end(), std::string(), |
| 286 [](std::string res, const ToastContentsView* toast) { |
| 287 const auto& bounds = |
| 288 toast->GetWidget()->GetWindowBoundsInScreen(); |
| 289 res += toast->id(); |
| 290 res += ' '; |
| 291 res += std::to_string(bounds.y()); |
| 292 res += ", "; |
| 293 res += std::to_string(bounds.y() + bounds.height()); |
| 294 res += '\n'; |
| 295 return res; |
| 296 }); |
| 297 } |
| 298 |
| 299 // static |
| 300 int MessagePopupCollectionTest::CheckedAnimationDelegate::ComputeYDistance( |
| 301 const ToastContentsView& top, |
| 302 const ToastContentsView& bottom) { |
| 303 const auto* top_widget = top.GetWidget(); |
| 304 const auto* bottom_widget = bottom.GetWidget(); |
| 305 const auto& top_bounds = top_widget->GetWindowBoundsInScreen(); |
| 306 const auto& bottom_bounds = bottom_widget->GetWindowBoundsInScreen(); |
| 307 return bottom_bounds.y() - (top_bounds.y() + top_bounds.height()); |
| 308 } |
| 309 |
| 135 #if defined(OS_CHROMEOS) | 310 #if defined(OS_CHROMEOS) |
| 136 TEST_F(MessagePopupCollectionTest, DismissOnClick) { | 311 TEST_F(MessagePopupCollectionTest, DismissOnClick) { |
| 137 | 312 |
| 138 std::string id1 = AddNotification(); | 313 std::string id1 = AddNotification(); |
| 139 std::string id2 = AddNotification(); | 314 std::string id2 = AddNotification(); |
| 140 WaitForTransitionsDone(); | 315 WaitForTransitionsDone(); |
| 141 | 316 |
| 142 EXPECT_EQ(2u, GetToastCounts()); | 317 EXPECT_EQ(2u, GetToastCounts()); |
| 143 EXPECT_TRUE(IsToastShown(id1)); | 318 EXPECT_TRUE(IsToastShown(id1)); |
| 144 EXPECT_TRUE(IsToastShown(id2)); | 319 EXPECT_TRUE(IsToastShown(id2)); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 EXPECT_TRUE(IsToastShown(id0)); | 434 EXPECT_TRUE(IsToastShown(id0)); |
| 260 EXPECT_TRUE(IsToastShown(id1)); | 435 EXPECT_TRUE(IsToastShown(id1)); |
| 261 | 436 |
| 262 EXPECT_EQ(r0.width(), r1.width()); | 437 EXPECT_EQ(r0.width(), r1.width()); |
| 263 EXPECT_EQ(r0.height(), r1.height()); | 438 EXPECT_EQ(r0.height(), r1.height()); |
| 264 EXPECT_GT(r0.y(), r1.y()); | 439 EXPECT_GT(r0.y(), r1.y()); |
| 265 EXPECT_EQ(r0.x(), r1.x()); | 440 EXPECT_EQ(r0.x(), r1.x()); |
| 266 | 441 |
| 267 CloseAllToasts(); | 442 CloseAllToasts(); |
| 268 EXPECT_EQ(0u, GetToastCounts()); | 443 EXPECT_EQ(0u, GetToastCounts()); |
| 269 | |
| 270 // Restore simulated taskbar position to bottom. | |
| 271 SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | |
| 272 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
| 273 | |
| 274 WaitForTransitionsDone(); | 444 WaitForTransitionsDone(); |
| 275 } | 445 } |
| 276 | 446 |
| 277 TEST_F(MessagePopupCollectionTest, TopDownPositioningWithTopTaskbar) { | 447 TEST_F(MessagePopupCollectionTest, TopDownPositioningWithTopTaskbar) { |
| 278 // Simulate a taskbar at the top. | 448 // Simulate a taskbar at the top. |
| 279 SetDisplayInfo(gfx::Rect(0, 10, 600, 390), // Work-area. | 449 SetDisplayInfo(gfx::Rect(0, 10, 600, 390), // Work-area. |
| 280 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | 450 gfx::Rect(0, 0, 600, 400)); // Display-bounds. |
| 281 std::string id0 = AddNotification(); | 451 std::string id0 = AddNotification(); |
| 282 std::string id1 = AddNotification(); | 452 std::string id1 = AddNotification(); |
| 283 WaitForTransitionsDone(); | 453 WaitForTransitionsDone(); |
| 284 | 454 |
| 285 gfx::Rect r0 = GetToastRectAt(0); | 455 gfx::Rect r0 = GetToastRectAt(0); |
| 286 gfx::Rect r1 = GetToastRectAt(1); | 456 gfx::Rect r1 = GetToastRectAt(1); |
| 287 | 457 |
| 288 // 2 toasts are shown, equal size, vertical stack. | 458 // 2 toasts are shown, equal size, vertical stack. |
| 289 EXPECT_TRUE(IsToastShown(id0)); | 459 EXPECT_TRUE(IsToastShown(id0)); |
| 290 EXPECT_TRUE(IsToastShown(id1)); | 460 EXPECT_TRUE(IsToastShown(id1)); |
| 291 | 461 |
| 292 EXPECT_EQ(r0.width(), r1.width()); | 462 EXPECT_EQ(r0.width(), r1.width()); |
| 293 EXPECT_EQ(r0.height(), r1.height()); | 463 EXPECT_EQ(r0.height(), r1.height()); |
| 294 EXPECT_LT(r0.y(), r1.y()); | 464 EXPECT_LT(r0.y(), r1.y()); |
| 295 EXPECT_EQ(r0.x(), r1.x()); | 465 EXPECT_EQ(r0.x(), r1.x()); |
| 296 | 466 |
| 297 CloseAllToasts(); | 467 CloseAllToasts(); |
| 298 EXPECT_EQ(0u, GetToastCounts()); | 468 EXPECT_EQ(0u, GetToastCounts()); |
| 299 WaitForTransitionsDone(); | 469 WaitForTransitionsDone(); |
| 300 | |
| 301 // Restore simulated taskbar position to bottom. | |
| 302 SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | |
| 303 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
| 304 } | 470 } |
| 305 | 471 |
| 306 TEST_F(MessagePopupCollectionTest, TopDownPositioningWithLeftAndTopTaskbar) { | 472 TEST_F(MessagePopupCollectionTest, TopDownPositioningWithLeftAndTopTaskbar) { |
| 307 // If there "seems" to be a taskbar on left and top (like in Unity), it is | 473 // If there "seems" to be a taskbar on left and top (like in Unity), it is |
| 308 // assumed that the actual taskbar is the top one. | 474 // assumed that the actual taskbar is the top one. |
| 309 | 475 |
| 310 // Simulate a taskbar at the top and left. | 476 // Simulate a taskbar at the top and left. |
| 311 SetDisplayInfo(gfx::Rect(10, 10, 590, 390), // Work-area. | 477 SetDisplayInfo(gfx::Rect(10, 10, 590, 390), // Work-area. |
| 312 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | 478 gfx::Rect(0, 0, 600, 400)); // Display-bounds. |
| 313 std::string id0 = AddNotification(); | 479 std::string id0 = AddNotification(); |
| 314 std::string id1 = AddNotification(); | 480 std::string id1 = AddNotification(); |
| 315 WaitForTransitionsDone(); | 481 WaitForTransitionsDone(); |
| 316 | 482 |
| 317 gfx::Rect r0 = GetToastRectAt(0); | 483 gfx::Rect r0 = GetToastRectAt(0); |
| 318 gfx::Rect r1 = GetToastRectAt(1); | 484 gfx::Rect r1 = GetToastRectAt(1); |
| 319 | 485 |
| 320 // 2 toasts are shown, equal size, vertical stack. | 486 // 2 toasts are shown, equal size, vertical stack. |
| 321 EXPECT_TRUE(IsToastShown(id0)); | 487 EXPECT_TRUE(IsToastShown(id0)); |
| 322 EXPECT_TRUE(IsToastShown(id1)); | 488 EXPECT_TRUE(IsToastShown(id1)); |
| 323 | 489 |
| 324 EXPECT_EQ(r0.width(), r1.width()); | 490 EXPECT_EQ(r0.width(), r1.width()); |
| 325 EXPECT_EQ(r0.height(), r1.height()); | 491 EXPECT_EQ(r0.height(), r1.height()); |
| 326 EXPECT_LT(r0.y(), r1.y()); | 492 EXPECT_LT(r0.y(), r1.y()); |
| 327 EXPECT_EQ(r0.x(), r1.x()); | 493 EXPECT_EQ(r0.x(), r1.x()); |
| 328 | 494 |
| 329 CloseAllToasts(); | 495 CloseAllToasts(); |
| 330 EXPECT_EQ(0u, GetToastCounts()); | 496 EXPECT_EQ(0u, GetToastCounts()); |
| 331 WaitForTransitionsDone(); | 497 WaitForTransitionsDone(); |
| 332 | |
| 333 // Restore simulated taskbar position to bottom. | |
| 334 SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | |
| 335 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
| 336 } | 498 } |
| 337 | 499 |
| 338 TEST_F(MessagePopupCollectionTest, TopDownPositioningWithBottomAndTopTaskbar) { | 500 TEST_F(MessagePopupCollectionTest, TopDownPositioningWithBottomAndTopTaskbar) { |
| 339 // If there "seems" to be a taskbar on bottom and top (like in Gnome), it is | 501 // If there "seems" to be a taskbar on bottom and top (like in Gnome), it is |
| 340 // assumed that the actual taskbar is the top one. | 502 // assumed that the actual taskbar is the top one. |
| 341 | 503 |
| 342 // Simulate a taskbar at the top and bottom. | 504 // Simulate a taskbar at the top and bottom. |
| 343 SetDisplayInfo(gfx::Rect(0, 10, 580, 400), // Work-area. | 505 SetDisplayInfo(gfx::Rect(0, 10, 580, 400), // Work-area. |
| 344 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | 506 gfx::Rect(0, 0, 600, 400)); // Display-bounds. |
| 345 std::string id0 = AddNotification(); | 507 std::string id0 = AddNotification(); |
| 346 std::string id1 = AddNotification(); | 508 std::string id1 = AddNotification(); |
| 347 WaitForTransitionsDone(); | 509 WaitForTransitionsDone(); |
| 348 | 510 |
| 349 gfx::Rect r0 = GetToastRectAt(0); | 511 gfx::Rect r0 = GetToastRectAt(0); |
| 350 gfx::Rect r1 = GetToastRectAt(1); | 512 gfx::Rect r1 = GetToastRectAt(1); |
| 351 | 513 |
| 352 // 2 toasts are shown, equal size, vertical stack. | 514 // 2 toasts are shown, equal size, vertical stack. |
| 353 EXPECT_TRUE(IsToastShown(id0)); | 515 EXPECT_TRUE(IsToastShown(id0)); |
| 354 EXPECT_TRUE(IsToastShown(id1)); | 516 EXPECT_TRUE(IsToastShown(id1)); |
| 355 | 517 |
| 356 EXPECT_EQ(r0.width(), r1.width()); | 518 EXPECT_EQ(r0.width(), r1.width()); |
| 357 EXPECT_EQ(r0.height(), r1.height()); | 519 EXPECT_EQ(r0.height(), r1.height()); |
| 358 EXPECT_LT(r0.y(), r1.y()); | 520 EXPECT_LT(r0.y(), r1.y()); |
| 359 EXPECT_EQ(r0.x(), r1.x()); | 521 EXPECT_EQ(r0.x(), r1.x()); |
| 360 | 522 |
| 361 CloseAllToasts(); | 523 CloseAllToasts(); |
| 362 EXPECT_EQ(0u, GetToastCounts()); | 524 EXPECT_EQ(0u, GetToastCounts()); |
| 363 WaitForTransitionsDone(); | 525 WaitForTransitionsDone(); |
| 364 | |
| 365 // Restore simulated taskbar position to bottom. | |
| 366 SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | |
| 367 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
| 368 } | 526 } |
| 369 | 527 |
| 370 TEST_F(MessagePopupCollectionTest, LeftPositioningWithLeftTaskbar) { | 528 TEST_F(MessagePopupCollectionTest, LeftPositioningWithLeftTaskbar) { |
| 371 // Simulate a taskbar at the left. | 529 // Simulate a taskbar at the left. |
| 372 SetDisplayInfo(gfx::Rect(10, 0, 590, 400), // Work-area. | 530 SetDisplayInfo(gfx::Rect(10, 0, 590, 400), // Work-area. |
| 373 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | 531 gfx::Rect(0, 0, 600, 400)); // Display-bounds. |
| 374 std::string id0 = AddNotification(); | 532 std::string id0 = AddNotification(); |
| 375 std::string id1 = AddNotification(); | 533 std::string id1 = AddNotification(); |
| 376 WaitForTransitionsDone(); | 534 WaitForTransitionsDone(); |
| 377 | 535 |
| 378 gfx::Rect r0 = GetToastRectAt(0); | 536 gfx::Rect r0 = GetToastRectAt(0); |
| 379 gfx::Rect r1 = GetToastRectAt(1); | 537 gfx::Rect r1 = GetToastRectAt(1); |
| 380 | 538 |
| 381 // 2 toasts are shown, equal size, vertical stack. | 539 // 2 toasts are shown, equal size, vertical stack. |
| 382 EXPECT_TRUE(IsToastShown(id0)); | 540 EXPECT_TRUE(IsToastShown(id0)); |
| 383 EXPECT_TRUE(IsToastShown(id1)); | 541 EXPECT_TRUE(IsToastShown(id1)); |
| 384 | 542 |
| 385 EXPECT_EQ(r0.width(), r1.width()); | 543 EXPECT_EQ(r0.width(), r1.width()); |
| 386 EXPECT_EQ(r0.height(), r1.height()); | 544 EXPECT_EQ(r0.height(), r1.height()); |
| 387 EXPECT_GT(r0.y(), r1.y()); | 545 EXPECT_GT(r0.y(), r1.y()); |
| 388 EXPECT_EQ(r0.x(), r1.x()); | 546 EXPECT_EQ(r0.x(), r1.x()); |
| 389 | 547 |
| 390 // Ensure that toasts are on the left. | 548 // Ensure that toasts are on the left. |
| 391 EXPECT_LT(r1.x(), GetWorkArea().CenterPoint().x()); | 549 EXPECT_LT(r1.x(), GetWorkArea().CenterPoint().x()); |
| 392 | 550 |
| 393 CloseAllToasts(); | 551 CloseAllToasts(); |
| 394 EXPECT_EQ(0u, GetToastCounts()); | 552 EXPECT_EQ(0u, GetToastCounts()); |
| 395 WaitForTransitionsDone(); | 553 WaitForTransitionsDone(); |
| 396 | |
| 397 // Restore simulated taskbar position to bottom. | |
| 398 SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | |
| 399 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
| 400 } | 554 } |
| 401 | 555 |
| 402 TEST_F(MessagePopupCollectionTest, DetectMouseHover) { | 556 TEST_F(MessagePopupCollectionTest, DetectMouseHover) { |
| 403 std::string id0 = AddNotification(); | 557 std::string id0 = AddNotification(); |
| 404 std::string id1 = AddNotification(); | 558 std::string id1 = AddNotification(); |
| 405 WaitForTransitionsDone(); | 559 WaitForTransitionsDone(); |
| 406 | 560 |
| 407 views::WidgetDelegateView* toast0 = GetToast(id0); | 561 views::WidgetDelegateView* toast0 = GetToast(id0); |
| 408 EXPECT_TRUE(toast0 != NULL); | 562 EXPECT_TRUE(toast0 != NULL); |
| 409 views::WidgetDelegateView* toast1 = GetToast(id1); | 563 views::WidgetDelegateView* toast1 = GetToast(id1); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 WaitForTransitionsDone(); | 667 WaitForTransitionsDone(); |
| 514 | 668 |
| 515 // Confirms that there is no toast. | 669 // Confirms that there is no toast. |
| 516 EXPECT_EQ(0u, GetToastCounts()); | 670 EXPECT_EQ(0u, GetToastCounts()); |
| 517 // But the notification still exists. | 671 // But the notification still exists. |
| 518 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); | 672 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 519 } | 673 } |
| 520 | 674 |
| 521 #endif // defined(OS_CHROMEOS) | 675 #endif // defined(OS_CHROMEOS) |
| 522 | 676 |
| 677 // When notifications were displayed on top, change of notification |
| 678 // size didn't affect corresponding widget. |
| 679 TEST_F(MessagePopupCollectionTest, ChangingNotificationSize) { |
| 680 // Simulate a taskbar at the top. |
| 681 SetDisplayInfo(gfx::Rect(0, 10, 600, 390), // Work-area. |
| 682 gfx::Rect(0, 0, 600, 400)); // Display-bounds. |
| 683 |
| 684 struct TestCase { |
| 685 std::string name; |
| 686 std::string text; |
| 687 }; |
| 688 std::vector<TestCase> updates = { |
| 689 {"shrinking", ""}, |
| 690 {"enlarging", "abc\ndef\nghk\n"}, |
| 691 {"restoring", "abc\ndef\n"}, |
| 692 }; |
| 693 |
| 694 std::vector<std::string> notification_ids; |
| 695 // adding notifications |
| 696 { |
| 697 constexpr int max_visible_popup_notifications = 3; |
| 698 notification_ids.reserve(max_visible_popup_notifications); |
| 699 for (int i = 0; i < max_visible_popup_notifications; ++i) { |
| 700 notification_ids.push_back(std::to_string(i)); |
| 701 auto notification = |
| 702 CreateTestNotification(notification_ids.back(), updates.back().text); |
| 703 MessageCenter::Get()->AddNotification(std::move(notification)); |
| 704 } |
| 705 } |
| 706 |
| 707 WaitForTransitionsDone(); |
| 708 |
| 709 // updating notifications one by one |
| 710 for (const std::string& id : notification_ids) { |
| 711 for (const auto& update : updates) { |
| 712 MessageCenter::Get()->UpdateNotification( |
| 713 id, CreateTestNotification(id, update.text)); |
| 714 |
| 715 CheckedAnimationDelegate checked_animation(this); |
| 716 |
| 717 WaitForTransitionsDone(); |
| 718 |
| 719 EXPECT_FALSE(checked_animation.error_msg()) |
| 720 << "Animation error, test case: " << id << ' ' << update.name << ":\n" |
| 721 << *checked_animation.error_msg(); |
| 722 } |
| 723 } |
| 724 |
| 725 CloseAllToasts(); |
| 726 WaitForTransitionsDone(); |
| 727 } |
| 728 |
| 523 } // namespace test | 729 } // namespace test |
| 524 } // namespace message_center | 730 } // namespace message_center |
| OLD | NEW |