Commit a4726f57 authored by chinsenj's avatar chinsenj Committed by Commit Bot

cros: Window cycle event filter checks whether cycle view exists.

With the changes to make the window cycle list more interactive, the
window cycle event filter checks whether mouse events occur within the
window cycle view. However, if the cycle view does not exist, it will
crash.

This CL makes it so IsEventInCycleView() returns false if the cycle
view does not exist.

      MouseEventWhenCycleViewDoesNotExist

Test: InteractiveWindowCycleControllerTest.
Bug: 1067327
Change-Id: I9eae1f60c2a58e5c5e8b3eba751f003249358a77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380551
Commit-Queue: Jeremy Chinsen <chinsenj@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803296}
parent 21946b03
......@@ -123,6 +123,13 @@ class WindowCycleControllerTest : public AshTestBase {
->GetWindowCycleItemViewsForTesting();
}
bool CycleViewExists() const {
return Shell::Get()
->window_cycle_controller()
->window_cycle_list()
->cycle_view_for_testing();
}
private:
std::unique_ptr<ShelfViewTestAPI> shelf_view_test_;
......@@ -597,7 +604,7 @@ TEST_F(WindowCycleControllerTest, MouseEventsCaptured) {
ui::test::EventGenerator* generator = GetEventGenerator();
wm::ActivateWindow(w0.get());
// Events get through.
// Events get through while not cycling.
generator->MoveMouseToCenterOf(w0.get());
generator->ClickLeftButton();
EXPECT_LT(0, event_count.GetMouseEventCountAndReset());
......@@ -606,11 +613,11 @@ TEST_F(WindowCycleControllerTest, MouseEventsCaptured) {
WindowCycleController* controller = Shell::Get()->window_cycle_controller();
controller->HandleCycleWindow(WindowCycleController::FORWARD);
// Most mouse events don't get through.
// Mouse events not over the cycle view don't get through.
generator->PressLeftButton();
EXPECT_EQ(0, event_count.GetMouseEventCountAndReset());
// Although releases do.
// Although releases do, regardless of mouse position.
generator->ReleaseLeftButton();
EXPECT_LT(0, event_count.GetMouseEventCountAndReset());
......@@ -865,6 +872,32 @@ class InteractiveWindowCycleControllerTest : public WindowCycleControllerTest {
base::test::ScopedFeatureList scoped_feature_list_;
};
// Tests that when the cycle view is not open, the event filter does not check
// whether events occur within the cycle view.
// TODO(chinsenj): Add this to WindowCycleControllerTest.MouseEventsCaptured
// after feature launch.
TEST_F(InteractiveWindowCycleControllerTest,
MouseEventWhenCycleViewDoesNotExist) {
aura::test::TestWindowDelegate delegate;
std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 100, 100)));
EventCounter event_count;
w0->AddPreTargetHandler(&event_count);
ui::test::EventGenerator* generator = GetEventGenerator();
WindowCycleController* controller = Shell::Get()->window_cycle_controller();
// Mouse events get through if the cycle view is not open.
// Cycling with one window open ensures the UI doesn't show but the event
// filter is.
controller->HandleCycleWindow(WindowCycleController::FORWARD);
generator->MoveMouseToCenterOf(w0.get());
generator->ClickLeftButton();
EXPECT_TRUE(controller->IsCycling());
EXPECT_FALSE(CycleViewExists());
EXPECT_LT(0, event_count.GetMouseEventCountAndReset());
controller->CompleteCycling();
}
// When a user hovers their mouse over an item, it should cycle to it.
// If a user clicks on an item, it should complete cycling and activate
// the hovered item.
......
......@@ -565,6 +565,9 @@ void WindowCycleList::StepToWindow(aura::Window* window) {
}
bool WindowCycleList::IsEventInCycleView(ui::LocatedEvent* event) {
if (!cycle_view_)
return false;
aura::Window* target = static_cast<aura::Window*>(event->target());
aura::Window* event_root = target->GetRootWindow();
gfx::Point event_screen_point = event->root_location();
......
......@@ -48,7 +48,8 @@ class ASH_EXPORT WindowCycleList : public aura::WindowObserver,
// Skip window cycle list directly to |window|.
void StepToWindow(aura::Window* window);
// Checks whether |event| occurs within the cycle view.
// Checks whether |event| occurs within the cycle view. Returns false if
// |cycle_view_| does not exist.
bool IsEventInCycleView(ui::LocatedEvent* event);
void set_user_did_accept(bool user_did_accept) {
......@@ -90,6 +91,8 @@ class ASH_EXPORT WindowCycleList : public aura::WindowObserver,
// Returns the views for the window cycle list.
const views::View::Views& GetWindowCycleItemViewsForTesting() const;
WindowCycleView* cycle_view_for_testing() const { return cycle_view_; }
// List of weak pointers to windows to use while cycling with the keyboard.
// List is built when the user initiates the gesture (i.e. hits alt-tab the
// first time) and is emptied when the gesture is complete (i.e. releases the
......
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