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

Unified Diff: ash/system/web_notification/web_notification_tray_unittest.cc

Issue 20598004: Do not hide the web notification popups by the system tray, rather let them avoid (2nd) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 5 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: ash/system/web_notification/web_notification_tray_unittest.cc
diff --git a/ash/system/web_notification/web_notification_tray_unittest.cc b/ash/system/web_notification/web_notification_tray_unittest.cc
index 8117523fe8d2bb8e84926f37db898c33e65e1601..026500f179838266cdfe817574dfa0a9d7d21c49 100644
--- a/ash/system/web_notification/web_notification_tray_unittest.cc
+++ b/ash/system/web_notification/web_notification_tray_unittest.cc
@@ -8,9 +8,11 @@
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
+#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
+#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_item.h"
#include "ash/system/tray/test_system_tray_delegate.h"
#include "ash/test/ash_test_base.h"
@@ -56,6 +58,34 @@ message_center::MessageCenter* GetMessageCenter() {
return GetTray()->message_center();
}
+SystemTray* GetSystemTray() {
+ return Shell::GetPrimaryRootWindowController()->shelf()->
+ status_area_widget()->system_tray();
+}
+
+// Trivial item implementation for testing PopupAndSystemTray test case.
+class TestItem : public SystemTrayItem {
+ public:
+ TestItem() : SystemTrayItem(GetSystemTray()) {}
+
+ virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE {
+ views::View* default_view = new views::View;
+ default_view->SetLayoutManager(new views::FillLayout);
+ default_view->AddChildView(new views::Label(UTF8ToUTF16("Default")));
+ return default_view;
+ }
+
+ virtual views::View* CreateNotificationView(
+ user::LoginStatus status) OVERRIDE {
+ return new views::View;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestItem);
+};
+
+} // namespace
+
class WebNotificationTrayTest : public test::AshTestBase {
public:
WebNotificationTrayTest() {}
@@ -106,12 +136,18 @@ class WebNotificationTrayTest : public test::AshTestBase {
return GetTray()->GetWidget();
}
+ gfx::Rect GetPopupWorkArea() {
+ return GetPopupWorkAreaForTray(GetTray());
+ }
+
+ gfx::Rect GetPopupWorkAreaForTray(WebNotificationTray* tray) {
+ return tray->popup_collection_->work_area_;
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(WebNotificationTrayTest);
};
-} // namespace
-
TEST_F(WebNotificationTrayTest, WebNotifications) {
// TODO(mukai): move this test case to ui/message_center.
ASSERT_TRUE(GetWidget());
@@ -196,9 +232,7 @@ TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) {
std::string id = base::StringPrintf("test_id%d", static_cast<int>(i));
AddNotification(id);
}
- // Hide and reshow the bubble so that it is updated immediately, not delayed.
- GetTray()->SetHidePopupBubble(true);
- GetTray()->SetHidePopupBubble(false);
+ GetTray()->ShowPopups();
EXPECT_TRUE(GetTray()->IsPopupVisible());
EXPECT_EQ(notifications_to_add,
GetMessageCenter()->NotificationCount());
@@ -210,8 +244,11 @@ TEST_F(WebNotificationTrayTest, DISABLED_ManyPopupNotifications) {
#if defined(OS_CHROMEOS)
// Display notification is ChromeOS only.
#define MAYBE_PopupShownOnBothDisplays PopupShownOnBothDisplays
+#define MAYBE_PopupAndSystemTrayMultiDisplay PopupAndSystemTrayMultiDisplay
#else
#define MAYBE_PopupShownOnBothDisplays DISABLED_PopupShownOnBothDisplays
+#define MAYBE_PopupAndSystemTrayMultiDisplay \
+ DISABLED_PopupAndSystemTrayMultiDisplay
#endif
// Verifies if the notification appears on both displays when extended mode.
@@ -252,4 +289,80 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupShownOnBothDisplays) {
EXPECT_TRUE(secondary_tray->IsPopupVisible());
}
+#if defined(OS_CHROMEOS)
+// PopupAndSystemTray may fail in platforms other than ChromeOS because the
+// RootWindow's bound can be bigger than gfx::Display's work area so that
+// openingsystem tray doesn't affect at all the work area of popups.
+#define MAYBE_PopupAndSystemTray PopupAndSystemTray
+#else
+#define MAYBE_PopupAndSystemTray DISABLED_PopupAndSystemTray
+#endif
+
+TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) {
+ TestItem* test_item = new TestItem;
+ GetSystemTray()->AddTrayItem(test_item);
+
+ AddNotification("test_id");
+ EXPECT_TRUE(GetTray()->IsPopupVisible());
+ gfx::Rect work_area = GetPopupWorkArea();
+
+ // System tray is created, the popup's work area should be narrowed but still
+ // visible.
+ GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
+ EXPECT_TRUE(GetTray()->IsPopupVisible());
+ gfx::Rect work_area_with_tray = GetPopupWorkArea();
+ EXPECT_GT(work_area.size().GetArea(), work_area_with_tray.size().GetArea());
+
+ // System tray notification is also created, the popup's work area is narrowed
+ // even more, but still visible.
+ GetSystemTray()->ShowNotificationView(test_item);
+ EXPECT_TRUE(GetTray()->IsPopupVisible());
+ gfx::Rect work_area_with_tray_notificaiton = GetPopupWorkArea();
+ EXPECT_GT(work_area.size().GetArea(),
+ work_area_with_tray_notificaiton.size().GetArea());
+ EXPECT_GT(work_area_with_tray.size().GetArea(),
+ work_area_with_tray_notificaiton.size().GetArea());
+
+ // Close system tray, only system tray notifications.
+ GetSystemTray()->ClickedOutsideBubble();
+ EXPECT_TRUE(GetTray()->IsPopupVisible());
+ gfx::Rect work_area_with_notification = GetPopupWorkArea();
+ EXPECT_GT(work_area.size().GetArea(),
+ work_area_with_notification.size().GetArea());
+ EXPECT_LT(work_area_with_tray_notificaiton.size().GetArea(),
+ work_area_with_notification.size().GetArea());
+
+ // Close the notifications.
+ GetSystemTray()->HideNotificationView(test_item);
+ EXPECT_TRUE(GetTray()->IsPopupVisible());
+ EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString());
+}
+
+TEST_F(WebNotificationTrayTest, PopupAndSystemTrayAlignment) {
+ Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
+ SetAlignment(SHELF_ALIGNMENT_LEFT);
+ AddNotification("test_id");
+ gfx::Rect work_area = GetPopupWorkArea();
+
+ // System tray is created, but the work area is not affected since the tray
+ // appears at the left-bottom while the popups appear at the right bottom.
+ GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
+ EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString());
+}
+
+TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) {
+ UpdateDisplay("800x600,600x400");
+
+ AddNotification("test_id");
+ gfx::Rect work_area = GetPopupWorkArea();
+ gfx::Rect work_area_second = GetPopupWorkAreaForTray(GetSecondaryTray());
+
+ // System tray is created on the primary display. The popups in the secondary
+ // tray aren't affected.
+ GetSystemTray()->ShowDefaultView(BUBBLE_CREATE_NEW);
+ EXPECT_GT(work_area.size().GetArea(), GetPopupWorkArea().size().GetArea());
+ EXPECT_EQ(work_area_second.ToString(),
+ GetPopupWorkAreaForTray(GetSecondaryTray()).ToString());
+}
+
} // namespace ash
« no previous file with comments | « ash/system/web_notification/web_notification_tray.cc ('k') | ui/message_center/views/message_popup_collection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698