summaryrefslogtreecommitdiff
path: root/xfa/fwl
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-04-27 20:09:09 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-27 20:09:09 +0000
commitf54ea0f44d53a6b1b3c4cb2c3a3285149510cccc (patch)
treeada091a76ee0b6c24294e085b67c10ca3f8cffa7 /xfa/fwl
parent60ef3a231ba778d6a667068bdbb17f712eb335e4 (diff)
downloadpdfium-f54ea0f44d53a6b1b3c4cb2c3a3285149510cccc.tar.xz
Fix backspace on 1st character of a line erases the line break.
Bug: chromium:836361 Change-Id: I39a0a3f9cb59ceb81f944dd5d0d4fd38a2e18a6b Reviewed-on: https://pdfium-review.googlesource.com/31411 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fwl')
-rw-r--r--xfa/fwl/cfwl_edit.cpp2
-rw-r--r--xfa/fwl/cfwl_edit_embeddertest.cpp108
2 files changed, 105 insertions, 5 deletions
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index afa9aac87d..8ebc155a80 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -1252,7 +1252,7 @@ void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) {
switch (c) {
case L'\b':
if (m_CursorPosition > 0) {
- SetCursorPosition(m_EdtEngine.GetIndexBefore(m_CursorPosition));
+ SetCursorPosition(m_CursorPosition - 1);
m_EdtEngine.Delete(m_CursorPosition, 1);
}
break;
diff --git a/xfa/fwl/cfwl_edit_embeddertest.cpp b/xfa/fwl/cfwl_edit_embeddertest.cpp
index 7415e05845..ecc3b5ed13 100644
--- a/xfa/fwl/cfwl_edit_embeddertest.cpp
+++ b/xfa/fwl/cfwl_edit_embeddertest.cpp
@@ -8,13 +8,13 @@
#include "testing/embedder_test.h"
#include "testing/embedder_test_timer_handling_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/xfa_js_embedder_test.h"
-class CFWLEditEmbeddertest : public EmbedderTest {
+class CFWLEditEmbeddertest : public XFAJSEmbedderTest {
protected:
void SetUp() override {
EmbedderTest::SetUp();
SetDelegate(&delegate_);
- CreateAndInitializeFormPDF();
}
void TearDown() override {
@@ -22,8 +22,8 @@ class CFWLEditEmbeddertest : public EmbedderTest {
EmbedderTest::TearDown();
}
- void CreateAndInitializeFormPDF() {
- EXPECT_TRUE(OpenDocument("xfa/email_recommended.pdf"));
+ void CreateAndInitializeFormPDF(const char* filename) {
+ EXPECT_TRUE(OpenDocument(filename));
page_ = LoadPage(0);
ASSERT_TRUE(page_);
}
@@ -37,10 +37,12 @@ class CFWLEditEmbeddertest : public EmbedderTest {
};
TEST_F(CFWLEditEmbeddertest, Trivial) {
+ CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
ASSERT_EQ(0u, delegate().GetAlerts().size());
}
TEST_F(CFWLEditEmbeddertest, LeftClickMouseSelection) {
+ CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
for (size_t i = 0; i < 10; ++i)
FORM_OnChar(form_handle(), page(), 'a' + i, 0);
@@ -58,6 +60,7 @@ TEST_F(CFWLEditEmbeddertest, LeftClickMouseSelection) {
}
TEST_F(CFWLEditEmbeddertest, DragMouseSelection) {
+ CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
for (size_t i = 0; i < 10; ++i)
FORM_OnChar(form_handle(), page(), 'a' + i, 0);
@@ -72,4 +75,101 @@ TEST_F(CFWLEditEmbeddertest, DragMouseSelection) {
unsigned short buf[128];
unsigned long len = FORM_GetSelectedText(form_handle(), page(), &buf, 128);
EXPECT_STREQ(L"defgh", WideString::FromUTF16LE(buf, len).c_str());
+
+ // TODO(hnakashima): This is incorrect. Visually 'abcdefgh' are selected.
+ const char kDraggedMD5[] = "69c13fe53b5fc422ebeab56d101a4658";
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderPageWithFlags(page(), form_handle(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, kDraggedMD5);
+ }
+}
+
+TEST_F(CFWLEditEmbeddertest, SimpleFill) {
+ CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
+ const char kBlankMD5[] = "eea5c72701270ac4a7edcc4df66d812a";
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderPageWithFlags(page(), form_handle(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, kBlankMD5);
+ }
+
+ FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
+ for (size_t i = 0; i < 10; ++i)
+ FORM_OnChar(form_handle(), page(), 'a' + i, 0);
+
+ const char kFilledMD5[] = "e73263fcea46c18d874b3d5a79f53805";
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderPageWithFlags(page(), form_handle(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ }
+}
+
+TEST_F(CFWLEditEmbeddertest, FillWithNewLineWithoutMultiline) {
+ CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
+ FORM_OnLButtonDown(form_handle(), page(), 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);
+ for (size_t i = 5; i < 10; ++i)
+ FORM_OnChar(form_handle(), page(), 'a' + i, 0);
+
+ const char kFilledMD5[] = "e73263fcea46c18d874b3d5a79f53805";
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderPageWithFlags(page(), form_handle(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ }
+}
+
+// Disabled due to flakiness.
+TEST_F(CFWLEditEmbeddertest, DISABLED_FillWithNewLineWithMultiline) {
+ CreateAndInitializeFormPDF("xfa/xfa_multiline_textfield.pdf");
+ FORM_OnLButtonDown(form_handle(), page(), 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);
+ for (size_t i = 5; i < 10; ++i)
+ FORM_OnChar(form_handle(), page(), 'a' + i, 0);
+
+ // Should look like:
+ // abcde
+ // fghij|
+ {
+#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+ const char kFilledMultilineMD5[] = "fc1f4d5fdb2c5755005fc525b0a60ec9";
+#else
+ const char kFilledMultilineMD5[] = "a5654e027d8b1667c20f3b86d1918003";
+#endif // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+ ScopedFPDFBitmap page_bitmap =
+ RenderPageWithFlags(page(), form_handle(), 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);
+
+ // Should look like:
+ // abcde
+ // f|ghij
+
+ // 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);
+
+ // Should look like:
+ // abcde|ghij
+ {
+#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+ const char kMultilineBackspaceMD5[] = "8bb62a8100ff1e1cc113d4033e0d824e";
+#else
+ const char kMultilineBackspaceMD5[] = "a2f1dcab92bb1fb7c2f9ccc70100c989";
+#endif // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+ ScopedFPDFBitmap page_bitmap =
+ RenderPageWithFlags(page(), form_handle(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, kMultilineBackspaceMD5);
+ }
}