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