summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfannot_embeddertest.cpp
diff options
context:
space:
mode:
authorDiana Gage <drgage@google.com>2017-07-19 18:16:03 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-07-20 01:30:30 +0000
commit40870db0aadef4e145fd3b2b95fa5a083afb3161 (patch)
tree75115b1c00857ac28d3ea4913d6a0e9e37239aa4 /fpdfsdk/fpdfannot_embeddertest.cpp
parent7e0c05d7a3329fd0a262d13b8aea74eaf33ba997 (diff)
downloadpdfium-40870db0aadef4e145fd3b2b95fa5a083afb3161.tar.xz
Add FPDFAnnot_GetFormFieldAtPoint() and embedder tests.
Given a point on a page, this method returns the interactive form annotation whose rectangle contains that point. If there is no such annotation, nullptr is returned. FPDFPage_CloseAnnot() must be called after the annotation this method returns is no longer needed. The tests for this method use the returned annotation to check its interactive form annotation flags via FPDFAnnot_GetFormFieldFlags(). BUG=chromium:59266 Change-Id: I8728792bea5367c172e08fdb6bae83eafb70eb68 Reviewed-on: https://pdfium-review.googlesource.com/7970 Commit-Queue: Diana Gage <drgage@google.com> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfannot_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfannot_embeddertest.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfannot_embeddertest.cpp b/fpdfsdk/fpdfannot_embeddertest.cpp
index b50f73f3ab..58a00067a7 100644
--- a/fpdfsdk/fpdfannot_embeddertest.cpp
+++ b/fpdfsdk/fpdfannot_embeddertest.cpp
@@ -956,3 +956,88 @@ TEST_F(FPDFAnnotEmbeddertest, GetFormFieldFlagsComboBox) {
UnloadPage(page);
}
+
+TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotNull) {
+ // Open file with form text fields.
+ EXPECT_TRUE(OpenDocument("text_form.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Attempt to get an annotation where no annotation exists on page.
+ FPDF_ANNOTATION annot =
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 0, 0);
+ EXPECT_FALSE(annot);
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsTextField) {
+ // Open file with form text fields.
+ EXPECT_TRUE(OpenDocument("text_form_multiple.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Retrieve user-editable text field annotation.
+ FPDF_ANNOTATION annot =
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 118);
+ ASSERT_TRUE(annot);
+
+ // Check that interactive form annotation flag values are as expected.
+ int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
+ FPDFPage_CloseAnnot(annot);
+
+ // Retrieve read-only text field annotation.
+ annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 105, 202);
+ ASSERT_TRUE(annot);
+
+ // Check that interactive form annotation flag values are as expected.
+ flags = FPDFAnnot_GetFormFieldFlags(page, annot);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
+ FPDFPage_CloseAnnot(annot);
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFAnnotEmbeddertest, GetFormAnnotAndCheckFlagsComboBox) {
+ // Open file with form comboboxes.
+ EXPECT_TRUE(OpenDocument("combobox_form.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Retrieve user-editable combobox annotation.
+ FPDF_ANNOTATION annot =
+ FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 63);
+ ASSERT_TRUE(annot);
+
+ // Check that interactive form annotation flag values are as expected.
+ int flags = FPDFAnnot_GetFormFieldFlags(page, annot);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
+ FPDFPage_CloseAnnot(annot);
+
+ // Retrieve regular combobox annotation.
+ annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 113);
+ ASSERT_TRUE(annot);
+
+ // Check that interactive form annotation flag values are as expected.
+ flags = FPDFAnnot_GetFormFieldFlags(page, annot);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
+ FPDFPage_CloseAnnot(annot);
+
+ // Retrieve read-only combobox annotation.
+ annot = FPDFAnnot_GetFormFieldAtPoint(form_handle(), page, 102, 213);
+ ASSERT_TRUE(annot);
+
+ // Check that interactive form annotation flag values are as expected.
+ flags = FPDFAnnot_GetFormFieldFlags(page, annot);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_CHOICE_COMBO);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_CHOICE_EDIT);
+ FPDFPage_CloseAnnot(annot);
+
+ UnloadPage(page);
+}