summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_formfill_embeddertest.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-04-19 20:55:54 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-19 20:55:54 +0000
commitee96772e0878fa385b9a4a736a2fc109e19fd01e (patch)
treedef5fed9024c0aef25d7d1f81729b6f0a6687179 /fpdfsdk/fpdf_formfill_embeddertest.cpp
parentc84ea8eda5a53229cf1faaed7cb54013b9ea18c3 (diff)
downloadpdfium-ee96772e0878fa385b9a4a736a2fc109e19fd01e.tar.xz
Add public APIs for undo / redo in forms.
Add FORM_CanUndo(), FORM_CanRedo(), FORM_Undo(), and FORM_Redo(). BUG=chromium:764260 Change-Id: I1d9ea67152d9b35d9b8e1d7ef7d019706fdfa30a Reviewed-on: https://pdfium-review.googlesource.com/30872 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_formfill_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdf_formfill_embeddertest.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index 5dd4d1e1c1..09e0c200d3 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -134,6 +134,18 @@ class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest {
EXPECT_EQ(expected_string, WideString::FromUTF16LE(buf.data(), num_chars));
}
+ void CheckCanUndo(bool expected_result) {
+ EXPECT_EQ(expected_result, !!FORM_CanUndo(form_handle(), page_));
+ }
+
+ void CheckCanRedo(bool expected_result) {
+ EXPECT_EQ(expected_result, !!FORM_CanRedo(form_handle(), page_));
+ }
+
+ void PerformUndo() { EXPECT_TRUE(FORM_Undo(form_handle(), page_)); }
+
+ void PerformRedo() { EXPECT_TRUE(FORM_Redo(form_handle(), page_)); }
+
private:
FPDF_PAGE page_ = nullptr;
};
@@ -1544,3 +1556,68 @@ TEST_F(FPDFFormFillComboBoxFormEmbeddertest, FocusChanges) {
SelectEditableFormOption(0);
CheckFocusedFieldText(L"Foo");
}
+
+TEST_F(FPDFFormFillTextFormEmbeddertest, UndoRedo) {
+ ClickOnFormFieldAtPoint(RegularFormBegin());
+ CheckFocusedFieldText(L"");
+ CheckCanUndo(false);
+ CheckCanRedo(false);
+
+ TypeTextIntoTextField(5, RegularFormBegin());
+ CheckFocusedFieldText(L"ABCDE");
+ CheckCanUndo(true);
+ CheckCanRedo(false);
+
+ PerformUndo();
+ CheckFocusedFieldText(L"ABCD");
+ CheckCanUndo(true);
+ CheckCanRedo(true);
+ PerformUndo();
+ CheckFocusedFieldText(L"ABC");
+ CheckCanUndo(true);
+ CheckCanRedo(true);
+
+ PerformRedo();
+ CheckFocusedFieldText(L"ABCD");
+ CheckCanUndo(true);
+ CheckCanRedo(true);
+ PerformRedo();
+ CheckFocusedFieldText(L"ABCDE");
+ CheckCanUndo(true);
+ CheckCanRedo(false);
+}
+
+TEST_F(FPDFFormFillComboBoxFormEmbeddertest, UndoRedo) {
+ ClickOnFormFieldAtPoint(NonEditableFormBegin());
+ CheckFocusedFieldText(L"Banana");
+ CheckCanUndo(false);
+ CheckCanRedo(false);
+
+ ClickOnFormFieldAtPoint(EditableFormBegin());
+ CheckFocusedFieldText(L"");
+ CheckCanUndo(false);
+ CheckCanRedo(false);
+
+ TypeTextIntoTextField(3, EditableFormBegin());
+ CheckFocusedFieldText(L"ABC");
+ CheckCanUndo(true);
+ CheckCanRedo(false);
+
+ PerformUndo();
+ CheckFocusedFieldText(L"AB");
+ CheckCanUndo(true);
+ CheckCanRedo(true);
+ PerformUndo();
+ CheckFocusedFieldText(L"A");
+ CheckCanUndo(true);
+ CheckCanRedo(true);
+ PerformUndo();
+ CheckFocusedFieldText(L"");
+ CheckCanUndo(false);
+ CheckCanRedo(true);
+
+ PerformRedo();
+ CheckFocusedFieldText(L"A");
+ CheckCanUndo(true);
+ CheckCanRedo(true);
+}