Refresh the link under cursor in a PDF when right clicking.
When the user right clicks in the PDF Viewer, the cached link under the cursor may be out of date. Refresh it so Blink can get the correct URL and create the context menu as expected. Along the way, update some test case names in pdfium_engine_unittest.cc to reduce naming redundancy. Bug: 1088296 Change-Id: I1c942d768c4ab1c31e9717bad44ed570697105f0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3782160 Reviewed-by: K. Moon <kmoon@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1028452}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
12d4a6abf0
commit
bbdc42e01a
@ -1363,6 +1363,10 @@ bool PDFiumEngine::OnRightMouseDown(const blink::WebMouseEvent& event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Before examining the selection, first refresh the link. Due to keyboard
|
||||
// events and possibly other events, the saved link info may be stale.
|
||||
UpdateLinkUnderCursor(GetLinkAtPosition(point));
|
||||
|
||||
// Handle the case when focus starts outside a form text area and stays
|
||||
// outside.
|
||||
if (selection_.empty())
|
||||
|
@ -60,6 +60,16 @@ MATCHER_P(LayoutWithOptions, options, "") {
|
||||
return arg.options() == options;
|
||||
}
|
||||
|
||||
blink::WebMouseEvent CreateRightClickWebMouseEventAtPosition(
|
||||
const gfx::PointF& position) {
|
||||
return blink::WebMouseEvent(
|
||||
blink::WebInputEvent::Type::kMouseDown, /*position=*/position,
|
||||
/*global_position=*/position, blink::WebPointerProperties::Button::kRight,
|
||||
/*click_count_param=*/1,
|
||||
blink::WebInputEvent::Modifiers::kRightButtonDown,
|
||||
blink::WebInputEvent::GetStaticTimeStampForTests());
|
||||
}
|
||||
|
||||
class MockTestClient : public TestClient {
|
||||
public:
|
||||
MockTestClient() {
|
||||
@ -800,7 +810,7 @@ class PDFiumEngineTabbingTest : public PDFiumTestBase {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, LinkUnderCursorTest) {
|
||||
TEST_F(PDFiumEngineTabbingTest, LinkUnderCursor) {
|
||||
/*
|
||||
* Document structure
|
||||
* Document
|
||||
@ -845,6 +855,50 @@ TEST_F(PDFiumEngineTabbingTest, LinkUnderCursorTest) {
|
||||
HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kShiftKey));
|
||||
}
|
||||
|
||||
// Test case for crbug.com/1088296
|
||||
TEST_F(PDFiumEngineTabbingTest, LinkUnderCursorAfterTabAndRightClick) {
|
||||
NiceMock<MockTestClient> client;
|
||||
std::unique_ptr<PDFiumEngine> engine =
|
||||
InitializeEngine(&client, FILE_PATH_LITERAL("annots.pdf"));
|
||||
ASSERT_TRUE(engine);
|
||||
|
||||
// Ensure the plugin has a pre-determined size, to enable the hit tests below.
|
||||
engine->PluginSizeUpdated({612, 792});
|
||||
|
||||
// Tab to right before the first non-link annotation.
|
||||
EXPECT_CALL(client, DocumentFocusChanged(true));
|
||||
ASSERT_TRUE(HandleTabEvent(engine.get(), /*modifiers=*/0));
|
||||
|
||||
// Tab through non-link annotations and validate link under cursor.
|
||||
{
|
||||
InSequence sequence;
|
||||
EXPECT_CALL(client, SetLinkUnderCursor(""));
|
||||
EXPECT_CALL(client, DocumentFocusChanged(false));
|
||||
}
|
||||
|
||||
ASSERT_TRUE(HandleTabEvent(engine.get(), /*modifiers=*/0));
|
||||
EXPECT_CALL(client, SetLinkUnderCursor(""));
|
||||
ASSERT_TRUE(HandleTabEvent(engine.get(), /*modifiers=*/0));
|
||||
EXPECT_CALL(client, SetLinkUnderCursor(""));
|
||||
ASSERT_TRUE(HandleTabEvent(engine.get(), /*modifiers=*/0));
|
||||
|
||||
// Tab to Link annotation.
|
||||
EXPECT_CALL(client, SetLinkUnderCursor("https://www.google.com/"));
|
||||
ASSERT_TRUE(HandleTabEvent(engine.get(), /*modifiers=*/0));
|
||||
|
||||
// Right click somewhere far away should reset the link.
|
||||
constexpr gfx::PointF kOffScreenPosition(0, 0);
|
||||
EXPECT_CALL(client, SetLinkUnderCursor(""));
|
||||
EXPECT_FALSE(engine->HandleInputEvent(
|
||||
CreateRightClickWebMouseEventAtPosition(kOffScreenPosition)));
|
||||
|
||||
// Right click on the link should set it again.
|
||||
constexpr gfx::PointF kLinkPosition(170, 595);
|
||||
EXPECT_CALL(client, SetLinkUnderCursor("https://www.google.com/"));
|
||||
EXPECT_FALSE(engine->HandleInputEvent(
|
||||
CreateRightClickWebMouseEventAtPosition(kLinkPosition)));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, TabbingSupportedAnnots) {
|
||||
/*
|
||||
* Document structure
|
||||
@ -901,7 +955,7 @@ TEST_F(PDFiumEngineTabbingTest, TabbingSupportedAnnots) {
|
||||
GetFocusedElementType(engine.get()));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, TabbingForwardTest) {
|
||||
TEST_F(PDFiumEngineTabbingTest, TabbingForward) {
|
||||
/*
|
||||
* Document structure
|
||||
* Document
|
||||
@ -953,7 +1007,7 @@ TEST_F(PDFiumEngineTabbingTest, TabbingForwardTest) {
|
||||
GetFocusedElementType(engine.get()));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, TabbingBackwardTest) {
|
||||
TEST_F(PDFiumEngineTabbingTest, TabbingBackward) {
|
||||
/*
|
||||
* Document structure
|
||||
* Document
|
||||
@ -1063,7 +1117,7 @@ TEST_F(PDFiumEngineTabbingTest, TabbingWithModifiers) {
|
||||
HandleTabEvent(engine.get(), blink::WebInputEvent::Modifiers::kAltKey));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, NoFocusableElementTabbingTest) {
|
||||
TEST_F(PDFiumEngineTabbingTest, NoFocusableElementTabbing) {
|
||||
/*
|
||||
* Document structure
|
||||
* Document
|
||||
@ -1109,7 +1163,7 @@ TEST_F(PDFiumEngineTabbingTest, NoFocusableElementTabbingTest) {
|
||||
GetFocusedElementType(engine.get()));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, RestoringDocumentFocusTest) {
|
||||
TEST_F(PDFiumEngineTabbingTest, RestoringDocumentFocus) {
|
||||
/*
|
||||
* Document structure
|
||||
* Document
|
||||
@ -1154,7 +1208,7 @@ TEST_F(PDFiumEngineTabbingTest, RestoringDocumentFocusTest) {
|
||||
GetFocusedElementType(engine.get()));
|
||||
}
|
||||
|
||||
TEST_F(PDFiumEngineTabbingTest, RestoringAnnotFocusTest) {
|
||||
TEST_F(PDFiumEngineTabbingTest, RestoringAnnotFocus) {
|
||||
/*
|
||||
* Document structure
|
||||
* Document
|
||||
|
Reference in New Issue
Block a user