1 // Copyright 2017 PDFium Authors. All rights reserved. 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 "core/fxcrt/widestring.h" 6 #include "public/fpdf_formfill.h" 7 #include "public/fpdf_fwlevent.h" 8 #include "testing/embedder_test.h" 9 #include "testing/embedder_test_timer_handling_delegate.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 class CFWLEditEmbeddertest : public EmbedderTest { 13 protected: 14 void SetUp() override { 15 EmbedderTest::SetUp(); 16 SetDelegate(&delegate_); 17 CreateAndInitializeFormPDF(); 18 } 19 20 void TearDown() override { 21 UnloadPage(page()); 22 EmbedderTest::TearDown(); 23 } 24 25 void CreateAndInitializeFormPDF() { 26 EXPECT_TRUE(OpenDocument("xfa/email_recommended.pdf")); 27 page_ = LoadPage(0); 28 ASSERT_TRUE(page_); 29 } 30 31 FPDF_PAGE page() const { return page_; } 32 EmbedderTestTimerHandlingDelegate delegate() const { return delegate_; } 33 34 private: 35 FPDF_PAGE page_; 36 EmbedderTestTimerHandlingDelegate delegate_; 37 }; 38 39 TEST_F(CFWLEditEmbeddertest, Trivial) { 40 ASSERT_EQ(1u, delegate().GetAlerts().size()); 41 auto alert = delegate().GetAlerts()[0]; 42 EXPECT_STREQ(L"PDFium", alert.title.c_str()); 43 EXPECT_STREQ(L"The value you entered for Text Field is invalid.", 44 alert.message.c_str()); 45 } 46 47 TEST_F(CFWLEditEmbeddertest, LeftClickMouseSelection) { 48 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); 49 for (size_t i = 0; i < 10; ++i) 50 FORM_OnChar(form_handle(), page(), 'a' + i, 0); 51 52 // Mouse selection 53 FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58); 54 FORM_OnLButtonDown(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58); 55 56 // 12 == (2 * strlen(defgh)) + 2 (for \0\0) 57 EXPECT_EQ(12UL, FORM_GetSelectedText(form_handle(), page(), nullptr, 0)); 58 59 unsigned short buf[128]; 60 unsigned long len = FORM_GetSelectedText(form_handle(), page(), &buf, 128); 61 EXPECT_STREQ(L"defgh", WideString::FromUTF16LE(buf, len).c_str()); 62 } 63 64 TEST_F(CFWLEditEmbeddertest, DragMouseSelection) { 65 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); 66 for (size_t i = 0; i < 10; ++i) 67 FORM_OnChar(form_handle(), page(), 'a' + i, 0); 68 69 // Mouse selection 70 FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58); 71 FORM_OnMouseMove(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58); 72 73 // 12 == (2 * strlen(defgh)) + 2 (for \0\0) 74 EXPECT_EQ(12UL, FORM_GetSelectedText(form_handle(), page(), nullptr, 0)); 75 76 unsigned short buf[128]; 77 unsigned long len = FORM_GetSelectedText(form_handle(), page(), &buf, 128); 78 EXPECT_STREQ(L"defgh", WideString::FromUTF16LE(buf, len).c_str()); 79 } 80