Commit f971997e authored by rsadam's avatar rsadam Committed by Commit bot

Fix infinite loop causing iterator to go out of bounds.

BUG=430252

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

Cr-Commit-Position: refs/heads/master@{#302748}
parent 0535571e
...@@ -72,13 +72,11 @@ void VirtualKeyboardController::UpdateDevices() { ...@@ -72,13 +72,11 @@ void VirtualKeyboardController::UpdateDevices() {
// Checks for keyboards. // Checks for keyboards.
has_external_keyboard_ = false; has_external_keyboard_ = false;
has_internal_keyboard_ = false; has_internal_keyboard_ = false;
std::vector<ui::KeyboardDevice> keyboards = for (const ui::KeyboardDevice& device :
device_data_manager->keyboard_devices(); device_data_manager->keyboard_devices()) {
for (auto iter = keyboards.begin(); if (has_internal_keyboard_ && has_external_keyboard_)
iter != keyboards.end() || break;
(has_internal_keyboard_ && has_external_keyboard_); ui::InputDeviceType type = device.type;
++iter) {
ui::InputDeviceType type = (*iter).type;
if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL)
has_internal_keyboard_ = true; has_internal_keyboard_ = true;
if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL) if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)
......
...@@ -185,5 +185,18 @@ TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) { ...@@ -185,5 +185,18 @@ TEST_F(VirtualKeyboardControllerAutoTest, SuppressedIfExternalKeyboardPresent) {
ASSERT_FALSE(IsVirtualKeyboardSuppressed()); ASSERT_FALSE(IsVirtualKeyboardSuppressed());
} }
// Tests handling multiple keyboards. Catches crbug.com/430252
TEST_F(VirtualKeyboardControllerAutoTest, HandleMultipleKeyboardsPresent) {
std::vector<ui::KeyboardDevice> keyboards;
keyboards.push_back(ui::KeyboardDevice(
1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard"));
keyboards.push_back(ui::KeyboardDevice(
2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
keyboards.push_back(ui::KeyboardDevice(
3, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "keyboard"));
UpdateKeyboardDevices(keyboards);
ASSERT_FALSE(keyboard::IsKeyboardEnabled());
}
} // namespace test } // namespace test
} // namespace ash } // 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