Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
fpdf_formfill_embeddertest.cpp
Go to the documentation of this file.
1// Copyright 2015 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <vector>
6
7#include "build/build_config.h"
8#include "constants/ascii.h"
9#include "core/fxcrt/fx_coordinates.h"
10#include "core/fxcrt/fx_string.h"
11#include "core/fxcrt/fx_system.h"
12#include "core/fxge/cfx_defaultrenderdevice.h"
13#include "public/cpp/fpdf_scopers.h"
14#include "public/fpdf_formfill.h"
15#include "public/fpdf_fwlevent.h"
16#include "public/fpdf_progressive.h"
17#include "testing/embedder_test.h"
18#include "testing/embedder_test_constants.h"
19#include "testing/embedder_test_mock_delegate.h"
20#include "testing/embedder_test_timer_handling_delegate.h"
21#include "testing/gmock/include/gmock/gmock.h"
22#include "testing/gtest/include/gtest/gtest.h"
23#include "third_party/base/check.h"
24#include "third_party/base/check_op.h"
25
26using pdfium::TextFormChecksum;
27
28using testing::_;
29using testing::InSequence;
30using testing::NiceMock;
31using testing::StrEq;
32
33using FPDFFormFillEmbedderTest = EmbedderTest;
34
35// A base class for many related tests that involve clicking and typing into
36// form fields.
37class FPDFFormFillInteractiveEmbedderTest : public FPDFFormFillEmbedderTest {
38 protected:
41
42 void SetUp() override {
43 FPDFFormFillEmbedderTest::SetUp();
44 ASSERT_TRUE(OpenDocument(GetDocumentName()));
45 page_ = LoadPage(0);
46 ASSERT_TRUE(page_);
48 }
49
51 UnloadPage(page_);
52 FPDFFormFillEmbedderTest::TearDown();
53 }
54
55 // Returns the name of the PDF to use.
56 virtual const char* GetDocumentName() const = 0;
57
58 // Returns the type of field(s) in the PDF.
59 virtual int GetFormType() const = 0;
60
61 // Optionally do some sanity check on the document after loading.
62 virtual void FormSanityChecks() {}
63
64 FPDF_PAGE page() { return page_; }
65
66 int GetFormTypeAtPoint(const CFX_PointF& point) {
67 return FPDFPage_HasFormFieldAtPoint(form_handle(), page_, point.x, point.y);
68 }
69
70 void ClickOnFormFieldAtPoint(const CFX_PointF& point) {
71 // Click on the text field or combobox as specified by coordinates.
72 FORM_OnMouseMove(form_handle(), page_, 0, point.x, point.y);
73 FORM_OnLButtonDown(form_handle(), page_, 0, point.x, point.y);
74 FORM_OnLButtonUp(form_handle(), page_, 0, point.x, point.y);
75 }
76
77 void DoubleClickOnFormFieldAtPoint(const CFX_PointF& point) {
78 // Click on the text field or combobox as specified by coordinates.
79 FORM_OnMouseMove(form_handle(), page_, 0, point.x, point.y);
80 FORM_OnLButtonDoubleClick(form_handle(), page_, 0, point.x, point.y);
81 }
82
83 void TypeTextIntoTextField(int num_chars, const CFX_PointF& point) {
84 EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(point));
86
87 // Type text starting with 'A' to as many chars as specified by |num_chars|.
88 for (int i = 0; i < num_chars; ++i) {
89 FORM_OnChar(form_handle(), page_, 'A' + i, 0);
90 }
91 }
92
93 // Navigates to text field using the mouse and then selects text via the
94 // shift and specfied left or right arrow key.
95 void SelectTextWithKeyboard(int num_chars,
96 int arrow_key,
97 const CFX_PointF& point) {
98 // Navigate to starting position for selection.
100
101 // Hold down shift (and don't release until entire text is selected).
102 FORM_OnKeyDown(form_handle(), page_, FWL_VKEY_Shift, 0);
103
104 // Select text char by char via left or right arrow key.
105 for (int i = 0; i < num_chars; ++i) {
106 FORM_OnKeyDown(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
107 FORM_OnKeyUp(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
108 }
109 FORM_OnKeyUp(form_handle(), page_, FWL_VKEY_Shift, 0);
110 }
111
112 // Uses the mouse to navigate to text field and select text.
113 void SelectTextWithMouse(const CFX_PointF& start, const CFX_PointF& end) {
114 DCHECK_EQ(start.y, end.y);
115
116 // Navigate to starting position and click mouse.
117 FORM_OnMouseMove(form_handle(), page_, 0, start.x, start.y);
118 FORM_OnLButtonDown(form_handle(), page_, 0, start.x, start.y);
119
120 // Hold down mouse until reach end of desired selection.
121 FORM_OnMouseMove(form_handle(), page_, 0, end.x, end.y);
122 FORM_OnLButtonUp(form_handle(), page_, 0, end.x, end.y);
123 }
124
125 void SelectAllTextAtPoint(const CFX_PointF& point) {
126 FocusOnPoint(point);
127 EXPECT_TRUE(FORM_SelectAllText(form_handle(), page_));
128 }
129
130 void CheckSelection(ByteStringView expected_string) {
131 unsigned long actual_len =
132 FORM_GetSelectedText(form_handle(), page_, nullptr, 0);
133 ASSERT_NE(actual_len, 0U);
134 ASSERT_LT(actual_len, 1000U);
135 ASSERT_EQ(actual_len % sizeof(FPDF_WCHAR), 0U);
136
137 std::vector<FPDF_WCHAR> buf(actual_len / sizeof(FPDF_WCHAR));
138 ASSERT_EQ(actual_len, FORM_GetSelectedText(form_handle(), page_, buf.data(),
139 actual_len));
140 EXPECT_EQ(expected_string, ByteStringView(GetPlatformString(buf.data())));
141 }
142
143 void FocusOnPoint(const CFX_PointF& point) {
144 EXPECT_TRUE(FORM_OnFocus(form_handle(), page(), 0, point.x, point.y));
145 }
146
147 void CheckFocusedFieldText(ByteStringView expected_string) {
148 unsigned long actual_len =
149 FORM_GetFocusedText(form_handle(), page_, nullptr, 0);
150 ASSERT_NE(actual_len, 0U);
151 ASSERT_LT(actual_len, 1000U);
152 ASSERT_EQ(actual_len % sizeof(FPDF_WCHAR), 0U);
153
154 std::vector<FPDF_WCHAR> buf(actual_len / sizeof(FPDF_WCHAR));
155 ASSERT_EQ(actual_len, FORM_GetFocusedText(form_handle(), page_, buf.data(),
156 actual_len));
157 EXPECT_EQ(expected_string, ByteStringView(GetPlatformString(buf.data())));
158 }
159
160 void CheckCanUndo(bool expected_result) {
161 EXPECT_EQ(expected_result, !!FORM_CanUndo(form_handle(), page_));
162 }
163
164 void CheckCanRedo(bool expected_result) {
165 EXPECT_EQ(expected_result, !!FORM_CanRedo(form_handle(), page_));
166 }
167
168 void PerformUndo() { EXPECT_TRUE(FORM_Undo(form_handle(), page_)); }
169
170 void PerformRedo() { EXPECT_TRUE(FORM_Redo(form_handle(), page_)); }
171
172 void SetIndexSelectedShouldSucceed(int index, bool selected) {
173 EXPECT_TRUE(FORM_SetIndexSelected(form_handle(), page_, index, selected));
174 }
175
176 void SetIndexSelectedShouldFail(int index, bool selected) {
177 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page_, index, selected));
178 }
179
180 void CheckIsIndexSelected(int index, bool expected) {
181 EXPECT_EQ(expected, FORM_IsIndexSelected(form_handle(), page_, index));
182 }
183
184 private:
185 FPDF_PAGE page_ = nullptr;
186};
187
190 protected:
192 ~FPDFFormFillTextFormEmbedderTest() override = default;
193
194 const char* GetDocumentName() const override {
195 // PDF with several form text fields:
196 // - "Text Box" - Regular text box with no special attributes.
197 // - "ReadOnly" - Ff: 1.
198 // - "CharLimit" - MaxLen: 10, V: Elephant.
199 return "text_form_multiple.pdf";
200 }
201
202 int GetFormType() const override { return FPDF_FORMFIELD_TEXTFIELD; }
203
210
214
218
219 const CFX_PointF& CharLimitFormBegin() const {
220 static const CFX_PointF point = CharLimitFormAtX(kFormBeginX);
221 return point;
222 }
223
224 const CFX_PointF& CharLimitFormEnd() const {
225 static const CFX_PointF point = CharLimitFormAtX(kFormEndX);
226 return point;
227 }
228
229 const CFX_PointF& RegularFormBegin() const {
230 static const CFX_PointF point = RegularFormAtX(kFormBeginX);
231 return point;
232 }
233
234 const CFX_PointF& RegularFormEnd() const {
235 static const CFX_PointF point = RegularFormAtX(kFormEndX);
236 return point;
237 }
238
239 static CFX_PointF CharLimitFormAtX(float x) {
240 DCHECK(x >= kFormBeginX);
241 DCHECK(x <= kFormEndX);
242 return CFX_PointF(x, kCharLimitFormY);
243 }
244
245 static CFX_PointF RegularFormAtX(float x) {
246 DCHECK(x >= kFormBeginX);
247 DCHECK(x <= kFormEndX);
248 return CFX_PointF(x, kRegularFormY);
249 }
250
251 private:
252 static constexpr float kFormBeginX = 102.0;
253 static constexpr float kFormEndX = 195.0;
254 static constexpr float kCharLimitFormY = 60.0;
255 static constexpr float kRegularFormY = 115.0;
256};
257
260 protected:
263
264 const char* GetDocumentName() const override {
265 // PDF with form comboboxes:
266 // - "Combo_Editable" - Ff: 393216, 3 options with pair values.
267 // - "Combo1" - Ff: 131072, 3 options with single values.
268 // - "Combo_ReadOnly" - Ff: 131073, 3 options with single values.
269 return "combobox_form.pdf";
270 }
271
272 int GetFormType() const override { return FPDF_FORMFIELD_COMBOBOX; }
273
282
283 void SelectEditableFormOption(int item_index) {
284 DCHECK(item_index >= 0);
285 DCHECK(item_index < 3);
286 SelectOption(item_index, EditableFormDropDown());
287 }
288
289 void SelectNonEditableFormOption(int item_index) {
290 DCHECK(item_index >= 0);
291 DCHECK(item_index < 26);
292 SelectOption(item_index, NonEditableFormDropDown());
293 }
294
298
300
302
303 const CFX_PointF& EditableFormBegin() const {
304 static const CFX_PointF point = EditableFormAtX(kFormBeginX);
305 return point;
306 }
307
308 const CFX_PointF& EditableFormEnd() const {
309 static const CFX_PointF point = EditableFormAtX(kFormEndX);
310 return point;
311 }
312
313 const CFX_PointF& EditableFormDropDown() const {
314 static const CFX_PointF point(kFormDropDownX, kEditableFormY);
315 return point;
316 }
317
318 const CFX_PointF& NonEditableFormBegin() const {
319 static const CFX_PointF point = NonEditableFormAtX(kFormBeginX);
320 return point;
321 }
322
323 const CFX_PointF& NonEditableFormEnd() const {
324 static const CFX_PointF point = NonEditableFormAtX(kFormEndX);
325 return point;
326 }
327
328 const CFX_PointF& NonEditableFormDropDown() const {
329 static const CFX_PointF point(kFormDropDownX, kNonEditableFormY);
330 return point;
331 }
332
333 static CFX_PointF EditableFormAtX(float x) {
334 DCHECK(x >= kFormBeginX);
335 DCHECK(x <= kFormEndX);
336 return CFX_PointF(x, kEditableFormY);
337 }
338
339 static CFX_PointF NonEditableFormAtX(float x) {
340 DCHECK(x >= kFormBeginX);
341 DCHECK(x <= kFormEndX);
342 return CFX_PointF(x, kNonEditableFormY);
343 }
344
345 private:
346 // Selects one of the pre-selected values from a combobox with three options.
347 // Options are specified by |item_index|, which is 0-based.
348 void SelectOption(int item_index, const CFX_PointF& point) {
349 // Navigate to button for drop down and click mouse to reveal options.
351
352 // Calculate to Y-coordinate of dropdown option to be selected.
353 constexpr double kChoiceHeight = 15;
354 CFX_PointF option_point = point;
355 option_point.y -= kChoiceHeight * (item_index + 1);
356
357 // Move left to avoid scrollbar.
358 option_point.x -= 20;
359
360 // Navigate to option and click mouse to select it.
361 ClickOnFormFieldAtPoint(option_point);
362 }
363
364 static constexpr float kFormBeginX = 102.0;
365 static constexpr float kFormEndX = 183.0;
366 static constexpr float kFormDropDownX = 192.0;
367 static constexpr float kEditableFormY = 360.0;
368 static constexpr float kNonEditableFormY = 410.0;
369};
370
373 protected:
376
377 const char* GetDocumentName() const override {
378 // PDF with form listboxes:
379 // - "Listbox_SingleSelect" - Ff: 0, 3 options with pair values.
380 // - "Listbox_MultiSelect" - Ff: 2097152, 26 options with single values.
381 // - "Listbox_ReadOnly" - Ff: 1, 3 options with single values.
382 // - "Listbox_MultiSelectMultipleIndices" - Ff: 2097152, 5 options with
383 // single values.
384 // - "Listbox_MultiSelectMultipleValues" - same configs as above.
385 // - "Listbox_MultiSelectMultipleMismatch" - same configs as above.
386 // - "Listbox_SingleSelectLastSelected" - Ff: 0, 10 options with single
387 // values.
388 return "listbox_form.pdf";
389 }
390
391 int GetFormType() const override { return FPDF_FORMFIELD_LISTBOX; }
392
426
427 void ClickOnSingleSelectFormOption(int item_index) {
428 // Only the first two indices are visible so can only click on those
429 // without scrolling.
430 DCHECK(item_index >= 0);
431 DCHECK(item_index < 2);
432 if (item_index == 0) {
434 } else {
436 }
437 }
438
439 void ClickOnMultiSelectFormOption(int item_index) {
440 // Only the first two indices are visible so can only click on those
441 // without scrolling.
442 DCHECK(item_index >= 0);
443 DCHECK(item_index < 2);
444 if (item_index == 0) {
446 } else {
448 }
449 }
450
452 // Only two indices are visible so can only click on those
453 // without scrolling.
454 DCHECK(item_index >= 0);
455 DCHECK(item_index < 2);
456 if (item_index == 0) {
458 } else {
460 }
461 }
462
464 // Only two indices are visible so can only click on those
465 // without scrolling.
466 DCHECK(item_index >= 0);
467 DCHECK(item_index < 2);
468 if (item_index == 0) {
470 } else {
472 }
473 }
474
478
482
486
490
494
498
499 void FocusOnPoint(const CFX_PointF& point) {
500 EXPECT_EQ(true, FORM_OnFocus(form_handle(), page(), 0, point.x, point.y));
501 }
502
503 const CFX_PointF& SingleSelectFirstVisibleOption() const {
504 static const CFX_PointF point(kFormBeginX, kSingleFormYFirstVisibleOption);
505 return point;
506 }
507
508 const CFX_PointF& SingleSelectSecondVisibleOption() const {
509 static const CFX_PointF point(kFormBeginX, kSingleFormYSecondVisibleOption);
510 return point;
511 }
512
513 const CFX_PointF& MultiSelectFirstVisibleOption() const {
514 static const CFX_PointF point(kFormBeginX, kMultiFormYFirstVisibleOption);
515 return point;
516 }
517
518 const CFX_PointF& MultiSelectSecondVisibleOption() const {
519 static const CFX_PointF point(kFormBeginX, kMultiFormYSecondVisibleOption);
520 return point;
521 }
522
524 static const CFX_PointF point(kFormBeginX,
525 kMultiFormMultipleIndicesYFirstVisibleOption);
526 return point;
527 }
528
530 static const CFX_PointF point(
531 kFormBeginX, kMultiFormMultipleIndicesYSecondVisibleOption);
532 return point;
533 }
534
536 static const CFX_PointF point(kFormBeginX,
537 kMultiFormMultipleValuesYFirstVisibleOption);
538 return point;
539 }
540
542 static const CFX_PointF point(kFormBeginX,
543 kMultiFormMultipleValuesYSecondVisibleOption);
544 return point;
545 }
546
548 static const CFX_PointF point(
549 kFormBeginX, kMultiFormMultipleMismatchYFirstVisibleOption);
550 return point;
551 }
552
554 static const CFX_PointF point(
555 kFormBeginX, kMultiFormMultipleMismatchYSecondVisibleOption);
556 return point;
557 }
558
560 static const CFX_PointF point(kFormBeginX,
561 kSingleFormLastSelectedYFirstVisibleOption);
562 return point;
563 }
564
566 static const CFX_PointF point(kFormBeginX,
567 kSingleFormLastSelectedYSecondVisibleOption);
568 return point;
569 }
570
571 private:
572 static constexpr float kFormBeginX = 102.0;
573 static constexpr float kSingleFormYFirstVisibleOption = 371.0;
574 static constexpr float kSingleFormYSecondVisibleOption = 358.0;
575 static constexpr float kMultiFormYFirstVisibleOption = 423.0;
576 static constexpr float kMultiFormYSecondVisibleOption = 408.0;
577 static constexpr float kMultiFormMultipleIndicesYFirstVisibleOption = 273.0;
578 static constexpr float kMultiFormMultipleIndicesYSecondVisibleOption = 258.0;
579 static constexpr float kMultiFormMultipleValuesYFirstVisibleOption = 223.0;
580 static constexpr float kMultiFormMultipleValuesYSecondVisibleOption = 208.0;
581 static constexpr float kMultiFormMultipleMismatchYFirstVisibleOption = 173.0;
582 static constexpr float kMultiFormMultipleMismatchYSecondVisibleOption = 158.0;
583 static constexpr float kSingleFormLastSelectedYFirstVisibleOption = 123.0;
584 static constexpr float kSingleFormLastSelectedYSecondVisibleOption = 108.0;
585};
586
594
595TEST_F(FPDFFormFillEmbedderTest, FirstTest) {
597 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
598 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
599 EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
600 EXPECT_CALL(mock, KillTimer(_)).Times(0);
601 EXPECT_CALL(mock, OnFocusChange(_, _, _)).Times(0);
602 EXPECT_CALL(mock, DoURIAction(_)).Times(0);
603 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(_, _, _)).Times(0);
604 EXPECT_CALL(mock, DoGoToAction(_, _, _, _, _)).Times(0);
605 SetDelegate(&mock);
606
607 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
608 FPDF_PAGE page = LoadPage(0);
609 EXPECT_TRUE(page);
610 UnloadPage(page);
611}
612
613TEST_F(FPDFFormFillEmbedderTest, BUG_487928) {
614 EmbedderTestTimerHandlingDelegate delegate;
615 SetDelegate(&delegate);
616
617 ASSERT_TRUE(OpenDocument("bug_487928.pdf"));
618 FPDF_PAGE page = LoadPage(0);
619 EXPECT_TRUE(page);
620 DoOpenActions();
621 delegate.AdvanceTime(5000);
622 UnloadPage(page);
623}
624
625TEST_F(FPDFFormFillEmbedderTest, BUG_507316) {
626 EmbedderTestTimerHandlingDelegate delegate;
627 SetDelegate(&delegate);
628
629 ASSERT_TRUE(OpenDocument("bug_507316.pdf"));
630 FPDF_PAGE page = LoadPage(2);
631 EXPECT_TRUE(page);
632 DoOpenActions();
633 delegate.AdvanceTime(4000);
634 UnloadPage(page);
635}
636
637TEST_F(FPDFFormFillEmbedderTest, BUG_514690) {
638 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
639 FPDF_PAGE page = LoadPage(0);
640 EXPECT_TRUE(page);
641
642 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
643 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
644 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
645
646 UnloadPage(page);
647}
648
649TEST_F(FPDFFormFillEmbedderTest, BUG_900552) {
650 EmbedderTestTimerHandlingDelegate delegate;
651 SetDelegate(&delegate);
652
653 ASSERT_TRUE(OpenDocument("bug_900552.pdf"));
654 FPDF_PAGE page = LoadPage(0);
655 ASSERT_TRUE(page);
656 DoOpenActions();
657 delegate.AdvanceTime(4000);
658
659 // Simulate a repaint.
660 FPDF_BITMAP bitmap = FPDFBitmap_Create(512, 512, 0);
661 ASSERT_TRUE(bitmap);
662 FPDF_RenderPageBitmap_Start(bitmap, page, 0, 0, 512, 512, 0, 0, nullptr);
664 UnloadPage(page);
665}
666
667TEST_F(FPDFFormFillEmbedderTest, BUG_901654) {
668 EmbedderTestTimerHandlingDelegate delegate;
669 SetDelegate(&delegate);
670
671 ASSERT_TRUE(OpenDocument("bug_901654.pdf"));
672 FPDF_PAGE page = LoadPage(0);
673 ASSERT_TRUE(page);
674 DoOpenActions();
675 delegate.AdvanceTime(4000);
676
677 // Simulate a repaint.
678 {
679 ScopedFPDFBitmap bitmap(FPDFBitmap_Create(512, 512, 0));
680 FPDF_RenderPageBitmap_Start(bitmap.get(), page, 0, 0, 512, 512, 0, 0,
681 nullptr);
682 }
683 UnloadPage(page);
684}
685
686TEST_F(FPDFFormFillEmbedderTest, BUG_901654_2) {
687 EmbedderTestTimerHandlingDelegate delegate;
688 SetDelegate(&delegate);
689
690 ASSERT_TRUE(OpenDocument("bug_901654_2.pdf"));
691 FPDF_PAGE page = LoadPage(0);
692 ASSERT_TRUE(page);
693 DoOpenActions();
694 delegate.AdvanceTime(4000);
695
696 // Simulate a repaint.
697 {
698 ScopedFPDFBitmap bitmap(FPDFBitmap_Create(512, 512, 0));
699 FPDF_RenderPageBitmap_Start(bitmap.get(), page, 0, 0, 512, 512, 0, 0,
700 nullptr);
701 }
702 UnloadPage(page);
703}
704
705TEST_F(FPDFFormFillEmbedderTest, GetFocusedAnnotation) {
706 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
707 std::vector<FPDF_PAGE> pages;
708 for (size_t i = 0; i < 3; ++i) {
709 pages.push_back(LoadPage(i));
710 ASSERT_TRUE(pages.back());
711 }
712
713 // Ensure that there is no focused annotation.
714 FPDF_ANNOTATION annot = nullptr;
715 int page_index = -2;
716 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
717 EXPECT_FALSE(annot);
718 EXPECT_EQ(-1, page_index);
719
720 // Validate that nullptr values are handled properly.
721 EXPECT_FALSE(FORM_GetFocusedAnnot(nullptr, &page_index, &annot));
722 EXPECT_FALSE(FORM_GetFocusedAnnot(form_handle(), &page_index, nullptr));
723 EXPECT_FALSE(FORM_GetFocusedAnnot(form_handle(), nullptr, &annot));
724
725 const CFX_PointF right_bottom_annot_point(410.0f, 210.0f);
726 constexpr int kExpectedAnnotIndex = 3;
727
728 for (size_t i = 0; i < pages.size(); ++i) {
729 // Invoke click on the form field to bring it to focus.
730 FORM_OnMouseMove(form_handle(), pages[i], 0, right_bottom_annot_point.x,
731 right_bottom_annot_point.y);
732 FORM_OnLButtonDown(form_handle(), pages[i], 0, right_bottom_annot_point.x,
733 right_bottom_annot_point.y);
734 FORM_OnLButtonUp(form_handle(), pages[i], 0, right_bottom_annot_point.x,
735 right_bottom_annot_point.y);
736
737 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
738 ASSERT_TRUE(annot);
739
740 EXPECT_EQ(kExpectedAnnotIndex, FPDFPage_GetAnnotIndex(pages[i], annot));
741 EXPECT_EQ(static_cast<int>(i), page_index);
742
744 }
745
746 for (FPDF_PAGE page : pages)
747 UnloadPage(page);
748}
749
750TEST_F(FPDFFormFillEmbedderTest, SetFocusedAnnotation) {
751 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
752 std::vector<FPDF_PAGE> pages;
753 for (size_t i = 0; i < 3; ++i) {
754 pages.push_back(LoadPage(i));
755 ASSERT_TRUE(pages.back());
756 }
757
758 // Ensure that there is no focused annotation.
759 FPDF_ANNOTATION annot = nullptr;
760 int page_index = -2;
761 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
762 EXPECT_FALSE(annot);
763 EXPECT_EQ(-1, page_index);
764
765 // Validate that nullptr values are handled properly.
766 EXPECT_FALSE(FORM_SetFocusedAnnot(nullptr, annot));
767 EXPECT_FALSE(FORM_SetFocusedAnnot(form_handle(), nullptr));
768
769 constexpr int kExpectedAnnotIndex = 2;
770
771 for (size_t i = 0; i < pages.size(); ++i) {
772 // Setting focus on an annotation on page i.
773 ScopedFPDFAnnotation focused_annot(
774 FPDFPage_GetAnnot(pages[i], kExpectedAnnotIndex));
775 ASSERT_TRUE(focused_annot);
776
777 ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
778
779 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
780 EXPECT_EQ(kExpectedAnnotIndex, FPDFPage_GetAnnotIndex(pages[i], annot));
781 EXPECT_EQ(static_cast<int>(i), page_index);
782
784 }
785
786 for (FPDF_PAGE page : pages)
787 UnloadPage(page);
788}
789
790TEST_F(FPDFFormFillEmbedderTest, FormFillFirstTab) {
791 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
792 FPDF_PAGE page = LoadPage(0);
793 ASSERT_TRUE(page);
794
795 // Invoking first tab on the page.
796 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
797 int page_index = -2;
798 FPDF_ANNOTATION annot = nullptr;
799 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
800 EXPECT_EQ(0, page_index);
801 ASSERT_TRUE(annot);
802 EXPECT_EQ(1, FPDFPage_GetAnnotIndex(page, annot));
804
805 UnloadPage(page);
806}
807
808TEST_F(FPDFFormFillEmbedderTest, FormFillFirstShiftTab) {
809 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
810 FPDF_PAGE page = LoadPage(0);
811 ASSERT_TRUE(page);
812
813 // Invoking first shift-tab on the page.
814 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
816 int page_index = -2;
817 FPDF_ANNOTATION annot = nullptr;
818 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
819 EXPECT_EQ(0, page_index);
820 ASSERT_TRUE(annot);
821 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
823
824 UnloadPage(page);
825}
826
827TEST_F(FPDFFormFillEmbedderTest, FormFillContinuousTab) {
828 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
829 FPDF_PAGE page = LoadPage(0);
830 ASSERT_TRUE(page);
831
832 static constexpr int kExpectedAnnotIndex[] = {1, 2, 3, 0};
833 // Tabs should iterate focus over annotations.
834 for (size_t i = 0; i < std::size(kExpectedAnnotIndex); ++i) {
835 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
836 int page_index = -2;
837 FPDF_ANNOTATION annot = nullptr;
838 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
839 EXPECT_EQ(0, page_index);
840 ASSERT_TRUE(annot);
841 EXPECT_EQ(kExpectedAnnotIndex[i], FPDFPage_GetAnnotIndex(page, annot));
843 }
844
845 // Tab should not be handled as the last annotation of the page is in focus.
846 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
847
848 UnloadPage(page);
849}
850
851TEST_F(FPDFFormFillEmbedderTest, FormFillContinuousShiftTab) {
852 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
853 FPDF_PAGE page = LoadPage(0);
854 ASSERT_TRUE(page);
855
856 static constexpr int kExpectedAnnotIndex[] = {0, 3, 2, 1};
857 // Shift-tabs should iterate focus over annotations.
858 for (size_t i = 0; i < std::size(kExpectedAnnotIndex); ++i) {
859 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
861 int page_index = -2;
862 FPDF_ANNOTATION annot = nullptr;
863 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
864 EXPECT_EQ(0, page_index);
865 ASSERT_TRUE(annot);
866 EXPECT_EQ(kExpectedAnnotIndex[i], FPDFPage_GetAnnotIndex(page, annot));
868 }
869
870 // Shift-tab should not be handled as the first annotation of the page is in
871 // focus.
872 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
874
875 UnloadPage(page);
876}
877
878TEST_F(FPDFFormFillEmbedderTest, TabWithModifiers) {
879 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
880 FPDF_PAGE page = LoadPage(0);
881 ASSERT_TRUE(page);
882
883 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
885
886 ASSERT_FALSE(
887 FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, FWL_EVENTFLAG_AltKey));
888
889 ASSERT_FALSE(
890 FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
892
893 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
895
896 UnloadPage(page);
897}
898
899TEST_F(FPDFFormFillEmbedderTest, KeyPressWithNoFocusedAnnot) {
900 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
901 FPDF_PAGE page = LoadPage(0);
902 ASSERT_TRUE(page);
903
904 // There should be no focused annotation to start with.
905 int page_index = -2;
906 FPDF_ANNOTATION annot = nullptr;
907 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
908 EXPECT_EQ(-1, page_index);
909 EXPECT_FALSE(annot);
910
911 static constexpr int kKeysToPress[] = {
915 };
916 for (int key : kKeysToPress) {
917 // Pressing random keys when there is no focus should not trigger focus.
918 EXPECT_FALSE(FORM_OnKeyDown(form_handle(), page, key, 0));
919 page_index = -2;
920 annot = nullptr;
921 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
922 EXPECT_EQ(-1, page_index);
923 EXPECT_FALSE(annot);
924 }
925
926 UnloadPage(page);
927}
928
929#ifdef PDF_ENABLE_XFA
930TEST_F(FPDFFormFillEmbedderTest, XFAFormFillFirstTab) {
931 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
932 FPDF_PAGE page = LoadPage(0);
933 ASSERT_TRUE(page);
934
935 // Invoking first tab on the page.
936 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
937
938 UnloadPage(page);
939}
940
941TEST_F(FPDFFormFillEmbedderTest, XFAFormFillFirstShiftTab) {
942 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
943 FPDF_PAGE page = LoadPage(0);
944 ASSERT_TRUE(page);
945
946 // Invoking first shift-tab on the page.
947 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
948 FWL_EVENTFLAG_ShiftKey));
949
950 UnloadPage(page);
951}
952
953TEST_F(FPDFFormFillEmbedderTest, XFAFormFillContinuousTab) {
954 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
955 FPDF_PAGE page = LoadPage(0);
956 ASSERT_TRUE(page);
957
958 // Invoking first tab on the page.
959 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
960
961 // Subsequent tabs should move focus over annotations.
962 for (size_t i = 0; i < 9; ++i)
963 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
964
965 // Tab should not be handled as the last annotation of the page is in focus.
966 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
967
968 UnloadPage(page);
969}
970
971TEST_F(FPDFFormFillEmbedderTest, XFAFormFillContinuousShiftTab) {
972 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
973 FPDF_PAGE page = LoadPage(0);
974 ASSERT_TRUE(page);
975
976 // Invoking first shift-tab on the page.
977 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
978 FWL_EVENTFLAG_ShiftKey));
979
980 // Subsequent shift-tabs should move focus over annotations.
981 for (size_t i = 0; i < 9; ++i) {
982 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
983 FWL_EVENTFLAG_ShiftKey));
984 }
985
986 // Shift-tab should not be handled as the first annotation of the page is in
987 // focus.
988 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
989 FWL_EVENTFLAG_ShiftKey));
990
991 UnloadPage(page);
992}
993#endif // PDF_ENABLE_XFA
994
995class DoURIActionBlockedDelegate final : public EmbedderTest::Delegate {
996 public:
997 void DoURIAction(FPDF_BYTESTRING uri) override {
998 FAIL() << "Navigated to " << uri;
999 }
1000};
1001
1002TEST_F(FPDFFormFillEmbedderTest, BUG_851821) {
1003 DoURIActionBlockedDelegate delegate;
1004 SetDelegate(&delegate);
1005
1006 ASSERT_TRUE(OpenDocument("redirect.pdf"));
1007 FPDF_PAGE page = LoadPage(0);
1008 EXPECT_TRUE(page);
1009 DoOpenActions();
1010
1011 UnloadPage(page);
1012}
1013
1014TEST_F(FPDFFormFillEmbedderTest, CheckReadOnlyInCheckbox) {
1015 EmbedderTestTimerHandlingDelegate delegate;
1016 SetDelegate(&delegate);
1017
1018 ASSERT_TRUE(OpenDocument("click_form.pdf"));
1019 FPDF_PAGE page = LoadPage(0);
1020 ASSERT_TRUE(page);
1021
1022 {
1023 // Check for read-only checkbox.
1024 ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1));
1025 ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
1026
1027 // Shift-tab to the previous control.
1028 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
1030 FPDF_ANNOTATION annot = nullptr;
1031 int page_index = -1;
1032 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
1033 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
1034
1035 // The read-only checkbox is initially in checked state.
1036 EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
1037
1038 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
1039 EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
1040
1041 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
1042 EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
1043
1045 }
1046 UnloadPage(page);
1047}
1048
1049TEST_F(FPDFFormFillEmbedderTest, CheckReadOnlyInRadiobutton) {
1050 EmbedderTestTimerHandlingDelegate delegate;
1051 SetDelegate(&delegate);
1052
1053 ASSERT_TRUE(OpenDocument("click_form.pdf"));
1054 FPDF_PAGE page = LoadPage(0);
1055 ASSERT_TRUE(page);
1056
1057 {
1058 // Check for read-only radio button.
1059 ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1));
1060 ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
1061
1062 // Tab to the next control.
1063 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
1064
1065 FPDF_ANNOTATION annot = nullptr;
1066 int page_index = -1;
1067 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
1068 EXPECT_EQ(2, FPDFPage_GetAnnotIndex(page, annot));
1069 // The read-only radio button is initially in checked state.
1070 EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
1071
1072 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
1073 EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
1074
1075 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
1076 EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
1077
1079 }
1080 UnloadPage(page);
1081}
1082
1083#ifdef PDF_ENABLE_V8
1084TEST_F(FPDFFormFillEmbedderTest, DisableJavaScript) {
1085 // Test that timers and intervals can't fire without JS.
1086 EmbedderTestTimerHandlingDelegate delegate;
1087 SetDelegate(&delegate);
1088
1089 ASSERT_TRUE(OpenDocumentWithoutJavaScript("bug_551248.pdf"));
1090 FPDF_PAGE page = LoadPage(0);
1091 EXPECT_TRUE(page);
1092 DoOpenActions();
1093
1094 const auto& alerts = delegate.GetAlerts();
1095 EXPECT_EQ(0U, alerts.size());
1096
1097 delegate.AdvanceTime(1000);
1098 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1099 delegate.AdvanceTime(1000);
1100 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1101 delegate.AdvanceTime(1000);
1102 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1103 delegate.AdvanceTime(1000);
1104 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1105 delegate.AdvanceTime(1000);
1106 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1107 delegate.AdvanceTime(1000);
1108 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1109 delegate.AdvanceTime(1000);
1110 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1111 UnloadPage(page);
1112}
1113
1114TEST_F(FPDFFormFillEmbedderTest, DocumentAActions) {
1115 EmbedderTestTimerHandlingDelegate delegate;
1116 SetDelegate(&delegate);
1117
1118 ASSERT_TRUE(OpenDocument("document_aactions.pdf"));
1119 FPDF_PAGE page = LoadPage(0);
1120 EXPECT_TRUE(page);
1121
1122 const auto& alerts = delegate.GetAlerts();
1123 EXPECT_EQ(0U, alerts.size());
1124
1125 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WS);
1126 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DS);
1127 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WP);
1128 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DP);
1129 UnloadPage(page);
1130
1131 ASSERT_EQ(4U, alerts.size());
1132 EXPECT_STREQ(L"Will Save", alerts[0].message.c_str());
1133 EXPECT_STREQ(L"Did Save", alerts[1].message.c_str());
1134 EXPECT_STREQ(L"Will Print", alerts[2].message.c_str());
1135 EXPECT_STREQ(L"Did Print", alerts[3].message.c_str());
1136}
1137
1138TEST_F(FPDFFormFillEmbedderTest, DocumentAActionsDisableJavaScript) {
1139 EmbedderTestTimerHandlingDelegate delegate;
1140 SetDelegate(&delegate);
1141
1142 ASSERT_TRUE(OpenDocumentWithoutJavaScript("document_aactions.pdf"));
1143 FPDF_PAGE page = LoadPage(0);
1144 EXPECT_TRUE(page);
1145
1146 const auto& alerts = delegate.GetAlerts();
1147 EXPECT_EQ(0U, alerts.size());
1148
1149 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WS);
1150 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DS);
1151 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WP);
1152 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DP);
1153 UnloadPage(page);
1154
1155 ASSERT_EQ(0U, alerts.size());
1156}
1157
1158TEST_F(FPDFFormFillEmbedderTest, BUG_551248) {
1159 // Test that timers fire once and intervals fire repeatedly.
1160 EmbedderTestTimerHandlingDelegate delegate;
1161 SetDelegate(&delegate);
1162
1163 ASSERT_TRUE(OpenDocument("bug_551248.pdf"));
1164 FPDF_PAGE page = LoadPage(0);
1165 EXPECT_TRUE(page);
1166 DoOpenActions();
1167
1168 const auto& alerts = delegate.GetAlerts();
1169 EXPECT_EQ(0U, alerts.size());
1170
1171 delegate.AdvanceTime(1000);
1172 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1173 delegate.AdvanceTime(1000);
1174 EXPECT_EQ(1U, alerts.size()); // interval fired.
1175 delegate.AdvanceTime(1000);
1176 EXPECT_EQ(2U, alerts.size()); // timer fired.
1177 delegate.AdvanceTime(1000);
1178 EXPECT_EQ(3U, alerts.size()); // interval fired again.
1179 delegate.AdvanceTime(1000);
1180 EXPECT_EQ(3U, alerts.size()); // nothing fired.
1181 delegate.AdvanceTime(1000);
1182 EXPECT_EQ(4U, alerts.size()); // interval fired again.
1183 delegate.AdvanceTime(1000);
1184 EXPECT_EQ(4U, alerts.size()); // nothing fired.
1185 UnloadPage(page);
1186
1187 ASSERT_EQ(4U, alerts.size()); // nothing else fired.
1188
1189 EXPECT_STREQ(L"interval fired", alerts[0].message.c_str());
1190 EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
1191 EXPECT_EQ(0, alerts[0].type);
1192 EXPECT_EQ(0, alerts[0].icon);
1193
1194 EXPECT_STREQ(L"timer fired", alerts[1].message.c_str());
1195 EXPECT_STREQ(L"Alert", alerts[1].title.c_str());
1196 EXPECT_EQ(0, alerts[1].type);
1197 EXPECT_EQ(0, alerts[1].icon);
1198
1199 EXPECT_STREQ(L"interval fired", alerts[2].message.c_str());
1200 EXPECT_STREQ(L"Alert", alerts[2].title.c_str());
1201 EXPECT_EQ(0, alerts[2].type);
1202 EXPECT_EQ(0, alerts[2].icon);
1203
1204 EXPECT_STREQ(L"interval fired", alerts[3].message.c_str());
1205 EXPECT_STREQ(L"Alert", alerts[3].title.c_str());
1206 EXPECT_EQ(0, alerts[3].type);
1207 EXPECT_EQ(0, alerts[3].icon);
1208}
1209
1210TEST_F(FPDFFormFillEmbedderTest, BUG_620428) {
1211 // Test that timers and intervals are cancelable.
1212 EmbedderTestTimerHandlingDelegate delegate;
1213 SetDelegate(&delegate);
1214
1215 ASSERT_TRUE(OpenDocument("bug_620428.pdf"));
1216 FPDF_PAGE page = LoadPage(0);
1217 EXPECT_TRUE(page);
1218 DoOpenActions();
1219 delegate.AdvanceTime(5000);
1220 UnloadPage(page);
1221
1222 const auto& alerts = delegate.GetAlerts();
1223 ASSERT_EQ(1U, alerts.size());
1224 EXPECT_STREQ(L"done", alerts[0].message.c_str());
1225}
1226
1227TEST_F(FPDFFormFillEmbedderTest, BUG_634394) {
1228 // Cancel timer inside timer callback.
1229 EmbedderTestTimerHandlingDelegate delegate;
1230 SetDelegate(&delegate);
1231
1232 ASSERT_TRUE(OpenDocument("bug_634394.pdf"));
1233 FPDF_PAGE page = LoadPage(0);
1234 EXPECT_TRUE(page);
1235 DoOpenActions();
1236
1237 // Timers fire at most once per AdvanceTime(), allow intervals
1238 // to fire several times if possible.
1239 delegate.AdvanceTime(1000);
1240 delegate.AdvanceTime(1000);
1241 delegate.AdvanceTime(1000);
1242 delegate.AdvanceTime(1000);
1243 delegate.AdvanceTime(1000);
1244 UnloadPage(page);
1245
1246 const auto& alerts = delegate.GetAlerts();
1247 EXPECT_EQ(2U, alerts.size());
1248}
1249
1250TEST_F(FPDFFormFillEmbedderTest, BUG_634716) {
1251 EmbedderTestTimerHandlingDelegate delegate;
1252 SetDelegate(&delegate);
1253
1254 ASSERT_TRUE(OpenDocument("bug_634716.pdf"));
1255 FPDF_PAGE page = LoadPage(0);
1256 EXPECT_TRUE(page);
1257 DoOpenActions();
1258
1259 // Timers fire at most once per AdvanceTime(), allow intervals
1260 // to fire several times if possible.
1261 delegate.AdvanceTime(1000);
1262 delegate.AdvanceTime(1000);
1263 delegate.AdvanceTime(1000);
1264 delegate.AdvanceTime(1000);
1265 delegate.AdvanceTime(1000);
1266 UnloadPage(page);
1267
1268 const auto& alerts = delegate.GetAlerts();
1269 EXPECT_EQ(2U, alerts.size());
1270}
1271
1272TEST_F(FPDFFormFillEmbedderTest, BUG_679649) {
1273 EmbedderTestTimerHandlingDelegate delegate;
1274 SetDelegate(&delegate);
1275
1276 ASSERT_TRUE(OpenDocument("bug_679649.pdf"));
1277 FPDF_PAGE page = LoadPage(0);
1278 EXPECT_TRUE(page);
1279
1280 delegate.SetFailNextTimer();
1281 DoOpenActions();
1282 delegate.AdvanceTime(2000);
1283 UnloadPage(page);
1284
1285 const auto& alerts = delegate.GetAlerts();
1286 EXPECT_EQ(0u, alerts.size());
1287}
1288
1289TEST_F(FPDFFormFillEmbedderTest, BUG_707673) {
1290 EmbedderTestTimerHandlingDelegate delegate;
1291 SetDelegate(&delegate);
1292
1293 ASSERT_TRUE(OpenDocument("bug_707673.pdf"));
1294 FPDF_PAGE page = LoadPage(0);
1295 EXPECT_TRUE(page);
1296
1297 DoOpenActions();
1298 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
1299 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
1300 delegate.AdvanceTime(1000);
1301 UnloadPage(page);
1302
1303 const auto& alerts = delegate.GetAlerts();
1304 EXPECT_EQ(0u, alerts.size());
1305}
1306
1307TEST_F(FPDFFormFillEmbedderTest, BUG_765384) {
1308 ASSERT_TRUE(OpenDocument("bug_765384.pdf"));
1309 FPDF_PAGE page = LoadPage(0);
1310 EXPECT_TRUE(page);
1311
1312 DoOpenActions();
1313 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
1314 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
1315 UnloadPage(page);
1316}
1317
1318// Test passes if DCHECK() not hit.
1319TEST_F(FPDFFormFillEmbedderTest, BUG_1477093) {
1320 EmbedderTestTimerHandlingDelegate delegate;
1321 SetDelegate(&delegate);
1322
1323 ASSERT_TRUE(OpenDocument("bug_1477093.pdf"));
1324 FPDF_PAGE page = LoadPage(0);
1325 EXPECT_TRUE(page);
1326
1327 DoOpenActions();
1328 delegate.AdvanceTime(1000);
1329 delegate.AdvanceTime(1000);
1330 UnloadPage(page);
1331}
1332
1333#endif // PDF_ENABLE_V8
1334
1335TEST_F(FPDFFormFillEmbedderTest, FormText) {
1336 const char* focused_text_form_with_abc_checksum = []() {
1337 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1338#if BUILDFLAG(IS_WIN)
1339 return "8b743c7a6186360862ca6f6db8f55c8f";
1340#elif BUILDFLAG(IS_APPLE)
1341 return "d8cf4e7ef7e1c287441bf350006e66d6";
1342#else
1343 return "b9fb2245a98ac48146da84237a37f8cc";
1344#endif
1345 }
1346#if BUILDFLAG(IS_APPLE)
1347 return "9fb14198d75ca0a107060c60ca21b0c7";
1348#else
1349 return "6e6f790bb14c4fc6107faf8c17d23dbd";
1350#endif
1351 }();
1352 const char* unfocused_text_form_with_abc_checksum = []() {
1353 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1354#if BUILDFLAG(IS_WIN)
1355 return "37328bf7614d6fc05b03893ee030aec4";
1356#elif BUILDFLAG(IS_APPLE)
1357 return "b9702814ac50dc5ef413ea2e9c4002f1";
1358#else
1359 return "5f3205f0189d9dde54665f970838f614";
1360#endif
1361 }
1362#if BUILDFLAG(IS_APPLE)
1363 return "3c3209357e0c057a0620afa7d83eb784";
1364#else
1365 return "94b7e10ac8c662b73e33628ca2f5e63b";
1366#endif
1367 }();
1368 {
1369 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1370 FPDF_PAGE page = LoadPage(0);
1371 ASSERT_TRUE(page);
1372 ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page);
1373 CompareBitmap(bitmap1.get(), 300, 300, TextFormChecksum());
1374
1375 // Click on the textfield
1376 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1377 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
1378 EXPECT_EQ(
1379 0, FPDFPage_FormFieldZOrderAtPoint(form_handle(), page, 120.0, 120.0));
1380 FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
1381 FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
1382 FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
1383
1384 // Write "ABC"
1385 FORM_OnChar(form_handle(), page, 'A', 0);
1386 FORM_OnChar(form_handle(), page, 'B', 0);
1387 FORM_OnChar(form_handle(), page, 'C', 0);
1388 ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
1389 CompareBitmap(bitmap2.get(), 300, 300, focused_text_form_with_abc_checksum);
1390
1391 // Focus remains despite right clicking out of the textfield
1392 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
1393 FORM_OnRButtonDown(form_handle(), page, 0, 15.0, 15.0);
1394 FORM_OnRButtonUp(form_handle(), page, 0, 15.0, 15.0);
1395 ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
1396 CompareBitmap(bitmap3.get(), 300, 300, focused_text_form_with_abc_checksum);
1397
1398 // Take out focus by clicking out of the textfield
1399 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
1400 FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
1401 FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
1402 ScopedFPDFBitmap bitmap4 = RenderLoadedPage(page);
1403 CompareBitmap(bitmap4.get(), 300, 300,
1404 unfocused_text_form_with_abc_checksum);
1405
1406 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1407
1408 // Close page
1409 UnloadPage(page);
1410 }
1411 // Check saved document
1412 VerifySavedDocument(300, 300, unfocused_text_form_with_abc_checksum);
1413}
1414
1415// Tests using FPDF_REVERSE_BYTE_ORDER with FPDF_FFLDraw(). The two rendered
1416// bitmaps should be different.
1417TEST_F(FPDFFormFillEmbedderTest, BUG_1281) {
1418 const char* reverse_byte_order_checksum = []() {
1419 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1420 return "8077970bbd10333f18186a9bb459bbe6";
1421 }
1422 return "24fff03d1e663b7ece5f6e69ad837124";
1423 }();
1424
1425 ASSERT_TRUE(OpenDocument("bug_890322.pdf"));
1426 FPDF_PAGE page = LoadPage(0);
1427 ASSERT_TRUE(page);
1428
1429 ScopedFPDFBitmap bitmap_normal = RenderLoadedPage(page);
1430 CompareBitmap(bitmap_normal.get(), 200, 200, pdfium::Bug890322Checksum());
1431
1432 ScopedFPDFBitmap bitmap_reverse_byte_order =
1433 RenderLoadedPageWithFlags(page, FPDF_REVERSE_BYTE_ORDER);
1434 CompareBitmap(bitmap_reverse_byte_order.get(), 200, 200,
1435 reverse_byte_order_checksum);
1436
1437 UnloadPage(page);
1438}
1439
1440TEST_F(FPDFFormFillEmbedderTest, Bug1302455RenderOnly) {
1441 const char* checksum = []() {
1442 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1443 return "520c4415c9977f40d6b4af5a0a94d764";
1444 }
1445 return "bbee92af1daec2340c81f482878744d8";
1446 }();
1447 {
1448 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1449 FPDF_PAGE page = LoadPage(0);
1450 ASSERT_TRUE(page);
1451
1452 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1453 CompareBitmap(bitmap.get(), 300, 300, checksum);
1454
1455 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1456
1457 UnloadPage(page);
1458 }
1459 VerifySavedDocument(300, 300, checksum);
1460}
1461
1462TEST_F(FPDFFormFillEmbedderTest, Bug1302455EditFirstForm) {
1463 const char* checksum = []() {
1464 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1465#if BUILDFLAG(IS_WIN)
1466 return "2e5d64e4280ca954eb528e82f92abb75";
1467#elif BUILDFLAG(IS_APPLE)
1468 return "79538a800f8eb0b4965d43a052303592";
1469#else
1470 return "143c2bb79fcaecf24f5aa104dce27beb";
1471#endif
1472 }
1473#if BUILDFLAG(IS_APPLE)
1474 return "bf5423874f188427d2500a2bc4abebbe";
1475#else
1476 return "6a4ac9a15d2c34589616c8f2b05fbedd";
1477#endif
1478 }();
1479 {
1480 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1481 FPDF_PAGE page = LoadPage(0);
1482 ASSERT_TRUE(page);
1483
1484 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1485 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 110));
1486 FORM_OnMouseMove(form_handle(), page, 0, 110, 110);
1487 FORM_OnLButtonDown(form_handle(), page, 0, 110, 110);
1488 FORM_OnLButtonUp(form_handle(), page, 0, 110, 110);
1489 FORM_OnChar(form_handle(), page, 'A', 0);
1490
1491 FORM_ForceToKillFocus(form_handle());
1492 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1493 CompareBitmap(bitmap.get(), 300, 300, checksum);
1494
1495 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1496
1497 UnloadPage(page);
1498 }
1499 VerifySavedDocument(300, 300, checksum);
1500}
1501
1502TEST_F(FPDFFormFillEmbedderTest, Bug1302455EditSecondForm) {
1503 const char* checksum = []() {
1504 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1505#if BUILDFLAG(IS_WIN)
1506 return "8408fc1796bf17d48b947ed0e4d65ef2";
1507#elif BUILDFLAG(IS_APPLE)
1508 return "074449f4bd27611a2e12aef3ad121cd8";
1509#else
1510 return "e36726414acb616dc203e8851b510e2c";
1511#endif
1512 }
1513#if BUILDFLAG(IS_APPLE)
1514 return "8a0fd8772dba6e1e952e49d159cc64b5";
1515#else
1516 return "45a7694933c2ba3c5dc8f6cc18b79175";
1517#endif
1518 }();
1519 {
1520 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1521 FPDF_PAGE page = LoadPage(0);
1522 ASSERT_TRUE(page);
1523
1524 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1525 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 170));
1526 FORM_OnMouseMove(form_handle(), page, 0, 110, 170);
1527 FORM_OnLButtonDown(form_handle(), page, 0, 110, 170);
1528 FORM_OnLButtonUp(form_handle(), page, 0, 110, 170);
1529 FORM_OnChar(form_handle(), page, 'B', 0);
1530
1531 FORM_ForceToKillFocus(form_handle());
1532 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1533 CompareBitmap(bitmap.get(), 300, 300, checksum);
1534
1535 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1536
1537 UnloadPage(page);
1538 }
1539 VerifySavedDocument(300, 300, checksum);
1540}
1541
1542TEST_F(FPDFFormFillEmbedderTest, Bug1302455EditBothForms) {
1543 const char* checksum = []() {
1544 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1545#if BUILDFLAG(IS_WIN)
1546 return "1c2b618f68d1ad2cfa01fcf38efc4831";
1547#elif BUILDFLAG(IS_APPLE)
1548 return "f5a3b8d2db662cad38b4573ef1dd3f1d";
1549#else
1550 return "f82a807c056e22aa55d3d7228eedfe6f";
1551#endif
1552 }
1553#if BUILDFLAG(IS_APPLE)
1554 return "1f422ee1c520ad74b1a993b64bd4dc4a";
1555#else
1556 return "13984969b1e141079ab5f4aa80185463";
1557#endif
1558 }();
1559 {
1560 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1561 FPDF_PAGE page = LoadPage(0);
1562 ASSERT_TRUE(page);
1563
1564 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1565 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 110));
1566 FORM_OnMouseMove(form_handle(), page, 0, 110, 110);
1567 FORM_OnLButtonDown(form_handle(), page, 0, 110, 110);
1568 FORM_OnLButtonUp(form_handle(), page, 0, 110, 110);
1569 FORM_OnChar(form_handle(), page, 'A', 0);
1570
1571 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1572 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 170));
1573 FORM_OnMouseMove(form_handle(), page, 0, 110, 170);
1574 FORM_OnLButtonDown(form_handle(), page, 0, 110, 170);
1575 FORM_OnLButtonUp(form_handle(), page, 0, 110, 170);
1576 FORM_OnChar(form_handle(), page, 'B', 0);
1577
1578 FORM_ForceToKillFocus(form_handle());
1579 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1580 CompareBitmap(bitmap.get(), 300, 300, checksum);
1581
1582 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1583
1584 UnloadPage(page);
1585 }
1586 VerifySavedDocument(300, 300, checksum);
1587}
1588
1589TEST_F(FPDFFormFillEmbedderTest, RemoveFormFieldHighlight) {
1590 const char* no_highlight_checksum = []() {
1591 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1592#if BUILDFLAG(IS_WIN)
1593 return "2235e2ba8349552de0c818ae53257949";
1594#elif BUILDFLAG(IS_APPLE)
1595 return "e0ad5b4fe007e2e2c27cf6c6fb5b6529";
1596#else
1597 return "3bfddb2529085021ad283b7e65f71525";
1598#endif
1599 }
1600#if BUILDFLAG(IS_APPLE)
1601 return "5c82aa43e3b478aa1e4c94bb9ef1f11f";
1602#else
1603 return "a6268304f7eedfa9ee98fac3caaf2efb";
1604#endif
1605 }();
1606
1607 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1608 FPDF_PAGE page = LoadPage(0);
1609 ASSERT_TRUE(page);
1610 ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page);
1611 CompareBitmap(bitmap1.get(), 300, 300, TextFormChecksum());
1612
1613 // Removing the highlight changes the rendering.
1614 FPDF_RemoveFormFieldHighlight(form_handle());
1615 ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
1616 CompareBitmap(bitmap2.get(), 300, 300, no_highlight_checksum);
1617
1618 // Restoring it gives the original rendering.
1619 SetInitialFormFieldHighlight(form_handle());
1620 ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
1621 CompareBitmap(bitmap3.get(), 300, 300, TextFormChecksum());
1622
1623 UnloadPage(page);
1624}
1625
1626TEST_F(FPDFFormFillEmbedderTest, HasFormInfoNone) {
1627 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
1628 EXPECT_EQ(FORMTYPE_NONE, FPDF_GetFormType(document()));
1629}
1630
1631TEST_F(FPDFFormFillEmbedderTest, HasFormInfoAcroForm) {
1632 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1633 EXPECT_EQ(FORMTYPE_ACRO_FORM, FPDF_GetFormType(document()));
1634}
1635
1636TEST_F(FPDFFormFillEmbedderTest, HasFormInfoXFAFull) {
1637 ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
1638 EXPECT_EQ(FORMTYPE_XFA_FULL, FPDF_GetFormType(document()));
1639}
1640
1641TEST_F(FPDFFormFillEmbedderTest, HasFormInfoXFAForeground) {
1642 ASSERT_TRUE(OpenDocument("bug_216.pdf"));
1643 EXPECT_EQ(FORMTYPE_XFA_FOREGROUND, FPDF_GetFormType(document()));
1644}
1645
1646TEST_F(FPDFFormFillEmbedderTest, BadApiInputsText) {
1647 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1648 FPDF_PAGE page = LoadPage(0);
1649 ASSERT_TRUE(page);
1650
1651 EXPECT_FALSE(FORM_SetIndexSelected(nullptr, nullptr, 0, true));
1652 EXPECT_FALSE(FORM_SetIndexSelected(nullptr, page, 0, true));
1653 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), nullptr, 0, true));
1654 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
1655 EXPECT_FALSE(FORM_IsIndexSelected(nullptr, nullptr, 0));
1656 EXPECT_FALSE(FORM_IsIndexSelected(nullptr, page, 0));
1657 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), nullptr, 0));
1658 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
1659
1660 UnloadPage(page);
1661}
1662
1663TEST_F(FPDFFormFillEmbedderTest, BadApiInputsComboBox) {
1664 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
1665 FPDF_PAGE page = LoadPage(0);
1666 ASSERT_TRUE(page);
1667
1668 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
1669 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, 100, true));
1670 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
1671 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, 100));
1672
1673 UnloadPage(page);
1674}
1675
1676TEST_F(FPDFFormFillEmbedderTest, BadApiInputsListBox) {
1677 ASSERT_TRUE(OpenDocument("listbox_form.pdf"));
1678 FPDF_PAGE page = LoadPage(0);
1679 ASSERT_TRUE(page);
1680
1681 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
1682 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, 100, true));
1683 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
1684 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, 100));
1685
1686 UnloadPage(page);
1687}
1688
1689TEST_F(FPDFFormFillEmbedderTest, HasFormFieldAtPointForXFADoc) {
1690 ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
1691 FPDF_PAGE page = LoadPage(0);
1692 ASSERT_TRUE(page);
1693
1694 EXPECT_EQ(-1, FPDFPage_HasFormFieldAtPoint(form_handle(), page, 612, 792));
1695
1696#ifdef PDF_ENABLE_XFA
1697 constexpr int kExpectedFieldType = FPDF_FORMFIELD_XFA_TEXTFIELD;
1698#else
1699 constexpr int kExpectedFieldType = -1;
1700#endif
1701 EXPECT_EQ(kExpectedFieldType,
1702 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 50, 30));
1703
1704 UnloadPage(page);
1705}
1706
1707TEST_F(FPDFFormFillEmbedderTest, SelectAllText) {
1708 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1709 FPDF_PAGE page = LoadPage(0);
1710 ASSERT_TRUE(page);
1711
1712 // Test bad arguments.
1713 EXPECT_FALSE(FORM_SelectAllText(nullptr, nullptr));
1714 EXPECT_FALSE(FORM_SelectAllText(form_handle(), nullptr));
1715 EXPECT_FALSE(FORM_SelectAllText(nullptr, page));
1716
1717 // Focus on the text field and add some text.
1718 EXPECT_TRUE(FORM_OnFocus(form_handle(), page, 0, 115, 115));
1719 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
1720 FORM_ReplaceSelection(form_handle(), page, text_to_insert.get());
1721
1722 // Sanity check text field data.
1723 uint16_t buffer[6];
1724 ASSERT_EQ(12u, FORM_GetFocusedText(form_handle(), page, nullptr, 0));
1725 ASSERT_EQ(12u,
1726 FORM_GetFocusedText(form_handle(), page, buffer, sizeof(buffer)));
1727 EXPECT_EQ("Hello", GetPlatformString(buffer));
1728
1729 // Check there is no selection.
1730 ASSERT_EQ(2u, FORM_GetSelectedText(form_handle(), page, nullptr, 0));
1731 ASSERT_EQ(2u,
1732 FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer)));
1733 EXPECT_EQ("", GetPlatformString(buffer));
1734
1735 // Check FORM_SelectAllText() works.
1736 EXPECT_TRUE(FORM_SelectAllText(form_handle(), page));
1737 ASSERT_EQ(12u, FORM_GetSelectedText(form_handle(), page, nullptr, 0));
1738 ASSERT_EQ(12u,
1739 FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer)));
1740 EXPECT_EQ("Hello", GetPlatformString(buffer));
1741
1742 UnloadPage(page);
1743}
1744
1746 // Test empty selection.
1747 CheckFocusedFieldText("");
1748 CheckSelection("");
1749
1750 // Test basic selection.
1751 TypeTextIntoTextField(3, RegularFormBegin());
1752 CheckFocusedFieldText("ABC");
1753 SelectTextWithKeyboard(3, FWL_VKEY_Left, RegularFormAtX(123.0));
1754 CheckSelection("ABC");
1755}
1756
1758 // Test empty selection.
1759 CheckFocusedFieldText("");
1760 CheckSelection("");
1761
1762 // Test basic selection.
1763 TypeTextIntoTextField(3, RegularFormBegin());
1764 CheckFocusedFieldText("ABC");
1765 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormBegin());
1766 CheckSelection("ABC");
1767}
1768
1770 TypeTextIntoTextField(12, RegularFormBegin());
1771 CheckFocusedFieldText("ABCDEFGHIJKL");
1772
1773 // Test selecting first character in forward direction.
1774 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
1775 CheckSelection("A");
1776
1777 // Test selecting entire long string in backwards direction.
1778 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
1779 CheckSelection("ABCDEFGHIJKL");
1780
1781 // Test selecting middle section in backwards direction.
1782 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(170.0));
1783 CheckSelection("DEFGHI");
1784
1785 // Test selecting middle selection in forward direction.
1786 SelectTextWithKeyboard(6, FWL_VKEY_Right, RegularFormAtX(125.0));
1787 CheckSelection("DEFGHI");
1788
1789 // Test selecting last character in backwards direction.
1790 SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd());
1791 CheckSelection("L");
1792 CheckFocusedFieldText("ABCDEFGHIJKL");
1793}
1794
1796 TypeTextIntoTextField(12, RegularFormBegin());
1797
1798 // Test selecting first character in forward direction.
1799 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(106.0));
1800 CheckSelection("A");
1801
1802 // Test selecting entire long string in backwards direction.
1803 SelectAllRegularFormTextWithMouse();
1804 CheckSelection("ABCDEFGHIJKL");
1805
1806 // Test selecting middle section in backwards direction.
1807 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
1808 CheckSelection("DEFGHI");
1809
1810 // Test selecting middle selection in forward direction.
1811 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormAtX(170.0));
1812 CheckSelection("DEFGHI");
1813
1814 // Test selecting last character in backwards direction.
1815 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(186.0));
1816 CheckSelection("L");
1817}
1818
1821 // Test empty selection.
1822 CheckSelection("");
1823 CheckFocusedFieldText("");
1824
1825 // Non-editable comboboxes don't allow selection with keyboard.
1826 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(142.0));
1827 CheckFocusedFieldText("Banana");
1828 CheckSelection("Banana");
1829
1830 // Select other another provided option.
1831 SelectNonEditableFormOption(0);
1832 CheckFocusedFieldText("Apple");
1833 CheckSelection("Apple");
1834}
1835
1838 // Test empty selection.
1839 CheckSelection("");
1840 CheckFocusedFieldText("");
1841
1842 // Test basic selection of text within user editable combobox using keyboard.
1843 TypeTextIntoTextField(3, EditableFormBegin());
1844 CheckFocusedFieldText("ABC");
1845 SelectTextWithKeyboard(3, FWL_VKEY_Left, EditableFormAtX(128.0));
1846 CheckSelection("ABC");
1847
1848 // Select a provided option.
1849 SelectEditableFormOption(1);
1850 CheckSelection("Bar");
1851 CheckFocusedFieldText("Bar");
1852}
1853
1856 // Test empty selection.
1857 CheckSelection("");
1858
1859 // Test basic selection of text within user editable combobox using mouse.
1860 TypeTextIntoTextField(3, EditableFormBegin());
1861 SelectTextWithMouse(EditableFormAtX(128.0), EditableFormBegin());
1862 CheckSelection("ABC");
1863
1864 // Select a provided option.
1865 SelectEditableFormOption(2);
1866 CheckFocusedFieldText("Qux");
1867 CheckSelection("Qux");
1868}
1869
1872 CheckFocusedFieldText("");
1873
1874 // Test selecting first character in forward direction.
1875 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(107.0));
1876 CheckFocusedFieldText("Banana");
1877 CheckSelection("B");
1878
1879 // Test selecting entire string in backwards direction.
1880 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormBegin());
1881 CheckSelection("Banana");
1882
1883 // Test selecting middle section in backwards direction.
1884 SelectTextWithMouse(NonEditableFormAtX(135.0), NonEditableFormAtX(117.0));
1885 CheckSelection("nan");
1886
1887 // Test selecting middle section in forward direction.
1888 SelectTextWithMouse(NonEditableFormAtX(117.0), NonEditableFormAtX(135.0));
1889 CheckSelection("nan");
1890
1891 // Test selecting last character in backwards direction.
1892 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormAtX(138.0));
1893 CheckSelection("a");
1894 CheckFocusedFieldText("Banana");
1895
1896 // Select another option and then reset selection as first three chars.
1897 SelectNonEditableFormOption(2);
1898 CheckFocusedFieldText("Cherry");
1899 CheckSelection("Cherry");
1900 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(122.0));
1901 CheckSelection("Che");
1902}
1903
1906 CheckFocusedFieldText("");
1907 TypeTextIntoTextField(10, EditableFormBegin());
1908 CheckFocusedFieldText("ABCDEFGHIJ");
1909
1910 // Test selecting first character in forward direction.
1911 SelectTextWithKeyboard(1, FWL_VKEY_Right, EditableFormBegin());
1912 CheckSelection("A");
1913
1914 // Test selecting entire long string in backwards direction.
1915 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
1916 CheckSelection("ABCDEFGHIJ");
1917
1918 // Test selecting middle section in backwards direction.
1919 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(168.0));
1920 CheckSelection("DEFGH");
1921
1922 // Test selecting middle selection in forward direction.
1923 SelectTextWithKeyboard(5, FWL_VKEY_Right, EditableFormAtX(127.0));
1924 CheckSelection("DEFGH");
1925
1926 // Test selecting last character in backwards direction.
1927 SelectTextWithKeyboard(1, FWL_VKEY_Left, EditableFormEnd());
1928 CheckSelection("J");
1929
1930 // Select a provided option and then reset selection as first two chars.
1931 SelectEditableFormOption(0);
1932 CheckSelection("Foo");
1933 SelectTextWithKeyboard(2, FWL_VKEY_Right, EditableFormBegin());
1934 CheckSelection("Fo");
1935 CheckFocusedFieldText("Foo");
1936}
1937
1940 TypeTextIntoTextField(10, EditableFormBegin());
1941
1942 // Test selecting first character in forward direction.
1943 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(107.0));
1944 CheckSelection("A");
1945
1946 // Test selecting entire long string in backwards direction.
1947 SelectAllEditableFormTextWithMouse();
1948 CheckSelection("ABCDEFGHIJ");
1949
1950 // Test selecting middle section in backwards direction.
1951 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
1952 CheckSelection("DEFGH");
1953
1954 // Test selecting middle selection in forward direction.
1955 SelectTextWithMouse(EditableFormAtX(127.0), EditableFormAtX(168.0));
1956 CheckSelection("DEFGH");
1957
1958 // Test selecting last character in backwards direction.
1959 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(174.0));
1960 CheckSelection("J");
1961 CheckFocusedFieldText("ABCDEFGHIJ");
1962}
1963
1966 // Focus on non-editable form field and check that the value is as expected.
1967 // This is the value that is present in the field upon opening, we have not
1968 // changed it by setting focus.
1969 FocusOnNonEditableForm();
1970 CheckFocusedFieldText("Banana");
1971
1972 // Make selections to change the value of the focused annotation
1973 // programmatically.
1974 SetIndexSelectedShouldSucceed(0, true);
1975 CheckFocusedFieldText("Apple");
1976
1977 // Selecting an index that is already selected is success.
1978 SetIndexSelectedShouldSucceed(0, true);
1979 CheckFocusedFieldText("Apple");
1980
1981 SetIndexSelectedShouldSucceed(9, true);
1982 CheckFocusedFieldText("Jackfruit");
1983
1984 // Cannot deselect a combobox field - value unchanged.
1985 SetIndexSelectedShouldFail(9, false);
1986 CheckFocusedFieldText("Jackfruit");
1987
1988 // Cannot select indices that are out of range - value unchanged.
1989 SetIndexSelectedShouldFail(100, true);
1990 SetIndexSelectedShouldFail(-100, true);
1991 CheckFocusedFieldText("Jackfruit");
1992
1993 // Check that above actions are interchangeable with click actions, should be
1994 // able to use a combination of both.
1995 SelectNonEditableFormOption(1);
1996 CheckFocusedFieldText("Banana");
1997}
1998
2001 // Focus on editable form field and check that the value is as expected.
2002 // This is the value that is present in the field upon opening, we have not
2003 // changed it by setting focus.
2004 FocusOnEditableForm();
2005 CheckFocusedFieldText("");
2006
2007 // Make selections to change value of the focused annotation
2008 // programmatically.
2009 SetIndexSelectedShouldSucceed(0, true);
2010 CheckFocusedFieldText("Foo");
2011
2012 SetIndexSelectedShouldSucceed(1, true);
2013 CheckFocusedFieldText("Bar");
2014
2015 // Selecting an index that is already selected is success.
2016 SetIndexSelectedShouldSucceed(1, true);
2017 CheckFocusedFieldText("Bar");
2018
2019 // Cannot deselect a combobox field - value unchanged.
2020 SetIndexSelectedShouldFail(0, false);
2021 CheckFocusedFieldText("Bar");
2022
2023 // Cannot select indices that are out of range - value unchanged.
2024 SetIndexSelectedShouldFail(100, true);
2025 SetIndexSelectedShouldFail(-100, true);
2026 CheckFocusedFieldText("Bar");
2027
2028 // Check that above actions are interchangeable with click actions, should be
2029 // able to use a combination of both.
2030 SelectEditableFormOption(0);
2031 CheckFocusedFieldText("Foo");
2032
2033 // Check that above actions are interchangeable with typing actions, should
2034 // be able to use a combination of both. Typing text into a text field after
2035 // selecting indices programmatically should be equivalent to doing so after
2036 // a user selects an index via click on the dropdown.
2037 SetIndexSelectedShouldSucceed(1, true);
2038 CheckFocusedFieldText("Bar");
2039 TypeTextIntoTextField(5, EditableFormBegin());
2040 CheckFocusedFieldText("ABCDEBar");
2041}
2042
2045 // Non-editable field is set to 'Banana' (index 1) upon opening.
2046 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2047 for (int i = 0; i < 26; i++) {
2048 bool expected = i == 1;
2049 CheckIsIndexSelected(i, expected);
2050 }
2051
2052 SelectNonEditableFormOption(0);
2053 CheckIsIndexSelected(0, true);
2054 for (int i = 1; i < 26; i++) {
2055 CheckIsIndexSelected(i, false);
2056 }
2057}
2058
2061 // Editable field has nothing selected upon opening.
2062 ClickOnFormFieldAtPoint(EditableFormBegin());
2063 CheckIsIndexSelected(0, false);
2064 CheckIsIndexSelected(1, false);
2065 CheckIsIndexSelected(2, false);
2066
2067 SelectEditableFormOption(0);
2068 CheckIsIndexSelected(0, true);
2069 CheckIsIndexSelected(1, false);
2070 CheckIsIndexSelected(2, false);
2071}
2072
2074 // Select entire contents of text field.
2075 TypeTextIntoTextField(12, RegularFormBegin());
2076 SelectAllRegularFormTextWithMouse();
2077 CheckFocusedFieldText("ABCDEFGHIJKL");
2078 CheckSelection("ABCDEFGHIJKL");
2079
2080 // Test deleting current text selection. Select what remains after deletion to
2081 // check that remaining text is as expected.
2082 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2083 CheckFocusedFieldText("");
2084
2085 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2086 CheckSelection("");
2087}
2088
2090 // Select middle section of text.
2091 TypeTextIntoTextField(12, RegularFormBegin());
2092 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
2093 CheckFocusedFieldText("ABCDEFGHIJKL");
2094 CheckSelection("DEFGHI");
2095
2096 // Test deleting current text selection. Select what remains after deletion to
2097 // check that remaining text is as expected.
2098 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2099 CheckFocusedFieldText("ABCJKL");
2100 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2101 CheckSelection("ABCJKL");
2102}
2103
2105 // Select first few characters of text.
2106 TypeTextIntoTextField(12, RegularFormBegin());
2107 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(132.0));
2108 CheckSelection("ABCD");
2109
2110 // Test deleting current text selection. Select what remains after deletion to
2111 // check that remaining text is as expected.
2112 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2113 CheckFocusedFieldText("EFGHIJKL");
2114 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2115 CheckSelection("EFGHIJKL");
2116}
2117
2119 // Select last few characters of text.
2120 TypeTextIntoTextField(12, RegularFormBegin());
2121 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(165.0));
2122 CheckSelection("IJKL");
2123
2124 // Test deleting current text selection. Select what remains after deletion to
2125 // check that remaining text is as expected.
2126 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2127 CheckFocusedFieldText("ABCDEFGH");
2128 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2129 CheckSelection("ABCDEFGH");
2130}
2131
2133 // Do not select text.
2134 TypeTextIntoTextField(12, RegularFormBegin());
2135 CheckSelection("");
2136
2137 // Test that attempt to delete empty text selection has no effect.
2138 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2139 CheckFocusedFieldText("ABCDEFGHIJKL");
2140 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2141 CheckSelection("ABCDEFGHIJKL");
2142}
2143
2146 // Select entire contents of user-editable combobox text field.
2147 TypeTextIntoTextField(10, EditableFormBegin());
2148 SelectAllEditableFormTextWithMouse();
2149 CheckSelection("ABCDEFGHIJ");
2150
2151 // Test deleting current text selection. Select what remains after deletion to
2152 // check that remaining text is as expected.
2153 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2154 CheckFocusedFieldText("");
2155 SelectAllEditableFormTextWithMouse();
2156 CheckSelection("");
2157}
2158
2161 // Select middle section of text.
2162 TypeTextIntoTextField(10, EditableFormBegin());
2163 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
2164 CheckSelection("DEFGH");
2165
2166 // Test deleting current text selection. Select what remains after deletion to
2167 // check that remaining text is as expected.
2168 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2169 CheckFocusedFieldText("ABCIJ");
2170 SelectAllEditableFormTextWithMouse();
2171 CheckSelection("ABCIJ");
2172}
2173
2176 // Select first few characters of text.
2177 TypeTextIntoTextField(10, EditableFormBegin());
2178 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(132.0));
2179 CheckSelection("ABCD");
2180
2181 // Test deleting current text selection. Select what remains after deletion to
2182 // check that remaining text is as expected.
2183 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2184 SelectAllEditableFormTextWithMouse();
2185 CheckSelection("EFGHIJ");
2186}
2187
2190 // Select last few characters of text.
2191 TypeTextIntoTextField(10, EditableFormBegin());
2192 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(152.0));
2193 CheckSelection("GHIJ");
2194
2195 // Test deleting current text selection. Select what remains after deletion to
2196 // check that remaining text is as expected.
2197 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2198 SelectAllEditableFormTextWithMouse();
2199 CheckSelection("ABCDEF");
2200}
2201
2204 // Do not select text.
2205 TypeTextIntoTextField(10, EditableFormBegin());
2206 CheckSelection("");
2207
2208 // Test that attempt to delete empty text selection has no effect.
2209 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2210 SelectAllEditableFormTextWithMouse();
2211 CheckSelection("ABCDEFGHIJ");
2212}
2213
2215 CheckFocusedFieldText("");
2216 ClickOnFormFieldAtPoint(RegularFormBegin());
2217 CheckFocusedFieldText("");
2218
2219 // Test inserting text into empty text field.
2220 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2221 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2222 CheckFocusedFieldText("Hello");
2223
2224 // Select entire contents of text field to check that insertion worked
2225 // as expected.
2226 CheckSelection("");
2227 SelectAllRegularFormTextWithMouse();
2228 CheckSelection("Hello");
2229}
2230
2232 TypeTextIntoTextField(8, RegularFormBegin());
2233 CheckFocusedFieldText("ABCDEFGH");
2234
2235 // Click on the leftmost part of the text field.
2236 ClickOnFormFieldAtPoint(RegularFormBegin());
2237 CheckFocusedFieldText("ABCDEFGH");
2238
2239 // Test inserting text in front of existing text in text field.
2240 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2241 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2242 CheckFocusedFieldText("HelloABCDEFGH");
2243
2244 // Select entire contents of text field to check that insertion worked
2245 // as expected.
2246 CheckSelection("");
2247 SelectAllRegularFormTextWithMouse();
2248 CheckSelection("HelloABCDEFGH");
2249}
2250
2252 TypeTextIntoTextField(8, RegularFormBegin());
2253
2254 // Click on the middle of the text field.
2255 ClickOnFormFieldAtPoint(RegularFormAtX(134.0));
2256
2257 // Test inserting text in the middle of existing text in text field.
2258 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2259 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2260 CheckFocusedFieldText("ABCDHelloEFGH");
2261
2262 // Select entire contents of text field to check that insertion worked
2263 // as expected.
2264 CheckSelection("");
2265 SelectAllRegularFormTextWithMouse();
2266 CheckSelection("ABCDHelloEFGH");
2267}
2268
2270 TypeTextIntoTextField(8, RegularFormBegin());
2271
2272 // Click on the rightmost part of the text field.
2273 ClickOnFormFieldAtPoint(RegularFormAtX(166.0));
2274
2275 // Test inserting text behind existing text in text field.
2276 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2277 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2278 CheckFocusedFieldText("ABCDEFGHHello");
2279
2280 // Select entire contents of text field to check that insertion worked
2281 // as expected.
2282 CheckSelection("");
2283 SelectAllRegularFormTextWithMouse();
2284 CheckSelection("ABCDEFGHHello");
2285}
2286
2289 TypeTextIntoTextField(12, RegularFormBegin());
2290
2291 // Select entire string in text field.
2292 CheckSelection("");
2293 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2294 CheckSelection("ABCDEFGHIJKL");
2295
2296 // Test replacing text selection with text to be inserted.
2297 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2298 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2299 CheckFocusedFieldText("Hello");
2300
2301 // Select entire contents of text field to check that insertion worked
2302 // as expected.
2303 CheckSelection("");
2304 SelectAllRegularFormTextWithMouse();
2305 CheckSelection("Hello");
2306}
2307
2310 TypeTextIntoTextField(12, RegularFormBegin());
2311
2312 // Select left portion of string in text field.
2313 CheckSelection("");
2314 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(148.0));
2315 CheckSelection("ABCDEF");
2316
2317 // Test replacing text selection with text to be inserted.
2318 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2319 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2320 CheckFocusedFieldText("HelloGHIJKL");
2321
2322 // Select entire contents of text field to check that insertion worked
2323 // as expected.
2324 CheckSelection("");
2325 SelectAllRegularFormTextWithMouse();
2326 CheckSelection("HelloGHIJKL");
2327}
2328
2331 TypeTextIntoTextField(12, RegularFormBegin());
2332
2333 // Select middle portion of string in text field.
2334 CheckSelection("");
2335 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(171.0));
2336 CheckSelection("DEFGHI");
2337
2338 // Test replacing text selection with text to be inserted.
2339 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2340 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2341
2342 // Select entire contents of text field to check that insertion worked
2343 // as expected.
2344 CheckSelection("");
2345 SelectAllRegularFormTextWithMouse();
2346 CheckSelection("ABCHelloJKL");
2347}
2348
2351 TypeTextIntoTextField(12, RegularFormBegin());
2352
2353 // Select right portion of string in text field.
2354 CheckSelection("");
2355 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormEnd());
2356 CheckSelection("GHIJKL");
2357
2358 // Test replacing text selection with text to be inserted.
2359 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2360 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2361
2362 // Select entire contents of text field to check that insertion worked
2363 // as expected.
2364 CheckSelection("");
2365 SelectAllRegularFormTextWithMouse();
2366 CheckSelection("ABCDEFHello");
2367}
2368
2371 ClickOnFormFieldAtPoint(EditableFormBegin());
2372 CheckFocusedFieldText("");
2373
2374 // Test inserting text into empty user-editable combobox.
2375 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2376 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2377 CheckFocusedFieldText("Hello");
2378
2379 // Select entire contents of user-editable combobox text field to check that
2380 // insertion worked as expected.
2381 CheckSelection("");
2382 SelectAllEditableFormTextWithMouse();
2383 CheckSelection("Hello");
2384}
2385
2388 TypeTextIntoTextField(6, EditableFormBegin());
2389
2390 // Click on the leftmost part of the user-editable combobox.
2391 ClickOnFormFieldAtPoint(EditableFormBegin());
2392
2393 // Test inserting text in front of existing text in user-editable combobox.
2394 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2395 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2396
2397 // Select entire contents of user-editable combobox text field to check that
2398 // insertion worked as expected.
2399 CheckSelection("");
2400 SelectAllEditableFormTextWithMouse();
2401 CheckSelection("HelloABCDEF");
2402}
2403
2406 TypeTextIntoTextField(6, EditableFormBegin());
2407
2408 // Click on the middle of the user-editable combobox.
2409 ClickOnFormFieldAtPoint(EditableFormAtX(126.0));
2410
2411 // Test inserting text in the middle of existing text in user-editable
2412 // combobox.
2413 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2414 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2415
2416 // Select entire contents of user-editable combobox text field to check that
2417 // insertion worked as expected.
2418 CheckSelection("");
2419 SelectAllEditableFormTextWithMouse();
2420 CheckSelection("ABCHelloDEF");
2421}
2422
2425 TypeTextIntoTextField(6, EditableFormBegin());
2426
2427 // Click on the rightmost part of the user-editable combobox.
2428 ClickOnFormFieldAtPoint(EditableFormEnd());
2429
2430 // Test inserting text behind existing text in user-editable combobox.
2431 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2432 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2433
2434 // Select entire contents of user-editable combobox text field to check that
2435 // insertion worked as expected.
2436 CheckSelection("");
2437 SelectAllEditableFormTextWithMouse();
2438 CheckSelection("ABCDEFHello");
2439}
2440
2443 TypeTextIntoTextField(10, EditableFormBegin());
2444
2445 // Select entire string in user-editable combobox.
2446 CheckSelection("");
2447 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
2448 CheckSelection("ABCDEFGHIJ");
2449
2450 // Test replacing text selection with text to be inserted.
2451 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2452 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2453
2454 // Select entire contents of user-editable combobox text field to check that
2455 // insertion worked as expected.
2456 CheckSelection("");
2457 SelectAllEditableFormTextWithMouse();
2458 CheckSelection("Hello");
2459}
2460
2463 TypeTextIntoTextField(10, EditableFormBegin());
2464
2465 // Select left portion of string in user-editable combobox.
2466 CheckSelection("");
2467 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(142.0));
2468 CheckSelection("ABCDE");
2469
2470 // Test replacing text selection with text to be inserted.
2471 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2472 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2473
2474 // Select entire contents of user-editable combobox text field to check that
2475 // insertion worked as expected.
2476 CheckSelection("");
2477 SelectAllEditableFormTextWithMouse();
2478 CheckSelection("HelloFGHIJ");
2479}
2480
2483 TypeTextIntoTextField(10, EditableFormBegin());
2484
2485 // Select middle portion of string in user-editable combobox.
2486 CheckSelection("");
2487 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(167.0));
2488 CheckSelection("DEFGH");
2489
2490 // Test replacing text selection with text to be inserted.
2491 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2492 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2493
2494 // Select entire contents of user-editable combobox text field to check that
2495 // insertion worked as expected.
2496 CheckSelection("");
2497 SelectAllEditableFormTextWithMouse();
2498 CheckSelection("ABCHelloIJ");
2499}
2500
2503 TypeTextIntoTextField(10, EditableFormBegin());
2504
2505 // Select right portion of string in user-editable combobox.
2506 CheckSelection("");
2507 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormEnd());
2508 CheckSelection("FGHIJ");
2509
2510 // Test replacing text selection with text to be inserted.
2511 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2512 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2513
2514 // Select entire contents of user-editable combobox text field to check that
2515 // insertion worked as expected.
2516 CheckSelection("");
2517 SelectAllEditableFormTextWithMouse();
2518 CheckSelection("ABCDEHello");
2519}
2520
2523 // Non-editable field is set to 'Banana' (index 1) upon opening.
2524 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2525 CheckIsIndexSelected(0, false);
2526 CheckIsIndexSelected(1, true);
2527
2528 // Verify that the Return character is handled.
2529 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
2530
2531 // Change the selection in the combo-box using the arrow down key.
2532 EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
2533 CheckIsIndexSelected(1, false);
2534 CheckIsIndexSelected(2, true);
2535
2536 // Tab to the next control.
2537 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
2538
2539 // Shift-tab to the previous control.
2540 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
2542
2543 // Verify that the selection is unchanged.
2544 CheckIsIndexSelected(2, true);
2545
2546 // Verify that the Space character is handled.
2547 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kSpace, 0));
2548
2549 // Change the selection in the combo-box using the arrow down key.
2550 EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
2551 CheckIsIndexSelected(3, true);
2552
2553 // Tab to the next control.
2554 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
2555
2556 // Shift-tab to the previous control.
2557 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
2559
2560 // Verify that the selection is unchanged.
2561 CheckIsIndexSelected(3, true);
2562}
2563
2566 // Non-editable field is set to 'Banana' (index 1) upon opening.
2567 ClickOnFormFieldAtPoint(EditableFormBegin());
2568 CheckIsIndexSelected(0, false);
2569 CheckIsIndexSelected(1, false);
2570
2571 // Verify that the Return character is handled.
2572 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
2573
2574 // Change the selection in the combo-box using the arrow down key.
2575 EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
2576 CheckIsIndexSelected(0, true);
2577 CheckIsIndexSelected(1, false);
2578
2579 // Tab to the next control.
2580 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
2581
2582 // Shift-tab to the previous control.
2583 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
2585
2586 // Verify that the selection is unchanged.
2587 CheckIsIndexSelected(0, true);
2588
2589 // Verify that the Space character is handled.
2590 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kSpace, 0));
2591
2592 CheckFocusedFieldText(" ");
2593 CheckIsIndexSelected(0, false);
2594}
2595
2598 // Click on the textfield.
2599 CheckFocusedFieldText("");
2600 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2601 CheckFocusedFieldText("Elephant");
2602
2603 // Delete pre-filled contents of text field with char limit.
2604 CheckSelection("");
2605 SelectAllCharLimitFormTextWithMouse();
2606 CheckSelection("Elephant");
2607 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2608 CheckFocusedFieldText("");
2609
2610 // Test inserting text into now empty text field so text to be inserted
2611 // exceeds the char limit and is cut off.
2612 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2613 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2614 CheckFocusedFieldText("Hippopotam");
2615
2616 // Select entire contents of text field to check that insertion worked
2617 // as expected.
2618 CheckSelection("");
2619 SelectAllCharLimitFormTextWithMouse();
2620 CheckSelection("Hippopotam");
2621}
2622
2625 // Click on the textfield.
2626 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2627 CheckFocusedFieldText("Elephant");
2628
2629 // Delete pre-filled contents of text field with char limit.
2630 CheckSelection("");
2631 SelectAllCharLimitFormTextWithMouse();
2632 CheckSelection("Elephant");
2633 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2634
2635 // Test inserting text into now empty text field so text to be inserted
2636 // exceeds the char limit and is cut off.
2637 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Zebra");
2638 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2639 CheckFocusedFieldText("Zebra");
2640
2641 // Select entire contents of text field to check that insertion worked
2642 // as expected.
2643 CheckSelection("");
2644 SelectAllCharLimitFormTextWithMouse();
2645 CheckSelection("Zebra");
2646}
2647
2650 // Click on the leftmost part of the text field.
2651 ClickOnFormFieldAtPoint(CharLimitFormBegin());
2652
2653 // Test inserting text in front of existing text in text field.
2654 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2655 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2656
2657 // Select entire contents of text field to check that insertion worked
2658 // as expected.
2659 CheckSelection("");
2660 SelectAllCharLimitFormTextWithMouse();
2661 CheckSelection("HiElephant");
2662}
2663
2666 CheckFocusedFieldText("");
2667 TypeTextIntoTextField(8, RegularFormBegin());
2668 CheckFocusedFieldText("ABCDEFGH");
2669
2670 // Click on the middle of the text field.
2671 ClickOnFormFieldAtPoint(CharLimitFormAtX(134.0));
2672 CheckFocusedFieldText("Elephant");
2673
2674 // Test inserting text in the middle of existing text in text field.
2675 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2676 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2677 CheckFocusedFieldText("ElephHiant");
2678
2679 // Select entire contents of text field to check that insertion worked
2680 // as expected.
2681 CheckSelection("");
2682 SelectAllCharLimitFormTextWithMouse();
2683 CheckSelection("ElephHiant");
2684}
2685
2688 TypeTextIntoTextField(8, RegularFormBegin());
2689
2690 // Click on the rightmost part of the text field.
2691 ClickOnFormFieldAtPoint(CharLimitFormAtX(166.0));
2692
2693 // Test inserting text behind existing text in text field.
2694 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2695 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2696
2697 // Select entire contents of text field to check that insertion worked
2698 // as expected.
2699 CheckSelection("");
2700 SelectAllCharLimitFormTextWithMouse();
2701 CheckSelection("ElephantHi");
2702}
2703
2706 TypeTextIntoTextField(12, RegularFormBegin());
2707
2708 // Select entire string in text field.
2709 CheckSelection("");
2710 SelectTextWithKeyboard(12, FWL_VKEY_Left, CharLimitFormEnd());
2711 CheckSelection("Elephant");
2712
2713 // Test replacing text selection with text to be inserted.
2714 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2715 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2716
2717 // Select entire contents of text field to check that insertion worked
2718 // as expected.
2719 CheckSelection("");
2720 SelectAllCharLimitFormTextWithMouse();
2721 CheckSelection("Hippopotam");
2722}
2723
2726 TypeTextIntoTextField(12, RegularFormBegin());
2727
2728 // Select left portion of string in text field.
2729 CheckSelection("");
2730 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(122.0));
2731 CheckSelection("Elep");
2732
2733 // Test replacing text selection with text to be inserted.
2734 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2735 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2736
2737 // Select entire contents of text field to check that insertion worked
2738 // as expected.
2739 CheckSelection("");
2740 SelectAllCharLimitFormTextWithMouse();
2741 CheckSelection("Hippophant");
2742}
2743
2746 TypeTextIntoTextField(12, RegularFormBegin());
2747
2748 // Select middle portion of string in text field.
2749 CheckSelection("");
2750 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(136.0));
2751 CheckSelection("epha");
2752
2753 // Test replacing text selection with text to be inserted.
2754 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2755 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2756
2757 // Select entire contents of text field to check that insertion worked
2758 // as expected.
2759 CheckSelection("");
2760 SelectAllCharLimitFormTextWithMouse();
2761 CheckSelection("ElHippopnt");
2762}
2763
2766 TypeTextIntoTextField(12, RegularFormBegin());
2767
2768 // Select right portion of string in text field.
2769 CheckSelection("");
2770 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(152.0));
2771 CheckSelection("hant");
2772
2773 // Test replacing text selection with text to be inserted.
2774 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2775 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2776
2777 // Select entire contents of text field to check that insertion worked
2778 // as expected.
2779 CheckSelection("");
2780 SelectAllCharLimitFormTextWithMouse();
2781 CheckSelection("ElepHippop");
2782}
2783
2785 CheckFocusedFieldText("");
2786 ClickOnFormFieldAtPoint(RegularFormBegin());
2787 CheckFocusedFieldText("");
2788
2789 // Test inserting text into empty text field.
2790 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello World");
2791 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2792 CheckFocusedFieldText("Hello World");
2793
2794 // Make sure double clicking selects the entire line.
2795 CheckSelection("");
2796 DoubleClickOnFormFieldAtPoint(RegularFormBegin());
2797 CheckSelection("Hello World");
2798}
2799
2801 testing::NiceMock<EmbedderTestMockDelegate> mock;
2802 SetDelegate(&mock);
2803 CheckFocusedFieldText("");
2804
2805#ifdef PDF_ENABLE_XFA
2806 EXPECT_CALL(mock, OnFocusChange(_, _, 0)).Times(1);
2807#else // PDF_ENABLE_XFA
2808 EXPECT_CALL(mock, OnFocusChange(_, _, 0)).Times(0);
2809#endif // PDF_ENABLE_XFA
2810
2811 ClickOnFormFieldAtPoint(RegularFormBegin());
2812}
2813
2816 testing::NiceMock<EmbedderTestMockDelegate> mock;
2817 SetDelegate(&mock);
2818 CheckFocusedFieldText("");
2819
2820 EXPECT_CALL(mock, OnFocusChange(_, _, 0)).Times(1);
2821 ClickOnFormFieldAtPoint(RegularFormBegin());
2822}
2823
2825 static const CFX_PointF kNonFormPoint(1, 1);
2826 CheckFocusedFieldText("");
2827 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2828 CheckFocusedFieldText("Elephant");
2829 ClickOnFormFieldAtPoint(RegularFormBegin());
2830 CheckFocusedFieldText("");
2831 TypeTextIntoTextField(3, CharLimitFormBegin());
2832 CheckFocusedFieldText("ABElephant");
2833 TypeTextIntoTextField(5, RegularFormBegin());
2834 CheckFocusedFieldText("ABCDE");
2835 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2836 CheckFocusedFieldText("ABElephant");
2837 ClickOnFormFieldAtPoint(kNonFormPoint);
2838 CheckFocusedFieldText("");
2839 ClickOnFormFieldAtPoint(kNonFormPoint);
2840 CheckFocusedFieldText("");
2841 ClickOnFormFieldAtPoint(CharLimitFormBegin());
2842 CheckFocusedFieldText("ABElephant");
2843 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2844 CheckFocusedFieldText("ABElephant");
2845 ClickOnFormFieldAtPoint(RegularFormEnd());
2846 CheckFocusedFieldText("ABCDE");
2847 ClickOnFormFieldAtPoint(RegularFormBegin());
2848 CheckFocusedFieldText("ABCDE");
2849 ClickOnFormFieldAtPoint(RegularFormBegin());
2850 CheckFocusedFieldText("ABCDE");
2851 ClickOnFormFieldAtPoint(CharLimitFormBegin());
2852 CheckFocusedFieldText("ABElephant");
2853 FORM_ForceToKillFocus(form_handle());
2854 CheckFocusedFieldText("");
2855}
2856
2858 static const CFX_PointF kNonFormPoint(1, 1);
2859 CheckFocusedFieldText("");
2860 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2861 CheckFocusedFieldText("Banana");
2862 ClickOnFormFieldAtPoint(EditableFormBegin());
2863 CheckFocusedFieldText("");
2864 ClickOnFormFieldAtPoint(NonEditableFormEnd());
2865 CheckFocusedFieldText("Banana");
2866 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2867 CheckFocusedFieldText("Banana");
2868 FORM_ForceToKillFocus(form_handle());
2869 CheckFocusedFieldText("");
2870 ClickOnFormFieldAtPoint(EditableFormBegin());
2871 CheckFocusedFieldText("");
2872 TypeTextIntoTextField(3, EditableFormBegin());
2873 CheckFocusedFieldText("ABC");
2874 ClickOnFormFieldAtPoint(kNonFormPoint);
2875 CheckFocusedFieldText("");
2876 TypeTextIntoTextField(3, EditableFormEnd());
2877 CheckFocusedFieldText("ABCABC");
2878 ClickOnFormFieldAtPoint(kNonFormPoint);
2879 CheckFocusedFieldText("");
2880 ClickOnFormFieldAtPoint(EditableFormDropDown());
2881 CheckFocusedFieldText("ABCABC");
2882 FORM_ForceToKillFocus(form_handle());
2883 CheckFocusedFieldText("");
2884 ClickOnFormFieldAtPoint(NonEditableFormDropDown());
2885 CheckFocusedFieldText("Banana");
2886 ClickOnFormFieldAtPoint(kNonFormPoint);
2887 CheckFocusedFieldText("");
2888 ClickOnFormFieldAtPoint(NonEditableFormEnd());
2889 CheckFocusedFieldText("Banana");
2890
2891 // Typing into non-editable field results in selecting a different option.
2892 TypeTextIntoTextField(1, NonEditableFormEnd());
2893 CheckFocusedFieldText("Apple");
2894 TypeTextIntoTextField(3, NonEditableFormEnd());
2895 CheckFocusedFieldText("Cherry");
2896 TypeTextIntoTextField(2, NonEditableFormEnd());
2897 CheckFocusedFieldText("Banana");
2898
2899 SelectEditableFormOption(0);
2900 CheckFocusedFieldText("Foo");
2901 SelectEditableFormOption(1);
2902 CheckFocusedFieldText("Bar");
2903 SelectEditableFormOption(2);
2904 CheckFocusedFieldText("Qux");
2905 SelectNonEditableFormOption(1);
2906 CheckFocusedFieldText("Banana");
2907 SelectNonEditableFormOption(0);
2908 CheckFocusedFieldText("Apple");
2909 SelectNonEditableFormOption(2);
2910 CheckFocusedFieldText("Cherry");
2911
2912 // Typing into an editable field changes the text in the option.
2913 SelectEditableFormOption(0);
2914 CheckFocusedFieldText("Foo");
2915 TypeTextIntoTextField(5, EditableFormBegin());
2916 CheckFocusedFieldText("ABCDEFoo");
2917 SelectEditableFormOption(2);
2918 CheckFocusedFieldText("Qux");
2919 TypeTextIntoTextField(2, EditableFormEnd());
2920 CheckFocusedFieldText("QuxAB");
2921
2922 // But a previously edited option is reset when selected again.
2923 SelectEditableFormOption(0);
2924 CheckFocusedFieldText("Foo");
2925 TypeTextIntoTextField(1, EditableFormBegin());
2926 CheckFocusedFieldText("AFoo");
2927 SelectEditableFormOption(0);
2928 CheckFocusedFieldText("Foo");
2929}
2930
2932 ClickOnFormFieldAtPoint(RegularFormBegin());
2933 CheckFocusedFieldText("");
2934 CheckCanUndo(false);
2935 CheckCanRedo(false);
2936
2937 TypeTextIntoTextField(5, RegularFormBegin());
2938 CheckFocusedFieldText("ABCDE");
2939 CheckCanUndo(true);
2940 CheckCanRedo(false);
2941
2942 PerformUndo();
2943 CheckFocusedFieldText("ABCD");
2944 CheckCanUndo(true);
2945 CheckCanRedo(true);
2946 PerformUndo();
2947 CheckFocusedFieldText("ABC");
2948 CheckCanUndo(true);
2949 CheckCanRedo(true);
2950
2951 PerformRedo();
2952 CheckFocusedFieldText("ABCD");
2953 CheckCanUndo(true);
2954 CheckCanRedo(true);
2955 PerformRedo();
2956 CheckFocusedFieldText("ABCDE");
2957 CheckCanUndo(true);
2958 CheckCanRedo(false);
2959}
2960
2961// This action only applies to Listboxes and Comboboxes so should fail
2962// gracefully for Textboxes by returning false to all operations.
2964 // set focus and read text to confirm we have it
2965 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2966 CheckFocusedFieldText("Elephant");
2967
2968 SetIndexSelectedShouldFail(0, true);
2969 SetIndexSelectedShouldFail(0, false);
2970 SetIndexSelectedShouldFail(1, true);
2971 SetIndexSelectedShouldFail(1, false);
2972 SetIndexSelectedShouldFail(-1, true);
2973 SetIndexSelectedShouldFail(-1, false);
2974}
2975
2976// This action only applies to Listboxes and Comboboxes so should fail
2977// gracefully for Textboxes by returning false to all operations.
2979 // set focus and read text to confirm we have it
2980 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2981 CheckFocusedFieldText("Elephant");
2982
2983 CheckIsIndexSelected(0, false);
2984 CheckIsIndexSelected(1, false);
2985 CheckIsIndexSelected(-1, false);
2986}
2987
2989 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2990 CheckFocusedFieldText("Banana");
2991 CheckCanUndo(false);
2992 CheckCanRedo(false);
2993
2994 ClickOnFormFieldAtPoint(EditableFormBegin());
2995 CheckFocusedFieldText("");
2996 CheckCanUndo(false);
2997 CheckCanRedo(false);
2998
2999 TypeTextIntoTextField(3, EditableFormBegin());
3000 CheckFocusedFieldText("ABC");
3001 CheckCanUndo(true);
3002 CheckCanRedo(false);
3003
3004 PerformUndo();
3005 CheckFocusedFieldText("AB");
3006 CheckCanUndo(true);
3007 CheckCanRedo(true);
3008 PerformUndo();
3009 CheckFocusedFieldText("A");
3010 CheckCanUndo(true);
3011 CheckCanRedo(true);
3012 PerformUndo();
3013 CheckFocusedFieldText("");
3014 CheckCanUndo(false);
3015 CheckCanRedo(true);
3016
3017 PerformRedo();
3018 CheckFocusedFieldText("A");
3019 CheckCanUndo(true);
3020 CheckCanRedo(true);
3021}
3022
3025 // Nothing is selected in single select field upon opening.
3026 FocusOnSingleSelectForm();
3027 CheckIsIndexSelected(0, false);
3028 CheckIsIndexSelected(1, false);
3029 CheckIsIndexSelected(2, false);
3030
3031 ClickOnSingleSelectFormOption(1);
3032 CheckIsIndexSelected(0, false);
3033 CheckIsIndexSelected(1, true);
3034 CheckIsIndexSelected(2, false);
3035}
3036
3039 // Multiselect field set to 'Banana' (index 1) upon opening.
3040 FocusOnMultiSelectForm();
3041 for (int i = 0; i < 26; i++) {
3042 bool expected = i == 1;
3043 CheckIsIndexSelected(i, expected);
3044 }
3045
3046 // TODO(bug_1377): Behavior should be changed to the one described below.
3047 // Multiselect field set to 'Cherry' (index 2), which is index 1 among the
3048 // visible form options because the listbox is scrolled down to have 'Banana'
3049 // (index 1) at the top.
3050 ClickOnMultiSelectFormOption(1);
3051 for (int i = 0; i < 26; i++) {
3052 bool expected = i == 1;
3053 CheckIsIndexSelected(i, expected);
3054 }
3055}
3056
3059 // Nothing is selected in single select field upon opening.
3060 FocusOnSingleSelectForm();
3061 CheckFocusedFieldText("");
3062 CheckIsIndexSelected(0, false);
3063 CheckIsIndexSelected(1, false);
3064 CheckIsIndexSelected(2, false);
3065
3066 // Make selections to change the value of the focused annotation
3067 // programmatically showing that only one value remains selected at a time.
3068 SetIndexSelectedShouldSucceed(0, true);
3069 CheckFocusedFieldText("Foo");
3070 CheckIsIndexSelected(0, true);
3071 CheckIsIndexSelected(1, false);
3072 CheckIsIndexSelected(2, false);
3073
3074 SetIndexSelectedShouldSucceed(1, true);
3075 CheckFocusedFieldText("Bar");
3076 CheckIsIndexSelected(0, false);
3077 CheckIsIndexSelected(1, true);
3078 CheckIsIndexSelected(2, false);
3079
3080 // Selecting/deselecting an index that is already selected/deselected is
3081 // success.
3082 SetIndexSelectedShouldSucceed(1, true);
3083 CheckFocusedFieldText("Bar");
3084 CheckIsIndexSelected(0, false);
3085 CheckIsIndexSelected(1, true);
3086 CheckIsIndexSelected(2, false);
3087
3088 SetIndexSelectedShouldSucceed(2, false);
3089 CheckFocusedFieldText("Bar");
3090 CheckIsIndexSelected(0, false);
3091 CheckIsIndexSelected(1, true);
3092 CheckIsIndexSelected(2, false);
3093
3094 // Cannot select indices that are out of range.
3095 SetIndexSelectedShouldFail(100, true);
3096 SetIndexSelectedShouldFail(-100, true);
3097 SetIndexSelectedShouldFail(100, false);
3098 SetIndexSelectedShouldFail(-100, false);
3099 // Confirm that previous values were not changed.
3100 CheckFocusedFieldText("Bar");
3101 CheckIsIndexSelected(0, false);
3102 CheckIsIndexSelected(1, true);
3103 CheckIsIndexSelected(2, false);
3104
3105 // Unlike combobox, should be able to deselect all indices.
3106 SetIndexSelectedShouldSucceed(1, false);
3107 CheckFocusedFieldText("");
3108 CheckIsIndexSelected(0, false);
3109 CheckIsIndexSelected(1, false);
3110 CheckIsIndexSelected(2, false);
3111
3112 // Check that above actions are interchangeable with click actions, should be
3113 // able to use a combination of both.
3114 ClickOnSingleSelectFormOption(1);
3115 CheckFocusedFieldText("Bar");
3116 CheckIsIndexSelected(0, false);
3117 CheckIsIndexSelected(1, true);
3118 CheckIsIndexSelected(2, false);
3119}
3120
3121// Re: Focus Field Text - For multiselect listboxes a caret is set on the last
3122// item to be selected/deselected. The text of that item should be returned.
3125 // Multiselect field set to 'Banana' (index 1) upon opening.
3126 FocusOnMultiSelectForm();
3127 for (int i = 0; i < 26; i++) {
3128 bool expected = i == 1;
3129 CheckIsIndexSelected(i, expected);
3130 }
3131 CheckFocusedFieldText("Banana");
3132
3133 // Select some more options.
3134 SetIndexSelectedShouldSucceed(5, true);
3135 SetIndexSelectedShouldSucceed(6, true);
3136 SetIndexSelectedShouldSucceed(20, true);
3137 for (int i = 0; i < 26; i++) {
3138 bool expected = (i == 1 || i == 5 || i == 6 || i == 20);
3139 CheckIsIndexSelected(i, expected);
3140 }
3141 CheckFocusedFieldText("Ugli Fruit");
3142
3143 // Selecting indices that are already selected is success - changes nothing.
3144 SetIndexSelectedShouldSucceed(5, true);
3145 SetIndexSelectedShouldSucceed(6, true);
3146 SetIndexSelectedShouldSucceed(20, true);
3147 for (int i = 0; i < 26; i++) {
3148 bool expected = (i == 1 || i == 5 || i == 6 || i == 20);
3149 CheckIsIndexSelected(i, expected);
3150 }
3151 CheckFocusedFieldText("Ugli Fruit");
3152
3153 // Deselect some options.
3154 SetIndexSelectedShouldSucceed(20, false);
3155 SetIndexSelectedShouldSucceed(1, false);
3156 for (int i = 0; i < 26; i++) {
3157 bool expected = (i == 5 || i == 6);
3158 CheckIsIndexSelected(i, expected);
3159 }
3160 CheckFocusedFieldText("Banana");
3161
3162 // Deselecting indices that already aren't selected is success - does not
3163 // change the selected values but moves the focus text caret to last item we
3164 // executed on.
3165 SetIndexSelectedShouldSucceed(1, false);
3166 SetIndexSelectedShouldSucceed(3, false);
3167 for (int i = 0; i < 26; i++) {
3168 bool expected = (i == 5 || i == 6);
3169 CheckIsIndexSelected(i, expected);
3170 }
3171 CheckFocusedFieldText("Date");
3172
3173 // Cannot select indices that are out of range.
3174 SetIndexSelectedShouldFail(100, true);
3175 SetIndexSelectedShouldFail(-100, true);
3176 SetIndexSelectedShouldFail(100, false);
3177 SetIndexSelectedShouldFail(-100, false);
3178 // Confirm that previous values were not changed.
3179 CheckFocusedFieldText("Date");
3180 for (int i = 0; i < 26; i++) {
3181 bool expected = (i == 5 || i == 6);
3182 CheckIsIndexSelected(i, expected);
3183 }
3184
3185 // Check that above actions are interchangeable with click actions, should be
3186 // able to use a combination of both.
3187 // TODO(bug_1377): Change to click on form option 0 instead of form option 1
3188 ClickOnMultiSelectFormOption(1);
3189 for (int i = 0; i < 26; i++) {
3190 bool expected = i == 1;
3191 CheckIsIndexSelected(i, expected);
3192 }
3193 CheckFocusedFieldText("Banana");
3194}
3195
3197 // Multiselect field set to 'Belgium' (index 1) and 'Denmark' (index 3) upon
3198 // opening.
3199 FocusOnMultiSelectMultipleIndicesForm();
3200 for (int i = 0; i < 5; i++) {
3201 bool expected = (i == 1 || i == 3);
3202 CheckIsIndexSelected(i, expected);
3203 }
3204}
3205
3207 // Multiselect field set to 'Gamma' (index 2) and 'Epsilon' (index 4) upon
3208 // opening.
3209 FocusOnMultiSelectMultipleValuesForm();
3210 for (int i = 0; i < 5; i++) {
3211 bool expected = (i == 2 || i == 4);
3212 CheckIsIndexSelected(i, expected);
3213 }
3214}
3215
3217 // Multiselect field set to 'Alligator' (index 0) and 'Cougar' (index 2) upon
3218 // opening.
3219 FocusOnMultiSelectMultipleMismatchForm();
3220 for (int i = 0; i < 5; i++) {
3221 bool expected = (i == 0 || i == 2);
3222 CheckIsIndexSelected(i, expected);
3223 }
3224}
3225
3228 // Multiselect field set to 'Gamma' (index 2) and 'Epsilon' (index 4) upon
3229 // opening.
3230
3231 // TODO(bug_1377): Behavior should be changed to the one described below.
3232 // The top visible option is 'Gamma' (index 2), so the first selection should
3233 // not change. The second selection, 'Epsilon,' should be deselected.
3234 ClickOnMultiSelectMultipleValuesFormOption(0);
3235 for (int i = 0; i < 5; i++) {
3236 bool expected = i == 0;
3237 CheckIsIndexSelected(i, expected);
3238 }
3239}
3240
3242 // Only the last option in the list, 'Saskatchewan', is selected.
3243 FocusOnSingleSelectLastSelectedForm();
3244 for (int i = 0; i < 10; i++) {
3245 bool expected = i == 9;
3246 CheckIsIndexSelected(i, expected);
3247 }
3248
3249 // Even though the top index is specified to be at 'Saskatchewan' (index 9),
3250 // the top visible option will be the one above it, 'Quebec' (index 8), to
3251 // prevent overscrolling. Therefore, clicking on the first visible option of
3252 // the list should select 'Quebec' instead of 'Saskatchewan.'
3253 ClickOnSingleSelectLastSelectedFormOption(0);
3254 for (int i = 0; i < 10; i++) {
3255 bool expected = i == 8;
3256 CheckIsIndexSelected(i, expected);
3257 }
3258}
3259
3261 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"XYZ");
3262 ClickOnFormFieldAtPoint(RegularFormBegin());
3263 CheckCanUndo(false);
3264 CheckCanRedo(false);
3265
3266 TypeTextIntoTextField(2, RegularFormBegin());
3267 CheckFocusedFieldText("AB");
3268 CheckSelection("");
3269 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
3270 CheckSelection("A");
3271
3272 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert.get());
3273 CheckFocusedFieldText("XYZB");
3274 CheckSelection("XYZ");
3275 CheckCanUndo(true);
3276 CheckCanRedo(false);
3277
3278 PerformUndo();
3279 CheckFocusedFieldText("AB");
3280 CheckCanUndo(true);
3281 CheckCanRedo(true);
3282
3283 SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd());
3284 CheckSelection("B");
3285
3286 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert.get());
3287 CheckFocusedFieldText("AXYZ");
3288 CheckSelection("XYZ");
3289 CheckCanUndo(true);
3290 CheckCanRedo(false);
3291}
3292
3294 ScopedFPDFWideString text_to_insert1 = GetFPDFWideString(L"UVW");
3295
3296 ClickOnFormFieldAtPoint(RegularFormBegin());
3297 CheckFocusedFieldText("");
3298 CheckCanUndo(false);
3299 CheckCanRedo(false);
3300
3301 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert1.get());
3302 CheckFocusedFieldText("UVW");
3303 CheckSelection("UVW");
3304
3305 CheckCanUndo(true);
3306 CheckCanRedo(false);
3307
3308 PerformUndo();
3309 CheckFocusedFieldText("");
3310
3311 CheckCanUndo(false);
3312 CheckCanRedo(true);
3313 PerformRedo();
3314 CheckFocusedFieldText("UVW");
3315 CheckSelection("");
3316
3317 ScopedFPDFWideString text_to_insert2 = GetFPDFWideString(L"XYZ");
3318 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert2.get());
3319 CheckFocusedFieldText("UVWXYZ");
3320 CheckSelection("XYZ");
3321
3322 CheckCanUndo(true);
3323 PerformUndo();
3324 CheckFocusedFieldText("UVW");
3325 CheckSelection("");
3326}
3327
3329 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"XYZ");
3330 ClickOnFormFieldAtPoint(RegularFormBegin());
3331 CheckCanUndo(false);
3332 CheckCanRedo(false);
3333
3334 TypeTextIntoTextField(2, RegularFormBegin());
3335 CheckFocusedFieldText("AB");
3336 CheckSelection("");
3337 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
3338 CheckSelection("A");
3339
3340 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
3341 CheckFocusedFieldText("XYZB");
3342 CheckCanUndo(true);
3343 CheckCanRedo(false);
3344
3345 PerformUndo();
3346 CheckFocusedFieldText("AB");
3347 CheckCanUndo(true);
3348 CheckCanRedo(true);
3349
3350 PerformUndo();
3351 CheckFocusedFieldText("A");
3352 CheckCanUndo(true);
3353 CheckCanRedo(true);
3354
3355 PerformUndo();
3356 CheckFocusedFieldText("");
3357 CheckCanUndo(false);
3358 CheckCanRedo(true);
3359
3360 PerformRedo();
3361 CheckFocusedFieldText("A");
3362 CheckCanUndo(true);
3363 CheckCanRedo(true);
3364
3365 PerformRedo();
3366 CheckFocusedFieldText("AB");
3367 CheckCanUndo(true);
3368 CheckCanRedo(true);
3369
3370 PerformRedo();
3371 CheckFocusedFieldText("XYZB");
3372 CheckCanUndo(true);
3373 CheckCanRedo(false);
3374}
3375
3377 ScopedFPDFWideString text_to_insert1 = GetFPDFWideString(L"UVW");
3378
3379 ClickOnFormFieldAtPoint(RegularFormBegin());
3380 CheckFocusedFieldText("");
3381 CheckCanUndo(false);
3382 CheckCanRedo(false);
3383
3384 FORM_ReplaceSelection(form_handle(), page(), text_to_insert1.get());
3385 CheckFocusedFieldText("UVW");
3386 CheckSelection("");
3387
3388 CheckCanUndo(true);
3389 CheckCanRedo(false);
3390
3391 PerformUndo();
3392 CheckFocusedFieldText("");
3393
3394 CheckCanUndo(false);
3395 CheckCanRedo(true);
3396 PerformRedo();
3397 CheckFocusedFieldText("UVW");
3398 CheckSelection("");
3399
3400 ScopedFPDFWideString text_to_insert2 = GetFPDFWideString(L"XYZ");
3401 FORM_ReplaceSelection(form_handle(), page(), text_to_insert2.get());
3402 CheckFocusedFieldText("UVWXYZ");
3403
3404 CheckCanUndo(true);
3405 CheckCanRedo(false);
3406
3407 PerformUndo();
3408 CheckFocusedFieldText("UVW");
3409 CheckSelection("");
3410}
3411
3413 // Start with a couple of letters in the text form.
3414 TypeTextIntoTextField(2, RegularFormBegin());
3415 CheckFocusedFieldText("AB");
3416 CheckSelection("");
3417
3418 // Select all with the keyboard shortcut.
3419#if BUILDFLAG(IS_APPLE)
3420 constexpr int kCorrectModifier = FWL_EVENTFLAG_MetaKey;
3421#else
3422 constexpr int kCorrectModifier = FWL_EVENTFLAG_ControlKey;
3423#endif
3424 FORM_OnChar(form_handle(), page(), pdfium::ascii::kControlA,
3425 kCorrectModifier);
3426 CheckSelection("AB");
3427
3428 // Reset the selection again.
3429 ClickOnFormFieldAtPoint(RegularFormBegin());
3430 CheckSelection("");
3431
3432 // Select all with the keyboard shortcut using the wrong modifier key.
3433#if BUILDFLAG(IS_APPLE)
3434 constexpr int kWrongModifier = FWL_EVENTFLAG_ControlKey;
3435#else
3436 constexpr int kWrongModifier = FWL_EVENTFLAG_MetaKey;
3437#endif
3438 FORM_OnChar(form_handle(), page(), pdfium::ascii::kControlA, kWrongModifier);
3439 CheckSelection("");
3440}
3441
3444 protected:
3447
3448 const char* GetDocumentName() const override { return "bug_1055869.pdf"; }
3449 int GetFormType() const override { return FORMTYPE_XFA_FULL; }
3450};
3451
3453 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"XYZ");
3454 DoubleClickOnFormFieldAtPoint(CFX_PointF(100, 100));
3455 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
3456}
3457
3460 protected:
3463
3464 const char* GetDocumentName() const override { return "bug_1058653.pdf"; }
3465 int GetFormType() const override { return FORMTYPE_XFA_FULL; }
3466};
3467
3469 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"");
3470 DoubleClickOnFormFieldAtPoint(CFX_PointF(22, 22));
3471 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
3472}
3473
3475 protected:
3477 ~FPDFFormFillActionUriTest() override = default;
3478
3481 ASSERT_TRUE(OpenDocument("annots_action_handling.pdf"));
3482 page_ = LoadPage(0);
3483 ASSERT_TRUE(page_);
3484
3485 // Set Widget and Link as supported tabbable annots.
3486 constexpr FPDF_ANNOTATION_SUBTYPE kFocusableSubtypes[] = {FPDF_ANNOT_WIDGET,
3488 constexpr size_t kSubtypeCount = std::size(kFocusableSubtypes);
3489 ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(
3490 form_handle(), kFocusableSubtypes, kSubtypeCount));
3491 }
3492
3494 UnloadPage(page_);
3496 }
3497
3498 void SetFocusOnNthAnnot(size_t n) {
3499 DCHECK_NE(n, 0u);
3500 // Setting focus on first annot.
3501 FORM_OnMouseMove(form_handle(), page(), /*modifier=*/0, 100, 680);
3502 FORM_OnLButtonDown(form_handle(), page(), /*modifier=*/0, 100, 680);
3503 FORM_OnLButtonUp(form_handle(), page(), /*modifier=*/0, 100, 680);
3504 for (size_t i = 1; i < n; i++)
3505 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Tab, 0));
3506 }
3507
3508 FPDF_PAGE page() { return page_; }
3509
3510 private:
3511 FPDF_PAGE page_ = nullptr;
3512};
3513
3515 NiceMock<EmbedderTestMockDelegate> mock;
3516 // TODO(crbug.com/1028991): DoURIAction expect call should be 1.
3517 EXPECT_CALL(mock, DoURIAction(_)).Times(0);
3518 SetDelegate(&mock);
3519
3520 SetFocusOnNthAnnot(1);
3521
3522 // Tab once from first form to go to button widget.
3523 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Tab, 0));
3524
3525 // TODO(crbug.com/1028991): Following should be changed to ASSERT_TRUE after
3526 // handling key press implementation on buttons.
3527 ASSERT_FALSE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
3528}
3529
3531 NiceMock<EmbedderTestMockDelegate> mock;
3532 {
3533 InSequence sequence;
3534 const char kExpectedUri[] = "https://cs.chromium.org/";
3535#ifdef PDF_ENABLE_XFA
3536 EXPECT_CALL(mock,
3537 DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri), _))
3538 .Times(4);
3539#else // PDF_ENABLE_XFA
3540 EXPECT_CALL(mock, DoURIAction(StrEq(kExpectedUri))).Times(4);
3541 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(_, _, _)).Times(0);
3542#endif // PDF_ENABLE_XFA
3543 }
3544 SetDelegate(&mock);
3545 SetFocusOnNthAnnot(3);
3546 int modifier = 0;
3547 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3548 modifier = FWL_EVENTFLAG_ControlKey;
3549 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3550 modifier = FWL_EVENTFLAG_ShiftKey;
3551 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3552 modifier |= FWL_EVENTFLAG_ControlKey;
3553 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3554
3555 ASSERT_FALSE(FORM_OnKeyDown(nullptr, page(), FWL_VKEY_Return, modifier));
3556 ASSERT_FALSE(
3557 FORM_OnKeyDown(form_handle(), nullptr, FWL_VKEY_Return, modifier));
3558 // Following checks should be changed to ASSERT_TRUE if FORM_OnKeyDown starts
3559 // handling for Shift/Space/Control.
3560 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Shift, modifier));
3561 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Space, modifier));
3562 ASSERT_FALSE(
3563 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Control, modifier));
3564}
3565
3567 NiceMock<EmbedderTestMockDelegate> mock;
3568 EXPECT_CALL(mock, DoGoToAction(_, _, 1, _, _)).Times(12);
3569 SetDelegate(&mock);
3570
3571 SetFocusOnNthAnnot(4);
3572 int modifier = 0;
3573 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3574 modifier = FWL_EVENTFLAG_ControlKey;
3575 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3576 modifier = FWL_EVENTFLAG_ShiftKey;
3577 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3578 modifier |= FWL_EVENTFLAG_ControlKey;
3579 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3580
3581 SetFocusOnNthAnnot(5);
3582 modifier = 0;
3583 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3584 modifier = FWL_EVENTFLAG_ControlKey;
3585 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3586 modifier = FWL_EVENTFLAG_ShiftKey;
3587 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3588 modifier |= FWL_EVENTFLAG_ControlKey;
3589 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3590
3591 SetFocusOnNthAnnot(6);
3592 modifier = 0;
3593 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3594 modifier = FWL_EVENTFLAG_ControlKey;
3595 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3596 modifier = FWL_EVENTFLAG_ShiftKey;
3597 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3598 modifier |= FWL_EVENTFLAG_ControlKey;
3599 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3600
3601 ASSERT_FALSE(FORM_OnKeyDown(nullptr, page(), FWL_VKEY_Return, modifier));
3602 ASSERT_FALSE(
3603 FORM_OnKeyDown(form_handle(), nullptr, FWL_VKEY_Return, modifier));
3604 // Following checks should be changed to ASSERT_TRUE if FORM_OnKeyDown starts
3605 // handling for Shift/Space/Control.
3606 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Shift, modifier));
3607 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Space, modifier));
3608 ASSERT_FALSE(
3609 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Control, modifier));
3610}
3611
3618
3620 NiceMock<EmbedderTestMockDelegate> mock;
3621 {
3622 InSequence sequence;
3623 EXPECT_CALL(mock, DoURIAction(_)).Times(0);
3624 const char kExpectedUri[] = "https://cs.chromium.org/";
3625 EXPECT_CALL(mock,
3626 DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri), 0));
3627 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(
3628 _, StrEq(kExpectedUri), FWL_EVENTFLAG_ControlKey));
3629 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri),
3630 FWL_EVENTFLAG_ShiftKey));
3631 EXPECT_CALL(mock,
3632 DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri), 3));
3633 }
3634 SetDelegate(&mock);
3635 SetFocusOnNthAnnot(3);
3636 int modifier = 0;
3637 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3638 modifier = FWL_EVENTFLAG_ControlKey;
3639 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3640 modifier = FWL_EVENTFLAG_ShiftKey;
3641 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3642 modifier |= FWL_EVENTFLAG_ControlKey;
3643 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3644
3645 ASSERT_FALSE(FORM_OnKeyDown(nullptr, page(), FWL_VKEY_Return, modifier));
3646 ASSERT_FALSE(
3647 FORM_OnKeyDown(form_handle(), nullptr, FWL_VKEY_Return, modifier));
3648 // Following checks should be changed to ASSERT_TRUE if FORM_OnKeyDown starts
3649 // handling for Shift/Space/Control.
3650 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Shift, modifier));
3651 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Space, modifier));
3652 ASSERT_FALSE(
3653 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Control, modifier));
3654}
void DoURIAction(FPDF_BYTESTRING uri) override
void SetUp() override
void SetFormFillInfoVersion(int form_fill_info_version)
void TearDown() override
void UnloadPage(FPDF_PAGE page)
FPDF_PAGE LoadPage(int page_number)
FPDF_FORMHANDLE form_handle() const
bool OpenDocument(const std::string &filename)
~FPDFFormFillActionUriTest() override=default
FPDFFormFillActionUriTest()=default
~FPDFFormFillComboBoxFormEmbedderTest() override=default
void DoubleClickOnFormFieldAtPoint(const CFX_PointF &point)
void SelectTextWithKeyboard(int num_chars, int arrow_key, const CFX_PointF &point)
void TypeTextIntoTextField(int num_chars, const CFX_PointF &point)
virtual int GetFormType() const =0
void SetIndexSelectedShouldFail(int index, bool selected)
void CheckSelection(ByteStringView expected_string)
void SelectAllTextAtPoint(const CFX_PointF &point)
void CheckIsIndexSelected(int index, bool expected)
void ClickOnFormFieldAtPoint(const CFX_PointF &point)
virtual const char * GetDocumentName() const =0
void SetIndexSelectedShouldSucceed(int index, bool selected)
~FPDFFormFillInteractiveEmbedderTest() override=default
void SelectTextWithMouse(const CFX_PointF &start, const CFX_PointF &end)
void CheckFocusedFieldText(ByteStringView expected_string)
~FPDFFormFillListBoxFormEmbedderTest() override=default
const CFX_PointF & MultiSelectSecondVisibleOption() const
const CFX_PointF & SingleSelectFirstVisibleOption() const
const CFX_PointF & MultiSelectMultipleValuesSecondVisibleOption() const
const CFX_PointF & MultiSelectMultipleIndicesSecondVisibleOption() const
const CFX_PointF & MultiSelectMultipleMismatchFirstVisibleOption() const
const CFX_PointF & MultiSelectMultipleMismatchSecondVisibleOption() const
const CFX_PointF & SingleSelectLastSelectedSecondVisibleOption() const
const CFX_PointF & SingleSelectLastSelectedFirstVisibleOption() const
const CFX_PointF & MultiSelectMultipleIndicesFirstVisibleOption() const
const CFX_PointF & MultiSelectMultipleValuesFirstVisibleOption() const
const CFX_PointF & SingleSelectSecondVisibleOption() const
const CFX_PointF & MultiSelectFirstVisibleOption() const
const char * GetDocumentName() const override
~FPDFFormFillTextFormEmbedderTest() override=default
~FPDFXFAFormBug1055869EmbedderTest() override=default
~FPDFXFAFormBug1058653EmbedderTest() override=default
#define FPDF_ANNOT_WIDGET
Definition fpdf_annot.h:40
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_CloseAnnot(FPDF_ANNOTATION annot)
FPDF_EXPORT int FPDF_CALLCONV FPDFPage_GetAnnotIndex(FPDF_PAGE page, FPDF_ANNOTATION annot)
#define FPDF_ANNOT_LINK
Definition fpdf_annot.h:22
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_SetIndexSelected(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int index, FPDF_BOOL selected)
#define FORMTYPE_NONE
#define FPDF_FORMFIELD_COMBOBOX
#define FPDF_FORMFIELD_TEXTFIELD
#define FPDF_FORMFIELD_LISTBOX
#define FORMTYPE_XFA_FOREGROUND
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_SetFocusedAnnot(FPDF_FORMHANDLE handle, FPDF_ANNOTATION annot)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_GetFocusedAnnot(FPDF_FORMHANDLE handle, int *page_index, FPDF_ANNOTATION *annot)
#define FORMTYPE_XFA_FULL
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_IsIndexSelected(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int index)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_SelectAllText(FPDF_FORMHANDLE hHandle, FPDF_PAGE page)
#define FORMTYPE_ACRO_FORM
TEST_F(FPDFFormFillComboBoxFormEmbedderTest, GetSelectedTextEmptyAndBasicNormalComboBox)
TEST_F(FPDFFormFillTextFormEmbedderTestVersion2, FocusAnnotationUpdateToEmbedder)
TEST_F(FPDFXFAFormBug1055869EmbedderTest, Paste)
TEST_F(FPDFFormFillActionUriTest, ButtonActionInvokeTest)
TEST_F(FPDFXFAFormBug1058653EmbedderTest, Paste)
TEST_F(FPDFFormFillListBoxFormEmbedderTest, CheckIfIndexSelectedSingleSelectField)
TEST_F(FPDFFormFillTextFormEmbedderTest, GetSelectedTextEmptyAndBasicKeyboard)
TEST_F(FPDFFormFillActionUriTestVersion2, LinkActionInvokeTest)
@ FWL_EVENTFLAG_ShiftKey
@ FWL_EVENTFLAG_MetaKey
@ FWL_EVENTFLAG_AltKey
@ FWL_EVENTFLAG_ControlKey
@ FWL_VKEY_F1
@ FWL_VKEY_0
@ FWL_VKEY_Z
@ FWL_VKEY_Right
@ FWL_VKEY_Shift
@ FWL_VKEY_Down
@ FWL_VKEY_Control
@ FWL_VKEY_Tab
@ FWL_VKEY_NewLine
@ FWL_VKEY_A
@ FWL_VKEY_Space
@ FWL_VKEY_9
@ FWL_VKEY_Left
@ FWL_VKEY_Return
@ FWL_VKEY_Delete
TEST_F(FPDFParserDecodeEmbedderTest, Bug552046)
FPDF_EXPORT int FPDF_CALLCONV FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, IFSDK_PAUSE *pause)
FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap)
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width, int height, int alpha)
#define FPDF_REVERSE_BYTE_ORDER
Definition fpdfview.h:831
std::string GetPlatformString(FPDF_WIDESTRING wstr)
constexpr uint8_t kReturn
Definition ascii.h:20
constexpr uint8_t kSpace
Definition ascii.h:25
constexpr uint8_t kTab
Definition ascii.h:18
constexpr uint8_t kControlA
Definition ascii.h:14
const char * TextFormChecksum()
const char * Bug890322Checksum()