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 ASSERT_TRUE(OpenDocument("combobox_form.pdf")); 21 } 22 23 CPWLComboBoxEmbedderTest::ScopedEmbedderTestPage CreateAndInitializeFormComboboxPDF()24CPWLComboBoxEmbedderTest::CreateAndInitializeFormComboboxPDF() { 25 ScopedEmbedderTestPage page = LoadScopedPage(0); 26 if (!page) { 27 ADD_FAILURE(); 28 return ScopedEmbedderTestPage(); 29 } 30 m_pFormFillEnv = CPDFSDKFormFillEnvironmentFromFPDFFormHandle(form_handle()); 31 m_pPageView = m_pFormFillEnv->GetPageViewAtIndex(0); 32 CPDFSDK_AnnotIterator iter(m_pPageView, {CPDF_Annot::Subtype::WIDGET}); 33 34 // User editable combobox. 35 m_pAnnotEditable = ToCPDFSDKWidget(iter.GetFirstAnnot()); 36 if (!m_pAnnotEditable) { 37 ADD_FAILURE(); 38 return ScopedEmbedderTestPage(); 39 } 40 41 // Normal combobox with pre-selected value. 42 m_pAnnotNormal = ToCPDFSDKWidget(iter.GetNextAnnot(m_pAnnotEditable)); 43 if (!m_pAnnotEditable) { 44 ADD_FAILURE(); 45 return ScopedEmbedderTestPage(); 46 } 47 48 // Read-only combobox. 49 CPDFSDK_Annot* pAnnotReadOnly = iter.GetNextAnnot(m_pAnnotNormal); 50 CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot(); 51 if (pAnnotReadOnly != pLastAnnot) { 52 ADD_FAILURE(); 53 return ScopedEmbedderTestPage(); 54 } 55 return page; 56 } 57 FormFillerAndWindowSetup(CPDFSDK_Widget * pAnnotCombobox)58void CPWLComboBoxEmbedderTest::FormFillerAndWindowSetup( 59 CPDFSDK_Widget* pAnnotCombobox) { 60 CFFL_InteractiveFormFiller* pInteractiveFormFiller = 61 m_pFormFillEnv->GetInteractiveFormFiller(); 62 { 63 ObservedPtr<CPDFSDK_Widget> pObserved(pAnnotCombobox); 64 EXPECT_TRUE(pInteractiveFormFiller->OnSetFocus(pObserved, {})); 65 } 66 67 m_pFormField = pInteractiveFormFiller->GetFormFieldForTesting(pAnnotCombobox); 68 ASSERT_TRUE(m_pFormField); 69 70 CPWL_Wnd* pWindow = 71 m_pFormField->GetPWLWindow(m_pFormFillEnv->GetPageViewAtIndex(0)); 72 ASSERT_TRUE(pWindow); 73 m_pComboBox = static_cast<CPWL_ComboBox*>(pWindow); 74 } 75 TypeTextIntoTextField(int num_chars)76void CPWLComboBoxEmbedderTest::TypeTextIntoTextField(int num_chars) { 77 // Type text starting with 'A' to as many chars as specified by |num_chars|. 78 for (int i = 0; i < num_chars; ++i) { 79 EXPECT_TRUE( 80 GetCFFLFormField()->OnChar(GetCPDFSDKAnnotUserEditable(), i + 'A', {})); 81 } 82 } 83