Switch to LoadScopedPage() in //fpdfsdk/pwl Bug: 354025368 Change-Id: I1f8a365b6b39449b66801b2eeb29ff91fc153c58 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/124570 Commit-Queue: Tom Sepez <tsepez@google.com> Reviewed-by: Tom Sepez <tsepez@google.com> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_baannot_embeddertest.cpp b/fpdfsdk/cpdfsdk_baannot_embeddertest.cpp index b70ffa9..5b207b8 100644 --- a/fpdfsdk/cpdfsdk_baannot_embeddertest.cpp +++ b/fpdfsdk/cpdfsdk_baannot_embeddertest.cpp
@@ -17,25 +17,31 @@ public: void SetUp() override { EmbedderTest::SetUp(); - SetUpBAAnnot(); - } - - void TearDown() override { - UnloadPage(m_page); - EmbedderTest::TearDown(); - } - - void SetUpBAAnnot() { ASSERT_TRUE(OpenDocument("links_highlights_annots.pdf")); - m_page = LoadPage(0); - ASSERT_TRUE(m_page); + } + ScopedEmbedderTestPage SetUpBAAnnot() { + ScopedEmbedderTestPage page = LoadScopedPage(0); + if (!page) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } m_pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); - ASSERT_TRUE(m_pFormFillEnv); + if (!m_pFormFillEnv) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } + m_pPageView = - m_pFormFillEnv->GetOrCreatePageView(IPDFPageFromFPDFPage(m_page)); - ASSERT_TRUE(m_pPageView); + m_pFormFillEnv->GetOrCreatePageView(IPDFPageFromFPDFPage(page.get())); + + if (!m_pPageView) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } + + return page; } CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; } @@ -57,12 +63,14 @@ } private: - FPDF_PAGE m_page = nullptr; CPDFSDK_PageView* m_pPageView = nullptr; CPDFSDK_FormFillEnvironment* m_pFormFillEnv = nullptr; }; TEST_F(CPDFSDKBAAnnotTest, TabToLinkOrHighlightAnnot) { + ScopedEmbedderTestPage page = SetUpBAAnnot(); + ASSERT_TRUE(page); + std::vector<CPDF_Annot::Subtype> focusable_annot_types = { CPDF_Annot::Subtype::WIDGET, CPDF_Annot::Subtype::LINK, CPDF_Annot::Subtype::HIGHLIGHT};
diff --git a/fpdfsdk/formfiller/cffl_combobox_embeddertest.cpp b/fpdfsdk/formfiller/cffl_combobox_embeddertest.cpp index dbde075..4e63e41 100644 --- a/fpdfsdk/formfiller/cffl_combobox_embeddertest.cpp +++ b/fpdfsdk/formfiller/cffl_combobox_embeddertest.cpp
@@ -10,6 +10,8 @@ class CFFLComboBoxEmbedderTest : public CPWLComboBoxEmbedderTest {}; TEST_F(CFFLComboBoxEmbedderTest, GetActionData) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotNormal()); { CFFL_FieldAction result; @@ -35,6 +37,8 @@ } TEST_F(CFFLComboBoxEmbedderTest, SetActionData) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotNormal()); CFFL_FieldAction input_fa; input_fa.nSelStart = 2;
diff --git a/fpdfsdk/pwl/cpwl_combo_box_edit_embeddertest.cpp b/fpdfsdk/pwl/cpwl_combo_box_edit_embeddertest.cpp index 0c2c334..fe3c9f7 100644 --- a/fpdfsdk/pwl/cpwl_combo_box_edit_embeddertest.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box_edit_embeddertest.cpp
@@ -18,6 +18,9 @@ class CPWLComboBoxEditEmbedderTest : public CPWLComboBoxEmbedderTest {}; TEST_F(CPWLComboBoxEditEmbedderTest, GetSelectedTextEmptyAndBasicNormal) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotNormal()); // Automatically pre-filled with "Banana". @@ -40,6 +43,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, GetSelectedTextFragmentsNormal) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotNormal()); EXPECT_EQ(L"Banana", GetCPWLComboBox()->GetText()); @@ -66,6 +72,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, GetSelectedTextEmptyAndBasicEditable) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); EXPECT_TRUE(GetCPWLComboBox()->GetText().IsEmpty()); @@ -95,6 +104,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, GetSelectedTextFragmentsEditable) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(50); @@ -125,6 +137,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, DeleteEntireTextSelection) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(50); @@ -137,6 +152,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, DeleteTextSelectionMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(50); @@ -149,6 +167,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, DeleteTextSelectionLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(50); @@ -161,6 +182,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, DeleteTextSelectionRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(50); @@ -173,6 +197,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, DeleteEmptyTextSelection) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(50); @@ -182,6 +209,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextInEmptyEditableComboBox) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); GetCPWLComboBox()->ReplaceSelection(L"Hello"); EXPECT_EQ(L"Hello", GetCPWLComboBox()->GetText()); @@ -189,6 +219,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextInPopulatedEditableComboBoxLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -201,6 +234,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextInPopulatedEditableComboBoxMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -215,6 +251,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextInPopulatedEditableComboBoxRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -224,6 +263,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -235,6 +277,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -246,6 +291,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -257,6 +305,9 @@ TEST_F(CPWLComboBoxEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10); @@ -267,6 +318,9 @@ } TEST_F(CPWLComboBoxEditEmbedderTest, ReplaceAndKeepSelection) { + ScopedEmbedderTestPage page = CreateAndInitializeFormComboboxPDF(); + ASSERT_TRUE(page); + FormFillerAndWindowSetup(GetCPDFSDKAnnotUserEditable()); TypeTextIntoTextField(10);
diff --git a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp index 299672f..38c43e8 100644 --- a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
@@ -17,35 +17,42 @@ void CPWLComboBoxEmbedderTest::SetUp() { EmbedderTest::SetUp(); - CreateAndInitializeFormComboboxPDF(); -} - -void CPWLComboBoxEmbedderTest::TearDown() { - UnloadPage(GetPage()); - EmbedderTest::TearDown(); -} - -void CPWLComboBoxEmbedderTest::CreateAndInitializeFormComboboxPDF() { ASSERT_TRUE(OpenDocument("combobox_form.pdf")); - m_page = LoadPage(0); - ASSERT_TRUE(m_page); +} +CPWLComboBoxEmbedderTest::ScopedEmbedderTestPage +CPWLComboBoxEmbedderTest::CreateAndInitializeFormComboboxPDF() { + ScopedEmbedderTestPage page = LoadScopedPage(0); + if (!page) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } m_pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); m_pPageView = m_pFormFillEnv->GetPageViewAtIndex(0); CPDFSDK_AnnotIterator iter(m_pPageView, {CPDF_Annot::Subtype::WIDGET}); // User editable combobox. m_pAnnotEditable = ToCPDFSDKWidget(iter.GetFirstAnnot()); - ASSERT_TRUE(m_pAnnotEditable); + if (!m_pAnnotEditable) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } // Normal combobox with pre-selected value. m_pAnnotNormal = ToCPDFSDKWidget(iter.GetNextAnnot(m_pAnnotEditable)); - ASSERT_TRUE(m_pAnnotNormal); + if (!m_pAnnotEditable) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } // Read-only combobox. CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnotNormal); CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); - ASSERT_EQ(pAnnotReadOnly, pLastAnnot); + if (pAnnotReadOnly != pLastAnnot) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } + return page; } void CPWLComboBoxEmbedderTest::FormFillerAndWindowSetup(
diff --git a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.h b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.h index eaf0678..327e300 100644 --- a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.h +++ b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.h
@@ -5,7 +5,6 @@ #ifndef FPDFSDK_PWL_CPWL_COMBO_BOX_EMBEDDERTEST_H_ #define FPDFSDK_PWL_CPWL_COMBO_BOX_EMBEDDERTEST_H_ -#include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -18,12 +17,10 @@ class CPWLComboBoxEmbedderTest : public EmbedderTest { protected: void SetUp() override; - void TearDown() override; - void CreateAndInitializeFormComboboxPDF(); + ScopedEmbedderTestPage CreateAndInitializeFormComboboxPDF(); void FormFillerAndWindowSetup(CPDFSDK_Widget* pAnnotCombobox); void TypeTextIntoTextField(int num_chars); - FPDF_PAGE GetPage() const { return m_page; } CPWL_ComboBox* GetCPWLComboBox() const { return m_pComboBox; } CFFL_FormField* GetCFFLFormField() const { return m_pFormField; } CPDFSDK_Widget* GetCPDFSDKAnnotNormal() const { return m_pAnnotNormal; } @@ -36,7 +33,6 @@ CPDFSDK_PageView* GetPageView() const { return m_pPageView; } private: - FPDF_PAGE m_page; CPWL_ComboBox* m_pComboBox = nullptr; CFFL_FormField* m_pFormField = nullptr; CPDFSDK_Widget* m_pAnnotNormal = nullptr;
diff --git a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp index 0aaa0d4..9186abe 100644 --- a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp +++ b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
@@ -20,41 +20,53 @@ protected: void SetUp() override { EmbedderTest::SetUp(); - CreateAndInitializeFormPDF(); - } - - void TearDown() override { - UnloadPage(GetPage()); - EmbedderTest::TearDown(); - } - - void CreateAndInitializeFormPDF() { ASSERT_TRUE(OpenDocument("text_form_multiple.pdf")); - m_page = LoadPage(0); - ASSERT_TRUE(m_page); + } + ScopedEmbedderTestPage CreateAndInitializeFormPDF() { + ScopedEmbedderTestPage page = LoadScopedPage(0); + if (!page) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } m_pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); CPDFSDK_AnnotIterator iter(m_pFormFillEnv->GetPageViewAtIndex(0), {CPDF_Annot::Subtype::WIDGET}); // Normal text field. m_pAnnot = ToCPDFSDKWidget(iter.GetFirstAnnot()); - ASSERT_TRUE(m_pAnnot); + if (!m_pAnnot) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } // Read-only text field. CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnot); // Pre-filled text field with char limit of 10. m_pAnnotCharLimit = ToCPDFSDKWidget(iter.GetNextAnnot(pAnnotReadOnly)); - ASSERT_TRUE(m_pAnnotCharLimit); + if (!m_pAnnotCharLimit) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } // Password text field. CPDFSDK_Annot* password_annot = iter.GetNextAnnot(m_pAnnotCharLimit); - ASSERT_TRUE(password_annot); - ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, password_annot->GetAnnotSubtype()); + if (!password_annot) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } + if (CPDF_Annot::Subtype::WIDGET != password_annot->GetAnnotSubtype()) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); - ASSERT_EQ(password_annot, pLastAnnot); + if (password_annot != pLastAnnot) { + ADD_FAILURE(); + return ScopedEmbedderTestPage(); + } + return page; } void FormFillerAndWindowSetup(CPDFSDK_Widget* pAnnotTextField) { @@ -82,14 +94,12 @@ } } - FPDF_PAGE GetPage() { return m_page; } CPWL_Edit* GetCPWLEdit() { return m_pEdit; } CFFL_FormField* GetCFFLFormFiller() { return m_pFormFiller; } CPDFSDK_Widget* GetCPDFSDKAnnot() { return m_pAnnot; } CPDFSDK_Widget* GetCPDFSDKAnnotCharLimit() { return m_pAnnotCharLimit; } private: - FPDF_PAGE m_page; CPWL_Edit* m_pEdit; CFFL_FormField* m_pFormFiller; CPDFSDK_Widget* m_pAnnot; @@ -98,6 +108,8 @@ }; TEST_F(CPWLEditEmbedderTest, TypeText) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); EXPECT_TRUE(GetCPWLEdit()->GetText().IsEmpty()); EXPECT_TRUE(GetCFFLFormFiller()->OnChar(GetCPDFSDKAnnot(), 'a', {})); @@ -108,6 +120,8 @@ } TEST_F(CPWLEditEmbedderTest, GetSelectedTextEmptyAndBasic) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); // Attempt to set selection before text has been typed to test that // selection is identified as empty. @@ -125,6 +139,8 @@ } TEST_F(CPWLEditEmbedderTest, GetSelectedTextFragments) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(50); @@ -155,6 +171,8 @@ } TEST_F(CPWLEditEmbedderTest, DeleteEntireTextSelection) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(50); @@ -167,6 +185,8 @@ } TEST_F(CPWLEditEmbedderTest, DeleteTextSelectionMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(50); @@ -179,6 +199,8 @@ } TEST_F(CPWLEditEmbedderTest, DeleteTextSelectionLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(50); @@ -191,6 +213,8 @@ } TEST_F(CPWLEditEmbedderTest, DeleteTextSelectionRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(50); @@ -203,6 +227,8 @@ } TEST_F(CPWLEditEmbedderTest, DeleteEmptyTextSelection) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(50); @@ -212,12 +238,16 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInEmptyTextField) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->ReplaceSelection(L"Hello"); EXPECT_EQ(L"Hello", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedTextFieldLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -229,6 +259,8 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedTextFieldMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -242,6 +274,8 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedTextFieldRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -251,6 +285,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -262,6 +298,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -273,6 +311,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -284,6 +324,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedTextFieldRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10); @@ -294,6 +336,8 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInEmptyCharLimitTextFieldOverflow) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->SetSelection(0, -1); EXPECT_EQ(L"Elephant", GetCPWLEdit()->GetSelectedText()); @@ -304,6 +348,8 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInEmptyCharLimitTextFieldFit) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->SetSelection(0, -1); EXPECT_EQ(L"Elephant", GetCPWLEdit()->GetSelectedText()); @@ -314,12 +360,16 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedCharLimitTextFieldLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->ReplaceSelection(L"Hippopotamus"); EXPECT_EQ(L"HiElephant", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedCharLimitTextFieldMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); // Move cursor to middle of text field. for (int i = 0; i < 5; ++i) { @@ -331,6 +381,8 @@ } TEST_F(CPWLEditEmbedderTest, InsertTextInPopulatedCharLimitTextFieldRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); // Move cursor to end of text field. EXPECT_TRUE(GetCFFLFormFiller()->OnKeyDown(FWL_VKEY_End, {})); @@ -341,6 +393,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->SetSelection(0, -1); EXPECT_EQ(L"Elephant", GetCPWLEdit()->GetSelectedText()); @@ -350,6 +404,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->SetSelection(0, 4); EXPECT_EQ(L"Elep", GetCPWLEdit()->GetSelectedText()); @@ -359,6 +415,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->SetSelection(2, 6); EXPECT_EQ(L"epha", GetCPWLEdit()->GetSelectedText()); @@ -368,6 +426,8 @@ TEST_F(CPWLEditEmbedderTest, InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnotCharLimit()); GetCPWLEdit()->SetSelection(4, 8); EXPECT_EQ(L"hant", GetCPWLEdit()->GetSelectedText()); @@ -376,54 +436,72 @@ } TEST_F(CPWLEditEmbedderTest, SetTextWithEndCarriageFeed) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\r"); EXPECT_EQ(L"Foo", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithEndNewline) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\n"); EXPECT_EQ(L"Foo", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithEndCarriageFeedAndNewLine) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\r\n"); EXPECT_EQ(L"Foo", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithEndNewLineAndCarriageFeed) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\n\r"); EXPECT_EQ(L"Foo", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithBodyCarriageFeed) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\rBar"); EXPECT_EQ(L"FooBar", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithBodyNewline) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\nBar"); EXPECT_EQ(L"FooBar", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithBodyCarriageFeedAndNewLine) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\r\nBar"); EXPECT_EQ(L"FooBar", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, SetTextWithBodyNewLineAndCarriageFeed) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); GetCPWLEdit()->SetText(L"Foo\n\rBar"); EXPECT_EQ(L"FooBar", GetCPWLEdit()->GetText()); } TEST_F(CPWLEditEmbedderTest, ReplaceAndKeepSelection) { + ScopedEmbedderTestPage page = CreateAndInitializeFormPDF(); + ASSERT_TRUE(page); FormFillerAndWindowSetup(GetCPDFSDKAnnot()); TypeTextIntoTextField(10);
diff --git a/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp b/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp index c12f037..e9f1d6d 100644 --- a/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp +++ b/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp
@@ -15,20 +15,14 @@ protected: void SetUp() override { EmbedderTest::SetUp(); - CreateAndInitializeFormPDF(); + ASSERT_TRUE(OpenDocument("click_form.pdf")); } void TearDown() override { - UnloadPage(page_); EmbedderTest::TearDown(); } void CreateAndInitializeFormPDF() { - ASSERT_TRUE(OpenDocument("click_form.pdf")); - - page_ = LoadPage(0); - ASSERT_TRUE(page_); - formfill_env_ = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); CPDFSDK_AnnotIterator it(formfill_env_->GetPageViewAtIndex(0), {CPDF_Annot::Subtype::WIDGET}); @@ -98,7 +92,6 @@ CPWL_Wnd* GetWindow() const { return window_; } private: - FPDF_PAGE page_; CFFL_FormField* form_filler_; CPDFSDK_Widget* widget_checkbox_; CPDFSDK_Widget* widget_readonly_checkbox_; @@ -109,6 +102,10 @@ }; TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnReadOnlyCheckBox) { + ScopedEmbedderTestPage page = LoadScopedPage(0); + ASSERT_TRUE(page); + CreateAndInitializeFormPDF(); + FormFillerAndWindowSetup(GetCPDFSDKWidgetReadOnlyCheckBox()); CPWL_CheckBox* check_box = static_cast<CPWL_CheckBox*>(GetWindow()); EXPECT_TRUE(check_box->IsChecked()); @@ -118,6 +115,10 @@ } TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnCheckBox) { + ScopedEmbedderTestPage page = LoadScopedPage(0); + ASSERT_TRUE(page); + CreateAndInitializeFormPDF(); + FormFillerAndWindowSetup(GetCPDFSDKWidgetCheckBox()); CPWL_CheckBox* check_box = static_cast<CPWL_CheckBox*>(GetWindow()); EXPECT_TRUE(GetCPDFSDKFormFillEnv()->GetInteractiveFormFiller()->OnChar( @@ -130,6 +131,10 @@ } TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnReadOnlyRadioButton) { + ScopedEmbedderTestPage page = LoadScopedPage(0); + ASSERT_TRUE(page); + CreateAndInitializeFormPDF(); + FormFillerAndWindowSetup(GetCPDFSDKWidgetReadOnlyRadioButton()); CPWL_RadioButton* radio_button = static_cast<CPWL_RadioButton*>(GetWindow()); EXPECT_FALSE(radio_button->IsChecked()); @@ -139,6 +144,10 @@ } TEST_F(CPWLSpecialButtonEmbedderTest, EnterOnRadioButton) { + ScopedEmbedderTestPage page = LoadScopedPage(0); + ASSERT_TRUE(page); + CreateAndInitializeFormPDF(); + FormFillerAndWindowSetup(GetCPDFSDKWidgetRadioButton()); CPWL_RadioButton* radio_button = static_cast<CPWL_RadioButton*>(GetWindow()); EXPECT_TRUE(GetCPDFSDKFormFillEnv()->GetInteractiveFormFiller()->OnChar(
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 9ae5bc0..dadce90 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp
@@ -889,6 +889,9 @@ } #endif +EmbedderTest::ScopedEmbedderTestPage::ScopedEmbedderTestPage() + : test_(nullptr), page_(nullptr) {} + EmbedderTest::ScopedEmbedderTestPage::ScopedEmbedderTestPage(EmbedderTest* test, int page_index) : test_(test), page_(test->LoadPage(page_index)) {}
diff --git a/testing/embedder_test.h b/testing/embedder_test.h index a987daa..1ef2ff6 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h
@@ -91,6 +91,7 @@ class ScopedEmbedderTestPage { public: + ScopedEmbedderTestPage(); ScopedEmbedderTestPage(EmbedderTest* test, int page_index); ScopedEmbedderTestPage(const ScopedEmbedderTestPage&) = delete; ScopedEmbedderTestPage& operator=(const ScopedEmbedderTestPage&) = delete;
diff --git a/xfa/fwl/cfwl_edit_embeddertest.cpp b/xfa/fwl/cfwl_edit_embeddertest.cpp index 1caaf32..9ec922e 100644 --- a/xfa/fwl/cfwl_edit_embeddertest.cpp +++ b/xfa/fwl/cfwl_edit_embeddertest.cpp
@@ -39,49 +39,43 @@ void TearDown() override { FSDK_SetTimeFunction(nullptr); FSDK_SetLocaltimeFunction(nullptr); - // TODO(crbug.com/pdfium/11): A page might not have been loaded if a test - // is skipped at runtime. This check for a non-null page should be able to - // removed once none of the tests are being skipped for Skia. - if (page()) - UnloadPage(page()); EmbedderTest::TearDown(); } void CreateAndInitializeFormPDF(const char* filename) { ASSERT_TRUE(OpenDocument(filename)); - page_ = LoadPage(0); - ASSERT_TRUE(page_); } - FPDF_PAGE page() const { return page_; } EmbedderTestTimerHandlingDelegate delegate() const { return delegate_; } private: - FPDF_PAGE page_ = nullptr; EmbedderTestTimerHandlingDelegate delegate_; }; TEST_F(CFWLEditEmbedderTest, Trivial) { CreateAndInitializeFormPDF("xfa/email_recommended.pdf"); + ScopedEmbedderTestPage page = LoadScopedPage(0); ASSERT_EQ(0u, delegate().GetAlerts().size()); } TEST_F(CFWLEditEmbedderTest, LeftClickMouseSelection) { CreateAndInitializeFormPDF("xfa/email_recommended.pdf"); - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + ScopedEmbedderTestPage page = LoadScopedPage(0); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); for (size_t i = 0; i < 10; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); // Mouse selection - FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58); - FORM_OnLButtonDown(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 128, 58); + FORM_OnLButtonDown(form_handle(), page.get(), FWL_EVENTFLAG_ShiftKey, 152, + 58); // 12 == (2 * strlen(defgh)) + 2 (for \0\0) - ASSERT_EQ(12U, FORM_GetSelectedText(form_handle(), page(), nullptr, 0)); + ASSERT_EQ(12U, FORM_GetSelectedText(form_handle(), page.get(), nullptr, 0)); uint16_t buf[6]; ASSERT_EQ(12U, - FORM_GetSelectedText(form_handle(), page(), &buf, sizeof(buf))); + FORM_GetSelectedText(form_handle(), page.get(), &buf, sizeof(buf))); EXPECT_EQ("defgh", GetPlatformString(buf)); } @@ -92,27 +86,28 @@ } CreateAndInitializeFormPDF("xfa/email_recommended.pdf"); - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + ScopedEmbedderTestPage page = LoadScopedPage(0); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); for (size_t i = 0; i < 10; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); // Mouse selection - FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58); - FORM_OnMouseMove(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 128, 58); + FORM_OnMouseMove(form_handle(), page.get(), FWL_EVENTFLAG_ShiftKey, 152, 58); // 12 == (2 * strlen(defgh)) + 2 (for \0\0) - ASSERT_EQ(12U, FORM_GetSelectedText(form_handle(), page(), nullptr, 0)); + ASSERT_EQ(12U, FORM_GetSelectedText(form_handle(), page.get(), nullptr, 0)); uint16_t buf[6]; ASSERT_EQ(12U, - FORM_GetSelectedText(form_handle(), page(), &buf, sizeof(buf))); + FORM_GetSelectedText(form_handle(), page.get(), &buf, sizeof(buf))); EXPECT_EQ("defgh", GetPlatformString(buf)); // TODO(hnakashima): This is incorrect. Visually 'abcdefgh' are selected. const char kDraggedMD5[] = "f131526c8edd04e44de17b2647ec54c8"; { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kDraggedMD5); } } @@ -124,20 +119,21 @@ } CreateAndInitializeFormPDF("xfa/email_recommended.pdf"); + ScopedEmbedderTestPage page = LoadScopedPage(0); const char kBlankMD5[] = "8dda78a3afaf9f7b5210eb81cacc4600"; { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kBlankMD5); } - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); for (size_t i = 0; i < 10; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kEmailRecommendedFilledChecksum); } } @@ -149,16 +145,17 @@ } CreateAndInitializeFormPDF("xfa/email_recommended.pdf"); - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + ScopedEmbedderTestPage page = LoadScopedPage(0); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); for (size_t i = 0; i < 5; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); - FORM_OnChar(form_handle(), page(), '\r', 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), '\r', 0); for (size_t i = 5; i < 10; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kEmailRecommendedFilledChecksum); } } @@ -166,13 +163,14 @@ // Disabled due to flakiness. TEST_F(CFWLEditEmbedderTest, DISABLED_FillWithNewLineWithMultiline) { CreateAndInitializeFormPDF("xfa/xfa_multiline_textfield.pdf"); - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + ScopedEmbedderTestPage page = LoadScopedPage(0); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); for (size_t i = 0; i < 5; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); - FORM_OnChar(form_handle(), page(), '\r', 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), '\r', 0); for (size_t i = 5; i < 10; ++i) - FORM_OnChar(form_handle(), page(), 'a' + i, 0); + FORM_OnChar(form_handle(), page.get(), 'a' + i, 0); // Should look like: // abcde @@ -184,12 +182,12 @@ const char kFilledMultilineMD5[] = "a5654e027d8b1667c20f3b86d1918003"; #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kFilledMultilineMD5); } for (size_t i = 0; i < 4; ++i) - FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Left, 0); + FORM_OnKeyDown(form_handle(), page.get(), FWL_VKEY_Left, 0); // Should look like: // abcde @@ -198,7 +196,7 @@ // Two backspaces is a workaround because left arrow does not behave well // in the first character of a line. It skips back to the previous line. for (size_t i = 0; i < 2; ++i) - FORM_OnChar(form_handle(), page(), '\b', 0); + FORM_OnChar(form_handle(), page.get(), '\b', 0); // Should look like: // abcde|ghij @@ -209,7 +207,7 @@ const char kMultilineBackspaceMD5[] = "a2f1dcab92bb1fb7c2f9ccc70100c989"; #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kMultilineBackspaceMD5); } } @@ -221,23 +219,24 @@ } CreateAndInitializeFormPDF("xfa/xfa_date_time_edit.pdf"); + ScopedEmbedderTestPage page = LoadScopedPage(0); // Give focus to date time widget, creating down-arrow button. - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); - FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); + FORM_OnLButtonUp(form_handle(), page.get(), 0, 115, 58); const char kSelectedMD5[] = "1036b8837a9dba75c6bd8f9347ae2eb2"; { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, kSelectedMD5); } // Click down-arrow button, bringing up calendar widget. - FORM_OnLButtonDown(form_handle(), page(), 0, 446, 54); - FORM_OnLButtonUp(form_handle(), page(), 0, 446, 54); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 446, 54); + FORM_OnLButtonUp(form_handle(), page.get(), 0, 446, 54); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); // TODO(tsepez): hermetic fonts. // const char kCalendarOpenMD5[] = "02de64e7e83c82c1ef0ae484d671a51d"; @@ -245,11 +244,11 @@ } // Click on date on calendar, putting result into field as text. - FORM_OnLButtonDown(form_handle(), page(), 0, 100, 162); - FORM_OnLButtonUp(form_handle(), page(), 0, 100, 162); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 100, 162); + FORM_OnLButtonUp(form_handle(), page.get(), 0, 100, 162); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); // TODO(tsepez): hermetic fonts. // const char kFilledMD5[] = "1bce66c11f1c87b8d639ce0076ac36d3"; @@ -259,23 +258,26 @@ TEST_F(CFWLEditEmbedderTest, ImageEditTest) { CreateAndInitializeFormPDF("xfa/xfa_image_edit.pdf"); - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + ScopedEmbedderTestPage page = LoadScopedPage(0); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); const char* filled_checksum = []() { if (CFX_DefaultRenderDevice::UseSkiaRenderer()) { return "23658ed124114f05518372d41c80e41b"; } return "101cf6223fa2403fba4c413a8310ab02"; }(); - ScopedFPDFBitmap page_bitmap = RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + ScopedFPDFBitmap page_bitmap = + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, filled_checksum); } TEST_F(CFWLEditEmbedderTest, ComboBoxTest) { CreateAndInitializeFormPDF("xfa/xfa_combobox.pdf"); + ScopedEmbedderTestPage page = LoadScopedPage(0); // Give focus to widget. - FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); - FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 115, 58); + FORM_OnLButtonUp(form_handle(), page.get(), 0, 115, 58); { const char* filled_checksum = []() { if (CFX_DefaultRenderDevice::UseSkiaRenderer()) { @@ -284,37 +286,37 @@ return "dad642ae8a5afce2591ffbcabbfc58dd"; }(); ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); CompareBitmap(page_bitmap.get(), 612, 792, filled_checksum); } // Click on down-arrow button, dropdown list appears. - FORM_OnLButtonDown(form_handle(), page(), 0, 438, 53); - FORM_OnLButtonUp(form_handle(), page(), 0, 438, 53); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 438, 53); + FORM_OnLButtonUp(form_handle(), page.get(), 0, 438, 53); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); // TODO(tsepez): hermetic fonts. // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd"; // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5); } // Enter drop-down list, selection highlighted. - FORM_OnMouseMove(form_handle(), page(), 0, 253, 107); + FORM_OnMouseMove(form_handle(), page.get(), 0, 253, 107); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); // TODO(tsepez): hermetic fonts. // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd"; // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5); } // Click on selection, putting result into field. - FORM_OnLButtonDown(form_handle(), page(), 0, 253, 107); - FORM_OnLButtonUp(form_handle(), page(), 0, 253, 107); + FORM_OnLButtonDown(form_handle(), page.get(), 0, 253, 107); + FORM_OnLButtonUp(form_handle(), page.get(), 0, 253, 107); { ScopedFPDFBitmap page_bitmap = - RenderLoadedPageWithFlags(page(), FPDF_ANNOT); + RenderLoadedPageWithFlags(page.get(), FPDF_ANNOT); // TODO(tsepez): hermetic fonts. // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd"; // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);