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/check.h"
10#include "core/fxcrt/check_op.h"
11#include "core/fxcrt/fx_coordinates.h"
12#include "core/fxcrt/fx_string.h"
13#include "core/fxcrt/fx_system.h"
14#include "core/fxge/cfx_defaultrenderdevice.h"
15#include "public/cpp/fpdf_scopers.h"
16#include "public/fpdf_formfill.h"
17#include "public/fpdf_fwlevent.h"
18#include "public/fpdf_progressive.h"
19#include "testing/embedder_test.h"
20#include "testing/embedder_test_constants.h"
21#include "testing/embedder_test_mock_delegate.h"
22#include "testing/embedder_test_timer_handling_delegate.h"
23#include "testing/gmock/include/gmock/gmock.h"
24#include "testing/gtest/include/gtest/gtest.h"
25
26using pdfium::TextFormChecksum;
27
28using testing::_;
29using testing::InSequence;
30using testing::NiceMock;
31using testing::StrEq;
32
34
35// A base class for many related tests that involve clicking and typing into
36// form fields.
38 protected:
41
42 void SetUp() override {
44 ASSERT_TRUE(OpenDocument(GetDocumentName()));
45 page_ = LoadPage(0);
46 ASSERT_TRUE(page_);
48 }
49
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
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
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:
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
220 static const CFX_PointF point = CharLimitFormAtX(kFormBeginX);
221 return point;
222 }
223
225 static const CFX_PointF point = CharLimitFormAtX(kFormEndX);
226 return point;
227 }
228
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
304 static const CFX_PointF point = EditableFormAtX(kFormBeginX);
305 return point;
306 }
307
309 static const CFX_PointF point = EditableFormAtX(kFormEndX);
310 return point;
311 }
312
314 static const CFX_PointF point(kFormDropDownX, kEditableFormY);
315 return point;
316 }
317
319 static const CFX_PointF point = NonEditableFormAtX(kFormBeginX);
320 return point;
321 }
322
324 static const CFX_PointF point = NonEditableFormAtX(kFormEndX);
325 return point;
326 }
327
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
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
504 static const CFX_PointF point(kFormBeginX, kSingleFormYFirstVisibleOption);
505 return point;
506 }
507
509 static const CFX_PointF point(kFormBeginX, kSingleFormYSecondVisibleOption);
510 return point;
511 }
512
514 static const CFX_PointF point(kFormBeginX, kMultiFormYFirstVisibleOption);
515 return point;
516 }
517
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
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
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
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
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
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
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
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
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
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
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
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
828 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
829 FPDF_PAGE page = LoadPage(0);
830 ASSERT_TRUE(page);
831
832 // Tabs should iterate focus over annotations.
833 for (int expected : {1, 2, 3, 0}) {
834 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
835 int page_index = -2;
836 FPDF_ANNOTATION annot = nullptr;
837 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
838 EXPECT_EQ(0, page_index);
839 ASSERT_TRUE(annot);
840 EXPECT_EQ(expected, FPDFPage_GetAnnotIndex(page, annot));
841 FPDFPage_CloseAnnot(annot);
842 }
843
844 // Tab should not be handled as the last annotation of the page is in focus.
845 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
846
847 UnloadPage(page);
848}
849
851 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
852 FPDF_PAGE page = LoadPage(0);
853 ASSERT_TRUE(page);
854
855 // Shift-tabs should iterate focus over annotations.
856 for (int expected : {0, 3, 2, 1}) {
857 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
858 FWL_EVENTFLAG_ShiftKey));
859 int page_index = -2;
860 FPDF_ANNOTATION annot = nullptr;
861 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
862 EXPECT_EQ(0, page_index);
863 ASSERT_TRUE(annot);
864 EXPECT_EQ(expected, FPDFPage_GetAnnotIndex(page, annot));
865 FPDFPage_CloseAnnot(annot);
866 }
867
868 // Shift-tab should not be handled as the first annotation of the page is in
869 // focus.
870 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
872
873 UnloadPage(page);
874}
875
877 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
878 FPDF_PAGE page = LoadPage(0);
879 ASSERT_TRUE(page);
880
881 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
883
884 ASSERT_FALSE(
885 FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, FWL_EVENTFLAG_AltKey));
886
887 ASSERT_FALSE(
888 FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
890
891 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
893
894 UnloadPage(page);
895}
896
898 ASSERT_TRUE(OpenDocument("annotiter.pdf"));
899 FPDF_PAGE page = LoadPage(0);
900 ASSERT_TRUE(page);
901
902 // There should be no focused annotation to start with.
903 int page_index = -2;
904 FPDF_ANNOTATION annot = nullptr;
905 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
906 EXPECT_EQ(-1, page_index);
907 EXPECT_FALSE(annot);
908
909 static constexpr int kKeysToPress[] = {
913 };
914 for (int key : kKeysToPress) {
915 // Pressing random keys when there is no focus should not trigger focus.
916 EXPECT_FALSE(FORM_OnKeyDown(form_handle(), page, key, 0));
917 page_index = -2;
918 annot = nullptr;
919 EXPECT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
920 EXPECT_EQ(-1, page_index);
921 EXPECT_FALSE(annot);
922 }
923
924 UnloadPage(page);
925}
926
927#ifdef PDF_ENABLE_XFA
928TEST_F(FPDFFormFillEmbedderTest, XFAFormFillFirstTab) {
929 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
930 FPDF_PAGE page = LoadPage(0);
931 ASSERT_TRUE(page);
932
933 // Invoking first tab on the page.
934 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
935
936 UnloadPage(page);
937}
938
939TEST_F(FPDFFormFillEmbedderTest, XFAFormFillFirstShiftTab) {
940 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
941 FPDF_PAGE page = LoadPage(0);
942 ASSERT_TRUE(page);
943
944 // Invoking first shift-tab on the page.
945 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
946 FWL_EVENTFLAG_ShiftKey));
947
948 UnloadPage(page);
949}
950
951TEST_F(FPDFFormFillEmbedderTest, XFAFormFillContinuousTab) {
952 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
953 FPDF_PAGE page = LoadPage(0);
954 ASSERT_TRUE(page);
955
956 // Invoking first tab on the page.
957 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
958
959 // Subsequent tabs should move focus over annotations.
960 for (size_t i = 0; i < 9; ++i)
961 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
962
963 // Tab should not be handled as the last annotation of the page is in focus.
964 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
965
966 UnloadPage(page);
967}
968
969TEST_F(FPDFFormFillEmbedderTest, XFAFormFillContinuousShiftTab) {
970 ASSERT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
971 FPDF_PAGE page = LoadPage(0);
972 ASSERT_TRUE(page);
973
974 // Invoking first shift-tab on the page.
975 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
976 FWL_EVENTFLAG_ShiftKey));
977
978 // Subsequent shift-tabs should move focus over annotations.
979 for (size_t i = 0; i < 9; ++i) {
980 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
981 FWL_EVENTFLAG_ShiftKey));
982 }
983
984 // Shift-tab should not be handled as the first annotation of the page is in
985 // focus.
986 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
987 FWL_EVENTFLAG_ShiftKey));
988
989 UnloadPage(page);
990}
991#endif // PDF_ENABLE_XFA
992
993class DoURIActionBlockedDelegate final : public EmbedderTest::Delegate {
994 public:
995 void DoURIAction(FPDF_BYTESTRING uri) override {
996 FAIL() << "Navigated to " << uri;
997 }
998};
999
1001 DoURIActionBlockedDelegate delegate;
1002 SetDelegate(&delegate);
1003
1004 ASSERT_TRUE(OpenDocument("redirect.pdf"));
1005 FPDF_PAGE page = LoadPage(0);
1006 EXPECT_TRUE(page);
1007 DoOpenActions();
1008
1009 UnloadPage(page);
1010}
1011
1013 EmbedderTestTimerHandlingDelegate delegate;
1014 SetDelegate(&delegate);
1015
1016 ASSERT_TRUE(OpenDocument("click_form.pdf"));
1017 FPDF_PAGE page = LoadPage(0);
1018 ASSERT_TRUE(page);
1019
1020 {
1021 // Check for read-only checkbox.
1022 ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1));
1023 ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
1024
1025 // Shift-tab to the previous control.
1026 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab,
1028 FPDF_ANNOTATION annot = nullptr;
1029 int page_index = -1;
1030 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
1031 EXPECT_EQ(0, FPDFPage_GetAnnotIndex(page, annot));
1032
1033 // The read-only checkbox is initially in checked state.
1034 EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
1035
1036 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
1037 EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
1038
1039 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
1040 EXPECT_TRUE(FPDFAnnot_IsChecked(form_handle(), annot));
1041
1043 }
1044 UnloadPage(page);
1045}
1046
1048 EmbedderTestTimerHandlingDelegate delegate;
1049 SetDelegate(&delegate);
1050
1051 ASSERT_TRUE(OpenDocument("click_form.pdf"));
1052 FPDF_PAGE page = LoadPage(0);
1053 ASSERT_TRUE(page);
1054
1055 {
1056 // Check for read-only radio button.
1057 ScopedFPDFAnnotation focused_annot(FPDFPage_GetAnnot(page, 1));
1058 ASSERT_TRUE(FORM_SetFocusedAnnot(form_handle(), focused_annot.get()));
1059
1060 // Tab to the next control.
1061 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page, FWL_VKEY_Tab, 0));
1062
1063 FPDF_ANNOTATION annot = nullptr;
1064 int page_index = -1;
1065 ASSERT_TRUE(FORM_GetFocusedAnnot(form_handle(), &page_index, &annot));
1066 EXPECT_EQ(2, FPDFPage_GetAnnotIndex(page, annot));
1067 // The read-only radio button is initially in checked state.
1068 EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
1069
1070 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kReturn, 0));
1071 EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
1072
1073 EXPECT_TRUE(FORM_OnChar(form_handle(), page, pdfium::ascii::kSpace, 0));
1074 EXPECT_FALSE(FPDFAnnot_IsChecked(form_handle(), annot));
1075
1077 }
1078 UnloadPage(page);
1079}
1080
1081#ifdef PDF_ENABLE_V8
1082TEST_F(FPDFFormFillEmbedderTest, DisableJavaScript) {
1083 // Test that timers and intervals can't fire without JS.
1084 EmbedderTestTimerHandlingDelegate delegate;
1085 SetDelegate(&delegate);
1086
1087 ASSERT_TRUE(OpenDocumentWithoutJavaScript("bug_551248.pdf"));
1088 FPDF_PAGE page = LoadPage(0);
1089 EXPECT_TRUE(page);
1090 DoOpenActions();
1091
1092 const auto& alerts = delegate.GetAlerts();
1093 EXPECT_EQ(0U, alerts.size());
1094
1095 delegate.AdvanceTime(1000);
1096 EXPECT_EQ(0U, alerts.size()); // nothing fired.
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 UnloadPage(page);
1110}
1111
1112TEST_F(FPDFFormFillEmbedderTest, DocumentAActions) {
1113 EmbedderTestTimerHandlingDelegate delegate;
1114 SetDelegate(&delegate);
1115
1116 ASSERT_TRUE(OpenDocument("document_aactions.pdf"));
1117 FPDF_PAGE page = LoadPage(0);
1118 EXPECT_TRUE(page);
1119
1120 const auto& alerts = delegate.GetAlerts();
1121 EXPECT_EQ(0U, alerts.size());
1122
1123 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WS);
1124 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DS);
1125 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WP);
1126 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DP);
1127 UnloadPage(page);
1128
1129 ASSERT_EQ(4U, alerts.size());
1130 EXPECT_EQ(L"Will Save", alerts[0].message);
1131 EXPECT_EQ(L"Did Save", alerts[1].message);
1132 EXPECT_EQ(L"Will Print", alerts[2].message);
1133 EXPECT_EQ(L"Did Print", alerts[3].message);
1134}
1135
1136TEST_F(FPDFFormFillEmbedderTest, DocumentAActionsDisableJavaScript) {
1137 EmbedderTestTimerHandlingDelegate delegate;
1138 SetDelegate(&delegate);
1139
1140 ASSERT_TRUE(OpenDocumentWithoutJavaScript("document_aactions.pdf"));
1141 FPDF_PAGE page = LoadPage(0);
1142 EXPECT_TRUE(page);
1143
1144 const auto& alerts = delegate.GetAlerts();
1145 EXPECT_EQ(0U, alerts.size());
1146
1147 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WS);
1148 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DS);
1149 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_WP);
1150 FORM_DoDocumentAAction(form_handle(), FPDFDOC_AACTION_DP);
1151 UnloadPage(page);
1152
1153 ASSERT_EQ(0U, alerts.size());
1154}
1155
1156TEST_F(FPDFFormFillEmbedderTest, Bug551248) {
1157 // Test that timers fire once and intervals fire repeatedly.
1158 EmbedderTestTimerHandlingDelegate delegate;
1159 SetDelegate(&delegate);
1160
1161 ASSERT_TRUE(OpenDocument("bug_551248.pdf"));
1162 FPDF_PAGE page = LoadPage(0);
1163 EXPECT_TRUE(page);
1164 DoOpenActions();
1165
1166 const auto& alerts = delegate.GetAlerts();
1167 EXPECT_EQ(0U, alerts.size());
1168
1169 delegate.AdvanceTime(1000);
1170 EXPECT_EQ(0U, alerts.size()); // nothing fired.
1171 delegate.AdvanceTime(1000);
1172 EXPECT_EQ(1U, alerts.size()); // interval fired.
1173 delegate.AdvanceTime(1000);
1174 EXPECT_EQ(2U, alerts.size()); // timer fired.
1175 delegate.AdvanceTime(1000);
1176 EXPECT_EQ(3U, alerts.size()); // interval fired again.
1177 delegate.AdvanceTime(1000);
1178 EXPECT_EQ(3U, alerts.size()); // nothing fired.
1179 delegate.AdvanceTime(1000);
1180 EXPECT_EQ(4U, alerts.size()); // interval fired again.
1181 delegate.AdvanceTime(1000);
1182 EXPECT_EQ(4U, alerts.size()); // nothing fired.
1183 UnloadPage(page);
1184
1185 ASSERT_EQ(4U, alerts.size()); // nothing else fired.
1186
1187 EXPECT_EQ(L"interval fired", alerts[0].message);
1188 EXPECT_EQ(L"Alert", alerts[0].title);
1189 EXPECT_EQ(0, alerts[0].type);
1190 EXPECT_EQ(0, alerts[0].icon);
1191
1192 EXPECT_EQ(L"timer fired", alerts[1].message);
1193 EXPECT_EQ(L"Alert", alerts[1].title);
1194 EXPECT_EQ(0, alerts[1].type);
1195 EXPECT_EQ(0, alerts[1].icon);
1196
1197 EXPECT_EQ(L"interval fired", alerts[2].message);
1198 EXPECT_EQ(L"Alert", alerts[2].title);
1199 EXPECT_EQ(0, alerts[2].type);
1200 EXPECT_EQ(0, alerts[2].icon);
1201
1202 EXPECT_EQ(L"interval fired", alerts[3].message);
1203 EXPECT_EQ(L"Alert", alerts[3].title);
1204 EXPECT_EQ(0, alerts[3].type);
1205 EXPECT_EQ(0, alerts[3].icon);
1206}
1207
1208TEST_F(FPDFFormFillEmbedderTest, Bug620428) {
1209 // Test that timers and intervals are cancelable.
1210 EmbedderTestTimerHandlingDelegate delegate;
1211 SetDelegate(&delegate);
1212
1213 ASSERT_TRUE(OpenDocument("bug_620428.pdf"));
1214 FPDF_PAGE page = LoadPage(0);
1215 EXPECT_TRUE(page);
1216 DoOpenActions();
1217 delegate.AdvanceTime(5000);
1218 UnloadPage(page);
1219
1220 const auto& alerts = delegate.GetAlerts();
1221 ASSERT_EQ(1U, alerts.size());
1222 EXPECT_EQ(L"done", alerts[0].message);
1223}
1224
1225TEST_F(FPDFFormFillEmbedderTest, Bug634394) {
1226 // Cancel timer inside timer callback.
1227 EmbedderTestTimerHandlingDelegate delegate;
1228 SetDelegate(&delegate);
1229
1230 ASSERT_TRUE(OpenDocument("bug_634394.pdf"));
1231 FPDF_PAGE page = LoadPage(0);
1232 EXPECT_TRUE(page);
1233 DoOpenActions();
1234
1235 // Timers fire at most once per AdvanceTime(), allow intervals
1236 // to fire several times if possible.
1237 delegate.AdvanceTime(1000);
1238 delegate.AdvanceTime(1000);
1239 delegate.AdvanceTime(1000);
1240 delegate.AdvanceTime(1000);
1241 delegate.AdvanceTime(1000);
1242 UnloadPage(page);
1243
1244 const auto& alerts = delegate.GetAlerts();
1245 EXPECT_EQ(2U, alerts.size());
1246}
1247
1248TEST_F(FPDFFormFillEmbedderTest, Bug634716) {
1249 EmbedderTestTimerHandlingDelegate delegate;
1250 SetDelegate(&delegate);
1251
1252 ASSERT_TRUE(OpenDocument("bug_634716.pdf"));
1253 FPDF_PAGE page = LoadPage(0);
1254 EXPECT_TRUE(page);
1255 DoOpenActions();
1256
1257 // Timers fire at most once per AdvanceTime(), allow intervals
1258 // to fire several times if possible.
1259 delegate.AdvanceTime(1000);
1260 delegate.AdvanceTime(1000);
1261 delegate.AdvanceTime(1000);
1262 delegate.AdvanceTime(1000);
1263 delegate.AdvanceTime(1000);
1264 UnloadPage(page);
1265
1266 const auto& alerts = delegate.GetAlerts();
1267 EXPECT_EQ(2U, alerts.size());
1268}
1269
1270TEST_F(FPDFFormFillEmbedderTest, Bug679649) {
1271 EmbedderTestTimerHandlingDelegate delegate;
1272 SetDelegate(&delegate);
1273
1274 ASSERT_TRUE(OpenDocument("bug_679649.pdf"));
1275 FPDF_PAGE page = LoadPage(0);
1276 EXPECT_TRUE(page);
1277
1278 delegate.SetFailNextTimer();
1279 DoOpenActions();
1280 delegate.AdvanceTime(2000);
1281 UnloadPage(page);
1282
1283 const auto& alerts = delegate.GetAlerts();
1284 EXPECT_EQ(0u, alerts.size());
1285}
1286
1287TEST_F(FPDFFormFillEmbedderTest, Bug707673) {
1288 EmbedderTestTimerHandlingDelegate delegate;
1289 SetDelegate(&delegate);
1290
1291 ASSERT_TRUE(OpenDocument("bug_707673.pdf"));
1292 FPDF_PAGE page = LoadPage(0);
1293 EXPECT_TRUE(page);
1294
1295 DoOpenActions();
1296 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
1297 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
1298 delegate.AdvanceTime(1000);
1299 UnloadPage(page);
1300
1301 const auto& alerts = delegate.GetAlerts();
1302 EXPECT_EQ(0u, alerts.size());
1303}
1304
1305TEST_F(FPDFFormFillEmbedderTest, Bug765384) {
1306 ASSERT_TRUE(OpenDocument("bug_765384.pdf"));
1307 FPDF_PAGE page = LoadPage(0);
1308 EXPECT_TRUE(page);
1309
1310 DoOpenActions();
1311 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
1312 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
1313 UnloadPage(page);
1314}
1315
1316// Test passes if DCHECK() not hit.
1317TEST_F(FPDFFormFillEmbedderTest, Bug1477093) {
1318 EmbedderTestTimerHandlingDelegate delegate;
1319 SetDelegate(&delegate);
1320
1321 ASSERT_TRUE(OpenDocument("bug_1477093.pdf"));
1322 FPDF_PAGE page = LoadPage(0);
1323 EXPECT_TRUE(page);
1324
1325 DoOpenActions();
1326 delegate.AdvanceTime(1000);
1327 delegate.AdvanceTime(1000);
1328 UnloadPage(page);
1329}
1330
1331#endif // PDF_ENABLE_V8
1332
1334 const char* focused_text_form_with_abc_checksum = []() {
1335 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1336#if BUILDFLAG(IS_WIN)
1337 return "8b743c7a6186360862ca6f6db8f55c8f";
1338#elif BUILDFLAG(IS_APPLE)
1339 return "d8cf4e7ef7e1c287441bf350006e66d6";
1340#else
1341 return "b9fb2245a98ac48146da84237a37f8cc";
1342#endif
1343 }
1344#if BUILDFLAG(IS_APPLE)
1345 return "9fb14198d75ca0a107060c60ca21b0c7";
1346#else
1347 return "6e6f790bb14c4fc6107faf8c17d23dbd";
1348#endif
1349 }();
1350 const char* unfocused_text_form_with_abc_checksum = []() {
1351 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1352#if BUILDFLAG(IS_WIN)
1353 return "37328bf7614d6fc05b03893ee030aec4";
1354#elif BUILDFLAG(IS_APPLE)
1355 return "b9702814ac50dc5ef413ea2e9c4002f1";
1356#else
1357 return "5f3205f0189d9dde54665f970838f614";
1358#endif
1359 }
1360#if BUILDFLAG(IS_APPLE)
1361 return "3c3209357e0c057a0620afa7d83eb784";
1362#else
1363 return "94b7e10ac8c662b73e33628ca2f5e63b";
1364#endif
1365 }();
1366 {
1367 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1368 FPDF_PAGE page = LoadPage(0);
1369 ASSERT_TRUE(page);
1370 ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page);
1371 CompareBitmap(bitmap1.get(), 300, 300, TextFormChecksum());
1372
1373 // Click on the textfield
1374 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1375 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
1376 EXPECT_EQ(
1377 0, FPDFPage_FormFieldZOrderAtPoint(form_handle(), page, 120.0, 120.0));
1378 FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
1379 FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
1380 FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
1381
1382 // Write "ABC"
1383 FORM_OnChar(form_handle(), page, 'A', 0);
1384 FORM_OnChar(form_handle(), page, 'B', 0);
1385 FORM_OnChar(form_handle(), page, 'C', 0);
1386 ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
1387 CompareBitmap(bitmap2.get(), 300, 300, focused_text_form_with_abc_checksum);
1388
1389 // Focus remains despite right clicking out of the textfield
1390 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
1391 FORM_OnRButtonDown(form_handle(), page, 0, 15.0, 15.0);
1392 FORM_OnRButtonUp(form_handle(), page, 0, 15.0, 15.0);
1393 ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
1394 CompareBitmap(bitmap3.get(), 300, 300, focused_text_form_with_abc_checksum);
1395
1396 // Take out focus by clicking out of the textfield
1397 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
1398 FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
1399 FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
1400 ScopedFPDFBitmap bitmap4 = RenderLoadedPage(page);
1401 CompareBitmap(bitmap4.get(), 300, 300,
1402 unfocused_text_form_with_abc_checksum);
1403
1404 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1405
1406 // Close page
1407 UnloadPage(page);
1408 }
1409 // Check saved document
1410 VerifySavedDocument(300, 300, unfocused_text_form_with_abc_checksum);
1411}
1412
1413// Tests using FPDF_REVERSE_BYTE_ORDER with FPDF_FFLDraw(). The two rendered
1414// bitmaps should be different.
1416 const char* reverse_byte_order_checksum = []() {
1417 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1418 return "8077970bbd10333f18186a9bb459bbe6";
1419 }
1420 return "24fff03d1e663b7ece5f6e69ad837124";
1421 }();
1422
1423 ASSERT_TRUE(OpenDocument("bug_890322.pdf"));
1424 FPDF_PAGE page = LoadPage(0);
1425 ASSERT_TRUE(page);
1426
1427 ScopedFPDFBitmap bitmap_normal = RenderLoadedPage(page);
1428 CompareBitmap(bitmap_normal.get(), 200, 200, pdfium::Bug890322Checksum());
1429
1430 ScopedFPDFBitmap bitmap_reverse_byte_order =
1431 RenderLoadedPageWithFlags(page, FPDF_REVERSE_BYTE_ORDER);
1432 CompareBitmap(bitmap_reverse_byte_order.get(), 200, 200,
1433 reverse_byte_order_checksum);
1434
1435 UnloadPage(page);
1436}
1437
1439 const char* checksum = []() {
1440 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1441 return "520c4415c9977f40d6b4af5a0a94d764";
1442 }
1443 return "bbee92af1daec2340c81f482878744d8";
1444 }();
1445 {
1446 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1447 FPDF_PAGE page = LoadPage(0);
1448 ASSERT_TRUE(page);
1449
1450 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1451 CompareBitmap(bitmap.get(), 300, 300, checksum);
1452
1453 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1454
1455 UnloadPage(page);
1456 }
1457 VerifySavedDocument(300, 300, checksum);
1458}
1459
1461 const char* checksum = []() {
1462 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1463#if BUILDFLAG(IS_WIN)
1464 return "2e5d64e4280ca954eb528e82f92abb75";
1465#elif BUILDFLAG(IS_APPLE)
1466 return "79538a800f8eb0b4965d43a052303592";
1467#else
1468 return "143c2bb79fcaecf24f5aa104dce27beb";
1469#endif
1470 }
1471#if BUILDFLAG(IS_APPLE)
1472 return "bf5423874f188427d2500a2bc4abebbe";
1473#else
1474 return "6a4ac9a15d2c34589616c8f2b05fbedd";
1475#endif
1476 }();
1477 {
1478 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1479 FPDF_PAGE page = LoadPage(0);
1480 ASSERT_TRUE(page);
1481
1482 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1483 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 110));
1484 FORM_OnMouseMove(form_handle(), page, 0, 110, 110);
1485 FORM_OnLButtonDown(form_handle(), page, 0, 110, 110);
1486 FORM_OnLButtonUp(form_handle(), page, 0, 110, 110);
1487 FORM_OnChar(form_handle(), page, 'A', 0);
1488
1489 FORM_ForceToKillFocus(form_handle());
1490 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1491 CompareBitmap(bitmap.get(), 300, 300, checksum);
1492
1493 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1494
1495 UnloadPage(page);
1496 }
1497 VerifySavedDocument(300, 300, checksum);
1498}
1499
1501 const char* checksum = []() {
1502 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1503#if BUILDFLAG(IS_WIN)
1504 return "8408fc1796bf17d48b947ed0e4d65ef2";
1505#elif BUILDFLAG(IS_APPLE)
1506 return "074449f4bd27611a2e12aef3ad121cd8";
1507#else
1508 return "e36726414acb616dc203e8851b510e2c";
1509#endif
1510 }
1511#if BUILDFLAG(IS_APPLE)
1512 return "8a0fd8772dba6e1e952e49d159cc64b5";
1513#else
1514 return "45a7694933c2ba3c5dc8f6cc18b79175";
1515#endif
1516 }();
1517 {
1518 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1519 FPDF_PAGE page = LoadPage(0);
1520 ASSERT_TRUE(page);
1521
1522 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1523 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 170));
1524 FORM_OnMouseMove(form_handle(), page, 0, 110, 170);
1525 FORM_OnLButtonDown(form_handle(), page, 0, 110, 170);
1526 FORM_OnLButtonUp(form_handle(), page, 0, 110, 170);
1527 FORM_OnChar(form_handle(), page, 'B', 0);
1528
1529 FORM_ForceToKillFocus(form_handle());
1530 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1531 CompareBitmap(bitmap.get(), 300, 300, checksum);
1532
1533 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1534
1535 UnloadPage(page);
1536 }
1537 VerifySavedDocument(300, 300, checksum);
1538}
1539
1541 const char* checksum = []() {
1542 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1543#if BUILDFLAG(IS_WIN)
1544 return "1c2b618f68d1ad2cfa01fcf38efc4831";
1545#elif BUILDFLAG(IS_APPLE)
1546 return "f5a3b8d2db662cad38b4573ef1dd3f1d";
1547#else
1548 return "f82a807c056e22aa55d3d7228eedfe6f";
1549#endif
1550 }
1551#if BUILDFLAG(IS_APPLE)
1552 return "1f422ee1c520ad74b1a993b64bd4dc4a";
1553#else
1554 return "13984969b1e141079ab5f4aa80185463";
1555#endif
1556 }();
1557 {
1558 ASSERT_TRUE(OpenDocument("bug_1302455.pdf"));
1559 FPDF_PAGE page = LoadPage(0);
1560 ASSERT_TRUE(page);
1561
1562 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1563 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 110));
1564 FORM_OnMouseMove(form_handle(), page, 0, 110, 110);
1565 FORM_OnLButtonDown(form_handle(), page, 0, 110, 110);
1566 FORM_OnLButtonUp(form_handle(), page, 0, 110, 110);
1567 FORM_OnChar(form_handle(), page, 'A', 0);
1568
1569 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
1570 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 110, 170));
1571 FORM_OnMouseMove(form_handle(), page, 0, 110, 170);
1572 FORM_OnLButtonDown(form_handle(), page, 0, 110, 170);
1573 FORM_OnLButtonUp(form_handle(), page, 0, 110, 170);
1574 FORM_OnChar(form_handle(), page, 'B', 0);
1575
1576 FORM_ForceToKillFocus(form_handle());
1577 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
1578 CompareBitmap(bitmap.get(), 300, 300, checksum);
1579
1580 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
1581
1582 UnloadPage(page);
1583 }
1584 VerifySavedDocument(300, 300, checksum);
1585}
1586
1588 const char* no_highlight_checksum = []() {
1589 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
1590#if BUILDFLAG(IS_WIN)
1591 return "2235e2ba8349552de0c818ae53257949";
1592#elif BUILDFLAG(IS_APPLE)
1593 return "e0ad5b4fe007e2e2c27cf6c6fb5b6529";
1594#else
1595 return "3bfddb2529085021ad283b7e65f71525";
1596#endif
1597 }
1598#if BUILDFLAG(IS_APPLE)
1599 return "5c82aa43e3b478aa1e4c94bb9ef1f11f";
1600#else
1601 return "a6268304f7eedfa9ee98fac3caaf2efb";
1602#endif
1603 }();
1604
1605 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1606 FPDF_PAGE page = LoadPage(0);
1607 ASSERT_TRUE(page);
1608 ScopedFPDFBitmap bitmap1 = RenderLoadedPage(page);
1609 CompareBitmap(bitmap1.get(), 300, 300, TextFormChecksum());
1610
1611 // Removing the highlight changes the rendering.
1612 FPDF_RemoveFormFieldHighlight(form_handle());
1613 ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
1614 CompareBitmap(bitmap2.get(), 300, 300, no_highlight_checksum);
1615
1616 // Restoring it gives the original rendering.
1617 SetInitialFormFieldHighlight(form_handle());
1618 ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
1619 CompareBitmap(bitmap3.get(), 300, 300, TextFormChecksum());
1620
1621 UnloadPage(page);
1622}
1623
1625 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
1626 EXPECT_EQ(FORMTYPE_NONE, FPDF_GetFormType(document()));
1627}
1628
1630 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1631 EXPECT_EQ(FORMTYPE_ACRO_FORM, FPDF_GetFormType(document()));
1632}
1633
1635 ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
1636 EXPECT_EQ(FORMTYPE_XFA_FULL, FPDF_GetFormType(document()));
1637}
1638
1640 ASSERT_TRUE(OpenDocument("bug_216.pdf"));
1641 EXPECT_EQ(FORMTYPE_XFA_FOREGROUND, FPDF_GetFormType(document()));
1642}
1643
1645 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1646 FPDF_PAGE page = LoadPage(0);
1647 ASSERT_TRUE(page);
1648
1649 EXPECT_FALSE(FORM_SetIndexSelected(nullptr, nullptr, 0, true));
1650 EXPECT_FALSE(FORM_SetIndexSelected(nullptr, page, 0, true));
1651 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), nullptr, 0, true));
1652 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
1653 EXPECT_FALSE(FORM_IsIndexSelected(nullptr, nullptr, 0));
1654 EXPECT_FALSE(FORM_IsIndexSelected(nullptr, page, 0));
1655 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), nullptr, 0));
1656 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
1657
1658 UnloadPage(page);
1659}
1660
1662 ASSERT_TRUE(OpenDocument("combobox_form.pdf"));
1663 FPDF_PAGE page = LoadPage(0);
1664 ASSERT_TRUE(page);
1665
1666 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
1667 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, 100, true));
1668 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
1669 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, 100));
1670
1671 UnloadPage(page);
1672}
1673
1675 ASSERT_TRUE(OpenDocument("listbox_form.pdf"));
1676 FPDF_PAGE page = LoadPage(0);
1677 ASSERT_TRUE(page);
1678
1679 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, -1, true));
1680 EXPECT_FALSE(FORM_SetIndexSelected(form_handle(), page, 100, true));
1681 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, -1));
1682 EXPECT_FALSE(FORM_IsIndexSelected(form_handle(), page, 100));
1683
1684 UnloadPage(page);
1685}
1686
1688 ASSERT_TRUE(OpenDocument("simple_xfa.pdf"));
1689 FPDF_PAGE page = LoadPage(0);
1690 ASSERT_TRUE(page);
1691
1692 EXPECT_EQ(-1, FPDFPage_HasFormFieldAtPoint(form_handle(), page, 612, 792));
1693
1694#ifdef PDF_ENABLE_XFA
1695 constexpr int kExpectedFieldType = FPDF_FORMFIELD_XFA_TEXTFIELD;
1696#else
1697 constexpr int kExpectedFieldType = -1;
1698#endif
1699 EXPECT_EQ(kExpectedFieldType,
1700 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 50, 30));
1701
1702 UnloadPage(page);
1703}
1704
1706 ASSERT_TRUE(OpenDocument("text_form.pdf"));
1707 FPDF_PAGE page = LoadPage(0);
1708 ASSERT_TRUE(page);
1709
1710 // Test bad arguments.
1711 EXPECT_FALSE(FORM_SelectAllText(nullptr, nullptr));
1712 EXPECT_FALSE(FORM_SelectAllText(form_handle(), nullptr));
1713 EXPECT_FALSE(FORM_SelectAllText(nullptr, page));
1714
1715 // Focus on the text field and add some text.
1716 EXPECT_TRUE(FORM_OnFocus(form_handle(), page, 0, 115, 115));
1717 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
1718 FORM_ReplaceSelection(form_handle(), page, text_to_insert.get());
1719
1720 // Sanity check text field data.
1721 uint16_t buffer[6];
1722 ASSERT_EQ(12u, FORM_GetFocusedText(form_handle(), page, nullptr, 0));
1723 ASSERT_EQ(12u,
1724 FORM_GetFocusedText(form_handle(), page, buffer, sizeof(buffer)));
1725 EXPECT_EQ("Hello", GetPlatformString(buffer));
1726
1727 // Check there is no selection.
1728 ASSERT_EQ(2u, FORM_GetSelectedText(form_handle(), page, nullptr, 0));
1729 ASSERT_EQ(2u,
1730 FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer)));
1731 EXPECT_EQ("", GetPlatformString(buffer));
1732
1733 // Check FORM_SelectAllText() works.
1734 EXPECT_TRUE(FORM_SelectAllText(form_handle(), page));
1735 ASSERT_EQ(12u, FORM_GetSelectedText(form_handle(), page, nullptr, 0));
1736 ASSERT_EQ(12u,
1737 FORM_GetSelectedText(form_handle(), page, buffer, sizeof(buffer)));
1738 EXPECT_EQ("Hello", GetPlatformString(buffer));
1739
1740 UnloadPage(page);
1741}
1742
1744 // Test empty selection.
1745 CheckFocusedFieldText("");
1746 CheckSelection("");
1747
1748 // Test basic selection.
1749 TypeTextIntoTextField(3, RegularFormBegin());
1750 CheckFocusedFieldText("ABC");
1751 SelectTextWithKeyboard(3, FWL_VKEY_Left, RegularFormAtX(123.0));
1752 CheckSelection("ABC");
1753}
1754
1756 // Test empty selection.
1757 CheckFocusedFieldText("");
1758 CheckSelection("");
1759
1760 // Test basic selection.
1761 TypeTextIntoTextField(3, RegularFormBegin());
1762 CheckFocusedFieldText("ABC");
1763 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormBegin());
1764 CheckSelection("ABC");
1765}
1766
1768 TypeTextIntoTextField(12, RegularFormBegin());
1769 CheckFocusedFieldText("ABCDEFGHIJKL");
1770
1771 // Test selecting first character in forward direction.
1772 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
1773 CheckSelection("A");
1774
1775 // Test selecting entire long string in backwards direction.
1776 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
1777 CheckSelection("ABCDEFGHIJKL");
1778
1779 // Test selecting middle section in backwards direction.
1780 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(170.0));
1781 CheckSelection("DEFGHI");
1782
1783 // Test selecting middle selection in forward direction.
1784 SelectTextWithKeyboard(6, FWL_VKEY_Right, RegularFormAtX(125.0));
1785 CheckSelection("DEFGHI");
1786
1787 // Test selecting last character in backwards direction.
1788 SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd());
1789 CheckSelection("L");
1790 CheckFocusedFieldText("ABCDEFGHIJKL");
1791}
1792
1794 TypeTextIntoTextField(12, RegularFormBegin());
1795
1796 // Test selecting first character in forward direction.
1797 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(106.0));
1798 CheckSelection("A");
1799
1800 // Test selecting entire long string in backwards direction.
1801 SelectAllRegularFormTextWithMouse();
1802 CheckSelection("ABCDEFGHIJKL");
1803
1804 // Test selecting middle section in backwards direction.
1805 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
1806 CheckSelection("DEFGHI");
1807
1808 // Test selecting middle selection in forward direction.
1809 SelectTextWithMouse(RegularFormAtX(125.0), RegularFormAtX(170.0));
1810 CheckSelection("DEFGHI");
1811
1812 // Test selecting last character in backwards direction.
1813 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(186.0));
1814 CheckSelection("L");
1815}
1816
1819 // Test empty selection.
1820 CheckSelection("");
1821 CheckFocusedFieldText("");
1822
1823 // Non-editable comboboxes don't allow selection with keyboard.
1824 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(142.0));
1825 CheckFocusedFieldText("Banana");
1826 CheckSelection("Banana");
1827
1828 // Select other another provided option.
1829 SelectNonEditableFormOption(0);
1830 CheckFocusedFieldText("Apple");
1831 CheckSelection("Apple");
1832}
1833
1836 // Test empty selection.
1837 CheckSelection("");
1838 CheckFocusedFieldText("");
1839
1840 // Test basic selection of text within user editable combobox using keyboard.
1841 TypeTextIntoTextField(3, EditableFormBegin());
1842 CheckFocusedFieldText("ABC");
1843 SelectTextWithKeyboard(3, FWL_VKEY_Left, EditableFormAtX(128.0));
1844 CheckSelection("ABC");
1845
1846 // Select a provided option.
1847 SelectEditableFormOption(1);
1848 CheckSelection("Bar");
1849 CheckFocusedFieldText("Bar");
1850}
1851
1854 // Test empty selection.
1855 CheckSelection("");
1856
1857 // Test basic selection of text within user editable combobox using mouse.
1858 TypeTextIntoTextField(3, EditableFormBegin());
1859 SelectTextWithMouse(EditableFormAtX(128.0), EditableFormBegin());
1860 CheckSelection("ABC");
1861
1862 // Select a provided option.
1863 SelectEditableFormOption(2);
1864 CheckFocusedFieldText("Qux");
1865 CheckSelection("Qux");
1866}
1867
1870 CheckFocusedFieldText("");
1871
1872 // Test selecting first character in forward direction.
1873 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(107.0));
1874 CheckFocusedFieldText("Banana");
1875 CheckSelection("B");
1876
1877 // Test selecting entire string in backwards direction.
1878 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormBegin());
1879 CheckSelection("Banana");
1880
1881 // Test selecting middle section in backwards direction.
1882 SelectTextWithMouse(NonEditableFormAtX(135.0), NonEditableFormAtX(117.0));
1883 CheckSelection("nan");
1884
1885 // Test selecting middle section in forward direction.
1886 SelectTextWithMouse(NonEditableFormAtX(117.0), NonEditableFormAtX(135.0));
1887 CheckSelection("nan");
1888
1889 // Test selecting last character in backwards direction.
1890 SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormAtX(138.0));
1891 CheckSelection("a");
1892 CheckFocusedFieldText("Banana");
1893
1894 // Select another option and then reset selection as first three chars.
1895 SelectNonEditableFormOption(2);
1896 CheckFocusedFieldText("Cherry");
1897 CheckSelection("Cherry");
1898 SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(122.0));
1899 CheckSelection("Che");
1900}
1901
1904 CheckFocusedFieldText("");
1905 TypeTextIntoTextField(10, EditableFormBegin());
1906 CheckFocusedFieldText("ABCDEFGHIJ");
1907
1908 // Test selecting first character in forward direction.
1909 SelectTextWithKeyboard(1, FWL_VKEY_Right, EditableFormBegin());
1910 CheckSelection("A");
1911
1912 // Test selecting entire long string in backwards direction.
1913 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
1914 CheckSelection("ABCDEFGHIJ");
1915
1916 // Test selecting middle section in backwards direction.
1917 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(168.0));
1918 CheckSelection("DEFGH");
1919
1920 // Test selecting middle selection in forward direction.
1921 SelectTextWithKeyboard(5, FWL_VKEY_Right, EditableFormAtX(127.0));
1922 CheckSelection("DEFGH");
1923
1924 // Test selecting last character in backwards direction.
1925 SelectTextWithKeyboard(1, FWL_VKEY_Left, EditableFormEnd());
1926 CheckSelection("J");
1927
1928 // Select a provided option and then reset selection as first two chars.
1929 SelectEditableFormOption(0);
1930 CheckSelection("Foo");
1931 SelectTextWithKeyboard(2, FWL_VKEY_Right, EditableFormBegin());
1932 CheckSelection("Fo");
1933 CheckFocusedFieldText("Foo");
1934}
1935
1938 TypeTextIntoTextField(10, EditableFormBegin());
1939
1940 // Test selecting first character in forward direction.
1941 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(107.0));
1942 CheckSelection("A");
1943
1944 // Test selecting entire long string in backwards direction.
1945 SelectAllEditableFormTextWithMouse();
1946 CheckSelection("ABCDEFGHIJ");
1947
1948 // Test selecting middle section in backwards direction.
1949 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
1950 CheckSelection("DEFGH");
1951
1952 // Test selecting middle selection in forward direction.
1953 SelectTextWithMouse(EditableFormAtX(127.0), EditableFormAtX(168.0));
1954 CheckSelection("DEFGH");
1955
1956 // Test selecting last character in backwards direction.
1957 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(174.0));
1958 CheckSelection("J");
1959 CheckFocusedFieldText("ABCDEFGHIJ");
1960}
1961
1964 // Focus on non-editable form field and check that the value is as expected.
1965 // This is the value that is present in the field upon opening, we have not
1966 // changed it by setting focus.
1967 FocusOnNonEditableForm();
1968 CheckFocusedFieldText("Banana");
1969
1970 // Make selections to change the value of the focused annotation
1971 // programmatically.
1972 SetIndexSelectedShouldSucceed(0, true);
1973 CheckFocusedFieldText("Apple");
1974
1975 // Selecting an index that is already selected is success.
1976 SetIndexSelectedShouldSucceed(0, true);
1977 CheckFocusedFieldText("Apple");
1978
1979 SetIndexSelectedShouldSucceed(9, true);
1980 CheckFocusedFieldText("Jackfruit");
1981
1982 // Cannot deselect a combobox field - value unchanged.
1983 SetIndexSelectedShouldFail(9, false);
1984 CheckFocusedFieldText("Jackfruit");
1985
1986 // Cannot select indices that are out of range - value unchanged.
1987 SetIndexSelectedShouldFail(100, true);
1988 SetIndexSelectedShouldFail(-100, true);
1989 CheckFocusedFieldText("Jackfruit");
1990
1991 // Check that above actions are interchangeable with click actions, should be
1992 // able to use a combination of both.
1993 SelectNonEditableFormOption(1);
1994 CheckFocusedFieldText("Banana");
1995}
1996
1999 // Focus on editable form field and check that the value is as expected.
2000 // This is the value that is present in the field upon opening, we have not
2001 // changed it by setting focus.
2002 FocusOnEditableForm();
2003 CheckFocusedFieldText("");
2004
2005 // Make selections to change value of the focused annotation
2006 // programmatically.
2007 SetIndexSelectedShouldSucceed(0, true);
2008 CheckFocusedFieldText("Foo");
2009
2010 SetIndexSelectedShouldSucceed(1, true);
2011 CheckFocusedFieldText("Bar");
2012
2013 // Selecting an index that is already selected is success.
2014 SetIndexSelectedShouldSucceed(1, true);
2015 CheckFocusedFieldText("Bar");
2016
2017 // Cannot deselect a combobox field - value unchanged.
2018 SetIndexSelectedShouldFail(0, false);
2019 CheckFocusedFieldText("Bar");
2020
2021 // Cannot select indices that are out of range - value unchanged.
2022 SetIndexSelectedShouldFail(100, true);
2023 SetIndexSelectedShouldFail(-100, true);
2024 CheckFocusedFieldText("Bar");
2025
2026 // Check that above actions are interchangeable with click actions, should be
2027 // able to use a combination of both.
2028 SelectEditableFormOption(0);
2029 CheckFocusedFieldText("Foo");
2030
2031 // Check that above actions are interchangeable with typing actions, should
2032 // be able to use a combination of both. Typing text into a text field after
2033 // selecting indices programmatically should be equivalent to doing so after
2034 // a user selects an index via click on the dropdown.
2035 SetIndexSelectedShouldSucceed(1, true);
2036 CheckFocusedFieldText("Bar");
2037 TypeTextIntoTextField(5, EditableFormBegin());
2038 CheckFocusedFieldText("ABCDEBar");
2039}
2040
2043 // Non-editable field is set to 'Banana' (index 1) upon opening.
2044 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2045 for (int i = 0; i < 26; i++) {
2046 bool expected = i == 1;
2047 CheckIsIndexSelected(i, expected);
2048 }
2049
2050 SelectNonEditableFormOption(0);
2051 CheckIsIndexSelected(0, true);
2052 for (int i = 1; i < 26; i++) {
2053 CheckIsIndexSelected(i, false);
2054 }
2055}
2056
2059 // Editable field has nothing selected upon opening.
2060 ClickOnFormFieldAtPoint(EditableFormBegin());
2061 CheckIsIndexSelected(0, false);
2062 CheckIsIndexSelected(1, false);
2063 CheckIsIndexSelected(2, false);
2064
2065 SelectEditableFormOption(0);
2066 CheckIsIndexSelected(0, true);
2067 CheckIsIndexSelected(1, false);
2068 CheckIsIndexSelected(2, false);
2069}
2070
2072 // Select entire contents of text field.
2073 TypeTextIntoTextField(12, RegularFormBegin());
2074 SelectAllRegularFormTextWithMouse();
2075 CheckFocusedFieldText("ABCDEFGHIJKL");
2076 CheckSelection("ABCDEFGHIJKL");
2077
2078 // Test deleting current text selection. Select what remains after deletion to
2079 // check that remaining text is as expected.
2080 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2081 CheckFocusedFieldText("");
2082
2083 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2084 CheckSelection("");
2085}
2086
2088 // Select middle section of text.
2089 TypeTextIntoTextField(12, RegularFormBegin());
2090 SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0));
2091 CheckFocusedFieldText("ABCDEFGHIJKL");
2092 CheckSelection("DEFGHI");
2093
2094 // Test deleting current text selection. Select what remains after deletion to
2095 // check that remaining text is as expected.
2096 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2097 CheckFocusedFieldText("ABCJKL");
2098 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2099 CheckSelection("ABCJKL");
2100}
2101
2103 // Select first few characters of text.
2104 TypeTextIntoTextField(12, RegularFormBegin());
2105 SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(132.0));
2106 CheckSelection("ABCD");
2107
2108 // Test deleting current text selection. Select what remains after deletion to
2109 // check that remaining text is as expected.
2110 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2111 CheckFocusedFieldText("EFGHIJKL");
2112 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2113 CheckSelection("EFGHIJKL");
2114}
2115
2117 // Select last few characters of text.
2118 TypeTextIntoTextField(12, RegularFormBegin());
2119 SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(165.0));
2120 CheckSelection("IJKL");
2121
2122 // Test deleting current text selection. Select what remains after deletion to
2123 // check that remaining text is as expected.
2124 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2125 CheckFocusedFieldText("ABCDEFGH");
2126 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2127 CheckSelection("ABCDEFGH");
2128}
2129
2131 // Do not select text.
2132 TypeTextIntoTextField(12, RegularFormBegin());
2133 CheckSelection("");
2134
2135 // Test that attempt to delete empty text selection has no effect.
2136 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2137 CheckFocusedFieldText("ABCDEFGHIJKL");
2138 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2139 CheckSelection("ABCDEFGHIJKL");
2140}
2141
2144 // Select entire contents of user-editable combobox text field.
2145 TypeTextIntoTextField(10, EditableFormBegin());
2146 SelectAllEditableFormTextWithMouse();
2147 CheckSelection("ABCDEFGHIJ");
2148
2149 // Test deleting current text selection. Select what remains after deletion to
2150 // check that remaining text is as expected.
2151 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2152 CheckFocusedFieldText("");
2153 SelectAllEditableFormTextWithMouse();
2154 CheckSelection("");
2155}
2156
2159 // Select middle section of text.
2160 TypeTextIntoTextField(10, EditableFormBegin());
2161 SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0));
2162 CheckSelection("DEFGH");
2163
2164 // Test deleting current text selection. Select what remains after deletion to
2165 // check that remaining text is as expected.
2166 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2167 CheckFocusedFieldText("ABCIJ");
2168 SelectAllEditableFormTextWithMouse();
2169 CheckSelection("ABCIJ");
2170}
2171
2174 // Select first few characters of text.
2175 TypeTextIntoTextField(10, EditableFormBegin());
2176 SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(132.0));
2177 CheckSelection("ABCD");
2178
2179 // Test deleting current text selection. Select what remains after deletion to
2180 // check that remaining text is as expected.
2181 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2182 SelectAllEditableFormTextWithMouse();
2183 CheckSelection("EFGHIJ");
2184}
2185
2188 // Select last few characters of text.
2189 TypeTextIntoTextField(10, EditableFormBegin());
2190 SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(152.0));
2191 CheckSelection("GHIJ");
2192
2193 // Test deleting current text selection. Select what remains after deletion to
2194 // check that remaining text is as expected.
2195 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2196 SelectAllEditableFormTextWithMouse();
2197 CheckSelection("ABCDEF");
2198}
2199
2202 // Do not select text.
2203 TypeTextIntoTextField(10, EditableFormBegin());
2204 CheckSelection("");
2205
2206 // Test that attempt to delete empty text selection has no effect.
2207 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2208 SelectAllEditableFormTextWithMouse();
2209 CheckSelection("ABCDEFGHIJ");
2210}
2211
2213 CheckFocusedFieldText("");
2214 ClickOnFormFieldAtPoint(RegularFormBegin());
2215 CheckFocusedFieldText("");
2216
2217 // Test inserting text into empty text field.
2218 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2219 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2220 CheckFocusedFieldText("Hello");
2221
2222 // Select entire contents of text field to check that insertion worked
2223 // as expected.
2224 CheckSelection("");
2225 SelectAllRegularFormTextWithMouse();
2226 CheckSelection("Hello");
2227}
2228
2230 TypeTextIntoTextField(8, RegularFormBegin());
2231 CheckFocusedFieldText("ABCDEFGH");
2232
2233 // Click on the leftmost part of the text field.
2234 ClickOnFormFieldAtPoint(RegularFormBegin());
2235 CheckFocusedFieldText("ABCDEFGH");
2236
2237 // Test inserting text in front of existing text in text field.
2238 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2239 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2240 CheckFocusedFieldText("HelloABCDEFGH");
2241
2242 // Select entire contents of text field to check that insertion worked
2243 // as expected.
2244 CheckSelection("");
2245 SelectAllRegularFormTextWithMouse();
2246 CheckSelection("HelloABCDEFGH");
2247}
2248
2250 TypeTextIntoTextField(8, RegularFormBegin());
2251
2252 // Click on the middle of the text field.
2253 ClickOnFormFieldAtPoint(RegularFormAtX(134.0));
2254
2255 // Test inserting text in the middle of existing text in text field.
2256 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2257 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2258 CheckFocusedFieldText("ABCDHelloEFGH");
2259
2260 // Select entire contents of text field to check that insertion worked
2261 // as expected.
2262 CheckSelection("");
2263 SelectAllRegularFormTextWithMouse();
2264 CheckSelection("ABCDHelloEFGH");
2265}
2266
2268 TypeTextIntoTextField(8, RegularFormBegin());
2269
2270 // Click on the rightmost part of the text field.
2271 ClickOnFormFieldAtPoint(RegularFormAtX(166.0));
2272
2273 // Test inserting text behind existing text in text field.
2274 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2275 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2276 CheckFocusedFieldText("ABCDEFGHHello");
2277
2278 // Select entire contents of text field to check that insertion worked
2279 // as expected.
2280 CheckSelection("");
2281 SelectAllRegularFormTextWithMouse();
2282 CheckSelection("ABCDEFGHHello");
2283}
2284
2287 TypeTextIntoTextField(12, RegularFormBegin());
2288
2289 // Select entire string in text field.
2290 CheckSelection("");
2291 SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd());
2292 CheckSelection("ABCDEFGHIJKL");
2293
2294 // Test replacing text selection with text to be inserted.
2295 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2296 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2297 CheckFocusedFieldText("Hello");
2298
2299 // Select entire contents of text field to check that insertion worked
2300 // as expected.
2301 CheckSelection("");
2302 SelectAllRegularFormTextWithMouse();
2303 CheckSelection("Hello");
2304}
2305
2308 TypeTextIntoTextField(12, RegularFormBegin());
2309
2310 // Select left portion of string in text field.
2311 CheckSelection("");
2312 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(148.0));
2313 CheckSelection("ABCDEF");
2314
2315 // Test replacing text selection with text to be inserted.
2316 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2317 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2318 CheckFocusedFieldText("HelloGHIJKL");
2319
2320 // Select entire contents of text field to check that insertion worked
2321 // as expected.
2322 CheckSelection("");
2323 SelectAllRegularFormTextWithMouse();
2324 CheckSelection("HelloGHIJKL");
2325}
2326
2329 TypeTextIntoTextField(12, RegularFormBegin());
2330
2331 // Select middle portion of string in text field.
2332 CheckSelection("");
2333 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(171.0));
2334 CheckSelection("DEFGHI");
2335
2336 // Test replacing text selection with text to be inserted.
2337 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2338 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2339
2340 // Select entire contents of text field to check that insertion worked
2341 // as expected.
2342 CheckSelection("");
2343 SelectAllRegularFormTextWithMouse();
2344 CheckSelection("ABCHelloJKL");
2345}
2346
2349 TypeTextIntoTextField(12, RegularFormBegin());
2350
2351 // Select right portion of string in text field.
2352 CheckSelection("");
2353 SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormEnd());
2354 CheckSelection("GHIJKL");
2355
2356 // Test replacing text selection with text to be inserted.
2357 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2358 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2359
2360 // Select entire contents of text field to check that insertion worked
2361 // as expected.
2362 CheckSelection("");
2363 SelectAllRegularFormTextWithMouse();
2364 CheckSelection("ABCDEFHello");
2365}
2366
2369 ClickOnFormFieldAtPoint(EditableFormBegin());
2370 CheckFocusedFieldText("");
2371
2372 // Test inserting text into empty user-editable combobox.
2373 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2374 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2375 CheckFocusedFieldText("Hello");
2376
2377 // Select entire contents of user-editable combobox text field to check that
2378 // insertion worked as expected.
2379 CheckSelection("");
2380 SelectAllEditableFormTextWithMouse();
2381 CheckSelection("Hello");
2382}
2383
2386 TypeTextIntoTextField(6, EditableFormBegin());
2387
2388 // Click on the leftmost part of the user-editable combobox.
2389 ClickOnFormFieldAtPoint(EditableFormBegin());
2390
2391 // Test inserting text in front of existing text in user-editable combobox.
2392 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2393 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2394
2395 // Select entire contents of user-editable combobox text field to check that
2396 // insertion worked as expected.
2397 CheckSelection("");
2398 SelectAllEditableFormTextWithMouse();
2399 CheckSelection("HelloABCDEF");
2400}
2401
2404 TypeTextIntoTextField(6, EditableFormBegin());
2405
2406 // Click on the middle of the user-editable combobox.
2407 ClickOnFormFieldAtPoint(EditableFormAtX(126.0));
2408
2409 // Test inserting text in the middle of existing text in user-editable
2410 // combobox.
2411 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2412 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2413
2414 // Select entire contents of user-editable combobox text field to check that
2415 // insertion worked as expected.
2416 CheckSelection("");
2417 SelectAllEditableFormTextWithMouse();
2418 CheckSelection("ABCHelloDEF");
2419}
2420
2423 TypeTextIntoTextField(6, EditableFormBegin());
2424
2425 // Click on the rightmost part of the user-editable combobox.
2426 ClickOnFormFieldAtPoint(EditableFormEnd());
2427
2428 // Test inserting text behind existing text in user-editable combobox.
2429 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2430 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2431
2432 // Select entire contents of user-editable combobox text field to check that
2433 // insertion worked as expected.
2434 CheckSelection("");
2435 SelectAllEditableFormTextWithMouse();
2436 CheckSelection("ABCDEFHello");
2437}
2438
2441 TypeTextIntoTextField(10, EditableFormBegin());
2442
2443 // Select entire string in user-editable combobox.
2444 CheckSelection("");
2445 SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd());
2446 CheckSelection("ABCDEFGHIJ");
2447
2448 // Test replacing text selection with text to be inserted.
2449 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2450 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2451
2452 // Select entire contents of user-editable combobox text field to check that
2453 // insertion worked as expected.
2454 CheckSelection("");
2455 SelectAllEditableFormTextWithMouse();
2456 CheckSelection("Hello");
2457}
2458
2461 TypeTextIntoTextField(10, EditableFormBegin());
2462
2463 // Select left portion of string in user-editable combobox.
2464 CheckSelection("");
2465 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(142.0));
2466 CheckSelection("ABCDE");
2467
2468 // Test replacing text selection with text to be inserted.
2469 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2470 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2471
2472 // Select entire contents of user-editable combobox text field to check that
2473 // insertion worked as expected.
2474 CheckSelection("");
2475 SelectAllEditableFormTextWithMouse();
2476 CheckSelection("HelloFGHIJ");
2477}
2478
2481 TypeTextIntoTextField(10, EditableFormBegin());
2482
2483 // Select middle portion of string in user-editable combobox.
2484 CheckSelection("");
2485 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(167.0));
2486 CheckSelection("DEFGH");
2487
2488 // Test replacing text selection with text to be inserted.
2489 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2490 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2491
2492 // Select entire contents of user-editable combobox text field to check that
2493 // insertion worked as expected.
2494 CheckSelection("");
2495 SelectAllEditableFormTextWithMouse();
2496 CheckSelection("ABCHelloIJ");
2497}
2498
2501 TypeTextIntoTextField(10, EditableFormBegin());
2502
2503 // Select right portion of string in user-editable combobox.
2504 CheckSelection("");
2505 SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormEnd());
2506 CheckSelection("FGHIJ");
2507
2508 // Test replacing text selection with text to be inserted.
2509 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello");
2510 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2511
2512 // Select entire contents of user-editable combobox text field to check that
2513 // insertion worked as expected.
2514 CheckSelection("");
2515 SelectAllEditableFormTextWithMouse();
2516 CheckSelection("ABCDEHello");
2517}
2518
2521 // Non-editable field is set to 'Banana' (index 1) upon opening.
2522 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2523 CheckIsIndexSelected(0, false);
2524 CheckIsIndexSelected(1, true);
2525
2526 // Verify that the Return character is handled.
2527 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
2528
2529 // Change the selection in the combo-box using the arrow down key.
2530 EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
2531 CheckIsIndexSelected(1, false);
2532 CheckIsIndexSelected(2, true);
2533
2534 // Tab to the next control.
2535 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
2536
2537 // Shift-tab to the previous control.
2538 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
2540
2541 // Verify that the selection is unchanged.
2542 CheckIsIndexSelected(2, true);
2543
2544 // Verify that the Space character is handled.
2545 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kSpace, 0));
2546
2547 // Change the selection in the combo-box using the arrow down key.
2548 EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
2549 CheckIsIndexSelected(3, true);
2550
2551 // Tab to the next control.
2552 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
2553
2554 // Shift-tab to the previous control.
2555 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
2557
2558 // Verify that the selection is unchanged.
2559 CheckIsIndexSelected(3, true);
2560}
2561
2564 // Non-editable field is set to 'Banana' (index 1) upon opening.
2565 ClickOnFormFieldAtPoint(EditableFormBegin());
2566 CheckIsIndexSelected(0, false);
2567 CheckIsIndexSelected(1, false);
2568
2569 // Verify that the Return character is handled.
2570 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
2571
2572 // Change the selection in the combo-box using the arrow down key.
2573 EXPECT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Down, 0));
2574 CheckIsIndexSelected(0, true);
2575 CheckIsIndexSelected(1, false);
2576
2577 // Tab to the next control.
2578 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab, 0));
2579
2580 // Shift-tab to the previous control.
2581 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kTab,
2583
2584 // Verify that the selection is unchanged.
2585 CheckIsIndexSelected(0, true);
2586
2587 // Verify that the Space character is handled.
2588 EXPECT_TRUE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kSpace, 0));
2589
2590 CheckFocusedFieldText(" ");
2591 CheckIsIndexSelected(0, false);
2592}
2593
2596 // Click on the textfield.
2597 CheckFocusedFieldText("");
2598 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2599 CheckFocusedFieldText("Elephant");
2600
2601 // Delete pre-filled contents of text field with char limit.
2602 CheckSelection("");
2603 SelectAllCharLimitFormTextWithMouse();
2604 CheckSelection("Elephant");
2605 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2606 CheckFocusedFieldText("");
2607
2608 // Test inserting text into now empty text field so text to be inserted
2609 // exceeds the char limit and is cut off.
2610 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2611 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2612 CheckFocusedFieldText("Hippopotam");
2613
2614 // Select entire contents of text field to check that insertion worked
2615 // as expected.
2616 CheckSelection("");
2617 SelectAllCharLimitFormTextWithMouse();
2618 CheckSelection("Hippopotam");
2619}
2620
2623 // Click on the textfield.
2624 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2625 CheckFocusedFieldText("Elephant");
2626
2627 // Delete pre-filled contents of text field with char limit.
2628 CheckSelection("");
2629 SelectAllCharLimitFormTextWithMouse();
2630 CheckSelection("Elephant");
2631 FORM_ReplaceSelection(form_handle(), page(), nullptr);
2632
2633 // Test inserting text into now empty text field so text to be inserted
2634 // exceeds the char limit and is cut off.
2635 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Zebra");
2636 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2637 CheckFocusedFieldText("Zebra");
2638
2639 // Select entire contents of text field to check that insertion worked
2640 // as expected.
2641 CheckSelection("");
2642 SelectAllCharLimitFormTextWithMouse();
2643 CheckSelection("Zebra");
2644}
2645
2648 // Click on the leftmost part of the text field.
2649 ClickOnFormFieldAtPoint(CharLimitFormBegin());
2650
2651 // Test inserting text in front of existing text in text field.
2652 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2653 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2654
2655 // Select entire contents of text field to check that insertion worked
2656 // as expected.
2657 CheckSelection("");
2658 SelectAllCharLimitFormTextWithMouse();
2659 CheckSelection("HiElephant");
2660}
2661
2664 CheckFocusedFieldText("");
2665 TypeTextIntoTextField(8, RegularFormBegin());
2666 CheckFocusedFieldText("ABCDEFGH");
2667
2668 // Click on the middle of the text field.
2669 ClickOnFormFieldAtPoint(CharLimitFormAtX(134.0));
2670 CheckFocusedFieldText("Elephant");
2671
2672 // Test inserting text in the middle of existing text in text field.
2673 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2674 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2675 CheckFocusedFieldText("ElephHiant");
2676
2677 // Select entire contents of text field to check that insertion worked
2678 // as expected.
2679 CheckSelection("");
2680 SelectAllCharLimitFormTextWithMouse();
2681 CheckSelection("ElephHiant");
2682}
2683
2686 TypeTextIntoTextField(8, RegularFormBegin());
2687
2688 // Click on the rightmost part of the text field.
2689 ClickOnFormFieldAtPoint(CharLimitFormAtX(166.0));
2690
2691 // Test inserting text behind existing text in text field.
2692 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2693 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2694
2695 // Select entire contents of text field to check that insertion worked
2696 // as expected.
2697 CheckSelection("");
2698 SelectAllCharLimitFormTextWithMouse();
2699 CheckSelection("ElephantHi");
2700}
2701
2704 TypeTextIntoTextField(12, RegularFormBegin());
2705
2706 // Select entire string in text field.
2707 CheckSelection("");
2708 SelectTextWithKeyboard(12, FWL_VKEY_Left, CharLimitFormEnd());
2709 CheckSelection("Elephant");
2710
2711 // Test replacing text selection with text to be inserted.
2712 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2713 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2714
2715 // Select entire contents of text field to check that insertion worked
2716 // as expected.
2717 CheckSelection("");
2718 SelectAllCharLimitFormTextWithMouse();
2719 CheckSelection("Hippopotam");
2720}
2721
2724 TypeTextIntoTextField(12, RegularFormBegin());
2725
2726 // Select left portion of string in text field.
2727 CheckSelection("");
2728 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(122.0));
2729 CheckSelection("Elep");
2730
2731 // Test replacing text selection with text to be inserted.
2732 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2733 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2734
2735 // Select entire contents of text field to check that insertion worked
2736 // as expected.
2737 CheckSelection("");
2738 SelectAllCharLimitFormTextWithMouse();
2739 CheckSelection("Hippophant");
2740}
2741
2744 TypeTextIntoTextField(12, RegularFormBegin());
2745
2746 // Select middle portion of string in text field.
2747 CheckSelection("");
2748 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(136.0));
2749 CheckSelection("epha");
2750
2751 // Test replacing text selection with text to be inserted.
2752 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2753 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2754
2755 // Select entire contents of text field to check that insertion worked
2756 // as expected.
2757 CheckSelection("");
2758 SelectAllCharLimitFormTextWithMouse();
2759 CheckSelection("ElHippopnt");
2760}
2761
2764 TypeTextIntoTextField(12, RegularFormBegin());
2765
2766 // Select right portion of string in text field.
2767 CheckSelection("");
2768 SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(152.0));
2769 CheckSelection("hant");
2770
2771 // Test replacing text selection with text to be inserted.
2772 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hippopotamus");
2773 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2774
2775 // Select entire contents of text field to check that insertion worked
2776 // as expected.
2777 CheckSelection("");
2778 SelectAllCharLimitFormTextWithMouse();
2779 CheckSelection("ElepHippop");
2780}
2781
2783 CheckFocusedFieldText("");
2784 ClickOnFormFieldAtPoint(RegularFormBegin());
2785 CheckFocusedFieldText("");
2786
2787 // Test inserting text into empty text field.
2788 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"Hello World");
2789 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
2790 CheckFocusedFieldText("Hello World");
2791
2792 // Make sure double clicking selects the entire line.
2793 CheckSelection("");
2794 DoubleClickOnFormFieldAtPoint(RegularFormBegin());
2795 CheckSelection("Hello World");
2796}
2797
2799 testing::NiceMock<EmbedderTestMockDelegate> mock;
2800 SetDelegate(&mock);
2801 CheckFocusedFieldText("");
2802
2803#ifdef PDF_ENABLE_XFA
2804 EXPECT_CALL(mock, OnFocusChange(_, _, 0)).Times(1);
2805#else // PDF_ENABLE_XFA
2806 EXPECT_CALL(mock, OnFocusChange(_, _, 0)).Times(0);
2807#endif // PDF_ENABLE_XFA
2808
2809 ClickOnFormFieldAtPoint(RegularFormBegin());
2810}
2811
2814 testing::NiceMock<EmbedderTestMockDelegate> mock;
2815 SetDelegate(&mock);
2816 CheckFocusedFieldText("");
2817
2818 EXPECT_CALL(mock, OnFocusChange(_, _, 0)).Times(1);
2819 ClickOnFormFieldAtPoint(RegularFormBegin());
2820}
2821
2823 static const CFX_PointF kNonFormPoint(1, 1);
2824 CheckFocusedFieldText("");
2825 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2826 CheckFocusedFieldText("Elephant");
2827 ClickOnFormFieldAtPoint(RegularFormBegin());
2828 CheckFocusedFieldText("");
2829 TypeTextIntoTextField(3, CharLimitFormBegin());
2830 CheckFocusedFieldText("ABElephant");
2831 TypeTextIntoTextField(5, RegularFormBegin());
2832 CheckFocusedFieldText("ABCDE");
2833 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2834 CheckFocusedFieldText("ABElephant");
2835 ClickOnFormFieldAtPoint(kNonFormPoint);
2836 CheckFocusedFieldText("");
2837 ClickOnFormFieldAtPoint(kNonFormPoint);
2838 CheckFocusedFieldText("");
2839 ClickOnFormFieldAtPoint(CharLimitFormBegin());
2840 CheckFocusedFieldText("ABElephant");
2841 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2842 CheckFocusedFieldText("ABElephant");
2843 ClickOnFormFieldAtPoint(RegularFormEnd());
2844 CheckFocusedFieldText("ABCDE");
2845 ClickOnFormFieldAtPoint(RegularFormBegin());
2846 CheckFocusedFieldText("ABCDE");
2847 ClickOnFormFieldAtPoint(RegularFormBegin());
2848 CheckFocusedFieldText("ABCDE");
2849 ClickOnFormFieldAtPoint(CharLimitFormBegin());
2850 CheckFocusedFieldText("ABElephant");
2851 FORM_ForceToKillFocus(form_handle());
2852 CheckFocusedFieldText("");
2853}
2854
2856 static const CFX_PointF kNonFormPoint(1, 1);
2857 CheckFocusedFieldText("");
2858 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2859 CheckFocusedFieldText("Banana");
2860 ClickOnFormFieldAtPoint(EditableFormBegin());
2861 CheckFocusedFieldText("");
2862 ClickOnFormFieldAtPoint(NonEditableFormEnd());
2863 CheckFocusedFieldText("Banana");
2864 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2865 CheckFocusedFieldText("Banana");
2866 FORM_ForceToKillFocus(form_handle());
2867 CheckFocusedFieldText("");
2868 ClickOnFormFieldAtPoint(EditableFormBegin());
2869 CheckFocusedFieldText("");
2870 TypeTextIntoTextField(3, EditableFormBegin());
2871 CheckFocusedFieldText("ABC");
2872 ClickOnFormFieldAtPoint(kNonFormPoint);
2873 CheckFocusedFieldText("");
2874 TypeTextIntoTextField(3, EditableFormEnd());
2875 CheckFocusedFieldText("ABCABC");
2876 ClickOnFormFieldAtPoint(kNonFormPoint);
2877 CheckFocusedFieldText("");
2878 ClickOnFormFieldAtPoint(EditableFormDropDown());
2879 CheckFocusedFieldText("ABCABC");
2880 FORM_ForceToKillFocus(form_handle());
2881 CheckFocusedFieldText("");
2882 ClickOnFormFieldAtPoint(NonEditableFormDropDown());
2883 CheckFocusedFieldText("Banana");
2884 ClickOnFormFieldAtPoint(kNonFormPoint);
2885 CheckFocusedFieldText("");
2886 ClickOnFormFieldAtPoint(NonEditableFormEnd());
2887 CheckFocusedFieldText("Banana");
2888
2889 // Typing into non-editable field results in selecting a different option.
2890 TypeTextIntoTextField(1, NonEditableFormEnd());
2891 CheckFocusedFieldText("Apple");
2892 TypeTextIntoTextField(3, NonEditableFormEnd());
2893 CheckFocusedFieldText("Cherry");
2894 TypeTextIntoTextField(2, NonEditableFormEnd());
2895 CheckFocusedFieldText("Banana");
2896
2897 SelectEditableFormOption(0);
2898 CheckFocusedFieldText("Foo");
2899 SelectEditableFormOption(1);
2900 CheckFocusedFieldText("Bar");
2901 SelectEditableFormOption(2);
2902 CheckFocusedFieldText("Qux");
2903 SelectNonEditableFormOption(1);
2904 CheckFocusedFieldText("Banana");
2905 SelectNonEditableFormOption(0);
2906 CheckFocusedFieldText("Apple");
2907 SelectNonEditableFormOption(2);
2908 CheckFocusedFieldText("Cherry");
2909
2910 // Typing into an editable field changes the text in the option.
2911 SelectEditableFormOption(0);
2912 CheckFocusedFieldText("Foo");
2913 TypeTextIntoTextField(5, EditableFormBegin());
2914 CheckFocusedFieldText("ABCDEFoo");
2915 SelectEditableFormOption(2);
2916 CheckFocusedFieldText("Qux");
2917 TypeTextIntoTextField(2, EditableFormEnd());
2918 CheckFocusedFieldText("QuxAB");
2919
2920 // But a previously edited option is reset when selected again.
2921 SelectEditableFormOption(0);
2922 CheckFocusedFieldText("Foo");
2923 TypeTextIntoTextField(1, EditableFormBegin());
2924 CheckFocusedFieldText("AFoo");
2925 SelectEditableFormOption(0);
2926 CheckFocusedFieldText("Foo");
2927}
2928
2930 ClickOnFormFieldAtPoint(RegularFormBegin());
2931 CheckFocusedFieldText("");
2932 CheckCanUndo(false);
2933 CheckCanRedo(false);
2934
2935 TypeTextIntoTextField(5, RegularFormBegin());
2936 CheckFocusedFieldText("ABCDE");
2937 CheckCanUndo(true);
2938 CheckCanRedo(false);
2939
2940 PerformUndo();
2941 CheckFocusedFieldText("ABCD");
2942 CheckCanUndo(true);
2943 CheckCanRedo(true);
2944 PerformUndo();
2945 CheckFocusedFieldText("ABC");
2946 CheckCanUndo(true);
2947 CheckCanRedo(true);
2948
2949 PerformRedo();
2950 CheckFocusedFieldText("ABCD");
2951 CheckCanUndo(true);
2952 CheckCanRedo(true);
2953 PerformRedo();
2954 CheckFocusedFieldText("ABCDE");
2955 CheckCanUndo(true);
2956 CheckCanRedo(false);
2957}
2958
2959// This action only applies to Listboxes and Comboboxes so should fail
2960// gracefully for Textboxes by returning false to all operations.
2962 // set focus and read text to confirm we have it
2963 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2964 CheckFocusedFieldText("Elephant");
2965
2966 SetIndexSelectedShouldFail(0, true);
2967 SetIndexSelectedShouldFail(0, false);
2968 SetIndexSelectedShouldFail(1, true);
2969 SetIndexSelectedShouldFail(1, false);
2970 SetIndexSelectedShouldFail(-1, true);
2971 SetIndexSelectedShouldFail(-1, false);
2972}
2973
2974// This action only applies to Listboxes and Comboboxes so should fail
2975// gracefully for Textboxes by returning false to all operations.
2977 // set focus and read text to confirm we have it
2978 ClickOnFormFieldAtPoint(CharLimitFormEnd());
2979 CheckFocusedFieldText("Elephant");
2980
2981 CheckIsIndexSelected(0, false);
2982 CheckIsIndexSelected(1, false);
2983 CheckIsIndexSelected(-1, false);
2984}
2985
2987 ClickOnFormFieldAtPoint(NonEditableFormBegin());
2988 CheckFocusedFieldText("Banana");
2989 CheckCanUndo(false);
2990 CheckCanRedo(false);
2991
2992 ClickOnFormFieldAtPoint(EditableFormBegin());
2993 CheckFocusedFieldText("");
2994 CheckCanUndo(false);
2995 CheckCanRedo(false);
2996
2997 TypeTextIntoTextField(3, EditableFormBegin());
2998 CheckFocusedFieldText("ABC");
2999 CheckCanUndo(true);
3000 CheckCanRedo(false);
3001
3002 PerformUndo();
3003 CheckFocusedFieldText("AB");
3004 CheckCanUndo(true);
3005 CheckCanRedo(true);
3006 PerformUndo();
3007 CheckFocusedFieldText("A");
3008 CheckCanUndo(true);
3009 CheckCanRedo(true);
3010 PerformUndo();
3011 CheckFocusedFieldText("");
3012 CheckCanUndo(false);
3013 CheckCanRedo(true);
3014
3015 PerformRedo();
3016 CheckFocusedFieldText("A");
3017 CheckCanUndo(true);
3018 CheckCanRedo(true);
3019}
3020
3023 // Nothing is selected in single select field upon opening.
3024 FocusOnSingleSelectForm();
3025 CheckIsIndexSelected(0, false);
3026 CheckIsIndexSelected(1, false);
3027 CheckIsIndexSelected(2, false);
3028
3029 ClickOnSingleSelectFormOption(1);
3030 CheckIsIndexSelected(0, false);
3031 CheckIsIndexSelected(1, true);
3032 CheckIsIndexSelected(2, false);
3033}
3034
3037 // Multiselect field set to 'Banana' (index 1) upon opening.
3038 FocusOnMultiSelectForm();
3039 for (int i = 0; i < 26; i++) {
3040 bool expected = i == 1;
3041 CheckIsIndexSelected(i, expected);
3042 }
3043
3044 // TODO(bug_1377): Behavior should be changed to the one described below.
3045 // Multiselect field set to 'Cherry' (index 2), which is index 1 among the
3046 // visible form options because the listbox is scrolled down to have 'Banana'
3047 // (index 1) at the top.
3048 ClickOnMultiSelectFormOption(1);
3049 for (int i = 0; i < 26; i++) {
3050 bool expected = i == 1;
3051 CheckIsIndexSelected(i, expected);
3052 }
3053}
3054
3057 // Nothing is selected in single select field upon opening.
3058 FocusOnSingleSelectForm();
3059 CheckFocusedFieldText("");
3060 CheckIsIndexSelected(0, false);
3061 CheckIsIndexSelected(1, false);
3062 CheckIsIndexSelected(2, false);
3063
3064 // Make selections to change the value of the focused annotation
3065 // programmatically showing that only one value remains selected at a time.
3066 SetIndexSelectedShouldSucceed(0, true);
3067 CheckFocusedFieldText("Foo");
3068 CheckIsIndexSelected(0, true);
3069 CheckIsIndexSelected(1, false);
3070 CheckIsIndexSelected(2, false);
3071
3072 SetIndexSelectedShouldSucceed(1, true);
3073 CheckFocusedFieldText("Bar");
3074 CheckIsIndexSelected(0, false);
3075 CheckIsIndexSelected(1, true);
3076 CheckIsIndexSelected(2, false);
3077
3078 // Selecting/deselecting an index that is already selected/deselected is
3079 // success.
3080 SetIndexSelectedShouldSucceed(1, true);
3081 CheckFocusedFieldText("Bar");
3082 CheckIsIndexSelected(0, false);
3083 CheckIsIndexSelected(1, true);
3084 CheckIsIndexSelected(2, false);
3085
3086 SetIndexSelectedShouldSucceed(2, false);
3087 CheckFocusedFieldText("Bar");
3088 CheckIsIndexSelected(0, false);
3089 CheckIsIndexSelected(1, true);
3090 CheckIsIndexSelected(2, false);
3091
3092 // Cannot select indices that are out of range.
3093 SetIndexSelectedShouldFail(100, true);
3094 SetIndexSelectedShouldFail(-100, true);
3095 SetIndexSelectedShouldFail(100, false);
3096 SetIndexSelectedShouldFail(-100, false);
3097 // Confirm that previous values were not changed.
3098 CheckFocusedFieldText("Bar");
3099 CheckIsIndexSelected(0, false);
3100 CheckIsIndexSelected(1, true);
3101 CheckIsIndexSelected(2, false);
3102
3103 // Unlike combobox, should be able to deselect all indices.
3104 SetIndexSelectedShouldSucceed(1, false);
3105 CheckFocusedFieldText("");
3106 CheckIsIndexSelected(0, false);
3107 CheckIsIndexSelected(1, false);
3108 CheckIsIndexSelected(2, false);
3109
3110 // Check that above actions are interchangeable with click actions, should be
3111 // able to use a combination of both.
3112 ClickOnSingleSelectFormOption(1);
3113 CheckFocusedFieldText("Bar");
3114 CheckIsIndexSelected(0, false);
3115 CheckIsIndexSelected(1, true);
3116 CheckIsIndexSelected(2, false);
3117}
3118
3119// Re: Focus Field Text - For multiselect listboxes a caret is set on the last
3120// item to be selected/deselected. The text of that item should be returned.
3123 // Multiselect field set to 'Banana' (index 1) upon opening.
3124 FocusOnMultiSelectForm();
3125 for (int i = 0; i < 26; i++) {
3126 bool expected = i == 1;
3127 CheckIsIndexSelected(i, expected);
3128 }
3129 CheckFocusedFieldText("Banana");
3130
3131 // Select some more options.
3132 SetIndexSelectedShouldSucceed(5, true);
3133 SetIndexSelectedShouldSucceed(6, true);
3134 SetIndexSelectedShouldSucceed(20, true);
3135 for (int i = 0; i < 26; i++) {
3136 bool expected = (i == 1 || i == 5 || i == 6 || i == 20);
3137 CheckIsIndexSelected(i, expected);
3138 }
3139 CheckFocusedFieldText("Ugli Fruit");
3140
3141 // Selecting indices that are already selected is success - changes nothing.
3142 SetIndexSelectedShouldSucceed(5, true);
3143 SetIndexSelectedShouldSucceed(6, true);
3144 SetIndexSelectedShouldSucceed(20, true);
3145 for (int i = 0; i < 26; i++) {
3146 bool expected = (i == 1 || i == 5 || i == 6 || i == 20);
3147 CheckIsIndexSelected(i, expected);
3148 }
3149 CheckFocusedFieldText("Ugli Fruit");
3150
3151 // Deselect some options.
3152 SetIndexSelectedShouldSucceed(20, false);
3153 SetIndexSelectedShouldSucceed(1, false);
3154 for (int i = 0; i < 26; i++) {
3155 bool expected = (i == 5 || i == 6);
3156 CheckIsIndexSelected(i, expected);
3157 }
3158 CheckFocusedFieldText("Banana");
3159
3160 // Deselecting indices that already aren't selected is success - does not
3161 // change the selected values but moves the focus text caret to last item we
3162 // executed on.
3163 SetIndexSelectedShouldSucceed(1, false);
3164 SetIndexSelectedShouldSucceed(3, false);
3165 for (int i = 0; i < 26; i++) {
3166 bool expected = (i == 5 || i == 6);
3167 CheckIsIndexSelected(i, expected);
3168 }
3169 CheckFocusedFieldText("Date");
3170
3171 // Cannot select indices that are out of range.
3172 SetIndexSelectedShouldFail(100, true);
3173 SetIndexSelectedShouldFail(-100, true);
3174 SetIndexSelectedShouldFail(100, false);
3175 SetIndexSelectedShouldFail(-100, false);
3176 // Confirm that previous values were not changed.
3177 CheckFocusedFieldText("Date");
3178 for (int i = 0; i < 26; i++) {
3179 bool expected = (i == 5 || i == 6);
3180 CheckIsIndexSelected(i, expected);
3181 }
3182
3183 // Check that above actions are interchangeable with click actions, should be
3184 // able to use a combination of both.
3185 // TODO(bug_1377): Change to click on form option 0 instead of form option 1
3186 ClickOnMultiSelectFormOption(1);
3187 for (int i = 0; i < 26; i++) {
3188 bool expected = i == 1;
3189 CheckIsIndexSelected(i, expected);
3190 }
3191 CheckFocusedFieldText("Banana");
3192}
3193
3195 // Multiselect field set to 'Belgium' (index 1) and 'Denmark' (index 3) upon
3196 // opening.
3197 FocusOnMultiSelectMultipleIndicesForm();
3198 for (int i = 0; i < 5; i++) {
3199 bool expected = (i == 1 || i == 3);
3200 CheckIsIndexSelected(i, expected);
3201 }
3202}
3203
3205 // Multiselect field set to 'Gamma' (index 2) and 'Epsilon' (index 4) upon
3206 // opening.
3207 FocusOnMultiSelectMultipleValuesForm();
3208 for (int i = 0; i < 5; i++) {
3209 bool expected = (i == 2 || i == 4);
3210 CheckIsIndexSelected(i, expected);
3211 }
3212}
3213
3215 // Multiselect field set to 'Alligator' (index 0) and 'Cougar' (index 2) upon
3216 // opening.
3217 FocusOnMultiSelectMultipleMismatchForm();
3218 for (int i = 0; i < 5; i++) {
3219 bool expected = (i == 0 || i == 2);
3220 CheckIsIndexSelected(i, expected);
3221 }
3222}
3223
3226 // Multiselect field set to 'Gamma' (index 2) and 'Epsilon' (index 4) upon
3227 // opening.
3228
3229 // TODO(bug_1377): Behavior should be changed to the one described below.
3230 // The top visible option is 'Gamma' (index 2), so the first selection should
3231 // not change. The second selection, 'Epsilon,' should be deselected.
3232 ClickOnMultiSelectMultipleValuesFormOption(0);
3233 for (int i = 0; i < 5; i++) {
3234 bool expected = i == 0;
3235 CheckIsIndexSelected(i, expected);
3236 }
3237}
3238
3240 // Only the last option in the list, 'Saskatchewan', is selected.
3241 FocusOnSingleSelectLastSelectedForm();
3242 for (int i = 0; i < 10; i++) {
3243 bool expected = i == 9;
3244 CheckIsIndexSelected(i, expected);
3245 }
3246
3247 // Even though the top index is specified to be at 'Saskatchewan' (index 9),
3248 // the top visible option will be the one above it, 'Quebec' (index 8), to
3249 // prevent overscrolling. Therefore, clicking on the first visible option of
3250 // the list should select 'Quebec' instead of 'Saskatchewan.'
3251 ClickOnSingleSelectLastSelectedFormOption(0);
3252 for (int i = 0; i < 10; i++) {
3253 bool expected = i == 8;
3254 CheckIsIndexSelected(i, expected);
3255 }
3256}
3257
3259 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"XYZ");
3260 ClickOnFormFieldAtPoint(RegularFormBegin());
3261 CheckCanUndo(false);
3262 CheckCanRedo(false);
3263
3264 TypeTextIntoTextField(2, RegularFormBegin());
3265 CheckFocusedFieldText("AB");
3266 CheckSelection("");
3267 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
3268 CheckSelection("A");
3269
3270 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert.get());
3271 CheckFocusedFieldText("XYZB");
3272 CheckSelection("XYZ");
3273 CheckCanUndo(true);
3274 CheckCanRedo(false);
3275
3276 PerformUndo();
3277 CheckFocusedFieldText("AB");
3278 CheckCanUndo(true);
3279 CheckCanRedo(true);
3280
3281 SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd());
3282 CheckSelection("B");
3283
3284 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert.get());
3285 CheckFocusedFieldText("AXYZ");
3286 CheckSelection("XYZ");
3287 CheckCanUndo(true);
3288 CheckCanRedo(false);
3289}
3290
3292 ScopedFPDFWideString text_to_insert1 = GetFPDFWideString(L"UVW");
3293
3294 ClickOnFormFieldAtPoint(RegularFormBegin());
3295 CheckFocusedFieldText("");
3296 CheckCanUndo(false);
3297 CheckCanRedo(false);
3298
3299 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert1.get());
3300 CheckFocusedFieldText("UVW");
3301 CheckSelection("UVW");
3302
3303 CheckCanUndo(true);
3304 CheckCanRedo(false);
3305
3306 PerformUndo();
3307 CheckFocusedFieldText("");
3308
3309 CheckCanUndo(false);
3310 CheckCanRedo(true);
3311 PerformRedo();
3312 CheckFocusedFieldText("UVW");
3313 CheckSelection("");
3314
3315 ScopedFPDFWideString text_to_insert2 = GetFPDFWideString(L"XYZ");
3316 FORM_ReplaceAndKeepSelection(form_handle(), page(), text_to_insert2.get());
3317 CheckFocusedFieldText("UVWXYZ");
3318 CheckSelection("XYZ");
3319
3320 CheckCanUndo(true);
3321 PerformUndo();
3322 CheckFocusedFieldText("UVW");
3323 CheckSelection("");
3324}
3325
3327 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"XYZ");
3328 ClickOnFormFieldAtPoint(RegularFormBegin());
3329 CheckCanUndo(false);
3330 CheckCanRedo(false);
3331
3332 TypeTextIntoTextField(2, RegularFormBegin());
3333 CheckFocusedFieldText("AB");
3334 CheckSelection("");
3335 SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin());
3336 CheckSelection("A");
3337
3338 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
3339 CheckFocusedFieldText("XYZB");
3340 CheckCanUndo(true);
3341 CheckCanRedo(false);
3342
3343 PerformUndo();
3344 CheckFocusedFieldText("AB");
3345 CheckCanUndo(true);
3346 CheckCanRedo(true);
3347
3348 PerformUndo();
3349 CheckFocusedFieldText("A");
3350 CheckCanUndo(true);
3351 CheckCanRedo(true);
3352
3353 PerformUndo();
3354 CheckFocusedFieldText("");
3355 CheckCanUndo(false);
3356 CheckCanRedo(true);
3357
3358 PerformRedo();
3359 CheckFocusedFieldText("A");
3360 CheckCanUndo(true);
3361 CheckCanRedo(true);
3362
3363 PerformRedo();
3364 CheckFocusedFieldText("AB");
3365 CheckCanUndo(true);
3366 CheckCanRedo(true);
3367
3368 PerformRedo();
3369 CheckFocusedFieldText("XYZB");
3370 CheckCanUndo(true);
3371 CheckCanRedo(false);
3372}
3373
3375 ScopedFPDFWideString text_to_insert1 = GetFPDFWideString(L"UVW");
3376
3377 ClickOnFormFieldAtPoint(RegularFormBegin());
3378 CheckFocusedFieldText("");
3379 CheckCanUndo(false);
3380 CheckCanRedo(false);
3381
3382 FORM_ReplaceSelection(form_handle(), page(), text_to_insert1.get());
3383 CheckFocusedFieldText("UVW");
3384 CheckSelection("");
3385
3386 CheckCanUndo(true);
3387 CheckCanRedo(false);
3388
3389 PerformUndo();
3390 CheckFocusedFieldText("");
3391
3392 CheckCanUndo(false);
3393 CheckCanRedo(true);
3394 PerformRedo();
3395 CheckFocusedFieldText("UVW");
3396 CheckSelection("");
3397
3398 ScopedFPDFWideString text_to_insert2 = GetFPDFWideString(L"XYZ");
3399 FORM_ReplaceSelection(form_handle(), page(), text_to_insert2.get());
3400 CheckFocusedFieldText("UVWXYZ");
3401
3402 CheckCanUndo(true);
3403 CheckCanRedo(false);
3404
3405 PerformUndo();
3406 CheckFocusedFieldText("UVW");
3407 CheckSelection("");
3408}
3409
3411 // Start with a couple of letters in the text form.
3412 TypeTextIntoTextField(2, RegularFormBegin());
3413 CheckFocusedFieldText("AB");
3414 CheckSelection("");
3415
3416 // Select all with the keyboard shortcut.
3417#if BUILDFLAG(IS_APPLE)
3418 constexpr int kCorrectModifier = FWL_EVENTFLAG_MetaKey;
3419#else
3420 constexpr int kCorrectModifier = FWL_EVENTFLAG_ControlKey;
3421#endif
3422 FORM_OnChar(form_handle(), page(), pdfium::ascii::kControlA,
3423 kCorrectModifier);
3424 CheckSelection("AB");
3425
3426 // Reset the selection again.
3427 ClickOnFormFieldAtPoint(RegularFormBegin());
3428 CheckSelection("");
3429
3430 // Select all with the keyboard shortcut using the wrong modifier key.
3431#if BUILDFLAG(IS_APPLE)
3432 constexpr int kWrongModifier = FWL_EVENTFLAG_ControlKey;
3433#else
3434 constexpr int kWrongModifier = FWL_EVENTFLAG_MetaKey;
3435#endif
3436 FORM_OnChar(form_handle(), page(), pdfium::ascii::kControlA, kWrongModifier);
3437 CheckSelection("");
3438}
3439
3442 protected:
3445
3446 const char* GetDocumentName() const override { return "bug_1055869.pdf"; }
3447 int GetFormType() const override { return FORMTYPE_XFA_FULL; }
3448};
3449
3451 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"XYZ");
3452 DoubleClickOnFormFieldAtPoint(CFX_PointF(100, 100));
3453 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
3454}
3455
3458 protected:
3461
3462 const char* GetDocumentName() const override { return "bug_1058653.pdf"; }
3463 int GetFormType() const override { return FORMTYPE_XFA_FULL; }
3464};
3465
3467 ScopedFPDFWideString text_to_insert = GetFPDFWideString(L"");
3468 DoubleClickOnFormFieldAtPoint(CFX_PointF(22, 22));
3469 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
3470}
3471
3473 protected:
3476
3479 ASSERT_TRUE(OpenDocument("annots_action_handling.pdf"));
3480 page_ = LoadPage(0);
3481 ASSERT_TRUE(page_);
3482
3483 // Set Widget and Link as supported tabbable annots.
3484 constexpr FPDF_ANNOTATION_SUBTYPE kFocusableSubtypes[] = {FPDF_ANNOT_WIDGET,
3486 constexpr size_t kSubtypeCount = std::size(kFocusableSubtypes);
3487 ASSERT_TRUE(FPDFAnnot_SetFocusableSubtypes(
3488 form_handle(), kFocusableSubtypes, kSubtypeCount));
3489 }
3490
3492 UnloadPage(page_);
3494 }
3495
3496 void SetFocusOnNthAnnot(size_t n) {
3497 DCHECK_NE(n, 0u);
3498 // Setting focus on first annot.
3499 FORM_OnMouseMove(form_handle(), page(), /*modifier=*/0, 100, 680);
3500 FORM_OnLButtonDown(form_handle(), page(), /*modifier=*/0, 100, 680);
3501 FORM_OnLButtonUp(form_handle(), page(), /*modifier=*/0, 100, 680);
3502 for (size_t i = 1; i < n; i++)
3503 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Tab, 0));
3504 }
3505
3506 FPDF_PAGE page() { return page_; }
3507
3508 private:
3509 FPDF_PAGE page_ = nullptr;
3510};
3511
3513 NiceMock<EmbedderTestMockDelegate> mock;
3514 // TODO(crbug.com/1028991): DoURIAction expect call should be 1.
3515 EXPECT_CALL(mock, DoURIAction(_)).Times(0);
3516 SetDelegate(&mock);
3517
3518 SetFocusOnNthAnnot(1);
3519
3520 // Tab once from first form to go to button widget.
3521 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Tab, 0));
3522
3523 // TODO(crbug.com/1028991): Following should be changed to ASSERT_TRUE after
3524 // handling key press implementation on buttons.
3525 ASSERT_FALSE(FORM_OnChar(form_handle(), page(), pdfium::ascii::kReturn, 0));
3526}
3527
3529 NiceMock<EmbedderTestMockDelegate> mock;
3530 {
3531 InSequence sequence;
3532 const char kExpectedUri[] = "https://cs.chromium.org/";
3533#ifdef PDF_ENABLE_XFA
3534 EXPECT_CALL(mock,
3535 DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri), _))
3536 .Times(4);
3537#else // PDF_ENABLE_XFA
3538 EXPECT_CALL(mock, DoURIAction(StrEq(kExpectedUri))).Times(4);
3539 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(_, _, _)).Times(0);
3540#endif // PDF_ENABLE_XFA
3541 }
3542 SetDelegate(&mock);
3543 SetFocusOnNthAnnot(3);
3544 int modifier = 0;
3545 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3546 modifier = FWL_EVENTFLAG_ControlKey;
3547 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3548 modifier = FWL_EVENTFLAG_ShiftKey;
3549 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3550 modifier |= FWL_EVENTFLAG_ControlKey;
3551 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3552
3553 ASSERT_FALSE(FORM_OnKeyDown(nullptr, page(), FWL_VKEY_Return, modifier));
3554 ASSERT_FALSE(
3555 FORM_OnKeyDown(form_handle(), nullptr, FWL_VKEY_Return, modifier));
3556 // Following checks should be changed to ASSERT_TRUE if FORM_OnKeyDown starts
3557 // handling for Shift/Space/Control.
3558 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Shift, modifier));
3559 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Space, modifier));
3560 ASSERT_FALSE(
3561 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Control, modifier));
3562}
3563
3565 NiceMock<EmbedderTestMockDelegate> mock;
3566 EXPECT_CALL(mock, DoGoToAction(_, _, 1, _, _)).Times(12);
3567 SetDelegate(&mock);
3568
3569 SetFocusOnNthAnnot(4);
3570 int modifier = 0;
3571 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3572 modifier = FWL_EVENTFLAG_ControlKey;
3573 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3574 modifier = FWL_EVENTFLAG_ShiftKey;
3575 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3576 modifier |= FWL_EVENTFLAG_ControlKey;
3577 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3578
3579 SetFocusOnNthAnnot(5);
3580 modifier = 0;
3581 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3582 modifier = FWL_EVENTFLAG_ControlKey;
3583 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3584 modifier = FWL_EVENTFLAG_ShiftKey;
3585 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3586 modifier |= FWL_EVENTFLAG_ControlKey;
3587 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3588
3589 SetFocusOnNthAnnot(6);
3590 modifier = 0;
3591 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3592 modifier = FWL_EVENTFLAG_ControlKey;
3593 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3594 modifier = FWL_EVENTFLAG_ShiftKey;
3595 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3596 modifier |= FWL_EVENTFLAG_ControlKey;
3597 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3598
3599 ASSERT_FALSE(FORM_OnKeyDown(nullptr, page(), FWL_VKEY_Return, modifier));
3600 ASSERT_FALSE(
3601 FORM_OnKeyDown(form_handle(), nullptr, FWL_VKEY_Return, modifier));
3602 // Following checks should be changed to ASSERT_TRUE if FORM_OnKeyDown starts
3603 // handling for Shift/Space/Control.
3604 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Shift, modifier));
3605 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Space, modifier));
3606 ASSERT_FALSE(
3607 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Control, modifier));
3608}
3609
3616
3618 NiceMock<EmbedderTestMockDelegate> mock;
3619 {
3620 InSequence sequence;
3621 EXPECT_CALL(mock, DoURIAction(_)).Times(0);
3622 const char kExpectedUri[] = "https://cs.chromium.org/";
3623 EXPECT_CALL(mock,
3624 DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri), 0));
3625 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(
3626 _, StrEq(kExpectedUri), FWL_EVENTFLAG_ControlKey));
3627 EXPECT_CALL(mock, DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri),
3628 FWL_EVENTFLAG_ShiftKey));
3629 EXPECT_CALL(mock,
3630 DoURIActionWithKeyboardModifier(_, StrEq(kExpectedUri), 3));
3631 }
3632 SetDelegate(&mock);
3633 SetFocusOnNthAnnot(3);
3634 int modifier = 0;
3635 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3636 modifier = FWL_EVENTFLAG_ControlKey;
3637 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3638 modifier = FWL_EVENTFLAG_ShiftKey;
3639 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3640 modifier |= FWL_EVENTFLAG_ControlKey;
3641 ASSERT_TRUE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Return, modifier));
3642
3643 ASSERT_FALSE(FORM_OnKeyDown(nullptr, page(), FWL_VKEY_Return, modifier));
3644 ASSERT_FALSE(
3645 FORM_OnKeyDown(form_handle(), nullptr, FWL_VKEY_Return, modifier));
3646 // Following checks should be changed to ASSERT_TRUE if FORM_OnKeyDown starts
3647 // handling for Shift/Space/Control.
3648 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Shift, modifier));
3649 ASSERT_FALSE(FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Space, modifier));
3650 ASSERT_FALSE(
3651 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Control, modifier));
3652}
#define DCHECK
Definition check.h:33
#define DCHECK_NE(x, y)
Definition check_op.h:18
#define DCHECK_EQ(x, y)
Definition check_op.h:17
void DoURIAction(FPDF_BYTESTRING uri) override
void SetUp() override
void SetFormFillInfoVersion(int form_fill_info_version)
void TearDown() override
FPDF_PAGE LoadPage(int page_index)
void UnloadPage(FPDF_PAGE page)
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 FPDF_ANNOTATION FPDF_CALLCONV FPDFPage_GetAnnot(FPDF_PAGE page, int index)
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)
EmbedderTest FPDFFormFillEmbedderTest
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:817
CFX_PTemplate< float > CFX_PointF
std::unique_ptr< FPDF_WCHAR, pdfium::FreeDeleter > ScopedFPDFWideString
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()
fxcrt::ByteStringView ByteStringView