diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-09-20 16:21:31 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-21 13:29:50 +0000 |
commit | b8777a2c5f38ea4d6fc74ea01a114d3e056c0fdb (patch) | |
tree | 83acc47e45d932146a70941b7484e78c426b3b27 /xfa/fwl/cfwl_edit_embeddertest.cpp | |
parent | 36eed87d19e741be9909500c45dd12e50ff6a1ab (diff) | |
download | pdfium-b8777a2c5f38ea4d6fc74ea01a114d3e056c0fdb.tar.xz |
Add embeddertest for CFWL_Edit
This CL adds two mouse selection tests for CFWL_Edit. In order to do so
the needed selection code was added to the XFA widget handler and
plumbed down to the CFWL_Edit field as needed.
Bug: pdfium:840
Change-Id: Ia3b5f5d191494a4579c01524df8fb35b24cc0085
Reviewed-on: https://pdfium-review.googlesource.com/14530
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fwl/cfwl_edit_embeddertest.cpp')
-rw-r--r-- | xfa/fwl/cfwl_edit_embeddertest.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/xfa/fwl/cfwl_edit_embeddertest.cpp b/xfa/fwl/cfwl_edit_embeddertest.cpp new file mode 100644 index 0000000000..c1575689eb --- /dev/null +++ b/xfa/fwl/cfwl_edit_embeddertest.cpp @@ -0,0 +1,67 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/fxcrt/widestring.h" +#include "public/fpdf_formfill.h" +#include "public/fpdf_fwlevent.h" +#include "testing/embedder_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +class CFWLEditEmbeddertest : public EmbedderTest { + protected: + void SetUp() override { + EmbedderTest::SetUp(); + CreateAndInitializeFormPDF(); + } + + void TearDown() override { + UnloadPage(page()); + EmbedderTest::TearDown(); + } + + void CreateAndInitializeFormPDF() { + EXPECT_TRUE(OpenDocument("xfa/email_recommended.pdf")); + page_ = LoadPage(0); + ASSERT_TRUE(page_); + } + + FPDF_PAGE page() const { return page_; } + + private: + FPDF_PAGE page_; +}; + +TEST_F(CFWLEditEmbeddertest, LeftClickMouseSelection) { + FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + for (size_t i = 0; i < 10; ++i) + FORM_OnChar(form_handle(), page(), 'a' + i, 0); + + // Mouse selection + FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58); + FORM_OnLButtonDown(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58); + + // 12 == (2 * strlen(defgh)) + 2 (for \0\0) + EXPECT_EQ(12UL, FORM_GetSelectedText(form_handle(), page(), nullptr, 0)); + + unsigned short buf[128]; + unsigned long len = FORM_GetSelectedText(form_handle(), page(), &buf, 128); + EXPECT_STREQ(L"defgh", WideString::FromUTF16LE(buf, len).c_str()); +} + +TEST_F(CFWLEditEmbeddertest, DragMouseSelection) { + FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58); + for (size_t i = 0; i < 10; ++i) + FORM_OnChar(form_handle(), page(), 'a' + i, 0); + + // Mouse selection + FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58); + FORM_OnMouseMove(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58); + + // 12 == (2 * strlen(defgh)) + 2 (for \0\0) + EXPECT_EQ(12UL, FORM_GetSelectedText(form_handle(), page(), nullptr, 0)); + + unsigned short buf[128]; + unsigned long len = FORM_GetSelectedText(form_handle(), page(), &buf, 128); + EXPECT_STREQ(L"defgh", WideString::FromUTF16LE(buf, len).c_str()); +} |