1 // Copyright 2017 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "fpdfsdk/pwl/cpwl_combo_box_embeddertest.h" 6 7 #include "fpdfsdk/cpdfsdk_annotiterator.h" 8 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" 9 #include "fpdfsdk/cpdfsdk_helpers.h" 10 #include "fpdfsdk/cpdfsdk_widget.h" 11 #include "fpdfsdk/formfiller/cffl_formfield.h" 12 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" 13 #include "fpdfsdk/pwl/cpwl_combo_box.h" 14 #include "fpdfsdk/pwl/cpwl_wnd.h" 15 #include "public/fpdf_fwlevent.h" 16 #include "testing/gtest/include/gtest/gtest.h" 17 SetUp()18void CPWLComboBoxEmbedderTest::SetUp() { 19 EmbedderTest::SetUp(); 20 CreateAndInitializeFormComboboxPDF(); 21 } 22 TearDown()23void CPWLComboBoxEmbedderTest::TearDown() { 24 UnloadPage(GetPage()); 25 EmbedderTest::TearDown(); 26 } 27 CreateAndInitializeFormComboboxPDF()28void CPWLComboBoxEmbedderTest::CreateAndInitializeFormComboboxPDF() { 29 ASSERT_TRUE(OpenDocument("combobox_form.pdf")); 30 m_page = LoadPage(0); 31 ASSERT_TRUE(m_page); 32 33 m_pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); 34 m_pPageView = m_pFormFillEnv->GetPageViewAtIndex(0); 35 CPDFSDK_AnnotIterator iter(m_pPageView, {CPDF_Annot::Subtype::WIDGET}); 36 37 // User editable combobox. 38 m_pAnnotEditable = ToCPDFSDKWidget(iter.GetFirstAnnot()); 39 ASSERT_TRUE(m_pAnnotEditable); 40 41 // Normal combobox with pre-selected value. 42 m_pAnnotNormal = ToCPDFSDKWidget(iter.GetNextAnnot(m_pAnnotEditable)); 43 ASSERT_TRUE(m_pAnnotNormal); 44 45 // Read-only combobox. 46 CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnotNormal); 47 CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); 48 ASSERT_EQ(pAnnotReadOnly, pLastAnnot); 49 } 50 FormFillerAndWindowSetup(CPDFSDK_Widget * pAnnotCombobox)51void CPWLComboBoxEmbedderTest::FormFillerAndWindowSetup( 52 CPDFSDK_Widget* pAnnotCombobox) { 53 CFFL_InteractiveFormFiller* pInteractiveFormFiller = 54 m_pFormFillEnv->GetInteractiveFormFiller(); 55 { 56 ObservedPtr<CPDFSDK_Widget> pObserved(pAnnotCombobox); 57 EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(pObserved, {})); 58 } 59 60 m_pFormField = pInteractiveFormFiller->GetFormFieldForTesting(pAnnotCombobox); 61 ASSERT_TRUE(m_pFormField); 62 63 CPWL_Wnd* pWindow = 64 m_pFormField->GetPWLWindow(m_pFormFillEnv->GetPageViewAtIndex(0)); 65 ASSERT_TRUE(pWindow); 66 m_pComboBox = static_cast<CPWL_ComboBox*>(pWindow); 67 } 68 TypeTextIntoTextField(int num_chars)69void CPWLComboBoxEmbedderTest::TypeTextIntoTextField(int num_chars) { 70 // Type text starting with 'A' to as many chars as specified by |num_chars|. 71 for (int i = 0; i < num_chars; ++i) { 72 EXPECT_TRUE( 73 GetCFFLFormField()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', {})); 74 } 75 } 76