Chromium Code Reviews| 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 <list> | 9 #include <list> |
| 10 #include <memory> | |
|
Jun Mukai
2016/05/04 17:00:09
Is this necessary?
dyaroshev
2016/05/05 14:13:19
Done.
| |
| 10 #include <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 18 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
| 19 #include "ui/events/event_utils.h" | 20 #include "ui/events/event_utils.h" |
| 20 #include "ui/gfx/display.h" | 21 #include "ui/gfx/display.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/message_center/fake_message_center.h" | 23 #include "ui/message_center/fake_message_center.h" |
| 23 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" | 24 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" |
| 24 #include "ui/message_center/views/toast_contents_view.h" | 25 #include "ui/message_center/views/toast_contents_view.h" |
| 25 #include "ui/views/test/views_test_base.h" | 26 #include "ui/views/test/views_test_base.h" |
| 26 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/widget/widget_delegate.h" | 28 #include "ui/views/widget/widget_delegate.h" |
| 28 | 29 |
| 30 namespace { | |
| 31 | |
| 32 std::unique_ptr<message_center::Notification> CreateTestNotification( | |
| 33 std::string id, | |
| 34 std::string text) { | |
| 35 return base::WrapUnique(new message_center::Notification( | |
| 36 message_center::NOTIFICATION_TYPE_BASE_FORMAT, id, | |
| 37 base::UTF8ToUTF16("test title"), base::ASCIIToUTF16(text), gfx::Image(), | |
| 38 base::string16() /* display_source */, GURL(), | |
| 39 message_center::NotifierId(message_center::NotifierId::APPLICATION, id), | |
| 40 message_center::RichNotificationData(), | |
| 41 new message_center::NotificationDelegate())); | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 29 namespace message_center { | 46 namespace message_center { |
| 30 namespace test { | 47 namespace test { |
| 31 | 48 |
| 32 class MessagePopupCollectionTest : public views::ViewsTestBase { | 49 class MessagePopupCollectionTest : public views::ViewsTestBase { |
| 33 public: | 50 public: |
| 34 void SetUp() override { | 51 void SetUp() override { |
| 35 views::ViewsTestBase::SetUp(); | 52 views::ViewsTestBase::SetUp(); |
| 36 MessageCenter::Initialize(); | 53 MessageCenter::Initialize(); |
| 37 MessageCenter::Get()->DisableTimersForTest(); | 54 MessageCenter::Get()->DisableTimersForTest(); |
| 38 alignment_delegate_.reset(new DesktopPopupAlignmentDelegate); | 55 alignment_delegate_.reset(new DesktopPopupAlignmentDelegate); |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 WaitForTransitionsDone(); | 530 WaitForTransitionsDone(); |
| 514 | 531 |
| 515 // Confirms that there is no toast. | 532 // Confirms that there is no toast. |
| 516 EXPECT_EQ(0u, GetToastCounts()); | 533 EXPECT_EQ(0u, GetToastCounts()); |
| 517 // But the notification still exists. | 534 // But the notification still exists. |
| 518 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); | 535 EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 519 } | 536 } |
| 520 | 537 |
| 521 #endif // defined(OS_CHROMEOS) | 538 #endif // defined(OS_CHROMEOS) |
| 522 | 539 |
| 540 // When notifications were displayed on top, change of notification | |
| 541 // size didn't affect corresponding widget. | |
| 542 TEST_F(MessagePopupCollectionTest, ChangingNotificationSize) { | |
| 543 // Simulate a taskbar at the top. | |
| 544 SetDisplayInfo(gfx::Rect(0, 10, 600, 390), // Work-area. | |
| 545 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
| 546 | |
| 547 std::string id = AddNotification(); | |
|
Jun Mukai
2016/05/04 17:00:09
const std::string&
dyaroshev
2016/05/05 14:13:19
not apliable anymore
| |
| 548 WaitForTransitionsDone(); | |
| 549 | |
| 550 ToastContentsView* toast = GetToast(id); | |
| 551 ASSERT_TRUE(toast); | |
| 552 | |
| 553 struct { | |
| 554 std::string name; | |
| 555 std::string text; | |
| 556 } test_cases[] = { | |
| 557 {"shrinking", ""}, {"enlarging", "abc\ndef\nghk\n"}, | |
| 558 }; | |
|
stevenjb
2016/05/04 23:39:02
Should we also test a smaller notification after t
dyaroshev
2016/05/05 14:13:19
Done.
| |
| 559 | |
| 560 for (const auto& test_case : test_cases) { | |
| 561 EXPECT_EQ(toast->bounds(), GetWidget(id)->GetWindowBoundsInScreen()) | |
| 562 << test_case.name << " before update"; | |
| 563 | |
| 564 MessageCenter::Get()->UpdateNotification( | |
| 565 id, CreateTestNotification(id, test_case.text)); | |
| 566 EXPECT_EQ(toast->bounds(), GetWidget(id)->GetWindowBoundsInScreen()) | |
| 567 << test_case.name << " before transition"; | |
| 568 | |
| 569 WaitForTransitionsDone(); | |
| 570 EXPECT_EQ(toast->bounds(), GetWidget(id)->GetWindowBoundsInScreen()) | |
| 571 << test_case.name << " after transition"; | |
| 572 } | |
| 573 | |
| 574 CloseAllToasts(); | |
| 575 WaitForTransitionsDone(); | |
| 576 | |
| 577 // Restore simulated taskbar position to bottom. | |
| 578 SetDisplayInfo(gfx::Rect(0, 0, 600, 390), // Work-area. | |
| 579 gfx::Rect(0, 0, 600, 400)); // Display-bounds. | |
|
Jun Mukai
2016/05/04 17:00:09
I believe you don't have to reset it.
If necessary
dyaroshev
2016/05/05 14:13:19
I removed it in other tests too.
| |
| 580 } | |
| 581 | |
| 523 } // namespace test | 582 } // namespace test |
| 524 } // namespace message_center | 583 } // namespace message_center |
| OLD | NEW |