summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp16
-rw-r--r--fpdfsdk/fpdfformfill_embeddertest.cpp69
-rw-r--r--testing/resources/text_form.in57
-rw-r--r--testing/resources/text_form.pdf69
-rw-r--r--testing/test_support.cpp17
-rw-r--r--testing/test_support.h6
6 files changed, 217 insertions, 17 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 6454c34df1..952564db49 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -164,22 +164,6 @@ const char kExpectedPDF[] =
"379\r\n"
"%%EOF\r\n";
-int GetBlockFromString(void* param,
- unsigned long pos,
- unsigned char* buf,
- unsigned long size) {
- std::string* new_file = static_cast<std::string*>(param);
- if (!new_file || pos + size < pos)
- return 0;
-
- unsigned long file_size = new_file->size();
- if (pos + size > file_size)
- return 0;
-
- memcpy(buf, new_file->data() + pos, size);
- return 1;
-}
-
} // namespace
TEST_F(FPDFEditEmbeddertest, EmptyCreation) {
diff --git a/fpdfsdk/fpdfformfill_embeddertest.cpp b/fpdfsdk/fpdfformfill_embeddertest.cpp
index 47f1a75efb..631a6a2e7c 100644
--- a/fpdfsdk/fpdfformfill_embeddertest.cpp
+++ b/fpdfsdk/fpdfformfill_embeddertest.cpp
@@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <memory>
+#include <string>
+
+#include "core/fxcrt/fx_system.h"
+#include "public/cpp/fpdf_deleters.h"
#include "public/fpdf_formfill.h"
#include "testing/embedder_test.h"
#include "testing/embedder_test_mock_delegate.h"
@@ -12,7 +17,7 @@
using testing::_;
using testing::Return;
-class FPDFFormFillEmbeddertest : public EmbedderTest {};
+class FPDFFormFillEmbeddertest : public EmbedderTest, public TestSaver {};
TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
EmbedderTestMockDelegate mock;
@@ -197,3 +202,65 @@ TEST_F(FPDFFormFillEmbeddertest, BUG_679649) {
}
#endif // PDF_ENABLE_V8
+
+TEST_F(FPDFFormFillEmbeddertest, FormText) {
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff";
+ const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d";
+ const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe";
+#else
+ const char md5_1[] = "23baecc6e94d4c8b894cd39aa04c584c";
+ const char md5_2[] = "499df95d477dfe35ee65b823c69743b5";
+ const char md5_3[] = "8f91b62895fc505d9e17ff2d633756d4";
+#endif
+ {
+ EXPECT_TRUE(OpenDocument("text_form.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ std::unique_ptr<void, FPDFBitmapDeleter> bitmap1(RenderPage(page));
+ CompareBitmap(bitmap1.get(), 300, 300, md5_1);
+
+ // Click on the textfield
+ EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
+ FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
+ FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
+ FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
+ FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
+
+ // Write "ABC"
+ FORM_OnChar(form_handle(), page, 65, 0);
+ FORM_OnChar(form_handle(), page, 66, 0);
+ FORM_OnChar(form_handle(), page, 67, 0);
+ std::unique_ptr<void, FPDFBitmapDeleter> bitmap2(RenderPage(page));
+ CompareBitmap(bitmap2.get(), 300, 300, md5_2);
+
+ // Take out focus by clicking out of the textfield
+ FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
+ FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
+ FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
+ std::unique_ptr<void, FPDFBitmapDeleter> bitmap3(RenderPage(page));
+ CompareBitmap(bitmap3.get(), 300, 300, md5_3);
+
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+
+ // Close everything
+ UnloadPage(page);
+ FPDFDOC_ExitFormFillEnvironment(form_handle_);
+ FPDF_CloseDocument(document_);
+ }
+ // Check saved document
+ std::string new_file = GetString();
+ FPDF_FILEACCESS file_access;
+ memset(&file_access, 0, sizeof(file_access));
+ file_access.m_FileLen = new_file.size();
+ file_access.m_GetBlock = GetBlockFromString;
+ file_access.m_Param = &new_file;
+ document_ = FPDF_LoadCustomDocument(&file_access, nullptr);
+ SetupFormFillEnvironment();
+ EXPECT_EQ(1, FPDF_GetPageCount(document_));
+ std::unique_ptr<void, FPDFPageDeleter> new_page(FPDF_LoadPage(document_, 0));
+ ASSERT_TRUE(new_page.get());
+ std::unique_ptr<void, FPDFBitmapDeleter> new_bitmap(
+ RenderPage(new_page.get()));
+ CompareBitmap(new_bitmap.get(), 300, 300, md5_3);
+}
diff --git a/testing/resources/text_form.in b/testing/resources/text_form.in
new file mode 100644
index 0000000000..4872986af1
--- /dev/null
+++ b/testing/resources/text_form.in
@@ -0,0 +1,57 @@
+{{header}}
+{{object 1 0}}
+<<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm << /Fields [ 4 0 R ] /DR 5 0 R >>
+>>
+endobj
+{{object 2 0}}
+<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >>
+endobj
+{{object 3 0}}
+<<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources 5 0 R
+ /MediaBox [ 0 0 300 300 ]
+ /Contents 8 0 R
+ /Annots [ 4 0 R ]
+>>
+endobj
+{{object 4 0}}
+<<
+ /Type /Annot
+ /FT /Tx
+ /T (Text Box)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 100 200 130 ]
+ /Subtype /Widget
+>>
+endobj
+{{object 5 0}}
+<< /Font 6 0 R >>
+endobj
+{{object 6 0}}
+<< /F1 7 0 R >>
+endobj
+{{object 7 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+{{object 8 0}}
+<< /Length 51 >>
+stream
+BT
+0 0 0 rg
+/F1 12 Tf
+100 150 Td
+(Test Form) Tj
+ET
+endstream
+endobj
+{{xref}}
+trailer<< /Size 8 /Root 1 0 R >>
+{{startxref}}
+%%EOF
diff --git a/testing/resources/text_form.pdf b/testing/resources/text_form.pdf
new file mode 100644
index 0000000000..f72a73567b
--- /dev/null
+++ b/testing/resources/text_form.pdf
@@ -0,0 +1,69 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj
+<<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm << /Fields [ 4 0 R ] /DR 5 0 R >>
+>>
+endobj
+2 0 obj
+<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >>
+endobj
+3 0 obj
+<<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources 5 0 R
+ /MediaBox [ 0 0 300 300 ]
+ /Contents 8 0 R
+ /Annots [ 4 0 R ]
+>>
+endobj
+4 0 obj
+<<
+ /Type /Annot
+ /FT /Tx
+ /T (Text Box)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 100 200 130 ]
+ /Subtype /Widget
+>>
+endobj
+5 0 obj
+<< /Font 6 0 R >>
+endobj
+6 0 obj
+<< /F1 7 0 R >>
+endobj
+7 0 obj <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+8 0 obj
+<< /Length 51 >>
+stream
+BT
+0 0 0 rg
+/F1 12 Tf
+100 150 Td
+(Test Form) Tj
+ET
+endstream
+endobj
+xref
+0 9
+0000000000 65535 f
+0000000015 00000 n
+0000000114 00000 n
+0000000173 00000 n
+0000000309 00000 n
+0000000445 00000 n
+0000000478 00000 n
+0000000509 00000 n
+0000000578 00000 n
+trailer<< /Size 8 /Root 1 0 R >>
+startxref
+678
+%%EOF
diff --git a/testing/test_support.cpp b/testing/test_support.cpp
index 20f1cadf09..1f527811c4 100644
--- a/testing/test_support.cpp
+++ b/testing/test_support.cpp
@@ -212,6 +212,23 @@ int TestSaver::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite,
return 1;
}
+// static
+int TestSaver::GetBlockFromString(void* param,
+ unsigned long pos,
+ unsigned char* buf,
+ unsigned long size) {
+ std::string* new_file = static_cast<std::string*>(param);
+ if (!new_file || pos + size < pos)
+ return 0;
+
+ unsigned long file_size = new_file->size();
+ if (pos + size > file_size)
+ return 0;
+
+ memcpy(buf, new_file->data() + pos, size);
+ return 1;
+}
+
namespace pdfium {
void FPDF_Test::SetUp() {
diff --git a/testing/test_support.h b/testing/test_support.h
index b734bc31f0..f175811078 100644
--- a/testing/test_support.h
+++ b/testing/test_support.h
@@ -115,6 +115,12 @@ class TestSaver : public FPDF_FILEWRITE {
void ClearString();
const std::string& GetString() const { return m_String; }
+ protected:
+ static int GetBlockFromString(void* param,
+ unsigned long pos,
+ unsigned char* buf,
+ unsigned long size);
+
private:
static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite,
const void* data,