summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfformfill_embeddertest.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-04-13 15:28:20 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-13 19:52:31 +0000
commit742977f943b30638427d1ef6532acbc3d1c36bff (patch)
treeaa6d3fccc2479002ddf2550bc6d25c14d7567737 /fpdfsdk/fpdfformfill_embeddertest.cpp
parenta119340ec92412d07e60654b2b22a5a5bea979b0 (diff)
downloadpdfium-742977f943b30638427d1ef6532acbc3d1c36bff.tar.xz
Add embeddertest for form text rendering and saving
This CL adds an embeddertest that adds text to a textfield and saves it. It also adds a new 'charcode' option for .evt files in pdfium_test. Change-Id: I14fbf50e2b1d5ae0bdc68d1dd25dc4f889c49bfb Reviewed-on: https://pdfium-review.googlesource.com/4150 Commit-Queue: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfformfill_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfformfill_embeddertest.cpp69
1 files changed, 68 insertions, 1 deletions
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);
+}