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