Commit 294fe32e authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Constrain event location to root window bounds

if
a) the mouse event is not captured, or
b) even if captured, it's considered a plain click.

  see bug for repro step.

Bug: 900614
Test: updated tests to match this expectation. Also tested manually.
Change-Id: I2668fa5692a0e4381e72d2d22bf5543914a8ca34
Reviewed-on: https://chromium-review.googlesource.com/c/1328709
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarVladislav Kaznacheev <kaznacheev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607431}
parent 3d862b6a
...@@ -1287,13 +1287,14 @@ TEST_F(WindowTreeHostManagerTest, ConvertHostToRootCoords) { ...@@ -1287,13 +1287,14 @@ TEST_F(WindowTreeHostManagerTest, ConvertHostToRootCoords) {
ui::test::EventGenerator generator(root_windows[0]); ui::test::EventGenerator generator(root_windows[0]);
generator.MoveMouseToInHost(0, 0); generator.MoveMouseToInHost(0, 0);
EXPECT_EQ("0,375", event_handler.GetLocationAndReset()); // The mouse location must be inside the root bounds in dp.
EXPECT_EQ("0,374", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(599, 0); generator.MoveMouseToInHost(599, 0);
EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); EXPECT_EQ("0,0", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(599, 399); generator.MoveMouseToInHost(599, 399);
EXPECT_EQ("249,0", event_handler.GetLocationAndReset()); EXPECT_EQ("249,0", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(0, 399); generator.MoveMouseToInHost(0, 399);
EXPECT_EQ("249,375", event_handler.GetLocationAndReset()); EXPECT_EQ("249,374", event_handler.GetLocationAndReset());
UpdateDisplay("600x400*2/u@0.8"); UpdateDisplay("600x400*2/u@0.8");
display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
...@@ -1303,13 +1304,13 @@ TEST_F(WindowTreeHostManagerTest, ConvertHostToRootCoords) { ...@@ -1303,13 +1304,13 @@ TEST_F(WindowTreeHostManagerTest, ConvertHostToRootCoords) {
EXPECT_EQ(0.8f, GetStoredZoomScale(display1.id())); EXPECT_EQ(0.8f, GetStoredZoomScale(display1.id()));
generator.MoveMouseToInHost(0, 0); generator.MoveMouseToInHost(0, 0);
EXPECT_EQ("375,250", event_handler.GetLocationAndReset()); EXPECT_EQ("374,249", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(599, 0); generator.MoveMouseToInHost(599, 0);
EXPECT_EQ("0,250", event_handler.GetLocationAndReset()); EXPECT_EQ("0,249", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(599, 399); generator.MoveMouseToInHost(599, 399);
EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); EXPECT_EQ("0,0", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(0, 399); generator.MoveMouseToInHost(0, 399);
EXPECT_EQ("375,0", event_handler.GetLocationAndReset()); EXPECT_EQ("374,0", event_handler.GetLocationAndReset());
UpdateDisplay("600x400*2/l@0.8"); UpdateDisplay("600x400*2/l@0.8");
display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
...@@ -1319,9 +1320,9 @@ TEST_F(WindowTreeHostManagerTest, ConvertHostToRootCoords) { ...@@ -1319,9 +1320,9 @@ TEST_F(WindowTreeHostManagerTest, ConvertHostToRootCoords) {
EXPECT_EQ(0.8f, GetStoredZoomScale(display1.id())); EXPECT_EQ(0.8f, GetStoredZoomScale(display1.id()));
generator.MoveMouseToInHost(0, 0); generator.MoveMouseToInHost(0, 0);
EXPECT_EQ("250,0", event_handler.GetLocationAndReset()); EXPECT_EQ("249,0", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(599, 0); generator.MoveMouseToInHost(599, 0);
EXPECT_EQ("250,374", event_handler.GetLocationAndReset()); EXPECT_EQ("249,374", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(599, 399); generator.MoveMouseToInHost(599, 399);
EXPECT_EQ("0,374", event_handler.GetLocationAndReset()); EXPECT_EQ("0,374", event_handler.GetLocationAndReset());
generator.MoveMouseToInHost(0, 399); generator.MoveMouseToInHost(0, 399);
...@@ -1468,10 +1469,10 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) { ...@@ -1468,10 +1469,10 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) {
aura::Env* env = Shell::Get()->aura_env(); aura::Env* env = Shell::Get()->aura_env();
ui::test::EventGenerator generator(root_windows[0]); ui::test::EventGenerator generator_on_2nd(root_windows[1]);
// Set the initial position. // Set the initial position.
generator.MoveMouseToInHost(350, 150); generator_on_2nd.MoveMouseToInHost(150, 150);
EXPECT_EQ("350,150", env->last_mouse_location().ToString()); EXPECT_EQ("350,150", env->last_mouse_location().ToString());
// A mouse pointer will stay in the 2nd display. // A mouse pointer will stay in the 2nd display.
...@@ -1494,7 +1495,8 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) { ...@@ -1494,7 +1495,8 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) {
EXPECT_EQ("150,150", env->last_mouse_location().ToString()); EXPECT_EQ("150,150", env->last_mouse_location().ToString());
// Move the mouse pointer to the bottom of 1st display. // Move the mouse pointer to the bottom of 1st display.
generator.MoveMouseToInHost(150, 290); ui::test::EventGenerator generator_on_1st(root_windows[0]);
generator_on_1st.MoveMouseToInHost(150, 290);
EXPECT_EQ("150,290", env->last_mouse_location().ToString()); EXPECT_EQ("150,290", env->last_mouse_location().ToString());
// The mouse pointer is now on 2nd display. // The mouse pointer is now on 2nd display.
......
...@@ -421,8 +421,9 @@ TEST_F(HighlighterControllerTest, SelectionInsideScreen) { ...@@ -421,8 +421,9 @@ TEST_F(HighlighterControllerTest, SelectionInsideScreen) {
constexpr float display_scales[] = {1.f, 1.5f, 2.0f}; constexpr float display_scales[] = {1.f, 1.5f, 2.0f};
for (size_t i = 0; i < sizeof(display_scales) / sizeof(float); ++i) { for (size_t i = 0; i < sizeof(display_scales) / sizeof(float); ++i) {
std::string display_spec = // 2nd display is for offscreen test.
base::StringPrintf("1000x1000*%.2f", display_scales[i]); std::string display_spec = base::StringPrintf(
"1000x1000*%.2f,500x1000*%.2f", display_scales[i], display_scales[i]);
SCOPED_TRACE(display_spec); SCOPED_TRACE(display_spec);
UpdateDisplayAndWaitForCompositingEnded(display_spec); UpdateDisplayAndWaitForCompositingEnded(display_spec);
...@@ -462,11 +463,11 @@ TEST_F(HighlighterControllerTest, SelectionInsideScreen) { ...@@ -462,11 +463,11 @@ TEST_F(HighlighterControllerTest, SelectionInsideScreen) {
EXPECT_TRUE(controller_test_api_->HandleSelectionCalled()); EXPECT_TRUE(controller_test_api_->HandleSelectionCalled());
EXPECT_TRUE(screen.Contains(controller_test_api_->selection())); EXPECT_TRUE(screen.Contains(controller_test_api_->selection()));
// Horizontal stroke completely offscreen. // Vertical stroke completely offscreen.
controller_test_api_->ResetSelection(); controller_test_api_->ResetSelection();
event_generator->MoveTouch(gfx::Point(0, -100)); event_generator->MoveTouch(gfx::Point(1100, 100));
event_generator->PressTouch(); event_generator->PressTouch();
event_generator->MoveTouch(gfx::Point(1000, -100)); event_generator->MoveTouch(gfx::Point(1100, 500));
event_generator->ReleaseTouch(); event_generator->ReleaseTouch();
controller_test_api_->SimulateInterruptedStrokeTimeout(); controller_test_api_->SimulateInterruptedStrokeTimeout();
EXPECT_FALSE(controller_test_api_->HandleSelectionCalled()); EXPECT_FALSE(controller_test_api_->HandleSelectionCalled());
......
...@@ -131,6 +131,14 @@ class DockedMagnifierTest : public NoSessionAshTestBase { ...@@ -131,6 +131,14 @@ class DockedMagnifierTest : public NoSessionAshTestBase {
gfx::ToFlooredPoint(point_of_interest_in_root_f)); gfx::ToFlooredPoint(point_of_interest_in_root_f));
} }
void TouchPoint(const gfx::Point& touch_point_in_screen) {
// TODO(oshima): Currently touch event doesn't update the
// event dispatcher in the event generator. Fix it and use
// touch event insteead.
auto* generator = GetEventGenerator();
generator->GestureTapAt(touch_point_in_screen);
}
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -446,7 +454,7 @@ TEST_F(DockedMagnifierTest, TouchEvents) { ...@@ -446,7 +454,7 @@ TEST_F(DockedMagnifierTest, TouchEvents) {
// Generate some touch events in both displays and expect the magnifier // Generate some touch events in both displays and expect the magnifier
// viewport moves accordingly. // viewport moves accordingly.
gfx::Point touch_point(200, 350); gfx::Point touch_point(200, 350);
GetEventGenerator()->PressMoveAndReleaseTouchTo(touch_point); TouchPoint(touch_point);
const views::Widget* viewport_widget = const views::Widget* viewport_widget =
controller()->GetViewportWidgetForTesting(); controller()->GetViewportWidgetForTesting();
EXPECT_EQ(root_windows[0], viewport_widget->GetNativeView()->GetRootWindow()); EXPECT_EQ(root_windows[0], viewport_widget->GetNativeView()->GetRootWindow());
...@@ -454,7 +462,8 @@ TEST_F(DockedMagnifierTest, TouchEvents) { ...@@ -454,7 +462,8 @@ TEST_F(DockedMagnifierTest, TouchEvents) {
// Touch a new point in the other display. // Touch a new point in the other display.
touch_point = gfx::Point(900, 200); touch_point = gfx::Point(900, 200);
GetEventGenerator()->PressMoveAndReleaseTouchTo(touch_point); TouchPoint(touch_point);
// New viewport widget is created in the second display. // New viewport widget is created in the second display.
ASSERT_NE(viewport_widget, controller()->GetViewportWidgetForTesting()); ASSERT_NE(viewport_widget, controller()->GetViewportWidgetForTesting());
viewport_widget = controller()->GetViewportWidgetForTesting(); viewport_widget = controller()->GetViewportWidgetForTesting();
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include "ui/aura/client/drag_drop_client.h" #include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/screen_position_client.h"
#include "ui/aura/client/window_types.h" #include "ui/aura/client/window_types.h"
#include "ui/aura/null_window_targeter.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
...@@ -259,6 +260,80 @@ bool ShouldDestroyWindowInCloseChildWindows(aura::Window* window) { ...@@ -259,6 +260,80 @@ bool ShouldDestroyWindowInCloseChildWindows(aura::Window* window) {
return window->owned_by_parent(); return window->owned_by_parent();
} }
class RootWindowTargeter : public aura::WindowTargeter {
public:
RootWindowTargeter() = default;
~RootWindowTargeter() override = default;
protected:
aura::Window* FindTargetForLocatedEvent(aura::Window* window,
ui::LocatedEvent* event) override {
if (!window->parent() && !window->bounds().Contains(event->location()) &&
IsEventInsideDisplayForTelemetryHack(window, event)) {
auto* dispatcher = window->GetHost()->dispatcher();
bool has_capture_target = !!dispatcher->mouse_pressed_handler() ||
!!aura::client::GetCaptureWindow(window);
// Make sure that event location is within the root window bounds if
// 1) mouse event isn't captured.
// 2) A mouse is clicked without movement and capture.
//
// The event can be outside on some scale factor due to rounding, or due
// to not well calibrated a touch screen, or Detect this situation and
// adjust the location.
bool bounded_click = ShouldConstrainMouseClick(event, has_capture_target);
if (!has_capture_target || bounded_click) {
gfx::Point new_location =
FitPointToBounds(event->location(), window->bounds());
// Do not change |location_f|. It's used to compute pixel position and
// such client should know what they're doing.
event->set_location(new_location);
event->set_root_location(new_location);
}
}
return aura::WindowTargeter::FindTargetForLocatedEvent(window, event);
}
// Stop-gap workaround for telemetry tests that send events far outside of the
// display (e.g. 512, -4711). Fix the test and remove this (crbgu.com/904623).
bool IsEventInsideDisplayForTelemetryHack(aura::Window* window,
ui::LocatedEvent* event) {
constexpr int ExtraMarginForTelemetryTest = -10;
gfx::Rect bounds = window->bounds();
bounds.Inset(ExtraMarginForTelemetryTest, ExtraMarginForTelemetryTest);
return bounds.Contains(event->location());
}
private:
// Returns true if the mouse event should be constrainted.
bool ShouldConstrainMouseClick(ui::LocatedEvent* event,
bool has_capture_target) {
if (event->type() == ui::ET_MOUSE_PRESSED && !has_capture_target) {
last_mouse_event_type_ = ui::ET_MOUSE_PRESSED;
return true;
}
if (last_mouse_event_type_ == ui::ET_MOUSE_PRESSED &&
event->type() == ui::ET_MOUSE_RELEASED && has_capture_target) {
last_mouse_event_type_ = ui::ET_UNKNOWN;
return true;
}
// For other cases, reset the state
if (event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)
last_mouse_event_type_ = ui::ET_UNKNOWN;
return false;
}
gfx::Point FitPointToBounds(const gfx::Point p, const gfx::Rect& bounds) {
return gfx::Point(
std::min(std::max(bounds.x(), p.x()), bounds.right() - 1),
std::min(std::max(bounds.y(), p.y()), bounds.bottom() - 1));
}
ui::EventType last_mouse_event_type_ = ui::ET_UNKNOWN;
DISALLOW_COPY_AND_ASSIGN(RootWindowTargeter);
};
} // namespace } // namespace
// static // static
...@@ -429,6 +504,9 @@ const aura::Window* RootWindowController::GetContainer(int container_id) const { ...@@ -429,6 +504,9 @@ const aura::Window* RootWindowController::GetContainer(int container_id) const {
} }
void RootWindowController::Shutdown() { void RootWindowController::Shutdown() {
auto targeter = GetRootWindow()->SetEventTargeter(
std::make_unique<aura::NullWindowTargeter>());
touch_exploration_manager_.reset(); touch_exploration_manager_.reset();
ResetRootForNewWindowsIfNecessary(); ResetRootForNewWindowsIfNecessary();
...@@ -447,6 +525,12 @@ void RootWindowController::Shutdown() { ...@@ -447,6 +525,12 @@ void RootWindowController::Shutdown() {
system_wallpaper_.reset(); system_wallpaper_.reset();
lock_screen_action_background_controller_.reset(); lock_screen_action_background_controller_.reset();
aura::client::SetScreenPositionClient(root_window, nullptr); aura::client::SetScreenPositionClient(root_window, nullptr);
// The targeter may still on the stack, so delete it later.
if (targeter) {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
std::move(targeter));
}
} }
void RootWindowController::CloseChildWindows() { void RootWindowController::CloseChildWindows() {
...@@ -616,6 +700,9 @@ void RootWindowController::Init(RootWindowType root_window_type) { ...@@ -616,6 +700,9 @@ void RootWindowController::Init(RootWindowType root_window_type) {
aura::Window* root_window = GetRootWindow(); aura::Window* root_window = GetRootWindow();
Shell* shell = Shell::Get(); Shell* shell = Shell::Get();
shell->InitRootWindow(root_window); shell->InitRootWindow(root_window);
auto old_targeter =
root_window->SetEventTargeter(std::make_unique<RootWindowTargeter>());
DCHECK(!old_targeter);
CreateContainers(); CreateContainers();
CreateSystemWallpaper(root_window_type); CreateSystemWallpaper(root_window_type);
......
...@@ -748,26 +748,31 @@ TEST_F(VirtualKeyboardRootWindowControllerTest, ...@@ -748,26 +748,31 @@ TEST_F(VirtualKeyboardRootWindowControllerTest,
aura::Window* contents_window = aura::Window* contents_window =
keyboard::KeyboardController::Get()->GetKeyboardWindow(); keyboard::KeyboardController::Get()->GetKeyboardWindow();
contents_window->SetBounds(gfx::Rect());
contents_window->Show(); contents_window->Show();
keyboard::KeyboardController::Get()->ShowKeyboard(false);
// Make sure no pending mouse events in the queue. // Make sure no pending mouse events in the queue.
RunAllPendingInMessageLoop(); RunAllPendingInMessageLoop();
// TODO(oshima|yhanada): This simply make sure that targeting logic works, but
// doesn't mean it'll deliver the event to the target. Fix this to make this
// more reliable.
ui::test::TestEventHandler handler; ui::test::TestEventHandler handler;
root_window->AddPreTargetHandler(&handler); root_window->AddPreTargetHandler(&handler);
ui::test::EventGenerator event_generator(root_window, contents_window); ui::test::EventGenerator event_generator(root_window, contents_window);
event_generator.ClickLeftButton(); event_generator.ClickLeftButton();
int expected_mouse_presses = 1; EXPECT_EQ(2, handler.num_mouse_events());
EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
for (int block_reason = FIRST_BLOCK_REASON; for (int block_reason = FIRST_BLOCK_REASON;
block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) {
SCOPED_TRACE(base::StringPrintf("Reason: %d", block_reason));
BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
handler.Reset();
event_generator.ClickLeftButton(); event_generator.ClickLeftButton();
expected_mouse_presses++; // Click may generate CAPTURE_CHANGED event so make sure it's more than
EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2); // 2 (press,release);
EXPECT_LE(2, handler.num_mouse_events());
UnblockUserSession(); UnblockUserSession();
} }
root_window->RemovePreTargetHandler(&handler); root_window->RemovePreTargetHandler(&handler);
......
...@@ -147,6 +147,17 @@ class ShelfDragCallback { ...@@ -147,6 +147,17 @@ class ShelfDragCallback {
virtual ~ShelfDragCallback() = default; virtual ~ShelfDragCallback() = default;
void ProcessScroll(ui::EventType type, const gfx::Vector2dF& delta) { void ProcessScroll(ui::EventType type, const gfx::Vector2dF& delta) {
ProcessScrollInternal(type, delta, true);
}
void ProcessScrollNoBoundsCheck(ui::EventType type,
const gfx::Vector2dF& delta) {
ProcessScrollInternal(type, delta, false);
}
void ProcessScrollInternal(ui::EventType type,
const gfx::Vector2dF& delta,
bool bounds_check) {
if (GetShelfLayoutManager()->visibility_state() == SHELF_HIDDEN) if (GetShelfLayoutManager()->visibility_state() == SHELF_HIDDEN)
return; return;
...@@ -196,23 +207,30 @@ class ShelfDragCallback { ...@@ -196,23 +207,30 @@ class ShelfDragCallback {
} }
} else { } else {
// The shelf is invisible at the start of the drag. // The shelf is invisible at the start of the drag.
if (increasing_drag) { if (increasing_drag && bounds_check) {
constexpr float kEpsilon = 1.f;
// Moving the shelf into the screen. // Moving the shelf into the screen.
if (std::abs(scroll_delta) < shelf_size) { if (std::abs(scroll_delta) < shelf_size) {
// Tests that the shelf sticks with the touch point during the drag // Tests that the shelf sticks with the touch point during the drag
// until the shelf is completely visible. // until the shelf is completely visible.
if (SHELF_ALIGNMENT_BOTTOM == shelf->alignment()) { if (SHELF_ALIGNMENT_BOTTOM == shelf->alignment()) {
EXPECT_EQ(shelf_bounds.y(), auto_hidden_shelf_bounds_.y() + EXPECT_NEAR(shelf_bounds.y(),
kHiddenShelfInScreenPortion - auto_hidden_shelf_bounds_.y() +
std::abs(scroll_delta)); kHiddenShelfInScreenPortion -
std::abs(scroll_delta),
kEpsilon);
} else if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) { } else if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) {
EXPECT_EQ(shelf_bounds.x(), auto_hidden_shelf_bounds_.x() - EXPECT_NEAR(shelf_bounds.x(),
kHiddenShelfInScreenPortion + auto_hidden_shelf_bounds_.x() -
std::abs(scroll_delta)); kHiddenShelfInScreenPortion +
std::abs(scroll_delta),
kEpsilon);
} else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment()) { } else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment()) {
EXPECT_EQ(shelf_bounds.x(), auto_hidden_shelf_bounds_.x() + EXPECT_NEAR(shelf_bounds.x(),
kHiddenShelfInScreenPortion - auto_hidden_shelf_bounds_.x() +
std::abs(scroll_delta)); kHiddenShelfInScreenPortion -
std::abs(scroll_delta),
kEpsilon);
} }
} else { } else {
// Tests that after the shelf is completely visible, the shelf starts // Tests that after the shelf is completely visible, the shelf starts
...@@ -331,7 +349,14 @@ class ShelfLayoutManagerTest : public AshTestBase { ...@@ -331,7 +349,14 @@ class ShelfLayoutManagerTest : public AshTestBase {
return widget; return widget;
} }
void RunGestureDragTests(gfx::Vector2d); void RunGestureDragTests(const gfx::Point& shown, const gfx::Point& hidden);
gfx::Rect GetVisibleShelfWidgetBoundsInScreen() {
gfx::Rect bounds = GetShelfWidget()->GetWindowBoundsInScreen();
bounds.Intersect(
display::Screen::GetScreen()->GetPrimaryDisplay().bounds());
return bounds;
}
// Turn on the lock screen. // Turn on the lock screen.
void LockScreen() { void LockScreen() {
...@@ -405,7 +430,13 @@ class ShelfLayoutManagerTest : public AshTestBase { ...@@ -405,7 +430,13 @@ class ShelfLayoutManagerTest : public AshTestBase {
DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest); DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest);
}; };
void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { void ShelfLayoutManagerTest::RunGestureDragTests(
const gfx::Point& edge_to_hide,
const gfx::Point& edge_to_show) {
ui::test::EventGenerator* generator = GetEventGenerator();
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
generator->MoveMouseTo(display.bounds().CenterPoint());
Shelf* shelf = GetPrimaryShelf(); Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
...@@ -434,19 +465,17 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -434,19 +465,17 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
layout_manager->LayoutShelf(); layout_manager->LayoutShelf();
ui::test::EventGenerator* generator = GetEventGenerator();
const int kNumScrollSteps = 4; const int kNumScrollSteps = 4;
ShelfDragCallback handler(shelf_hidden, shelf_shown); ShelfDragCallback handler(shelf_hidden, shelf_shown);
// Swipe up on the always shown shelf should not change any state.
gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
gfx::Point end = start + delta;
// Swipe down on the always shown shelf should not auto-hide it. // Swipe down on the always shown shelf should not auto-hide it.
generator->GestureScrollSequenceWithCallback( {
start, end, kTimeDelta, kNumScrollSteps, SCOPED_TRACE("SWIPE_DOWN_ALWAYS_SHOWN");
base::Bind(&ShelfDragCallback::ProcessScroll, generator->GestureScrollSequenceWithCallback(
base::Unretained(&handler))); edge_to_hide, edge_to_show, kTimeDelta, kNumScrollSteps,
base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(window_bounds_with_shelf.ToString(), window->bounds().ToString()); EXPECT_EQ(window_bounds_with_shelf.ToString(), window->bounds().ToString());
...@@ -465,13 +494,15 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -465,13 +494,15 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
// Swiping up should show the shelf if shelf is hidden in fullscreen mode. // Swiping up should show the shelf if shelf is hidden in fullscreen mode.
generator->GestureScrollSequence(end, start, kTimeDelta, kNumScrollSteps); generator->GestureScrollSequence(edge_to_hide, edge_to_show, kTimeDelta,
kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
// Swiping down should hide the shelf. // Swiping down should hide the shelf.
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps); generator->GestureScrollSequence(edge_to_show, edge_to_hide, kTimeDelta,
kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
...@@ -493,10 +524,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -493,10 +524,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Swipe up the auto-hide shelf should show it. // Swipe up the auto-hide shelf should show it.
generator->GestureScrollSequenceWithCallback( {
end, start, kTimeDelta, kNumScrollSteps, SCOPED_TRACE("SWIPE_UP_AUTO_HIDE_SHOW");
base::Bind(&ShelfDragCallback::ProcessScroll, generator->GestureScrollSequenceWithCallback(
base::Unretained(&handler))); edge_to_hide, edge_to_show, kTimeDelta, kNumScrollSteps,
base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Gesture drag should not change the auto hide behavior of shelf, even though // Gesture drag should not change the auto hide behavior of shelf, even though
...@@ -509,14 +543,18 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -509,14 +543,18 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
GetShelfWidget()->GetWindowBoundsInScreen().ToString()); GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe down very little. It shouldn't change any state. // Swipe down very little. It shouldn't change any state.
end = start + delta; gfx::Point new_point(edge_to_show);
gfx::Vector2d diff = edge_to_hide - edge_to_show;
new_point.Offset(diff.x() * 3 / 10, diff.y() * 3 / 10);
/*
if (shelf->IsHorizontalAlignment()) if (shelf->IsHorizontalAlignment())
end.set_y(start.y() + shelf_shown.height() * 3 / 10); end.set_y(start.y() + shelf_shown.height() * 3 / 10);
else if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) else if (SHELF_ALIGNMENT_LEFT == shelf->alignment())
end.set_x(start.x() - shelf_shown.width() * 3 / 10); end.set_x(start.x() - shelf_shown.width() * 3 / 10);
else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment()) else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment())
end.set_x(start.x() + shelf_shown.width() * 3 / 10); end.set_x(start.x() + shelf_shown.width() * 3 / 10);
generator->GestureScrollSequence(start, end, kTimeDelta, 5); */
generator->GestureScrollSequence(edge_to_show, new_point, kTimeDelta, 5);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -524,12 +562,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -524,12 +562,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(shelf_shown.ToString(), EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString()); GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe down to hide the shelf. {
end = start + delta; SCOPED_TRACE("SWIPE_DOWN_AUTO_HIDE_1");
generator->GestureScrollSequenceWithCallback( generator->GestureScrollSequenceWithCallback(
start, end, kTimeDelta, kNumScrollSteps, edge_to_show, edge_to_hide, kTimeDelta, kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll, base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler))); base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -538,7 +577,7 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -538,7 +577,7 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
GetShelfWidget()->GetWindowBoundsInScreen().ToString()); GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe up in extended hit region to show it. // Swipe up in extended hit region to show it.
gfx::Point extended_start = start; gfx::Point extended_start = edge_to_show;
if (shelf->IsHorizontalAlignment()) if (shelf->IsHorizontalAlignment())
extended_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() - 1); extended_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() - 1);
else if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) else if (SHELF_ALIGNMENT_LEFT == shelf->alignment())
...@@ -546,11 +585,14 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -546,11 +585,14 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
1); 1);
else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment()) else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment())
extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1); extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
end = extended_start - delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_UP_EXTENDED_HIT");
extended_start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, extended_start, edge_to_show, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -559,11 +601,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -559,11 +601,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
GetShelfWidget()->GetWindowBoundsInScreen().ToString()); GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe down again to hide. // Swipe down again to hide.
end = start + delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_DOWN_AUTO_HIDE_2");
start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, edge_to_show, edge_to_hide, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -573,31 +617,27 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -573,31 +617,27 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe up outside the hit area. This should not change anything. // Swipe up outside the hit area. This should not change anything.
gfx::Point outside_start = gfx::Point outside_start =
gfx::Point((GetShelfWidget()->GetWindowBoundsInScreen().x() + GetShelfWidget()->GetWindowBoundsInScreen().top_center();
GetShelfWidget()->GetWindowBoundsInScreen().right()) / outside_start.set_y(outside_start.y() - 50);
2, gfx::Vector2d delta = edge_to_hide - edge_to_show;
GetShelfWidget()->GetWindowBoundsInScreen().y() - 50); generator->GestureScrollSequence(outside_start, outside_start + delta,
end = outside_start + delta; kTimeDelta, kNumScrollSteps);
generator->GestureScrollSequence(outside_start, end, kTimeDelta,
kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(window_bounds_with_noshelf.ToString(), window->bounds().ToString()); EXPECT_EQ(window_bounds_with_noshelf.ToString(), window->bounds().ToString());
EXPECT_EQ(shelf_hidden.ToString(), EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString()); GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe up from below the shelf where a bezel would be, this should show the // Swipe up from below the shelf where a bezel would be, this should show the
// shelf. // shelf.
gfx::Point below_start = start; gfx::Point below_start = edge_to_hide;
if (shelf->IsHorizontalAlignment()) if (shelf->IsHorizontalAlignment())
below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1); below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() - 1);
else if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) else if (SHELF_ALIGNMENT_LEFT == shelf->alignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1); below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x());
else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment()) else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1); below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() - 1);
end = below_start - delta; generator->GestureScrollSequence(below_start, edge_to_show, kTimeDelta,
generator->GestureScrollSequence(below_start, end, kTimeDelta,
kNumScrollSteps); kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
...@@ -607,11 +647,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -607,11 +647,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
GetShelfWidget()->GetWindowBoundsInScreen().ToString()); GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe down again to hide. // Swipe down again to hide.
end = start + delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_DOWN_AUTO_HIDE_3");
start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, edge_to_show, edge_to_hide, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -632,11 +674,15 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -632,11 +674,15 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
window_bounds_fullscreen.ToString()); window_bounds_fullscreen.ToString());
// Swipe up. This should show the shelf. // Swipe up. This should show the shelf.
end = below_start - delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_UP_AUTO_HIDE_1");
below_start, end, kTimeDelta, kNumScrollSteps, // Do not check bounds because the events outside of the bounds
base::Bind(&ShelfDragCallback::ProcessScroll, // will be clipped.
base::Unretained(&handler))); generator->GestureScrollSequenceWithCallback(
below_start, edge_to_show, kTimeDelta, kNumScrollSteps,
base::BindRepeating(&ShelfDragCallback::ProcessScrollNoBoundsCheck,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -645,11 +691,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -645,11 +691,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(window_bounds_fullscreen.ToString(), window->bounds().ToString()); EXPECT_EQ(window_bounds_fullscreen.ToString(), window->bounds().ToString());
// Swipe down to hide the shelf. // Swipe down to hide the shelf.
end = start + delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_DOWN_AUTO_HIDE_4");
start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, edge_to_show, edge_to_hide, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -666,14 +714,16 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -666,14 +714,16 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
// Swipe-up. This should not change anything. // Swipe-up. This should not change anything.
end = start - delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_UP_NO_CHANGE");
below_start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, below_start, edge_to_show, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
EXPECT_EQ(window_bounds_fullscreen.ToString(), window->bounds().ToString()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(window_bounds_fullscreen.ToString(), window->bounds().ToString());
}
// Minimize actually, otherwise further event may be affected since widget // Minimize actually, otherwise further event may be affected since widget
// is fullscreen status. // is fullscreen status.
...@@ -688,11 +738,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -688,11 +738,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe-down to hide. This should have no effect because there are no visible // Swipe-down to hide. This should have no effect because there are no visible
// windows. // windows.
end = start + delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_DOWN_AUTO_HIDE_5");
start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, edge_to_show, edge_to_hide, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
...@@ -706,11 +758,15 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -706,11 +758,15 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe up on the shelf. This should show the shelf but should not change the // Swipe up on the shelf. This should show the shelf but should not change the
// auto-hide behavior, since auto-hide behavior can only be changed through // auto-hide behavior, since auto-hide behavior can only be changed through
// context menu of the shelf. // context menu of the shelf.
end = below_start - delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_UP_AUTO_HIDE_2");
below_start, end, kTimeDelta, kNumScrollSteps, // Do not check bounds because the events outside of the bounds
base::Bind(&ShelfDragCallback::ProcessScroll, // will be clipped.
base::Unretained(&handler))); generator->GestureScrollSequenceWithCallback(
below_start, edge_to_show, kTimeDelta, kNumScrollSteps,
base::BindRepeating(&ShelfDragCallback::ProcessScrollNoBoundsCheck,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(), EXPECT_EQ(shelf_shown.ToString(),
...@@ -722,11 +778,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -722,11 +778,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe-down to hide. This should have no effect because there are no visible // Swipe-down to hide. This should have no effect because there are no visible
// windows. // windows.
end = start + delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_DOWN_AUTO_HIDE_6");
start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, edge_to_show, edge_to_hide, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(), EXPECT_EQ(shelf_shown.ToString(),
...@@ -734,11 +792,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -734,11 +792,13 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe up again on AUTO_HIDE_SHOWN shelf shouldn't change any state. // Swipe up again on AUTO_HIDE_SHOWN shelf shouldn't change any state.
// Swipe up on auto-hide shown shelf should still keep shelf shown. // Swipe up on auto-hide shown shelf should still keep shelf shown.
end = start - delta; {
generator->GestureScrollSequenceWithCallback( SCOPED_TRACE("SWIPE_UP_AUTO_HIDE_4");
start, end, kTimeDelta, kNumScrollSteps, generator->GestureScrollSequenceWithCallback(
base::Bind(&ShelfDragCallback::ProcessScroll, edge_to_hide, edge_to_show, kTimeDelta, kNumScrollSteps,
base::Unretained(&handler))); base::BindRepeating(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
}
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(shelf_shown.ToString(), EXPECT_EQ(shelf_shown.ToString(),
...@@ -1541,21 +1601,28 @@ TEST_F(ShelfLayoutManagerTest, GestureDrag) { ...@@ -1541,21 +1601,28 @@ TEST_F(ShelfLayoutManagerTest, GestureDrag) {
{ {
SCOPED_TRACE("BOTTOM"); SCOPED_TRACE("BOTTOM");
shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
RunGestureDragTests(gfx::Vector2d(0, 120)); gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point bottom_center = shelf_bounds.bottom_center();
bottom_center.Offset(0, -1); // Make sure the point is inside shelf.
RunGestureDragTests(bottom_center, shelf_bounds.top_center());
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
} }
{ {
SCOPED_TRACE("LEFT"); SCOPED_TRACE("LEFT");
shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
RunGestureDragTests(gfx::Vector2d(-120, 0)); gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point right_center = shelf_bounds.right_center();
right_center.Offset(-1, 0); // Make sure the point is inside shelf.
RunGestureDragTests(shelf_bounds.left_center(), right_center);
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
} }
{ {
SCOPED_TRACE("RIGHT"); SCOPED_TRACE("RIGHT");
shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
RunGestureDragTests(gfx::Vector2d(120, 0)); gfx::Rect shelf_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point right_center = shelf_bounds.right_center();
right_center.Offset(-1, 0); // Make sure the point is inside shelf.
RunGestureDragTests(right_center, shelf_bounds.left_center());
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
} }
} }
...@@ -1570,9 +1637,7 @@ TEST_F(ShelfLayoutManagerTest, FlingUpOnShelfForFullscreenAppList) { ...@@ -1570,9 +1637,7 @@ TEST_F(ShelfLayoutManagerTest, FlingUpOnShelfForFullscreenAppList) {
// Starts the drag from the center of the shelf's bottom. // Starts the drag from the center of the shelf's bottom.
gfx::Rect shelf_widget_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); gfx::Rect shelf_widget_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
gfx::Point start = gfx::Point start = shelf_widget_bounds.bottom_center();
gfx::Point(shelf_widget_bounds.x() + shelf_widget_bounds.width() / 2,
shelf_widget_bounds.bottom());
// Fling up that exceeds the velocity threshold should show the fullscreen app // Fling up that exceeds the velocity threshold should show the fullscreen app
// list. // list.
...@@ -1701,16 +1766,16 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest, ...@@ -1701,16 +1766,16 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest,
constexpr int kNumScrollSteps = 4; constexpr int kNumScrollSteps = 4;
// Starts the drag from the center of the shelf's bottom. // Starts the drag from the center of the shelf's bottom.
gfx::Rect shelf_widget_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); gfx::Rect shelf_widget_bounds = GetVisibleShelfWidgetBoundsInScreen();
gfx::Point start = gfx::Point shelf_bottom_center =
gfx::Point(shelf_widget_bounds.x() + shelf_widget_bounds.width() / 2, gfx::Point(shelf_widget_bounds.x() + shelf_widget_bounds.width() / 2,
shelf_widget_bounds.bottom()); shelf_widget_bounds.bottom() - 1);
gfx::Vector2d delta; gfx::Point point_to_fullscreen(shelf_bottom_center);
point_to_fullscreen.Offset(
0, -(ShelfLayoutManager::kAppListDragSnapToFullscreenThreshold + 10));
// Swiping up more than the threshold should show the app list. generator->GestureScrollSequence(shelf_bottom_center, point_to_fullscreen,
delta.set_y(ShelfLayoutManager::kAppListDragSnapToFullscreenThreshold + 10); kTimeDelta, kNumScrollSteps);
gfx::Point end = start - delta;
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true); GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState( GetAppListTestHelper()->CheckState(
...@@ -1723,12 +1788,15 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest, ...@@ -1723,12 +1788,15 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest,
GetAppListTestHelper()->CheckState(app_list::AppListViewState::CLOSED); GetAppListTestHelper()->CheckState(app_list::AppListViewState::CLOSED);
// Swiping up less or equal to the threshold should dismiss the app list. // Swiping up less or equal to the threshold should dismiss the app list.
delta.set_y(ShelfLayoutManager::kAppListDragSnapToFullscreenThreshold - 10); gfx::Point point_to_no_fullscreen(shelf_bottom_center);
end = start - delta; point_to_no_fullscreen.Offset(
0, -(ShelfLayoutManager::kAppListDragSnapToFullscreenThreshold - 10));
// TODO(minch): investigate failure without EnableMaximizeMode again here. // TODO(minch): investigate failure without EnableMaximizeMode again here.
// http://crbug.com/746481. // http://crbug.com/746481.
shell->tablet_mode_controller()->EnableTabletModeWindowManager(true); shell->tablet_mode_controller()->EnableTabletModeWindowManager(true);
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps); generator->GestureScrollSequence(shelf_bottom_center, point_to_no_fullscreen,
kTimeDelta, kNumScrollSteps);
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false); GetAppListTestHelper()->CheckVisibility(false);
GetAppListTestHelper()->CheckState(app_list::AppListViewState::CLOSED); GetAppListTestHelper()->CheckState(app_list::AppListViewState::CLOSED);
...@@ -1737,8 +1805,11 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest, ...@@ -1737,8 +1805,11 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest,
// Swiping down on the shelf should do nothing as always shown shelf can not // Swiping down on the shelf should do nothing as always shown shelf can not
// be dragged down to hide. // be dragged down to hide.
end = start + delta; gfx::Point shelf_top_center =
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps); gfx::Point(shelf_widget_bounds.x() + shelf_widget_bounds.width() / 2,
shelf_widget_bounds.y());
generator->GestureScrollSequence(shelf_top_center, shelf_bottom_center,
kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
// Verify that the shelf can still enter auto hide if the window requests to // Verify that the shelf can still enter auto hide if the window requests to
...@@ -1754,7 +1825,8 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest, ...@@ -1754,7 +1825,8 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest,
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
// Swiping up should show the shelf but not the app list if shelf is hidden. // Swiping up should show the shelf but not the app list if shelf is hidden.
generator->GestureScrollSequence(end, start, kTimeDelta, kNumScrollSteps); generator->GestureScrollSequence(shelf_bottom_center, point_to_fullscreen,
kTimeDelta, kNumScrollSteps);
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false); GetAppListTestHelper()->CheckVisibility(false);
GetAppListTestHelper()->CheckState(app_list::AppListViewState::CLOSED); GetAppListTestHelper()->CheckState(app_list::AppListViewState::CLOSED);
...@@ -1763,7 +1835,8 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest, ...@@ -1763,7 +1835,8 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest,
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
// Swiping down should hide the shelf. // Swiping down should hide the shelf.
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps); generator->GestureScrollSequence(shelf_top_center, shelf_bottom_center,
kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
...@@ -1779,9 +1852,8 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest, ...@@ -1779,9 +1852,8 @@ TEST_F(ShelfLayoutManagerNonHomeLauncherTest,
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
// Swiping up on the shelf in this state should open the app list. // Swiping up on the shelf in this state should open the app list.
delta.set_y(ShelfLayoutManager::kAppListDragSnapToFullscreenThreshold + 10); generator->GestureScrollSequence(shelf_bottom_center, point_to_fullscreen,
end = start - delta; kTimeDelta, kNumScrollSteps);
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
GetAppListTestHelper()->WaitUntilIdle(); GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true); GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState( GetAppListTestHelper()->CheckState(
......
...@@ -60,7 +60,7 @@ TEST_F(ScreenshotToolTest, EnablingCaptureRegionCallsDelegateAndDisablesTool) { ...@@ -60,7 +60,7 @@ TEST_F(ScreenshotToolTest, EnablingCaptureRegionCallsDelegateAndDisablesTool) {
EXPECT_CALL(*palette_tool_delegate_.get(), EXPECT_CALL(*palette_tool_delegate_.get(),
DisableTool(PaletteToolId::CAPTURE_REGION)); DisableTool(PaletteToolId::CAPTURE_REGION));
const gfx::Rect selection(100, 200, 300, 400); const gfx::Rect selection(100, 200, 300, 399);
ui::test::EventGenerator* event_generator = GetEventGenerator(); ui::test::EventGenerator* event_generator = GetEventGenerator();
event_generator->EnterPenPointerMode(); event_generator->EnterPenPointerMode();
event_generator->MoveTouch(selection.origin()); event_generator->MoveTouch(selection.origin());
......
...@@ -370,6 +370,8 @@ TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) { ...@@ -370,6 +370,8 @@ TEST_F(ImmersiveFullscreenControllerTest, RevealedLock) {
// Test mouse event processing for top-of-screen reveal triggering. // Test mouse event processing for top-of-screen reveal triggering.
TEST_F(ImmersiveFullscreenControllerTest, OnMouseEvent) { TEST_F(ImmersiveFullscreenControllerTest, OnMouseEvent) {
// Create 2nd display for off screen test.
UpdateDisplay("800x600, 800x600");
// Set up initial state. // Set up initial state.
SetEnabled(true); SetEnabled(true);
ASSERT_TRUE(controller()->IsEnabled()); ASSERT_TRUE(controller()->IsEnabled());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment