summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-01-30 14:41:50 -0800
committerTom Sepez <tsepez@chromium.org>2015-01-30 14:41:50 -0800
commitda8189e65547f87a9c7ba3ebb72f78ecdb47e120 (patch)
treebf8b076d906a28d728735cda767007e8180d6329
parent09dc51a44ba2c084ca553d8a52ba6e2e669f4f9c (diff)
downloadpdfium-da8189e65547f87a9c7ba3ebb72f78ecdb47e120.tar.xz
Merge to XFA: track formhandles in embeddder test class itself
TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/891763003
-rw-r--r--fpdfsdk/src/fpdftext_embeddertest.cpp16
-rw-r--r--fpdfsdk/src/fpdfview_embeddertest.cpp8
-rw-r--r--testing/embedder_test.cpp48
-rw-r--r--testing/embedder_test.h21
4 files changed, 38 insertions, 55 deletions
diff --git a/fpdfsdk/src/fpdftext_embeddertest.cpp b/fpdfsdk/src/fpdftext_embeddertest.cpp
index 1457832658..f0d9feb91d 100644
--- a/fpdfsdk/src/fpdftext_embeddertest.cpp
+++ b/fpdfsdk/src/fpdftext_embeddertest.cpp
@@ -30,8 +30,7 @@ class FPDFTextEmbeddertest : public EmbedderTest {
TEST_F(FPDFTextEmbeddertest, Text) {
EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf"));
- FPDF_FORMHANDLE form_handle = SetFormFillEnvironment();
- FPDF_PAGE page = LoadPage(0, form_handle);
+ FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
@@ -135,13 +134,11 @@ TEST_F(FPDFTextEmbeddertest, Text) {
EXPECT_EQ(0xbdbd, fixed_buffer[10]);
FPDFText_ClosePage(textpage);
- ClearFormFillEnvironment(form_handle);
}
TEST_F(FPDFTextEmbeddertest, TextSearch) {
EXPECT_TRUE(OpenDocument("testing/resources/hello_world.pdf"));
- FPDF_FORMHANDLE form_handle = SetFormFillEnvironment();
- FPDF_PAGE page = LoadPage(0, form_handle);
+ FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
@@ -242,14 +239,12 @@ TEST_F(FPDFTextEmbeddertest, TextSearch) {
FPDFText_FindClose(search);
FPDFText_ClosePage(textpage);
- ClearFormFillEnvironment(form_handle);
}
// Test that the page has characters despite a bad stream length.
TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) {
EXPECT_TRUE(OpenDocument("testing/resources/bug_57.pdf"));
- FPDF_FORMHANDLE form_handle = SetFormFillEnvironment();
- FPDF_PAGE page = LoadPage(0, form_handle);
+ FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
@@ -257,13 +252,11 @@ TEST_F(FPDFTextEmbeddertest, StreamLengthPastEndOfFile) {
EXPECT_EQ(13, FPDFText_CountChars(textpage));
FPDFText_ClosePage(textpage);
- ClearFormFillEnvironment(form_handle);
}
TEST_F(FPDFTextEmbeddertest, WebLinks) {
EXPECT_TRUE(OpenDocument("testing/resources/weblinks.pdf"));
- FPDF_FORMHANDLE form_handle = SetFormFillEnvironment();
- FPDF_PAGE page = LoadPage(0, form_handle);
+ FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
FPDF_TEXTPAGE textpage = FPDFText_LoadPage(page);
@@ -365,5 +358,4 @@ TEST_F(FPDFTextEmbeddertest, WebLinks) {
FPDFLink_CloseWebLinks(pagelink);
FPDFText_ClosePage(textpage);
- ClearFormFillEnvironment(form_handle);
}
diff --git a/fpdfsdk/src/fpdfview_embeddertest.cpp b/fpdfsdk/src/fpdfview_embeddertest.cpp
index 76dd9a5798..4827f76839 100644
--- a/fpdfsdk/src/fpdfview_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfview_embeddertest.cpp
@@ -27,14 +27,12 @@ TEST_F(FPDFViewEmbeddertest, Document) {
TEST_F(FPDFViewEmbeddertest, Page) {
EXPECT_TRUE(OpenDocument("testing/resources/about_blank.pdf"));
- FPDF_FORMHANDLE form_handle = SetFormFillEnvironment();
- FPDF_PAGE page = LoadPage(0, form_handle);
+ FPDF_PAGE page = LoadPage(0);
EXPECT_NE(nullptr, page);
EXPECT_EQ(612.0, FPDF_GetPageWidth(page));
EXPECT_EQ(792.0, FPDF_GetPageHeight(page));
- UnloadPage(page, form_handle);
- EXPECT_EQ(nullptr, LoadPage(1, form_handle));
- ClearFormFillEnvironment(form_handle);
+ UnloadPage(page);
+ EXPECT_EQ(nullptr, LoadPage(1));
}
TEST_F(FPDFViewEmbeddertest, ViewerRef) {
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index bebe307cf3..46eaf8c66d 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -190,7 +190,13 @@ void EmbedderTest::SetUp() {
}
void EmbedderTest::TearDown() {
- FPDF_CloseDocument(document_);
+ if (form_handle_) {
+ FORM_DoDocumentAAction(form_handle_, FPDFDOC_AACTION_WC);
+ FPDFDOC_ExitFormFillEnvironment(form_handle_);
+ }
+ if (document_) {
+ FPDF_CloseDocument(document_);
+ }
FPDFAvail_Destroy(avail_);
FPDF_DestroyLibrary();
if (loader_) {
@@ -232,10 +238,7 @@ bool EmbedderTest::OpenDocument(const std::string& filename) {
(void) FPDF_LoadXFA(document_);
(void) FPDF_GetDocPermissions(document_);
(void) FPDFAvail_IsFormAvail(avail_, &hints_);
- return true;
-}
-FPDF_FORMHANDLE EmbedderTest::SetFormFillEnvironment() {
IPDF_JSPLATFORM platform_callbacks;
memset(&platform_callbacks, '\0', sizeof(platform_callbacks));
platform_callbacks.version = 1;
@@ -246,21 +249,16 @@ FPDF_FORMHANDLE EmbedderTest::SetFormFillEnvironment() {
form_callbacks.version = 1;
form_callbacks.m_pJsPlatform = &platform_callbacks;
- FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(document_,
- &form_callbacks);
- FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD);
- FPDF_SetFormFieldHighlightAlpha(form, 100);
- return form;
-}
+ form_handle_ = FPDFDOC_InitFormFillEnvironment(document_, &form_callbacks);
+ FPDF_SetFormFieldHighlightColor(form_handle_, 0, 0xFFE4DD);
+ FPDF_SetFormFieldHighlightAlpha(form_handle_, 100);
-void EmbedderTest::ClearFormFillEnvironment(FPDF_FORMHANDLE form) {
- FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);
- FPDFDOC_ExitFormFillEnvironment(form);
+ return true;
}
-void EmbedderTest::DoOpenActions(FPDF_FORMHANDLE form) {
- FORM_DoDocumentJSAction(form);
- FORM_DoDocumentOpenAction(form);
+void EmbedderTest::DoOpenActions() {
+ FORM_DoDocumentJSAction(form_handle_);
+ FORM_DoDocumentOpenAction(form_handle_);
}
int EmbedderTest::GetFirstPageNum() {
@@ -277,31 +275,29 @@ int EmbedderTest::GetPageCount() {
return page_count;
}
-FPDF_PAGE EmbedderTest::LoadPage(int page_number,
- FPDF_FORMHANDLE form) {
+FPDF_PAGE EmbedderTest::LoadPage(int page_number) {
FPDF_PAGE page = FPDF_LoadPage(document_, page_number);
if (!page) {
return nullptr;
}
- FORM_OnAfterLoadPage(page, form);
- FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN);
+ FORM_OnAfterLoadPage(page, form_handle_);
+ FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_OPEN);
return page;
}
-FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page,
- FPDF_FORMHANDLE form) {
+FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) {
int width = static_cast<int>(FPDF_GetPageWidth(page));
int height = static_cast<int>(FPDF_GetPageHeight(page));
FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
- FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0);
+ FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0);
return bitmap;
}
-void EmbedderTest::UnloadPage(FPDF_PAGE page, FPDF_FORMHANDLE form) {
- FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE);
- FORM_OnBeforeClosePage(page, form);
+void EmbedderTest::UnloadPage(FPDF_PAGE page) {
+ FORM_DoPageAAction(page, form_handle_, FPDFPAGE_AACTION_CLOSE);
+ FORM_OnBeforeClosePage(page, form_handle_);
FPDF_ClosePage(page);
}
diff --git a/testing/embedder_test.h b/testing/embedder_test.h
index 3eb3be606f..072dce3bc3 100644
--- a/testing/embedder_test.h
+++ b/testing/embedder_test.h
@@ -22,6 +22,7 @@ class EmbedderTest : public ::testing::Test {
public:
EmbedderTest() :
document_(nullptr),
+ form_handle_(nullptr),
avail_(nullptr),
loader_(nullptr),
file_length_(0),
@@ -37,36 +38,32 @@ class EmbedderTest : public ::testing::Test {
void TearDown() override;
FPDF_DOCUMENT document() { return document_; }
+ FPDF_FORMHANDLE form_handle() { return form_handle_; }
- // Open the document specified by |filename|, or return false on failure.
+ // Open the document specified by |filename|, and create its form fill
+ // environment, or return false on failure.
virtual bool OpenDocument(const std::string& filename);
- // Create and return a handle to the form fill module for use with the
- // FORM_ family of functions from fpdfformfill.h, or return NULL on failure.
- virtual FPDF_FORMHANDLE SetFormFillEnvironment();
-
- // Release the resources obtained from SetFormFillEnvironment().
- virtual void ClearFormFillEnvironment(FPDF_FORMHANDLE form);
-
// Perform JavaScript actions that are to run at document open time.
- virtual void DoOpenActions(FPDF_FORMHANDLE form);
+ virtual void DoOpenActions();
// Determine the page numbers present in the document.
virtual int GetFirstPageNum();
virtual int GetPageCount();
// Load a specific page of the open document.
- virtual FPDF_PAGE LoadPage(int page_number, FPDF_FORMHANDLE form);
+ virtual FPDF_PAGE LoadPage(int page_number);
// Convert a loaded page into a bitmap.
- virtual FPDF_BITMAP RenderPage(FPDF_PAGE page, FPDF_FORMHANDLE form);
+ virtual FPDF_BITMAP RenderPage(FPDF_PAGE page);
// Relese the resources obtained from LoadPage(). Further use of |page|
// is prohibited after this call is made.
- virtual void UnloadPage(FPDF_PAGE page, FPDF_FORMHANDLE form);
+ virtual void UnloadPage(FPDF_PAGE page);
protected:
FPDF_DOCUMENT document_;
+ FPDF_FORMHANDLE form_handle_;
FPDF_AVAIL avail_;
FX_DOWNLOADHINTS hints_;
FPDF_FILEACCESS file_access_;