Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 1 | // Copyright 2015 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 | |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 5 | #include <memory> |
| 6 | #include <string> |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 7 | #include <vector> |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 8 | |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 9 | #include "core/fxcrt/fx_coordinates.h" |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 10 | #include "core/fxcrt/fx_string.h" |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 11 | #include "core/fxcrt/fx_system.h" |
| 12 | #include "public/cpp/fpdf_deleters.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 13 | #include "public/fpdf_formfill.h" |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 14 | #include "public/fpdf_fwlevent.h" |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 15 | #include "testing/embedder_test.h" |
| 16 | #include "testing/embedder_test_mock_delegate.h" |
| 17 | #include "testing/embedder_test_timer_handling_delegate.h" |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 18 | #include "testing/gmock/include/gmock/gmock.h" |
| 19 | #include "testing/gtest/include/gtest/gtest.h" |
| 20 | |
| 21 | using testing::_; |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 22 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 23 | using FPDFFormFillEmbeddertest = EmbedderTest; |
| 24 | |
| 25 | // A base class for many related tests that involve clicking and typing into |
| 26 | // form fields. |
| 27 | class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 28 | protected: |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 29 | FPDFFormFillInteractiveEmbeddertest() = default; |
| 30 | ~FPDFFormFillInteractiveEmbeddertest() override = default; |
| 31 | |
| 32 | void SetUp() override { |
| 33 | FPDFFormFillEmbeddertest::SetUp(); |
| 34 | ASSERT_TRUE(OpenDocument(GetDocumentName())); |
| 35 | page_ = LoadPage(0); |
| 36 | ASSERT_TRUE(page_); |
| 37 | FormSanityChecks(); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 40 | void TearDown() override { |
| 41 | UnloadPage(page_); |
| 42 | FPDFFormFillEmbeddertest::TearDown(); |
| 43 | } |
| 44 | |
| 45 | // Returns the name of the PDF to use. |
| 46 | virtual const char* GetDocumentName() const = 0; |
| 47 | |
Lei Zhang | 7bec2ff | 2017-08-25 23:28:23 -0700 | [diff] [blame] | 48 | // Returns the type of field(s) in the PDF. |
| 49 | virtual int GetFormType() const = 0; |
| 50 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 51 | // Optionally do some sanity check on the document after loading. |
| 52 | virtual void FormSanityChecks() {} |
| 53 | |
| 54 | FPDF_PAGE page() { return page_; } |
| 55 | |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 56 | int GetFormTypeAtPoint(const CFX_PointF& point) { |
| 57 | return FPDFPage_HasFormFieldAtPoint(form_handle(), page_, point.x, point.y); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 60 | void ClickOnFormFieldAtPoint(const CFX_PointF& point) { |
| 61 | // Click on the text field or combobox as specified by coordinates. |
| 62 | FORM_OnMouseMove(form_handle(), page_, 0, point.x, point.y); |
| 63 | FORM_OnLButtonDown(form_handle(), page_, 0, point.x, point.y); |
| 64 | FORM_OnLButtonUp(form_handle(), page_, 0, point.x, point.y); |
| 65 | } |
| 66 | |
| 67 | void TypeTextIntoTextField(int num_chars, const CFX_PointF& point) { |
| 68 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(point)); |
| 69 | ClickOnFormFieldAtPoint(point); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 70 | |
| 71 | // Type text starting with 'A' to as many chars as specified by |num_chars|. |
| 72 | for (int i = 0; i < num_chars; ++i) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 73 | FORM_OnChar(form_handle(), page_, 'A' + i, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 77 | // Navigates to text field using the mouse and then selects text via the |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 78 | // shift and specfied left or right arrow key. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 79 | void SelectTextWithKeyboard(int num_chars, |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 80 | int arrow_key, |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 81 | const CFX_PointF& point) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 82 | // Navigate to starting position for selection. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 83 | ClickOnFormFieldAtPoint(point); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 84 | |
| 85 | // Hold down shift (and don't release until entire text is selected). |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 86 | FORM_OnKeyDown(form_handle(), page_, FWL_VKEY_Shift, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 87 | |
| 88 | // Select text char by char via left or right arrow key. |
| 89 | for (int i = 0; i < num_chars; ++i) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 90 | FORM_OnKeyDown(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey); |
| 91 | FORM_OnKeyUp(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 92 | } |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 93 | FORM_OnKeyUp(form_handle(), page_, FWL_VKEY_Shift, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 96 | // Uses the mouse to navigate to text field and select text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 97 | void SelectTextWithMouse(const CFX_PointF& start, const CFX_PointF& end) { |
| 98 | ASSERT(start.y == end.y); |
| 99 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 100 | // Navigate to starting position and click mouse. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 101 | FORM_OnMouseMove(form_handle(), page_, 0, start.x, start.y); |
| 102 | FORM_OnLButtonDown(form_handle(), page_, 0, start.x, start.y); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 103 | |
| 104 | // Hold down mouse until reach end of desired selection. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 105 | FORM_OnMouseMove(form_handle(), page_, 0, end.x, end.y); |
| 106 | FORM_OnLButtonUp(form_handle(), page_, 0, end.x, end.y); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 109 | void CheckSelection(const WideStringView& expected_string) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 110 | // Calculate expected length for selected text. |
| 111 | int num_chars = expected_string.GetLength(); |
| 112 | |
| 113 | // Check actual selection against expected selection. |
| 114 | const unsigned long expected_length = |
| 115 | sizeof(unsigned short) * (num_chars + 1); |
| 116 | unsigned long sel_text_len = |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 117 | FORM_GetSelectedText(form_handle(), page_, nullptr, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 118 | ASSERT_EQ(expected_length, sel_text_len); |
| 119 | |
| 120 | std::vector<unsigned short> buf(sel_text_len); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 121 | EXPECT_EQ(expected_length, FORM_GetSelectedText(form_handle(), page_, |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 122 | buf.data(), sel_text_len)); |
| 123 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 124 | EXPECT_EQ(expected_string, WideString::FromUTF16LE(buf.data(), num_chars)); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 125 | } |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 126 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 127 | private: |
| 128 | FPDF_PAGE page_ = nullptr; |
| 129 | }; |
| 130 | |
| 131 | class FPDFFormFillTextFormEmbeddertest |
| 132 | : public FPDFFormFillInteractiveEmbeddertest { |
| 133 | protected: |
| 134 | FPDFFormFillTextFormEmbeddertest() = default; |
| 135 | ~FPDFFormFillTextFormEmbeddertest() override = default; |
| 136 | |
| 137 | const char* GetDocumentName() const override { |
| 138 | // PDF with several form text fields: |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 139 | // - "Text Box" - Regular text box with no special attributes. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 140 | // - "ReadOnly" - Ff: 1. |
| 141 | // - "CharLimit" - MaxLen: 10, V: Elephant. |
| 142 | return "text_form_multiple.pdf"; |
| 143 | } |
Lei Zhang | 7bec2ff | 2017-08-25 23:28:23 -0700 | [diff] [blame] | 144 | |
| 145 | int GetFormType() const override { return FPDF_FORMFIELD_TEXTFIELD; } |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 146 | |
| 147 | void FormSanityChecks() override { |
| 148 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(CharLimitFormBegin())); |
| 149 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(CharLimitFormEnd())); |
| 150 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(RegularFormBegin())); |
| 151 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(RegularFormEnd())); |
| 152 | } |
| 153 | |
| 154 | void SelectAllCharLimitFormTextWithMouse() { |
| 155 | SelectTextWithMouse(CharLimitFormEnd(), CharLimitFormBegin()); |
| 156 | } |
| 157 | |
| 158 | void SelectAllRegularFormTextWithMouse() { |
| 159 | SelectTextWithMouse(RegularFormEnd(), RegularFormBegin()); |
| 160 | } |
| 161 | |
| 162 | const CFX_PointF& CharLimitFormBegin() const { |
| 163 | static const CFX_PointF point = CharLimitFormAtX(kFormBeginX); |
| 164 | return point; |
| 165 | } |
| 166 | |
| 167 | const CFX_PointF& CharLimitFormEnd() const { |
| 168 | static const CFX_PointF point = CharLimitFormAtX(kFormEndX); |
| 169 | return point; |
| 170 | } |
| 171 | |
| 172 | const CFX_PointF& RegularFormBegin() const { |
| 173 | static const CFX_PointF point = RegularFormAtX(kFormBeginX); |
| 174 | return point; |
| 175 | } |
| 176 | |
| 177 | const CFX_PointF& RegularFormEnd() const { |
| 178 | static const CFX_PointF point = RegularFormAtX(kFormEndX); |
| 179 | return point; |
| 180 | } |
| 181 | |
| 182 | static CFX_PointF CharLimitFormAtX(float x) { |
| 183 | ASSERT(x >= kFormBeginX); |
| 184 | ASSERT(x <= kFormEndX); |
| 185 | return CFX_PointF(x, kCharLimitFormY); |
| 186 | } |
| 187 | |
| 188 | static CFX_PointF RegularFormAtX(float x) { |
| 189 | ASSERT(x >= kFormBeginX); |
| 190 | ASSERT(x <= kFormEndX); |
| 191 | return CFX_PointF(x, kRegularFormY); |
| 192 | } |
| 193 | |
| 194 | private: |
| 195 | static constexpr float kFormBeginX = 102.0; |
| 196 | static constexpr float kFormEndX = 195.0; |
| 197 | static constexpr float kCharLimitFormY = 60.0; |
| 198 | static constexpr float kRegularFormY = 115.0; |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | class FPDFFormFillComboBoxFormEmbeddertest |
| 202 | : public FPDFFormFillInteractiveEmbeddertest { |
| 203 | protected: |
| 204 | FPDFFormFillComboBoxFormEmbeddertest() = default; |
| 205 | ~FPDFFormFillComboBoxFormEmbeddertest() override = default; |
| 206 | |
| 207 | const char* GetDocumentName() const override { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 208 | // PDF with form comboboxes: |
| 209 | // - "Combo_Editable" - Ff: 393216, 3 options with pair values. |
| 210 | // - "Combo1" - Ff: 131072, 3 options with single values. |
| 211 | // - "Combo_ReadOnly" - Ff: 131073, 3 options with single values. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 212 | return "combobox_form.pdf"; |
| 213 | } |
| 214 | |
Lei Zhang | 7bec2ff | 2017-08-25 23:28:23 -0700 | [diff] [blame] | 215 | int GetFormType() const override { return FPDF_FORMFIELD_COMBOBOX; } |
| 216 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 217 | void FormSanityChecks() override { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 218 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormBegin())); |
| 219 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormEnd())); |
| 220 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(EditableFormDropDown())); |
| 221 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormBegin())); |
| 222 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormEnd())); |
| 223 | EXPECT_EQ(GetFormType(), GetFormTypeAtPoint(NonEditableFormDropDown())); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 226 | void SelectEditableFormOption(int item_index) { |
| 227 | SelectOption(item_index, EditableFormDropDown()); |
| 228 | } |
| 229 | |
| 230 | void SelectNonEditableFormOption(int item_index) { |
| 231 | SelectOption(item_index, NonEditableFormDropDown()); |
| 232 | } |
| 233 | |
| 234 | void SelectAllEditableFormTextWithMouse() { |
| 235 | SelectTextWithMouse(EditableFormEnd(), EditableFormBegin()); |
| 236 | } |
| 237 | |
| 238 | const CFX_PointF& EditableFormBegin() const { |
| 239 | static const CFX_PointF point = EditableFormAtX(kFormBeginX); |
| 240 | return point; |
| 241 | } |
| 242 | |
| 243 | const CFX_PointF& EditableFormEnd() const { |
| 244 | static const CFX_PointF point = EditableFormAtX(kFormEndX); |
| 245 | return point; |
| 246 | } |
| 247 | |
| 248 | const CFX_PointF& EditableFormDropDown() const { |
| 249 | static const CFX_PointF point(kFormDropDownX, kEditableFormY); |
| 250 | return point; |
| 251 | } |
| 252 | |
| 253 | const CFX_PointF& NonEditableFormBegin() const { |
| 254 | static const CFX_PointF point = NonEditableFormAtX(kFormBeginX); |
| 255 | return point; |
| 256 | } |
| 257 | |
| 258 | const CFX_PointF& NonEditableFormEnd() const { |
| 259 | static const CFX_PointF point = NonEditableFormAtX(kFormEndX); |
| 260 | return point; |
| 261 | } |
| 262 | |
| 263 | const CFX_PointF& NonEditableFormDropDown() const { |
| 264 | static const CFX_PointF point(kFormDropDownX, kNonEditableFormY); |
| 265 | return point; |
| 266 | } |
| 267 | |
| 268 | static CFX_PointF EditableFormAtX(float x) { |
| 269 | ASSERT(x >= kFormBeginX); |
| 270 | ASSERT(x <= kFormEndX); |
| 271 | return CFX_PointF(x, kEditableFormY); |
| 272 | } |
| 273 | |
| 274 | static CFX_PointF NonEditableFormAtX(float x) { |
| 275 | ASSERT(x >= kFormBeginX); |
| 276 | ASSERT(x <= kFormEndX); |
| 277 | return CFX_PointF(x, kNonEditableFormY); |
| 278 | } |
| 279 | |
| 280 | private: |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 281 | // Selects one of the pre-selected values from a combobox with three options. |
| 282 | // Options are specified by |item_index|, which is 0-based. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 283 | void SelectOption(int item_index, const CFX_PointF& point) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 284 | // Only relevant for comboboxes with three choices and the same dimensions |
| 285 | // as those in combobox_form.pdf. |
| 286 | ASSERT(item_index >= 0); |
| 287 | ASSERT(item_index < 3); |
| 288 | |
| 289 | // Navigate to button for drop down and click mouse to reveal options. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 290 | ClickOnFormFieldAtPoint(point); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 291 | |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 292 | // Calculate to Y-coordinate of dropdown option to be selected. |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 293 | constexpr double kChoiceHeight = 15; |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 294 | CFX_PointF option_point = point; |
| 295 | option_point.y -= kChoiceHeight * (item_index + 1); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 296 | |
| 297 | // Navigate to option and click mouse to select it. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 298 | ClickOnFormFieldAtPoint(option_point); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 299 | } |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 300 | |
| 301 | static constexpr float kFormBeginX = 102.0; |
| 302 | static constexpr float kFormEndX = 183.0; |
| 303 | static constexpr float kFormDropDownX = 192.0; |
| 304 | static constexpr float kEditableFormY = 60.0; |
| 305 | static constexpr float kNonEditableFormY = 110.0; |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 306 | }; |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 307 | |
| 308 | TEST_F(FPDFFormFillEmbeddertest, FirstTest) { |
| 309 | EmbedderTestMockDelegate mock; |
| 310 | EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0); |
| 311 | EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 312 | EXPECT_CALL(mock, SetTimer(_, _)).Times(0); |
| 313 | EXPECT_CALL(mock, KillTimer(_)).Times(0); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 314 | SetDelegate(&mock); |
| 315 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 316 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 317 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 318 | EXPECT_TRUE(page); |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 319 | UnloadPage(page); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 320 | } |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 321 | |
| 322 | TEST_F(FPDFFormFillEmbeddertest, BUG_487928) { |
| 323 | EmbedderTestTimerHandlingDelegate delegate; |
| 324 | SetDelegate(&delegate); |
| 325 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 326 | EXPECT_TRUE(OpenDocument("bug_487928.pdf")); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 327 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 328 | EXPECT_TRUE(page); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 329 | DoOpenActions(); |
| 330 | delegate.AdvanceTime(5000); |
| 331 | UnloadPage(page); |
| 332 | } |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 333 | |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 334 | TEST_F(FPDFFormFillEmbeddertest, BUG_507316) { |
| 335 | EmbedderTestTimerHandlingDelegate delegate; |
| 336 | SetDelegate(&delegate); |
| 337 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 338 | EXPECT_TRUE(OpenDocument("bug_507316.pdf")); |
weili | 0dadcc6 | 2016-08-23 21:10:57 -0700 | [diff] [blame] | 339 | FPDF_PAGE page = LoadPage(2); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 340 | EXPECT_TRUE(page); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 341 | DoOpenActions(); |
| 342 | delegate.AdvanceTime(4000); |
| 343 | UnloadPage(page); |
| 344 | } |
| 345 | |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 346 | TEST_F(FPDFFormFillEmbeddertest, BUG_514690) { |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 347 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 348 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 349 | EXPECT_TRUE(page); |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 350 | |
| 351 | // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES. |
| 352 | FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0); |
| 353 | FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0); |
| 354 | |
| 355 | UnloadPage(page); |
| 356 | } |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 357 | |
Tom Sepez | 4d07179 | 2016-02-04 16:53:26 -0800 | [diff] [blame] | 358 | #ifdef PDF_ENABLE_V8 |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 359 | TEST_F(FPDFFormFillEmbeddertest, BUG_551248) { |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 360 | // Test that timers fire once and intervals fire repeatedly. |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 361 | EmbedderTestTimerHandlingDelegate delegate; |
| 362 | SetDelegate(&delegate); |
| 363 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 364 | EXPECT_TRUE(OpenDocument("bug_551248.pdf")); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 365 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 366 | EXPECT_TRUE(page); |
| 367 | DoOpenActions(); |
| 368 | |
| 369 | const auto& alerts = delegate.GetAlerts(); |
| 370 | EXPECT_EQ(0U, alerts.size()); |
| 371 | |
| 372 | delegate.AdvanceTime(1000); |
| 373 | EXPECT_EQ(0U, alerts.size()); // nothing fired. |
| 374 | delegate.AdvanceTime(1000); |
| 375 | EXPECT_EQ(1U, alerts.size()); // interval fired. |
| 376 | delegate.AdvanceTime(1000); |
| 377 | EXPECT_EQ(2U, alerts.size()); // timer fired. |
| 378 | delegate.AdvanceTime(1000); |
| 379 | EXPECT_EQ(3U, alerts.size()); // interval fired again. |
| 380 | delegate.AdvanceTime(1000); |
| 381 | EXPECT_EQ(3U, alerts.size()); // nothing fired. |
| 382 | delegate.AdvanceTime(1000); |
| 383 | EXPECT_EQ(4U, alerts.size()); // interval fired again. |
| 384 | delegate.AdvanceTime(1000); |
| 385 | EXPECT_EQ(4U, alerts.size()); // nothing fired. |
| 386 | UnloadPage(page); |
| 387 | |
| 388 | ASSERT_EQ(4U, alerts.size()); // nothing else fired. |
| 389 | |
| 390 | EXPECT_STREQ(L"interval fired", alerts[0].message.c_str()); |
| 391 | EXPECT_STREQ(L"Alert", alerts[0].title.c_str()); |
| 392 | EXPECT_EQ(0, alerts[0].type); |
| 393 | EXPECT_EQ(0, alerts[0].icon); |
| 394 | |
| 395 | EXPECT_STREQ(L"timer fired", alerts[1].message.c_str()); |
| 396 | EXPECT_STREQ(L"Alert", alerts[1].title.c_str()); |
| 397 | EXPECT_EQ(0, alerts[1].type); |
| 398 | EXPECT_EQ(0, alerts[1].icon); |
| 399 | |
| 400 | EXPECT_STREQ(L"interval fired", alerts[2].message.c_str()); |
| 401 | EXPECT_STREQ(L"Alert", alerts[2].title.c_str()); |
| 402 | EXPECT_EQ(0, alerts[2].type); |
| 403 | EXPECT_EQ(0, alerts[2].icon); |
| 404 | |
| 405 | EXPECT_STREQ(L"interval fired", alerts[3].message.c_str()); |
| 406 | EXPECT_STREQ(L"Alert", alerts[3].title.c_str()); |
| 407 | EXPECT_EQ(0, alerts[3].type); |
| 408 | EXPECT_EQ(0, alerts[3].icon); |
| 409 | } |
| 410 | |
| 411 | TEST_F(FPDFFormFillEmbeddertest, BUG_620428) { |
| 412 | // Test that timers and intervals are cancelable. |
| 413 | EmbedderTestTimerHandlingDelegate delegate; |
| 414 | SetDelegate(&delegate); |
| 415 | |
| 416 | EXPECT_TRUE(OpenDocument("bug_620428.pdf")); |
| 417 | FPDF_PAGE page = LoadPage(0); |
| 418 | EXPECT_TRUE(page); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 419 | DoOpenActions(); |
| 420 | delegate.AdvanceTime(5000); |
| 421 | UnloadPage(page); |
| 422 | |
| 423 | const auto& alerts = delegate.GetAlerts(); |
tsepez | 0fa54b8 | 2016-08-04 12:07:28 -0700 | [diff] [blame] | 424 | ASSERT_EQ(1U, alerts.size()); |
| 425 | EXPECT_STREQ(L"done", alerts[0].message.c_str()); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 426 | } |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 427 | |
tsepez | 32e693f | 2016-08-04 12:47:42 -0700 | [diff] [blame] | 428 | TEST_F(FPDFFormFillEmbeddertest, BUG_634394) { |
| 429 | // Cancel timer inside timer callback. |
| 430 | EmbedderTestTimerHandlingDelegate delegate; |
| 431 | SetDelegate(&delegate); |
| 432 | |
| 433 | EXPECT_TRUE(OpenDocument("bug_634394.pdf")); |
| 434 | FPDF_PAGE page = LoadPage(0); |
| 435 | EXPECT_TRUE(page); |
| 436 | DoOpenActions(); |
| 437 | |
| 438 | // Timers fire at most once per AdvanceTime(), allow intervals |
| 439 | // to fire several times if possible. |
| 440 | delegate.AdvanceTime(1000); |
| 441 | delegate.AdvanceTime(1000); |
| 442 | delegate.AdvanceTime(1000); |
| 443 | delegate.AdvanceTime(1000); |
| 444 | delegate.AdvanceTime(1000); |
| 445 | UnloadPage(page); |
| 446 | |
| 447 | const auto& alerts = delegate.GetAlerts(); |
| 448 | EXPECT_EQ(2U, alerts.size()); |
| 449 | } |
| 450 | |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 451 | TEST_F(FPDFFormFillEmbeddertest, BUG_634716) { |
| 452 | EmbedderTestTimerHandlingDelegate delegate; |
| 453 | SetDelegate(&delegate); |
| 454 | |
| 455 | EXPECT_TRUE(OpenDocument("bug_634716.pdf")); |
| 456 | FPDF_PAGE page = LoadPage(0); |
| 457 | EXPECT_TRUE(page); |
| 458 | DoOpenActions(); |
| 459 | |
| 460 | // Timers fire at most once per AdvanceTime(), allow intervals |
| 461 | // to fire several times if possible. |
| 462 | delegate.AdvanceTime(1000); |
| 463 | delegate.AdvanceTime(1000); |
| 464 | delegate.AdvanceTime(1000); |
| 465 | delegate.AdvanceTime(1000); |
| 466 | delegate.AdvanceTime(1000); |
| 467 | UnloadPage(page); |
| 468 | |
| 469 | const auto& alerts = delegate.GetAlerts(); |
| 470 | EXPECT_EQ(2U, alerts.size()); |
| 471 | } |
| 472 | |
tsepez | 6cf5eca | 2017-01-12 11:21:12 -0800 | [diff] [blame] | 473 | TEST_F(FPDFFormFillEmbeddertest, BUG_679649) { |
| 474 | EmbedderTestTimerHandlingDelegate delegate; |
| 475 | SetDelegate(&delegate); |
| 476 | |
| 477 | EXPECT_TRUE(OpenDocument("bug_679649.pdf")); |
| 478 | FPDF_PAGE page = LoadPage(0); |
| 479 | EXPECT_TRUE(page); |
| 480 | |
| 481 | delegate.SetFailNextTimer(); |
| 482 | DoOpenActions(); |
| 483 | delegate.AdvanceTime(2000); |
| 484 | UnloadPage(page); |
| 485 | |
| 486 | const auto& alerts = delegate.GetAlerts(); |
| 487 | EXPECT_EQ(0u, alerts.size()); |
| 488 | } |
| 489 | |
Tom Sepez | fb7021c | 2017-05-31 10:29:25 -0700 | [diff] [blame] | 490 | TEST_F(FPDFFormFillEmbeddertest, BUG_707673) { |
| 491 | EmbedderTestTimerHandlingDelegate delegate; |
| 492 | SetDelegate(&delegate); |
| 493 | |
| 494 | EXPECT_TRUE(OpenDocument("bug_707673.pdf")); |
| 495 | FPDF_PAGE page = LoadPage(0); |
| 496 | EXPECT_TRUE(page); |
| 497 | |
| 498 | DoOpenActions(); |
| 499 | FORM_OnLButtonDown(form_handle(), page, 0, 140, 590); |
| 500 | FORM_OnLButtonUp(form_handle(), page, 0, 140, 590); |
| 501 | delegate.AdvanceTime(1000); |
| 502 | UnloadPage(page); |
| 503 | |
| 504 | const auto& alerts = delegate.GetAlerts(); |
| 505 | EXPECT_EQ(0u, alerts.size()); |
| 506 | } |
| 507 | |
Tom Sepez | b1f9205 | 2017-09-14 17:03:12 -0700 | [diff] [blame] | 508 | TEST_F(FPDFFormFillEmbeddertest, BUG_765384) { |
| 509 | EXPECT_TRUE(OpenDocument("bug_765384.pdf")); |
| 510 | FPDF_PAGE page = LoadPage(0); |
| 511 | EXPECT_TRUE(page); |
| 512 | |
| 513 | DoOpenActions(); |
| 514 | FORM_OnLButtonDown(form_handle(), page, 0, 140, 590); |
| 515 | FORM_OnLButtonUp(form_handle(), page, 0, 140, 590); |
| 516 | UnloadPage(page); |
| 517 | } |
| 518 | |
Tom Sepez | 4d07179 | 2016-02-04 16:53:26 -0800 | [diff] [blame] | 519 | #endif // PDF_ENABLE_V8 |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 520 | |
| 521 | TEST_F(FPDFFormFillEmbeddertest, FormText) { |
Dan Sinclair | 698aed7 | 2017-09-26 16:24:49 -0400 | [diff] [blame] | 522 | #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 523 | const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff"; |
| 524 | const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d"; |
| 525 | const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe"; |
| 526 | #else |
Nicolas Pena | 00c3cfd | 2017-07-10 17:29:54 -0400 | [diff] [blame] | 527 | const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a"; |
| 528 | const char md5_2[] = "4526b09382e144d5506ad92149399de6"; |
| 529 | const char md5_3[] = "80356067d860088864cf50ff85d8459e"; |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 530 | #endif |
| 531 | { |
| 532 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 533 | FPDF_PAGE page = LoadPage(0); |
| 534 | ASSERT_TRUE(page); |
| 535 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap1(RenderPage(page)); |
| 536 | CompareBitmap(bitmap1.get(), 300, 300, md5_1); |
| 537 | |
| 538 | // Click on the textfield |
| 539 | EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD, |
| 540 | FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0)); |
| 541 | FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0); |
| 542 | FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0); |
| 543 | FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0); |
| 544 | |
| 545 | // Write "ABC" |
| 546 | FORM_OnChar(form_handle(), page, 65, 0); |
| 547 | FORM_OnChar(form_handle(), page, 66, 0); |
| 548 | FORM_OnChar(form_handle(), page, 67, 0); |
| 549 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap2(RenderPage(page)); |
| 550 | CompareBitmap(bitmap2.get(), 300, 300, md5_2); |
| 551 | |
| 552 | // Take out focus by clicking out of the textfield |
| 553 | FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0); |
| 554 | FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0); |
| 555 | FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0); |
| 556 | std::unique_ptr<void, FPDFBitmapDeleter> bitmap3(RenderPage(page)); |
| 557 | CompareBitmap(bitmap3.get(), 300, 300, md5_3); |
| 558 | |
| 559 | EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
| 560 | |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 561 | // Close page |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 562 | UnloadPage(page); |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 563 | } |
| 564 | // Check saved document |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 565 | TestAndCloseSaved(300, 300, md5_3); |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 566 | } |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 567 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 568 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 569 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 570 | CheckSelection(L""); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 571 | |
| 572 | // Test basic selection. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 573 | TypeTextIntoTextField(3, RegularFormBegin()); |
| 574 | SelectTextWithKeyboard(3, FWL_VKEY_Left, RegularFormAtX(123.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 575 | CheckSelection(L"ABC"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 578 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicMouse) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 579 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 580 | CheckSelection(L""); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 581 | |
| 582 | // Test basic selection. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 583 | TypeTextIntoTextField(3, RegularFormBegin()); |
| 584 | SelectTextWithMouse(RegularFormAtX(125.0), RegularFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 585 | CheckSelection(L"ABC"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 588 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsKeyBoard) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 589 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 590 | |
| 591 | // Test selecting first character in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 592 | SelectTextWithKeyboard(1, FWL_VKEY_Right, RegularFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 593 | CheckSelection(L"A"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 594 | |
| 595 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 596 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 597 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 598 | |
| 599 | // Test selecting middle section in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 600 | SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(170.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 601 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 602 | |
| 603 | // Test selecting middle selection in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 604 | SelectTextWithKeyboard(6, FWL_VKEY_Right, RegularFormAtX(125.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 605 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 606 | |
| 607 | // Test selecting last character in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 608 | SelectTextWithKeyboard(1, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 609 | CheckSelection(L"L"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 612 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsMouse) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 613 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 614 | |
| 615 | // Test selecting first character in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 616 | SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(106.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 617 | CheckSelection(L"A"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 618 | |
| 619 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 620 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 621 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 622 | |
| 623 | // Test selecting middle section in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 624 | SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 625 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 626 | |
| 627 | // Test selecting middle selection in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 628 | SelectTextWithMouse(RegularFormAtX(125.0), RegularFormAtX(170.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 629 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 630 | |
| 631 | // Test selecting last character in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 632 | SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(186.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 633 | CheckSelection(L"L"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 634 | } |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 635 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 636 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 637 | GetSelectedTextEmptyAndBasicNormalComboBox) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 638 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 639 | CheckSelection(L""); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 640 | |
| 641 | // Non-editable comboboxes don't allow selection with keyboard. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 642 | SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(142.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 643 | CheckSelection(L"Banana"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 644 | |
| 645 | // Select other another provided option. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 646 | SelectNonEditableFormOption(0); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 647 | CheckSelection(L"Apple"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 650 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 651 | GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 652 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 653 | CheckSelection(L""); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 654 | |
| 655 | // Test basic selection of text within user editable combobox using keyboard. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 656 | TypeTextIntoTextField(3, EditableFormBegin()); |
| 657 | SelectTextWithKeyboard(3, FWL_VKEY_Left, EditableFormAtX(128.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 658 | CheckSelection(L"ABC"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 659 | |
| 660 | // Select a provided option. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 661 | SelectEditableFormOption(1); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 662 | CheckSelection(L"Bar"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 665 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 666 | GetSelectedTextEmptyAndBasicEditableComboBoxMouse) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 667 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 668 | CheckSelection(L""); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 669 | |
| 670 | // Test basic selection of text within user editable combobox using mouse. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 671 | TypeTextIntoTextField(3, EditableFormBegin()); |
| 672 | SelectTextWithMouse(EditableFormAtX(128.0), EditableFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 673 | CheckSelection(L"ABC"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 674 | |
| 675 | // Select a provided option. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 676 | SelectEditableFormOption(2); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 677 | CheckSelection(L"Qux"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 680 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 681 | GetSelectedTextFragmentsNormalComboBox) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 682 | // Test selecting first character in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 683 | SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(107.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 684 | CheckSelection(L"B"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 685 | |
| 686 | // Test selecting entire string in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 687 | SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 688 | CheckSelection(L"Banana"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 689 | |
| 690 | // Test selecting middle section in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 691 | SelectTextWithMouse(NonEditableFormAtX(135.0), NonEditableFormAtX(117.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 692 | CheckSelection(L"nan"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 693 | |
| 694 | // Test selecting middle section in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 695 | SelectTextWithMouse(NonEditableFormAtX(117.0), NonEditableFormAtX(135.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 696 | CheckSelection(L"nan"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 697 | |
| 698 | // Test selecting last character in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 699 | SelectTextWithMouse(NonEditableFormAtX(142.0), NonEditableFormAtX(138.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 700 | CheckSelection(L"a"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 701 | |
| 702 | // Select another option and then reset selection as first three chars. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 703 | SelectNonEditableFormOption(2); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 704 | CheckSelection(L"Cherry"); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 705 | SelectTextWithMouse(NonEditableFormBegin(), NonEditableFormAtX(122.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 706 | CheckSelection(L"Che"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 709 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 710 | GetSelectedTextFragmentsEditableComboBoxKeyboard) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 711 | TypeTextIntoTextField(10, EditableFormBegin()); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 712 | |
| 713 | // Test selecting first character in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 714 | SelectTextWithKeyboard(1, FWL_VKEY_Right, EditableFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 715 | CheckSelection(L"A"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 716 | |
| 717 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 718 | SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 719 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 720 | |
| 721 | // Test selecting middle section in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 722 | SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(168.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 723 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 724 | |
| 725 | // Test selecting middle selection in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 726 | SelectTextWithKeyboard(5, FWL_VKEY_Right, EditableFormAtX(127.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 727 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 728 | |
| 729 | // Test selecting last character in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 730 | SelectTextWithKeyboard(1, FWL_VKEY_Left, EditableFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 731 | CheckSelection(L"J"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 732 | |
| 733 | // Select a provided option and then reset selection as first two chars. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 734 | SelectEditableFormOption(0); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 735 | CheckSelection(L"Foo"); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 736 | SelectTextWithKeyboard(2, FWL_VKEY_Right, EditableFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 737 | CheckSelection(L"Fo"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 740 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 741 | GetSelectedTextFragmentsEditableComboBoxMouse) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 742 | TypeTextIntoTextField(10, EditableFormBegin()); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 743 | |
| 744 | // Test selecting first character in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 745 | SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(107.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 746 | CheckSelection(L"A"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 747 | |
| 748 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 749 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 750 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 751 | |
| 752 | // Test selecting middle section in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 753 | SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 754 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 755 | |
| 756 | // Test selecting middle selection in forward direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 757 | SelectTextWithMouse(EditableFormAtX(127.0), EditableFormAtX(168.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 758 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 759 | |
| 760 | // Test selecting last character in backwards direction. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 761 | SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(174.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 762 | CheckSelection(L"J"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 763 | } |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 764 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 765 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldEntireSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 766 | // Select entire contents of text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 767 | TypeTextIntoTextField(12, RegularFormBegin()); |
| 768 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 769 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 770 | |
| 771 | // Test deleting current text selection. Select what remains after deletion to |
| 772 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 773 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 774 | |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 775 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 776 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 779 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionMiddle) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 780 | // Select middle section of text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 781 | TypeTextIntoTextField(12, RegularFormBegin()); |
| 782 | SelectTextWithMouse(RegularFormAtX(170.0), RegularFormAtX(125.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 783 | CheckSelection(L"DEFGHI"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 784 | |
| 785 | // Test deleting current text selection. Select what remains after deletion to |
| 786 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 787 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 788 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 789 | CheckSelection(L"ABCJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 792 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionLeft) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 793 | // Select first few characters of text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 794 | TypeTextIntoTextField(12, RegularFormBegin()); |
| 795 | SelectTextWithMouse(RegularFormBegin(), RegularFormAtX(132.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 796 | CheckSelection(L"ABCD"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 797 | |
| 798 | // Test deleting current text selection. Select what remains after deletion to |
| 799 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 800 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 801 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 802 | CheckSelection(L"EFGHIJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 805 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionRight) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 806 | // Select last few characters of text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 807 | TypeTextIntoTextField(12, RegularFormBegin()); |
| 808 | SelectTextWithMouse(RegularFormEnd(), RegularFormAtX(165.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 809 | CheckSelection(L"IJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 810 | |
| 811 | // Test deleting current text selection. Select what remains after deletion to |
| 812 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 813 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 814 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 815 | CheckSelection(L"ABCDEFGH"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 818 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteEmptyTextFieldSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 819 | // Do not select text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 820 | TypeTextIntoTextField(12, RegularFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 821 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 822 | |
| 823 | // Test that attempt to delete empty text selection has no effect. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 824 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 825 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 826 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 829 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 830 | DeleteEditableComboBoxEntireSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 831 | // Select entire contents of user-editable combobox text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 832 | TypeTextIntoTextField(10, EditableFormBegin()); |
| 833 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 834 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 835 | |
| 836 | // Test deleting current text selection. Select what remains after deletion to |
| 837 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 838 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 839 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 840 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 843 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 844 | DeleteEditableComboBoxSelectionMiddle) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 845 | // Select middle section of text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 846 | TypeTextIntoTextField(10, EditableFormBegin()); |
| 847 | SelectTextWithMouse(EditableFormAtX(168.0), EditableFormAtX(127.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 848 | CheckSelection(L"DEFGH"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 849 | |
| 850 | // Test deleting current text selection. Select what remains after deletion to |
| 851 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 852 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 853 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 854 | CheckSelection(L"ABCIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 857 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 858 | DeleteEditableComboBoxSelectionLeft) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 859 | // Select first few characters of text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 860 | TypeTextIntoTextField(10, EditableFormBegin()); |
| 861 | SelectTextWithMouse(EditableFormBegin(), EditableFormAtX(132.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 862 | CheckSelection(L"ABCD"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 863 | |
| 864 | // Test deleting current text selection. Select what remains after deletion to |
| 865 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 866 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 867 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 868 | CheckSelection(L"EFGHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 871 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 872 | DeleteEditableComboBoxSelectionRight) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 873 | // Select last few characters of text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 874 | TypeTextIntoTextField(10, EditableFormBegin()); |
| 875 | SelectTextWithMouse(EditableFormEnd(), EditableFormAtX(152.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 876 | CheckSelection(L"GHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 877 | |
| 878 | // Test deleting current text selection. Select what remains after deletion to |
| 879 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 880 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 881 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 882 | CheckSelection(L"ABCDEF"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 885 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 886 | DeleteEmptyEditableComboBoxSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 887 | // Do not select text. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 888 | TypeTextIntoTextField(10, EditableFormBegin()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 889 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 890 | |
| 891 | // Test that attempt to delete empty text selection has no effect. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 892 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 893 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 894 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 895 | } |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 896 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 897 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInEmptyTextField) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 898 | ClickOnFormFieldAtPoint(RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 899 | |
| 900 | // Test inserting text into empty text field. |
| 901 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 902 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 903 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 904 | |
| 905 | // Select entire contents of text field to check that insertion worked |
| 906 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 907 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 908 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 911 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldLeft) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 912 | TypeTextIntoTextField(8, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 913 | |
| 914 | // Click on the leftmost part of the text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 915 | ClickOnFormFieldAtPoint(RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 916 | |
| 917 | // Test inserting text in front of existing text in text field. |
| 918 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 919 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 920 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 921 | |
| 922 | // Select entire contents of text field to check that insertion worked |
| 923 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 924 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 925 | CheckSelection(L"HelloABCDEFGH"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 928 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldMiddle) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 929 | TypeTextIntoTextField(8, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 930 | |
| 931 | // Click on the middle of the text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 932 | ClickOnFormFieldAtPoint(RegularFormAtX(134.0)); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 933 | |
| 934 | // Test inserting text in the middle of existing text in text field. |
| 935 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 936 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 937 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 938 | |
| 939 | // Select entire contents of text field to check that insertion worked |
| 940 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 941 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 942 | CheckSelection(L"ABCDHelloEFGH"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 945 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldRight) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 946 | TypeTextIntoTextField(8, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 947 | |
| 948 | // Click on the rightmost part of the text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 949 | ClickOnFormFieldAtPoint(RegularFormAtX(166.0)); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 950 | |
| 951 | // Test inserting text behind existing text in text field. |
| 952 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 953 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 954 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 955 | |
| 956 | // Select entire contents of text field to check that insertion worked |
| 957 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 958 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 959 | CheckSelection(L"ABCDEFGHHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 962 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 963 | InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 964 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 965 | |
| 966 | // Select entire string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 967 | SelectTextWithKeyboard(12, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 968 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 969 | |
| 970 | // Test replacing text selection with text to be inserted. |
| 971 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 972 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 973 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 974 | |
| 975 | // Select entire contents of text field to check that insertion worked |
| 976 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 977 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 978 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 981 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 982 | InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 983 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 984 | |
| 985 | // Select left portion of string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 986 | SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(148.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 987 | CheckSelection(L"ABCDEF"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 988 | |
| 989 | // Test replacing text selection with text to be inserted. |
| 990 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 991 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 992 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 993 | |
| 994 | // Select entire contents of text field to check that insertion worked |
| 995 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 996 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 997 | CheckSelection(L"HelloGHIJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1000 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1001 | InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1002 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1003 | |
| 1004 | // Select middle portion of string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1005 | SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormAtX(171.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1006 | CheckSelection(L"DEFGHI"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1007 | |
| 1008 | // Test replacing text selection with text to be inserted. |
| 1009 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1010 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1011 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1012 | |
| 1013 | // Select entire contents of text field to check that insertion worked |
| 1014 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1015 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1016 | CheckSelection(L"ABCHelloJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1019 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1020 | InsertTextAndReplaceSelectionInPopulatedTextFieldRight) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1021 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1022 | |
| 1023 | // Select right portion of string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1024 | SelectTextWithKeyboard(6, FWL_VKEY_Left, RegularFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1025 | CheckSelection(L"GHIJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1026 | |
| 1027 | // Test replacing text selection with text to be inserted. |
| 1028 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1029 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1030 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1031 | |
| 1032 | // Select entire contents of text field to check that insertion worked |
| 1033 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1034 | SelectAllRegularFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1035 | CheckSelection(L"ABCDEFHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1038 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 1039 | InsertTextInEmptyEditableComboBox) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1040 | ClickOnFormFieldAtPoint(EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1041 | |
| 1042 | // Test inserting text into empty user-editable combobox. |
| 1043 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1044 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1045 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1046 | |
| 1047 | // Select entire contents of user-editable combobox text field to check that |
| 1048 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1049 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1050 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1053 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 1054 | InsertTextInPopulatedEditableComboBoxLeft) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1055 | TypeTextIntoTextField(6, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1056 | |
| 1057 | // Click on the leftmost part of the user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1058 | ClickOnFormFieldAtPoint(EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1059 | |
| 1060 | // Test inserting text in front of existing text in user-editable combobox. |
| 1061 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1062 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1063 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1064 | |
| 1065 | // Select entire contents of user-editable combobox text field to check that |
| 1066 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1067 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1068 | CheckSelection(L"HelloABCDEF"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1071 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 1072 | InsertTextInPopulatedEditableComboBoxMiddle) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1073 | TypeTextIntoTextField(6, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1074 | |
| 1075 | // Click on the middle of the user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1076 | ClickOnFormFieldAtPoint(EditableFormAtX(126.0)); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1077 | |
| 1078 | // Test inserting text in the middle of existing text in user-editable |
| 1079 | // combobox. |
| 1080 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1081 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1082 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1083 | |
| 1084 | // Select entire contents of user-editable combobox text field to check that |
| 1085 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1086 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1087 | CheckSelection(L"ABCHelloDEF"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1090 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 1091 | InsertTextInPopulatedEditableComboBoxRight) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1092 | TypeTextIntoTextField(6, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1093 | |
| 1094 | // Click on the rightmost part of the user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1095 | ClickOnFormFieldAtPoint(EditableFormEnd()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1096 | |
| 1097 | // Test inserting text behind existing text in user-editable combobox. |
| 1098 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1099 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1100 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1101 | |
| 1102 | // Select entire contents of user-editable combobox text field to check that |
| 1103 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1104 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1105 | CheckSelection(L"ABCDEFHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1108 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1109 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1110 | TypeTextIntoTextField(10, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1111 | |
| 1112 | // Select entire string in user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1113 | SelectTextWithKeyboard(10, FWL_VKEY_Left, EditableFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1114 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1115 | |
| 1116 | // Test replacing text selection with text to be inserted. |
| 1117 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1118 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1119 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1120 | |
| 1121 | // Select entire contents of user-editable combobox text field to check that |
| 1122 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1123 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1124 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1127 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1128 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1129 | TypeTextIntoTextField(10, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1130 | |
| 1131 | // Select left portion of string in user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1132 | SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(142.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1133 | CheckSelection(L"ABCDE"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1134 | |
| 1135 | // Test replacing text selection with text to be inserted. |
| 1136 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1137 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1138 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1139 | |
| 1140 | // Select entire contents of user-editable combobox text field to check that |
| 1141 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1142 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1143 | CheckSelection(L"HelloFGHIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1146 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1147 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1148 | TypeTextIntoTextField(10, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1149 | |
| 1150 | // Select middle portion of string in user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1151 | SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormAtX(167.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1152 | CheckSelection(L"DEFGH"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1153 | |
| 1154 | // Test replacing text selection with text to be inserted. |
| 1155 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1156 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1157 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1158 | |
| 1159 | // Select entire contents of user-editable combobox text field to check that |
| 1160 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1161 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1162 | CheckSelection(L"ABCHelloIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1165 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1166 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1167 | TypeTextIntoTextField(10, EditableFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1168 | |
| 1169 | // Select right portion of string in user-editable combobox. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1170 | SelectTextWithKeyboard(5, FWL_VKEY_Left, EditableFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1171 | CheckSelection(L"FGHIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1172 | |
| 1173 | // Test replacing text selection with text to be inserted. |
| 1174 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1175 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1176 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1177 | |
| 1178 | // Select entire contents of user-editable combobox text field to check that |
| 1179 | // insertion worked as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1180 | SelectAllEditableFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1181 | CheckSelection(L"ABCDEHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1184 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1185 | InsertTextInEmptyCharLimitTextFieldOverflow) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1186 | // Click on the textfield. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1187 | ClickOnFormFieldAtPoint(CharLimitFormEnd()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1188 | |
| 1189 | // Delete pre-filled contents of text field with char limit. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1190 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1191 | CheckSelection(L"Elephant"); |
| 1192 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1193 | |
| 1194 | // Test inserting text into now empty text field so text to be inserted |
| 1195 | // exceeds the char limit and is cut off. |
| 1196 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1197 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1198 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1199 | |
| 1200 | // Select entire contents of text field to check that insertion worked |
| 1201 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1202 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1203 | CheckSelection(L"Hippopotam"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1206 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1207 | InsertTextInEmptyCharLimitTextFieldFit) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1208 | // Click on the textfield. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1209 | ClickOnFormFieldAtPoint(CharLimitFormEnd()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1210 | |
| 1211 | // Delete pre-filled contents of text field with char limit. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1212 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1213 | CheckSelection(L"Elephant"); |
| 1214 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1215 | |
| 1216 | // Test inserting text into now empty text field so text to be inserted |
| 1217 | // exceeds the char limit and is cut off. |
| 1218 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1219 | GetFPDFWideString(L"Zebra"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1220 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1221 | |
| 1222 | // Select entire contents of text field to check that insertion worked |
| 1223 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1224 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1225 | CheckSelection(L"Zebra"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1228 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1229 | InsertTextInPopulatedCharLimitTextFieldLeft) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1230 | // Click on the leftmost part of the text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1231 | ClickOnFormFieldAtPoint(CharLimitFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1232 | |
| 1233 | // Test inserting text in front of existing text in text field. |
| 1234 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1235 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1236 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1237 | |
| 1238 | // Select entire contents of text field to check that insertion worked |
| 1239 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1240 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1241 | CheckSelection(L"HiElephant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1244 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1245 | InsertTextInPopulatedCharLimitTextFieldMiddle) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1246 | TypeTextIntoTextField(8, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1247 | |
| 1248 | // Click on the middle of the text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1249 | ClickOnFormFieldAtPoint(CharLimitFormAtX(134.0)); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1250 | |
| 1251 | // Test inserting text in the middle of existing text in text field. |
| 1252 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1253 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1254 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1255 | |
| 1256 | // Select entire contents of text field to check that insertion worked |
| 1257 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1258 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1259 | CheckSelection(L"ElephHiant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1262 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1263 | InsertTextInPopulatedCharLimitTextFieldRight) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1264 | TypeTextIntoTextField(8, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1265 | |
| 1266 | // Click on the rightmost part of the text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1267 | ClickOnFormFieldAtPoint(CharLimitFormAtX(166.0)); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1268 | |
| 1269 | // Test inserting text behind existing text in text field. |
| 1270 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1271 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1272 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1273 | |
| 1274 | // Select entire contents of text field to check that insertion worked |
| 1275 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1276 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1277 | CheckSelection(L"ElephantHi"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1280 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1281 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1282 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1283 | |
| 1284 | // Select entire string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1285 | SelectTextWithKeyboard(12, FWL_VKEY_Left, CharLimitFormEnd()); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1286 | CheckSelection(L"Elephant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1287 | |
| 1288 | // Test replacing text selection with text to be inserted. |
| 1289 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1290 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1291 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1292 | |
| 1293 | // Select entire contents of text field to check that insertion worked |
| 1294 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1295 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1296 | CheckSelection(L"Hippopotam"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1299 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1300 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1301 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1302 | |
| 1303 | // Select left portion of string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1304 | SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(122.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1305 | CheckSelection(L"Elep"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1306 | |
| 1307 | // Test replacing text selection with text to be inserted. |
| 1308 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1309 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1310 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1311 | |
| 1312 | // Select entire contents of text field to check that insertion worked |
| 1313 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1314 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1315 | CheckSelection(L"Hippophant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1318 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1319 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1320 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1321 | |
| 1322 | // Select middle portion of string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1323 | SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(136.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1324 | CheckSelection(L"epha"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1325 | |
| 1326 | // Test replacing text selection with text to be inserted. |
| 1327 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1328 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1329 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1330 | |
| 1331 | // Select entire contents of text field to check that insertion worked |
| 1332 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1333 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1334 | CheckSelection(L"ElHippopnt"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1337 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1338 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) { |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1339 | TypeTextIntoTextField(12, RegularFormBegin()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1340 | |
| 1341 | // Select right portion of string in text field. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1342 | SelectTextWithKeyboard(4, FWL_VKEY_Left, CharLimitFormAtX(152.0)); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1343 | CheckSelection(L"hant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1344 | |
| 1345 | // Test replacing text selection with text to be inserted. |
| 1346 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1347 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1348 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1349 | |
| 1350 | // Select entire contents of text field to check that insertion worked |
| 1351 | // as expected. |
Lei Zhang | 31f7e4b | 2017-08-26 01:34:42 -0700 | [diff] [blame] | 1352 | SelectAllCharLimitFormTextWithMouse(); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame] | 1353 | CheckSelection(L"ElepHippop"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1354 | } |