Commit 646b208e authored by Ankit Kumar's avatar Ankit Kumar Committed by Commit Bot

Ensure simulated events are only passed on tab/shift-tab

Currently simulated tab events are sent to PDF plugin whenever PDF
plugin is focused. Ensure that simulated tab events are only passed in
case of focus received from tab/shift-tab.

Bug: 989046
Change-Id: I994d401f6896bc7dcb6f41669c38757b52413873
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2224881Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#774976}
parent 3eb5de14
......@@ -2643,21 +2643,28 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabInAndOutOfPDFPlugin) {
content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
ASSERT_TRUE(guest_contents);
// Set focus on PDF document.
ASSERT_TRUE(content::ExecuteScript(
guest_contents, "document.getElementById('plugin').focus();"));
// The script will ensure we return the id of the focused element on focus.
std::string script =
"function onFocus(e) {"
" domAutomationController.send(e.target.id);"
"}"
"const plugin = document.getElementById('plugin');"
"const button = "
"document.getElementById('zoom-toolbar').$['zoom-out-button'];"
"plugin.addEventListener('focus', onFocus);"
"button.addEventListener('focus', onFocus);";
ASSERT_TRUE(content::ExecuteScript(guest_contents, script));
// Set focus on last toolbar element (zoom-out-button).
ASSERT_TRUE(content::ExecuteScript(guest_contents,
R"(document.getElementById('zoom-toolbar')
.$['zoom-out-button']
.$$('cr-icon-button')
.focus();)"));
// The script will ensure we return the the focused element on focus.
const char kScript[] = R"(
const plugin = document.getElementById('plugin');
plugin.addEventListener('focus', () => {
window.domAutomationController.send('plugin');
});
const button = document.getElementById('zoom-toolbar')
.$['zoom-out-button']
.$$('cr-icon-button');
button.addEventListener('focus', () => {
window.domAutomationController.send('zoom-out-button');
});
)";
ASSERT_TRUE(content::ExecuteScript(guest_contents, kScript));
// Helper to simulate a tab press and wait for a focus message.
auto press_tab_and_wait_for_message = [guest_contents](bool reverse) {
......@@ -2669,11 +2676,11 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabInAndOutOfPDFPlugin) {
return reply;
};
// Press <tab> and ensure that PDF document receives focus.
EXPECT_EQ("\"plugin\"", press_tab_and_wait_for_message(false));
// Press <shift-tab> and ensure that last toolbar element (zoom-out-button)
// receives focus.
EXPECT_EQ("\"zoom-out-button\"", press_tab_and_wait_for_message(true));
// Press <tab> and ensure that PDF document receives focus.
EXPECT_EQ("\"plugin\"", press_tab_and_wait_for_message(false));
}
// This test suite does a simple text-extraction based on the accessibility
......
......@@ -221,17 +221,27 @@ void PepperWebPluginImpl::UpdateFocus(bool focused,
instance_->SetWebKitFocus(focused);
if (focused && instance_->SupportsKeyboardFocus()) {
int modifiers = blink::WebInputEvent::kNoModifiers;
if (focus_type == blink::mojom::FocusType::kBackward)
modifiers |= blink::WebInputEvent::kShiftKey;
// As part of focus management for plugin, blink brings plugin to focus
// but does not forward the tab event to plugin. Hence simulating tab
// event here to enable seamless tabbing across UI & plugin.
blink::WebKeyboardEvent simulated_event(
blink::WebInputEvent::Type::kKeyDown, modifiers, base::TimeTicks());
simulated_event.windows_key_code = ui::KeyboardCode::VKEY_TAB;
ui::Cursor cursor;
instance_->HandleInputEvent(simulated_event, &cursor);
switch (focus_type) {
case blink::mojom::FocusType::kForward:
case blink::mojom::FocusType::kBackward: {
int modifiers = blink::WebInputEvent::kNoModifiers;
if (focus_type == blink::mojom::FocusType::kBackward)
modifiers |= blink::WebInputEvent::kShiftKey;
// As part of focus management for plugin, blink brings plugin to
// focus but does not forward the tab event to plugin. Hence
// simulating tab event here to enable seamless tabbing across UI &
// plugin.
blink::WebKeyboardEvent simulated_event(
blink::WebInputEvent::Type::kKeyDown, modifiers,
base::TimeTicks());
simulated_event.windows_key_code = ui::KeyboardCode::VKEY_TAB;
ui::Cursor cursor;
instance_->HandleInputEvent(simulated_event, &cursor);
break;
}
default:
break;
}
}
}
}
......
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