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

Unified Diff: ash/system/tray/system_tray_unittest.cc

Issue 2930123002: Tablet WM : Swiping on system tray bubble. (Closed)
Patch Set: Fixed tdanderson's comments. Created 3 years, 6 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/tray/system_tray_unittest.cc
diff --git a/ash/system/tray/system_tray_unittest.cc b/ash/system/tray/system_tray_unittest.cc
index c8dc570c4f0103ed481221f980abfc7c284330cf..8c524af5494935de2d8197c14fda77955b0f6beb 100644
--- a/ash/system/tray/system_tray_unittest.cc
+++ b/ash/system/tray/system_tray_unittest.cc
@@ -21,6 +21,7 @@
#include "ash/test/ash_test_base.h"
#include "ash/test/status_area_widget_test_helper.h"
#include "ash/test/test_system_tray_item.h"
+#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/wm/window_util.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
@@ -56,7 +57,211 @@ class ModalWidgetDelegate : public views::WidgetDelegateView {
} // namespace
-typedef AshTestBase SystemTrayTest;
+class SystemTrayTest : public AshTestBase {
+ public:
+ SystemTrayTest() {}
+ ~SystemTrayTest() override {}
+
+ // Swiping on the system tray and end with finger released.
+ void SendGestureEvent(gfx::Point& start,
+ float delta,
+ bool is_fling,
+ float velocity_y) {
+ SystemTray* system_tray = GetPrimarySystemTray();
+ base::TimeTicks timestamp = base::TimeTicks::Now();
+ SendScrollStartAndUpdate(start, delta, timestamp);
+
+ ui::GestureEventDetails details =
+ is_fling
+ ? ui::GestureEventDetails(ui::ET_SCROLL_FLING_START, 0, velocity_y)
+ : ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_END);
+ ui::GestureEvent event = ui::GestureEvent(start.x(), start.y() + delta,
+ ui::EF_NONE, timestamp, details);
+ system_tray->OnGestureEvent(&event);
+ }
+
+ // Swiping on the system tray without releasing the finger.
+ void SendScrollStartAndUpdate(gfx::Point& start,
+ float delta,
+ base::TimeTicks& timestamp) {
+ SystemTray* system_tray = GetPrimarySystemTray();
+ ui::GestureEventDetails begin_details(ui::ET_GESTURE_SCROLL_BEGIN);
+ ui::GestureEvent begin_event = ui::GestureEvent(
+ start.x(), start.y(), ui::EF_NONE, timestamp, begin_details);
+ system_tray->OnGestureEvent(&begin_event);
+
+ ui::GestureEventDetails update_details(ui::ET_GESTURE_SCROLL_UPDATE, 0,
+ delta);
+ timestamp += base::TimeDelta::FromMilliseconds(100);
+ ui::GestureEvent update_event = ui::GestureEvent(
+ start.x(), start.y(), ui::EF_NONE, timestamp, update_details);
+ system_tray->OnGestureEvent(&update_event);
+ }
+
+ // Open the default system tray bubble to get the height of the bubble and
+ // then close it.
+ float GetSystemBubbleHeight() {
+ SystemTray* system_tray = GetPrimarySystemTray();
+ system_tray->ShowDefaultView(BUBBLE_CREATE_NEW);
+ gfx::Rect bounds = system_tray->GetSystemBubble()
+ ->bubble_view()
+ ->GetWidget()
+ ->GetWindowBoundsInScreen();
+ system_tray->CloseSystemBubble();
+
+ return bounds.height();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SystemTrayTest);
+};
+
+// Swiping on the system tray ends with fling event.
+TEST_F(SystemTrayTest, FlingOnSystemTray) {
+ Shelf* shelf = GetPrimaryShelf();
+ SystemTray* system_tray = GetPrimarySystemTray();
+ gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint();
+ shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
+ Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
+ true);
+
+ // Fling up on the system tray should show the bubble if the |velocity_y| is
+ // larger than kFlingVelocity and the dragging amount is larger than one third
+ // of the height of the bubble.
+ float delta = -GetSystemBubbleHeight();
+ SendGestureEvent(start, delta, true, -(kFlingVelocity + 1));
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+ system_tray->CloseSystemBubble();
+
+ // Fling up on the system tray should show the bubble if the |velocity_y| is
+ // larger than kFlingVelocity even the dragging amount is less than one third
+ // of the height of the bubble.
+ delta /= 4;
+ SendGestureEvent(start, delta, true, -(kFlingVelocity + 1));
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+ system_tray->CloseSystemBubble();
+
+ // Fling up on the system tray should show the bubble if the |velocity_y| is
+ // less than kFlingVelocity but the dragging amount if larger than one third
+ // of the height of the bubble.
+ delta = -GetSystemBubbleHeight();
+ SendGestureEvent(start, delta, true, -(kFlingVelocity - 1));
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+ system_tray->CloseSystemBubble();
+
+ // Fling up on the system tray should close the bubble if the |velocity_y|
+ // is less than kFlingVelocity and the dragging amount is less than one third
+ // of the height of the bubble.
+ delta /= 4;
+ SendGestureEvent(start, delta, true, -(kFlingVelocity - 1));
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Fling down on the system tray should close the bubble if the |velocity_y|
+ // is larger than kFLingVelocity.
+ SendGestureEvent(start, delta, true, kFlingVelocity + 1);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Fling down on the system tray should close the bubble if the |velocity_y|
+ // is larger than kFlingVelocity even the dragging amount is larger than one
+ // third of the height of the bubble.
+ delta = -GetSystemBubbleHeight();
+ SendGestureEvent(start, delta, true, kFlingVelocity + 1);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Fling down on the system tray should open the bubble if the |velocity_y| is
+ // less than kFlingVelocity but the dragging amount exceed one third of the
+ // height of the bubble.
+ SendGestureEvent(start, delta, true, kFlingVelocity - 1);
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+ system_tray->CloseSystemBubble();
+
+ // Fling down on the system tray should close the bubble if the |velocity_y|
+ // is less than kFlingVelocity and the dragging amount is less than one third
+ // of the height of the bubble.
+ delta /= 4;
+ SendGestureEvent(start, delta, true, kFlingVelocity - 1);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+}
+
+// Touch outside the system tray bubble during swiping should close the bubble.
+TEST_F(SystemTrayTest, TapOutsideCloseBubble) {
+ Shelf* shelf = GetPrimaryShelf();
+ SystemTray* system_tray = GetPrimarySystemTray();
+ gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint();
+ shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
+
+ float delta = -GetSystemBubbleHeight();
+ Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
+ true);
+ base::TimeTicks timestamp = base::TimeTicks::Now();
+ SendScrollStartAndUpdate(start, delta, timestamp);
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+
+ ui::test::EventGenerator& generator = GetEventGenerator();
+ gfx::Rect bounds = system_tray->GetSystemBubble()
+ ->bubble_view()
+ ->GetWidget()
+ ->GetWindowBoundsInScreen();
+ gfx::Point point_outside = gfx::Point(bounds.x() - 5, bounds.y() - 5);
+ generator.GestureTapAt(point_outside);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+}
+
+// Swiping on the system tray ends with scroll event.
+TEST_F(SystemTrayTest, SwipingOnSystemTray) {
+ Shelf* shelf = GetPrimaryShelf();
+ SystemTray* system_tray = GetPrimarySystemTray();
+ gfx::Point start = system_tray->GetBoundsInScreen().CenterPoint();
+ shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
+
+ // Swiping up on the system tray has no effect if it is not in maximize mode.
+ float delta = -GetSystemBubbleHeight();
+ Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
+ false);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Swiping up on the system tray should show the system tray bubble if it is
+ // in maximize mode.
+ Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
+ true);
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+ system_tray->CloseSystemBubble();
+
+ // Swiping up less than one third of the bubble's height should not show the
+ // bubble.
+ delta /= 4;
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Swiping up more than one third of the bubble's height should show the
+ // bubble.
+ delta = -GetSystemBubbleHeight() / 2;
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_TRUE(system_tray->HasSystemBubble());
+ system_tray->CloseSystemBubble();
+
+ // Swiping up on system tray should not show the system tray bubble if the
+ // shelf is left alignment.
+ delta = -GetSystemBubbleHeight();
+ shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Swiping up on system tray should not show the system tray bubble if the
+ // shelf is right alignment.
+ shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+
+ // Swiping down on the shelf should not show the system tray bubble.
+ shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
+ delta = -delta;
+ SendGestureEvent(start, delta, false, 0);
+ EXPECT_FALSE(system_tray->HasSystemBubble());
+}
// Verifies only the visible default views are recorded in the
// "Ash.SystemMenu.DefaultView.VisibleItems" histogram.

Powered by Google App Engine
This is Rietveld 408576698