Fix pressing enter key crashes overview mode without a

selection. 
This change adds a check before trying to select 
the window with the enter key that verifies that the 
selection is active. If it is not, pressing it has no 
effect.

BUG=381811
TEST=WindowSelectorTest.SelectWindowWithReturnKey

Review URL: https://codereview.chromium.org/324493004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275604 0039d316-1c4b-4281-b951-d872f2087c98
parent b63bfd43
......@@ -200,7 +200,6 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
if (event->type() != ui::ET_KEY_PRESSED)
return;
bool handled = true;
switch (event->key_code()) {
case ui::VKEY_ESCAPE:
CancelSelection();
......@@ -218,17 +217,17 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
Move(WindowSelector::LEFT);
break;
case ui::VKEY_RETURN:
wm::GetWindowState(
grid_list_[selected_grid_index_]->
// Ignore if no item is selected.
if (!grid_list_[selected_grid_index_]->is_selecting())
return;
wm::GetWindowState(grid_list_[selected_grid_index_]->
SelectedWindow()->SelectionWindow())->Activate();
break;
default:
// Not a key we are interested in.
handled = false;
break;
return;
}
if (handled)
event->SetHandled();
event->StopPropagation();
}
void WindowSelector::OnDisplayAdded(const gfx::Display& display) {
......
......@@ -861,4 +861,30 @@ TEST_F(WindowSelectorTest, BasicMultiMonitorArrowKeyNavigation) {
EXPECT_EQ(GetSelectedWindow(), window4.get());
}
// Tests selecting a window in overview mode with the return key.
TEST_F(WindowSelectorTest, SelectWindowWithReturnKey) {
gfx::Rect bounds(0, 0, 100, 100);
scoped_ptr<aura::Window> window2(CreateWindow(bounds));
scoped_ptr<aura::Window> window1(CreateWindow(bounds));
ToggleOverview();
// Pressing the return key without a selection widget should not do anything.
SendKey(ui::VKEY_RETURN);
EXPECT_TRUE(IsSelecting());
// Select the first window.
SendKey(ui::VKEY_RIGHT);
SendKey(ui::VKEY_RETURN);
ASSERT_FALSE(IsSelecting());
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
// Select the second window.
ToggleOverview();
SendKey(ui::VKEY_RIGHT);
SendKey(ui::VKEY_RIGHT);
SendKey(ui::VKEY_RETURN);
EXPECT_FALSE(IsSelecting());
EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
}
} // namespace ash
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