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) { ...@@ -2643,21 +2643,28 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabInAndOutOfPDFPlugin) {
content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
ASSERT_TRUE(guest_contents); ASSERT_TRUE(guest_contents);
// Set focus on PDF document. // Set focus on last toolbar element (zoom-out-button).
ASSERT_TRUE(content::ExecuteScript( ASSERT_TRUE(content::ExecuteScript(guest_contents,
guest_contents, "document.getElementById('plugin').focus();")); R"(document.getElementById('zoom-toolbar')
.$['zoom-out-button']
// The script will ensure we return the id of the focused element on focus. .$$('cr-icon-button')
std::string script = .focus();)"));
"function onFocus(e) {"
" domAutomationController.send(e.target.id);" // The script will ensure we return the the focused element on focus.
"}" const char kScript[] = R"(
"const plugin = document.getElementById('plugin');" const plugin = document.getElementById('plugin');
"const button = " plugin.addEventListener('focus', () => {
"document.getElementById('zoom-toolbar').$['zoom-out-button'];" window.domAutomationController.send('plugin');
"plugin.addEventListener('focus', onFocus);" });
"button.addEventListener('focus', onFocus);";
ASSERT_TRUE(content::ExecuteScript(guest_contents, script)); 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. // Helper to simulate a tab press and wait for a focus message.
auto press_tab_and_wait_for_message = [guest_contents](bool reverse) { auto press_tab_and_wait_for_message = [guest_contents](bool reverse) {
...@@ -2669,11 +2676,11 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabInAndOutOfPDFPlugin) { ...@@ -2669,11 +2676,11 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, TabInAndOutOfPDFPlugin) {
return reply; 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) // Press <shift-tab> and ensure that last toolbar element (zoom-out-button)
// receives focus. // receives focus.
EXPECT_EQ("\"zoom-out-button\"", press_tab_and_wait_for_message(true)); 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 // This test suite does a simple text-extraction based on the accessibility
......
...@@ -221,17 +221,27 @@ void PepperWebPluginImpl::UpdateFocus(bool focused, ...@@ -221,17 +221,27 @@ void PepperWebPluginImpl::UpdateFocus(bool focused,
instance_->SetWebKitFocus(focused); instance_->SetWebKitFocus(focused);
if (focused && instance_->SupportsKeyboardFocus()) { if (focused && instance_->SupportsKeyboardFocus()) {
int modifiers = blink::WebInputEvent::kNoModifiers; switch (focus_type) {
if (focus_type == blink::mojom::FocusType::kBackward) case blink::mojom::FocusType::kForward:
modifiers |= blink::WebInputEvent::kShiftKey; case blink::mojom::FocusType::kBackward: {
// As part of focus management for plugin, blink brings plugin to focus int modifiers = blink::WebInputEvent::kNoModifiers;
// but does not forward the tab event to plugin. Hence simulating tab if (focus_type == blink::mojom::FocusType::kBackward)
// event here to enable seamless tabbing across UI & plugin. modifiers |= blink::WebInputEvent::kShiftKey;
blink::WebKeyboardEvent simulated_event( // As part of focus management for plugin, blink brings plugin to
blink::WebInputEvent::Type::kKeyDown, modifiers, base::TimeTicks()); // focus but does not forward the tab event to plugin. Hence
simulated_event.windows_key_code = ui::KeyboardCode::VKEY_TAB; // simulating tab event here to enable seamless tabbing across UI &
ui::Cursor cursor; // plugin.
instance_->HandleInputEvent(simulated_event, &cursor); 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