Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / system / web_notification / web_notification_tray_unittest.cc
index ff7666c..113ed21 100644 (file)
 #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/web_notification/ash_popup_alignment_delegate.h"
 #include "ash/test/ash_test_base.h"
 #include "ash/test/status_area_widget_test_helper.h"
 #include "ash/test/test_system_tray_delegate.h"
 #include "ash/wm/window_state.h"
+#include "base/command_line.h"
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "ui/aura/client/aura_constants.h"
-#include "ui/aura/test/event_generator.h"
 #include "ui/aura/window.h"
+#include "ui/base/ui_base_switches.h"
+#include "ui/events/event.h"
+#include "ui/events/test/event_generator.h"
 #include "ui/gfx/display.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
 #include "ui/gfx/screen.h"
 #include "ui/message_center/message_center_style.h"
 #include "ui/message_center/message_center_tray.h"
@@ -66,15 +72,14 @@ class TestItem : public SystemTrayItem {
  public:
   TestItem() : SystemTrayItem(GetSystemTray()) {}
 
-  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE {
+  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(base::UTF8ToUTF16("Default")));
     return default_view;
   }
 
-  virtual views::View* CreateNotificationView(
-      user::LoginStatus status) OVERRIDE {
+  views::View* CreateNotificationView(user::LoginStatus status) override {
     return new views::View;
   }
 
@@ -87,9 +92,15 @@ class TestItem : public SystemTrayItem {
 class WebNotificationTrayTest : public test::AshTestBase {
  public:
   WebNotificationTrayTest() {}
-  virtual ~WebNotificationTrayTest() {}
+  ~WebNotificationTrayTest() override {}
 
-  virtual void TearDown() OVERRIDE {
+  void SetUp() override {
+    base::CommandLine::ForCurrentProcess()->AppendSwitch(
+        switches::kEnableTouchFeedback);
+    test::AshTestBase::SetUp();
+  }
+
+  void TearDown() override {
     GetMessageCenter()->RemoveAllNotifications(false);
     test::AshTestBase::TearDown();
   }
@@ -134,12 +145,12 @@ class WebNotificationTrayTest : public test::AshTestBase {
     return GetTray()->GetWidget();
   }
 
-  gfx::Rect GetPopupWorkArea() {
-    return GetPopupWorkAreaForTray(GetTray());
+  int GetPopupWorkAreaBottom() {
+    return GetPopupWorkAreaBottomForTray(GetTray());
   }
 
-  gfx::Rect GetPopupWorkAreaForTray(WebNotificationTray* tray) {
-    return tray->popup_collection_->work_area_;
+  int GetPopupWorkAreaBottomForTray(WebNotificationTray* tray) {
+    return tray->popup_alignment_delegate_->GetWorkAreaBottom();
   }
 
   bool IsPopupVisible() {
@@ -319,44 +330,40 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTray) {
 
   AddNotification("test_id");
   EXPECT_TRUE(GetTray()->IsPopupVisible());
-  gfx::Rect work_area = GetPopupWorkArea();
+  int bottom = GetPopupWorkAreaBottom();
 
   // 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());
+  int bottom_with_tray = GetPopupWorkAreaBottom();
+  EXPECT_GT(bottom, bottom_with_tray);
 
   // 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_notification = GetPopupWorkArea();
-  EXPECT_GT(work_area.size().GetArea(),
-            work_area_with_tray_notification.size().GetArea());
-  EXPECT_GT(work_area_with_tray.size().GetArea(),
-            work_area_with_tray_notification.size().GetArea());
+  int bottom_with_tray_notification = GetPopupWorkAreaBottom();
+  EXPECT_GT(bottom, bottom_with_tray_notification);
+  EXPECT_GT(bottom_with_tray, bottom_with_tray_notification);
 
   // 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_notification.size().GetArea(),
-            work_area_with_notification.size().GetArea());
+  int bottom_with_notification = GetPopupWorkAreaBottom();
+  EXPECT_GT(bottom, bottom_with_notification);
+  EXPECT_LT(bottom_with_tray_notification, bottom_with_notification);
 
   // Close the system tray notifications.
   GetSystemTray()->HideNotificationView(test_item);
   EXPECT_TRUE(GetTray()->IsPopupVisible());
-  EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString());
+  EXPECT_EQ(bottom, GetPopupWorkAreaBottom());
 }
 
 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) {
   AddNotification("test_id");
   EXPECT_TRUE(GetTray()->IsPopupVisible());
-  gfx::Rect work_area = GetPopupWorkArea();
+  int bottom = GetPopupWorkAreaBottom();
 
   // Shelf's auto-hide state won't be HIDDEN unless window exists.
   scoped_ptr<aura::Window> window(
@@ -366,14 +373,14 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) {
   shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
 
   EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
-  gfx::Rect work_area_auto_hidden = GetPopupWorkArea();
-  EXPECT_LT(work_area.size().GetArea(), work_area_auto_hidden.size().GetArea());
+  int bottom_auto_hidden = GetPopupWorkAreaBottom();
+  EXPECT_LT(bottom, bottom_auto_hidden);
 
   // Close the window, which shows the shelf.
   window.reset();
   EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
-  gfx::Rect work_area_auto_shown = GetPopupWorkArea();
-  EXPECT_EQ(work_area.ToString(), work_area_auto_shown.ToString());
+  int bottom_auto_shown = GetPopupWorkAreaBottom();
+  EXPECT_EQ(bottom, bottom_auto_shown);
 
   // Create the system tray during auto-hide.
   window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
@@ -383,42 +390,38 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupAndAutoHideShelf) {
 
   EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
   EXPECT_TRUE(GetTray()->IsPopupVisible());
-  gfx::Rect work_area_with_tray = GetPopupWorkArea();
-  EXPECT_GT(work_area_auto_shown.size().GetArea(),
-            work_area_with_tray.size().GetArea());
+  int bottom_with_tray = GetPopupWorkAreaBottom();
+  EXPECT_GT(bottom_auto_shown, bottom_with_tray);
 
   // Create tray notification.
   GetSystemTray()->ShowNotificationView(test_item);
   EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
-  gfx::Rect work_area_with_tray_notification = GetPopupWorkArea();
-  EXPECT_GT(work_area_with_tray.size().GetArea(),
-            work_area_with_tray_notification.size().GetArea());
+  int bottom_with_tray_notification = GetPopupWorkAreaBottom();
+  EXPECT_GT(bottom_with_tray, bottom_with_tray_notification);
 
   // Close the system tray.
   GetSystemTray()->ClickedOutsideBubble();
   shelf->UpdateAutoHideState();
   RunAllPendingInMessageLoop();
   EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
-  gfx::Rect work_area_hidden_with_tray_notification = GetPopupWorkArea();
-  EXPECT_LT(work_area_with_tray_notification.size().GetArea(),
-            work_area_hidden_with_tray_notification.size().GetArea());
-  EXPECT_GT(work_area_auto_hidden.size().GetArea(),
-            work_area_hidden_with_tray_notification.size().GetArea());
+  int bottom_hidden_with_tray_notification = GetPopupWorkAreaBottom();
+  EXPECT_LT(bottom_with_tray_notification,
+            bottom_hidden_with_tray_notification);
+  EXPECT_GT(bottom_auto_hidden, bottom_hidden_with_tray_notification);
 
   // Close the window again, which shows the shelf.
   window.reset();
   EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
-  gfx::Rect work_area_shown_with_tray_notification = GetPopupWorkArea();
-  EXPECT_GT(work_area_hidden_with_tray_notification.size().GetArea(),
-            work_area_shown_with_tray_notification.size().GetArea());
-  EXPECT_GT(work_area_auto_shown.size().GetArea(),
-            work_area_shown_with_tray_notification.size().GetArea());
+  int bottom_shown_with_tray_notification = GetPopupWorkAreaBottom();
+  EXPECT_GT(bottom_hidden_with_tray_notification,
+            bottom_shown_with_tray_notification);
+  EXPECT_GT(bottom_auto_shown, bottom_shown_with_tray_notification);
 }
 
 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) {
   AddNotification("test_id");
   EXPECT_TRUE(IsPopupVisible());
-  gfx::Rect work_area = GetPopupWorkArea();
+  int bottom = GetPopupWorkAreaBottom();
 
   // Checks the work area for normal auto-hidden state.
   scoped_ptr<aura::Window> window(
@@ -427,7 +430,7 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) {
       Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
   shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
   EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
-  gfx::Rect work_area_auto_hidden = GetPopupWorkArea();
+  int bottom_auto_hidden = GetPopupWorkAreaBottom();
   shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
 
   // Put |window| into fullscreen without forcing the shelf to hide. Currently,
@@ -440,39 +443,112 @@ TEST_F(WebNotificationTrayTest, MAYBE_PopupAndFullscreen) {
   // The work area for auto-hidden status of fullscreen is a bit larger
   // since it doesn't even have the 3-pixel width.
   EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
-  gfx::Rect work_area_fullscreen_hidden = GetPopupWorkArea();
-  EXPECT_EQ(work_area_auto_hidden.ToString(),
-            work_area_fullscreen_hidden.ToString());
+  int bottom_fullscreen_hidden = GetPopupWorkAreaBottom();
+  EXPECT_EQ(bottom_auto_hidden, bottom_fullscreen_hidden);
 
   // Move the mouse cursor at the bottom, which shows the shelf.
-  aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
+  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
   gfx::Point bottom_right =
       Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom_right();
   bottom_right.Offset(-1, -1);
   generator.MoveMouseTo(bottom_right);
   shelf->UpdateAutoHideStateNow();
   EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
-  EXPECT_EQ(work_area.ToString(), GetPopupWorkArea().ToString());
+  EXPECT_EQ(bottom, GetPopupWorkAreaBottom());
 
-  generator.MoveMouseTo(work_area.CenterPoint());
+  generator.MoveMouseTo(
+      Shell::GetScreen()->GetPrimaryDisplay().bounds().CenterPoint());
   shelf->UpdateAutoHideStateNow();
   EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
-  EXPECT_EQ(work_area_auto_hidden.ToString(), GetPopupWorkArea().ToString());
+  EXPECT_EQ(bottom_auto_hidden, GetPopupWorkAreaBottom());
 }
 
 TEST_F(WebNotificationTrayTest, MAYBE_PopupAndSystemTrayMultiDisplay) {
   UpdateDisplay("800x600,600x400");
 
   AddNotification("test_id");
-  gfx::Rect work_area = GetPopupWorkArea();
-  gfx::Rect work_area_second = GetPopupWorkAreaForTray(GetSecondaryTray());
+  int bottom = GetPopupWorkAreaBottom();
+  int bottom_second = GetPopupWorkAreaBottomForTray(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());
+  EXPECT_GT(bottom, GetPopupWorkAreaBottom());
+  EXPECT_EQ(bottom_second, GetPopupWorkAreaBottomForTray(GetSecondaryTray()));
+}
+
+// TODO(jonross): This test is failing on ASAN bots, fix the failure and
+// re-enable. (crbug.com/411881)
+// TODO(jonross): Replace manually creating TouchEvent with
+// EventGenerator.PressTouch/ReleaseTouch. Currently they set a width on the
+// touch event causing the gesture recognizer to target a different view.
+#if defined(OS_CHROMEOS)
+// Tests that there is visual feedback for touch presses.
+TEST_F(WebNotificationTrayTest, DISABLED_TouchFeedback) {
+  AddNotification("test_id");
+  RunAllPendingInMessageLoop();
+  WebNotificationTray* tray = GetTray();
+  EXPECT_TRUE(tray->visible());
+
+  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
+  const int touch_id = 0;
+  gfx::Point center_point = tray->GetBoundsInScreen().CenterPoint();
+
+  ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id,
+                       generator.Now());
+  generator.Dispatch(&press);
+  RunAllPendingInMessageLoop();
+  EXPECT_TRUE(tray->draw_background_as_active());
+
+  ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center_point, touch_id,
+      press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
+  generator.Dispatch(&release);
+  RunAllPendingInMessageLoop();
+  EXPECT_TRUE(tray->draw_background_as_active());
+  EXPECT_TRUE(tray->IsMessageCenterBubbleVisible());
+
+  generator.GestureTapAt(center_point);
+  RunAllPendingInMessageLoop();
+  EXPECT_FALSE(tray->draw_background_as_active());
+  EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
 }
 
+// TODO(jonross): This test is failing on ASAN bots, fix the failure and
+// re-enable. (crbug.com/411881)
+// Tests that while touch presses trigger visual feedback, that subsequent non
+// tap gestures cancel the feedback without triggering the message center.
+TEST_F(WebNotificationTrayTest, DISABLED_TouchFeedbackCancellation) {
+  AddNotification("test_id");
+  RunAllPendingInMessageLoop();
+  WebNotificationTray* tray = GetTray();
+  EXPECT_TRUE(tray->visible());
+
+  ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
+  const int touch_id = 0;
+  gfx::Rect bounds = tray->GetBoundsInScreen();
+  gfx::Point center_point = bounds.CenterPoint();
+
+  ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center_point, touch_id,
+                       generator.Now());
+  generator.Dispatch(&press);
+  RunAllPendingInMessageLoop();
+  EXPECT_TRUE(tray->draw_background_as_active());
+
+  gfx::Point out_of_bounds(bounds.x() - 1, center_point.y());
+  ui::TouchEvent move(ui::ET_TOUCH_MOVED, out_of_bounds, touch_id,
+                      press.time_stamp()+base::TimeDelta::FromMilliseconds(50));
+  generator.Dispatch(&move);
+  RunAllPendingInMessageLoop();
+  EXPECT_FALSE(tray->draw_background_as_active());
+
+  ui::TouchEvent release(ui::ET_TOUCH_RELEASED, out_of_bounds, touch_id,
+      move.time_stamp()+base::TimeDelta::FromMilliseconds(50));
+  generator.Dispatch(&release);
+  RunAllPendingInMessageLoop();
+  EXPECT_FALSE(tray->draw_background_as_active());
+  EXPECT_FALSE(tray->IsMessageCenterBubbleVisible());
+}
+
+#endif  // OS_CHROMEOS
+
 }  // namespace ash