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. |
| 659 | FORM_DeleteSelectedText(form_handle(), page); |
| 660 | SelectTextWithKeyboard(page, 12, FWL_VKEY_Left, 191.0, 115.5); |
| 661 | CheckSelection(page, CFX_WideString()); |
| 662 | |
| 663 | UnloadPage(page); |
| 664 | } |
| 665 | |
| 666 | TEST_F(FPDFFormFillEmbeddertest, DeleteTextFieldSelectionMiddle) { |
| 667 | // Open file with form text field. |
| 668 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 669 | FPDF_PAGE page = LoadPage(0); |
| 670 | ASSERT_TRUE(page); |
| 671 | |
| 672 | // Select middle section of text. |
| 673 | TypeTextIntoTextField(page, 12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 674 | SelectTextWithMouse(page, 170.0, 125.0, 115.5); |
| 675 | CheckSelection(page, CFX_WideString(L"DEFGHI")); |
| 676 | |
| 677 | // Test deleting current text selection. Select what remains after deletion to |
| 678 | // check that remaining text is as expected. |
| 679 | FORM_DeleteSelectedText(form_handle(), page); |
| 680 | SelectTextWithKeyboard(page, 12, FWL_VKEY_Left, 191.0, 115.5); |
| 681 | CheckSelection(page, CFX_WideString(L"ABCJKL")); |
| 682 | |
| 683 | UnloadPage(page); |
| 684 | } |
| 685 | |
| 686 | TEST_F(FPDFFormFillEmbeddertest, DeleteTextFieldSelectionLeft) { |
| 687 | // Open file with form text field. |
| 688 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 689 | FPDF_PAGE page = LoadPage(0); |
| 690 | ASSERT_TRUE(page); |
| 691 | |
| 692 | // Select first few characters of text. |
| 693 | TypeTextIntoTextField(page, 12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 694 | SelectTextWithMouse(page, 102.0, 132.0, 115.5); |
| 695 | CheckSelection(page, CFX_WideString(L"ABCD")); |
| 696 | |
| 697 | // Test deleting current text selection. Select what remains after deletion to |
| 698 | // check that remaining text is as expected. |
| 699 | FORM_DeleteSelectedText(form_handle(), page); |
| 700 | SelectTextWithKeyboard(page, 12, FWL_VKEY_Left, 191.0, 115.5); |
| 701 | CheckSelection(page, CFX_WideString(L"EFGHIJKL")); |
| 702 | |
| 703 | UnloadPage(page); |
| 704 | } |
| 705 | |
| 706 | TEST_F(FPDFFormFillEmbeddertest, DeleteTextFieldSelectionRight) { |
| 707 | // Open file with form text field. |
| 708 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 709 | FPDF_PAGE page = LoadPage(0); |
| 710 | ASSERT_TRUE(page); |
| 711 | |
| 712 | // Select last few characters of text. |
| 713 | TypeTextIntoTextField(page, 12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 714 | SelectTextWithMouse(page, 191.0, 165.0, 115.5); |
| 715 | CheckSelection(page, CFX_WideString(L"IJKL")); |
| 716 | |
| 717 | // Test deleting current text selection. Select what remains after deletion to |
| 718 | // check that remaining text is as expected. |
| 719 | FORM_DeleteSelectedText(form_handle(), page); |
| 720 | SelectTextWithKeyboard(page, 12, FWL_VKEY_Left, 191.0, 115.5); |
| 721 | CheckSelection(page, CFX_WideString(L"ABCDEFGH")); |
| 722 | |
| 723 | UnloadPage(page); |
| 724 | } |
| 725 | |
| 726 | TEST_F(FPDFFormFillEmbeddertest, DeleteEmptyTextFieldSelection) { |
| 727 | // Open file with form text field. |
| 728 | EXPECT_TRUE(OpenDocument("text_form.pdf")); |
| 729 | FPDF_PAGE page = LoadPage(0); |
| 730 | ASSERT_TRUE(page); |
| 731 | |
| 732 | // Do not select text. |
| 733 | TypeTextIntoTextField(page, 12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 734 | CheckSelection(page, CFX_WideString()); |
| 735 | |
| 736 | // Test that attempt to delete empty text selection has no effect. |
| 737 | FORM_DeleteSelectedText(form_handle(), page); |
| 738 | SelectTextWithKeyboard(page, 12, FWL_VKEY_Left, 191.0, 115.5); |
| 739 | CheckSelection(page, CFX_WideString(L"ABCDEFGHIJKL")); |
| 740 | |
| 741 | UnloadPage(page); |
| 742 | } |
| 743 | |
| 744 | TEST_F(FPDFFormFillEmbeddertest, DeleteEditableComboBoxEntireSelection) { |
| 745 | // Open file with form comboboxes. |
| 746 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 747 | FPDF_PAGE page = LoadPage(0); |
| 748 | ASSERT_TRUE(page); |
| 749 | |
| 750 | // Select entire contents of user-editable combobox text field. |
| 751 | TypeTextIntoTextField(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 752 | SelectTextWithMouse(page, 178.0, 102.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 753 | CheckSelection(page, CFX_WideString(L"ABCDEFGHIJ")); |
| 754 | |
| 755 | // Test deleting current text selection. Select what remains after deletion to |
| 756 | // check that remaining text is as expected. |
| 757 | FORM_DeleteSelectedText(form_handle(), page); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 758 | SelectTextWithMouse(page, 178.0, 102.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 759 | CheckSelection(page, CFX_WideString()); |
| 760 | |
| 761 | UnloadPage(page); |
| 762 | } |
| 763 | |
| 764 | TEST_F(FPDFFormFillEmbeddertest, DeleteEditableComboBoxSelectionMiddle) { |
| 765 | // Open file with form comboboxes. |
| 766 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 767 | FPDF_PAGE page = LoadPage(0); |
| 768 | ASSERT_TRUE(page); |
| 769 | |
| 770 | // Select middle section of text. |
| 771 | TypeTextIntoTextField(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 772 | SelectTextWithMouse(page, 168.0, 127.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 773 | CheckSelection(page, CFX_WideString(L"DEFGH")); |
| 774 | |
| 775 | // Test deleting current text selection. Select what remains after deletion to |
| 776 | // check that remaining text is as expected. |
| 777 | FORM_DeleteSelectedText(form_handle(), page); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 778 | SelectTextWithMouse(page, 178.0, 102.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 779 | CheckSelection(page, CFX_WideString(L"ABCIJ")); |
| 780 | |
| 781 | UnloadPage(page); |
| 782 | } |
| 783 | |
| 784 | TEST_F(FPDFFormFillEmbeddertest, DeleteEditableComboBoxSelectionLeft) { |
| 785 | // Open file with form comboboxes. |
| 786 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 787 | FPDF_PAGE page = LoadPage(0); |
| 788 | ASSERT_TRUE(page); |
| 789 | |
| 790 | // Select first few characters of text. |
| 791 | TypeTextIntoTextField(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 792 | SelectTextWithMouse(page, 102.0, 132.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 793 | CheckSelection(page, CFX_WideString(L"ABCD")); |
| 794 | |
| 795 | // Test deleting current text selection. Select what remains after deletion to |
| 796 | // check that remaining text is as expected. |
| 797 | FORM_DeleteSelectedText(form_handle(), page); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 798 | SelectTextWithMouse(page, 178.0, 102.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 799 | CheckSelection(page, CFX_WideString(L"EFGHIJ")); |
| 800 | |
| 801 | UnloadPage(page); |
| 802 | } |
| 803 | |
| 804 | TEST_F(FPDFFormFillEmbeddertest, DeleteEditableComboBoxSelectionRight) { |
| 805 | // Open file with form comboboxes. |
| 806 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 807 | FPDF_PAGE page = LoadPage(0); |
| 808 | ASSERT_TRUE(page); |
| 809 | |
| 810 | // Select last few characters of text. |
| 811 | TypeTextIntoTextField(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 812 | SelectTextWithMouse(page, 178.0, 152.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 813 | CheckSelection(page, CFX_WideString(L"GHIJ")); |
| 814 | |
| 815 | // Test deleting current text selection. Select what remains after deletion to |
| 816 | // check that remaining text is as expected. |
| 817 | FORM_DeleteSelectedText(form_handle(), page); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 818 | SelectTextWithMouse(page, 178.0, 102.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 819 | CheckSelection(page, CFX_WideString(L"ABCDEF")); |
| 820 | |
| 821 | UnloadPage(page); |
| 822 | } |
| 823 | |
| 824 | TEST_F(FPDFFormFillEmbeddertest, DeleteEmptyEditableComboBoxSelection) { |
| 825 | // Open file with form comboboxes. |
| 826 | EXPECT_TRUE(OpenDocument("combobox_form.pdf")); |
| 827 | FPDF_PAGE page = LoadPage(0); |
| 828 | ASSERT_TRUE(page); |
| 829 | |
| 830 | // Do not select text. |
| 831 | TypeTextIntoTextField(page, 10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 832 | CheckSelection(page, CFX_WideString()); |
| 833 | |
| 834 | // Test that attempt to delete empty text selection has no effect. |
| 835 | FORM_DeleteSelectedText(form_handle(), page); |
Diana Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame^] | 836 | SelectTextWithMouse(page, 178.0, 102.0, 62.0); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 837 | CheckSelection(page, CFX_WideString(L"ABCDEFGHIJ")); |
| 838 | |
| 839 | UnloadPage(page); |
| 840 | } |