blob: 9256d3fa769c6c7f59e2ecccb7bb8ea6bfcd575c [file] [log] [blame]
Tom Sepeza310e002015-02-27 13:03:07 -08001// 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 Pena742977f2017-04-13 15:28:20 -04005#include <memory>
6#include <string>
Diana Gagedce2d722017-06-20 11:17:11 -07007#include <vector>
Nicolas Pena742977f2017-04-13 15:28:20 -04008
Diana Gagedce2d722017-06-20 11:17:11 -07009#include "core/fxcrt/fx_string.h"
Nicolas Pena742977f2017-04-13 15:28:20 -040010#include "core/fxcrt/fx_system.h"
11#include "public/cpp/fpdf_deleters.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080012#include "public/fpdf_formfill.h"
Diana Gagedce2d722017-06-20 11:17:11 -070013#include "public/fpdf_fwlevent.h"
Wei Li091f7a02015-11-09 12:09:55 -080014#include "testing/embedder_test.h"
15#include "testing/embedder_test_mock_delegate.h"
16#include "testing/embedder_test_timer_handling_delegate.h"
Tom Sepeza310e002015-02-27 13:03:07 -080017#include "testing/gmock/include/gmock/gmock.h"
18#include "testing/gtest/include/gtest/gtest.h"
19
20using testing::_;
Tom Sepeza310e002015-02-27 13:03:07 -080021
Lei Zhang839692f2017-08-25 23:23:57 -070022using FPDFFormFillEmbeddertest = EmbedderTest;
23
24// A base class for many related tests that involve clicking and typing into
25// form fields.
26class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest {
Diana Gagedce2d722017-06-20 11:17:11 -070027 protected:
Lei Zhang839692f2017-08-25 23:23:57 -070028 FPDFFormFillInteractiveEmbeddertest() = default;
29 ~FPDFFormFillInteractiveEmbeddertest() override = default;
30
31 void SetUp() override {
32 FPDFFormFillEmbeddertest::SetUp();
33 ASSERT_TRUE(OpenDocument(GetDocumentName()));
34 page_ = LoadPage(0);
35 ASSERT_TRUE(page_);
36 FormSanityChecks();
Diana Gagef8c02762017-07-26 14:20:12 -070037 }
38
Lei Zhang839692f2017-08-25 23:23:57 -070039 void TearDown() override {
40 UnloadPage(page_);
41 FPDFFormFillEmbeddertest::TearDown();
42 }
43
44 // Returns the name of the PDF to use.
45 virtual const char* GetDocumentName() const = 0;
46
47 // Optionally do some sanity check on the document after loading.
48 virtual void FormSanityChecks() {}
49
50 FPDF_PAGE page() { return page_; }
51
52 void ClickOnFormFieldAtPoint(double x, double y) {
53 // Click on the text field or combobox as specified by coordinates.
54 FORM_OnMouseMove(form_handle(), page_, 0, x, y);
55 FORM_OnLButtonDown(form_handle(), page_, 0, x, y);
56 FORM_OnLButtonUp(form_handle(), page_, 0, x, y);
57 }
58
59 void TypeTextIntoTextField(int num_chars, int form_type, double x, double y) {
Diana Gagecb50b5f2017-06-29 09:54:19 -070060 ASSERT(form_type == FPDF_FORMFIELD_COMBOBOX ||
61 form_type == FPDF_FORMFIELD_TEXTFIELD);
62 EXPECT_EQ(form_type,
Lei Zhang839692f2017-08-25 23:23:57 -070063 FPDFPage_HasFormFieldAtPoint(form_handle(), page_, x, y));
64 ClickOnFormFieldAtPoint(x, y);
Diana Gagedce2d722017-06-20 11:17:11 -070065
66 // Type text starting with 'A' to as many chars as specified by |num_chars|.
67 for (int i = 0; i < num_chars; ++i) {
Lei Zhang839692f2017-08-25 23:23:57 -070068 FORM_OnChar(form_handle(), page_, 'A' + i, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070069 }
70 }
71
Diana Gagecb50b5f2017-06-29 09:54:19 -070072 // Navigates to text field using the mouse and then selects text via the
Diana Gagedce2d722017-06-20 11:17:11 -070073 // shift and specfied left or right arrow key.
Lei Zhang839692f2017-08-25 23:23:57 -070074 void SelectTextWithKeyboard(int num_chars,
Diana Gagedce2d722017-06-20 11:17:11 -070075 int arrow_key,
76 double x,
77 double y) {
78 // Navigate to starting position for selection.
Lei Zhang839692f2017-08-25 23:23:57 -070079 ClickOnFormFieldAtPoint(x, y);
Diana Gagedce2d722017-06-20 11:17:11 -070080
81 // Hold down shift (and don't release until entire text is selected).
Lei Zhang839692f2017-08-25 23:23:57 -070082 FORM_OnKeyDown(form_handle(), page_, FWL_VKEY_Shift, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070083
84 // Select text char by char via left or right arrow key.
85 for (int i = 0; i < num_chars; ++i) {
Lei Zhang839692f2017-08-25 23:23:57 -070086 FORM_OnKeyDown(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
87 FORM_OnKeyUp(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey);
Diana Gagedce2d722017-06-20 11:17:11 -070088 }
Lei Zhang839692f2017-08-25 23:23:57 -070089 FORM_OnKeyUp(form_handle(), page_, FWL_VKEY_Shift, 0);
Diana Gagedce2d722017-06-20 11:17:11 -070090 }
91
Diana Gagecb50b5f2017-06-29 09:54:19 -070092 // Uses the mouse to navigate to text field and select text.
Lei Zhang839692f2017-08-25 23:23:57 -070093 void SelectTextWithMouse(double start_x, double end_x, double y) {
Diana Gagedce2d722017-06-20 11:17:11 -070094 // Navigate to starting position and click mouse.
Lei Zhang839692f2017-08-25 23:23:57 -070095 FORM_OnMouseMove(form_handle(), page_, 0, start_x, y);
96 FORM_OnLButtonDown(form_handle(), page_, 0, start_x, y);
Diana Gagedce2d722017-06-20 11:17:11 -070097
98 // Hold down mouse until reach end of desired selection.
Lei Zhang839692f2017-08-25 23:23:57 -070099 FORM_OnMouseMove(form_handle(), page_, 0, end_x, y);
100 FORM_OnLButtonUp(form_handle(), page_, 0, end_x, y);
Diana Gagedce2d722017-06-20 11:17:11 -0700101 }
102
Lei Zhang839692f2017-08-25 23:23:57 -0700103 void CheckSelection(const CFX_WideStringC& expected_string) {
Diana Gagedce2d722017-06-20 11:17:11 -0700104 // Calculate expected length for selected text.
105 int num_chars = expected_string.GetLength();
106
107 // Check actual selection against expected selection.
108 const unsigned long expected_length =
109 sizeof(unsigned short) * (num_chars + 1);
110 unsigned long sel_text_len =
Lei Zhang839692f2017-08-25 23:23:57 -0700111 FORM_GetSelectedText(form_handle(), page_, nullptr, 0);
Diana Gagedce2d722017-06-20 11:17:11 -0700112 ASSERT_EQ(expected_length, sel_text_len);
113
114 std::vector<unsigned short> buf(sel_text_len);
Lei Zhang839692f2017-08-25 23:23:57 -0700115 EXPECT_EQ(expected_length, FORM_GetSelectedText(form_handle(), page_,
Diana Gagedce2d722017-06-20 11:17:11 -0700116 buf.data(), sel_text_len));
117
118 EXPECT_EQ(expected_string,
119 CFX_WideString::FromUTF16LE(buf.data(), num_chars));
120 }
Diana Gagecb50b5f2017-06-29 09:54:19 -0700121
Lei Zhang839692f2017-08-25 23:23:57 -0700122 private:
123 FPDF_PAGE page_ = nullptr;
124};
125
126class FPDFFormFillTextFormEmbeddertest
127 : public FPDFFormFillInteractiveEmbeddertest {
128 protected:
129 FPDFFormFillTextFormEmbeddertest() = default;
130 ~FPDFFormFillTextFormEmbeddertest() override = default;
131
132 const char* GetDocumentName() const override {
133 // PDF with several form text fields:
134 // - "Text Box" - No special attributes.
135 // - "ReadOnly" - Ff: 1.
136 // - "CharLimit" - MaxLen: 10, V: Elephant.
137 return "text_form_multiple.pdf";
138 }
139};
140
141class FPDFFormFillComboBoxFormEmbeddertest
142 : public FPDFFormFillInteractiveEmbeddertest {
143 protected:
144 FPDFFormFillComboBoxFormEmbeddertest() = default;
145 ~FPDFFormFillComboBoxFormEmbeddertest() override = default;
146
147 const char* GetDocumentName() const override {
148 // PDF with form comboboxes.
149 return "combobox_form.pdf";
150 }
151
152 void FormSanityChecks() override {
153 EXPECT_EQ(
154 FPDF_FORMFIELD_COMBOBOX,
155 FPDFPage_HasFormFieldAtPoint(form_handle(), page(), 102.0, 113.0));
156 }
157
Diana Gagecb50b5f2017-06-29 09:54:19 -0700158 // Selects one of the pre-selected values from a combobox with three options.
159 // Options are specified by |item_index|, which is 0-based.
Lei Zhang839692f2017-08-25 23:23:57 -0700160 void SelectOption(int32_t item_index, double x, double y) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700161 // Only relevant for comboboxes with three choices and the same dimensions
162 // as those in combobox_form.pdf.
163 ASSERT(item_index >= 0);
164 ASSERT(item_index < 3);
165
166 // Navigate to button for drop down and click mouse to reveal options.
Lei Zhang839692f2017-08-25 23:23:57 -0700167 ClickOnFormFieldAtPoint(x, y);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700168
169 // Y coordinate of dropdown option to be selected.
170 constexpr double kChoiceHeight = 15;
171 double option_y = y - kChoiceHeight * (item_index + 1);
172
173 // Navigate to option and click mouse to select it.
Lei Zhang839692f2017-08-25 23:23:57 -0700174 ClickOnFormFieldAtPoint(x, option_y);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700175 }
Diana Gagedce2d722017-06-20 11:17:11 -0700176};
Tom Sepeza310e002015-02-27 13:03:07 -0800177
178TEST_F(FPDFFormFillEmbeddertest, FirstTest) {
179 EmbedderTestMockDelegate mock;
180 EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0);
181 EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700182 EXPECT_CALL(mock, SetTimer(_, _)).Times(0);
183 EXPECT_CALL(mock, KillTimer(_)).Times(0);
Tom Sepeza310e002015-02-27 13:03:07 -0800184 SetDelegate(&mock);
185
Wei Li091f7a02015-11-09 12:09:55 -0800186 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepeza310e002015-02-27 13:03:07 -0800187 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700188 EXPECT_TRUE(page);
Lei Zhangd27acae2015-05-15 15:36:02 -0700189 UnloadPage(page);
Tom Sepeza310e002015-02-27 13:03:07 -0800190}
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700191
192TEST_F(FPDFFormFillEmbeddertest, BUG_487928) {
193 EmbedderTestTimerHandlingDelegate delegate;
194 SetDelegate(&delegate);
195
Wei Li091f7a02015-11-09 12:09:55 -0800196 EXPECT_TRUE(OpenDocument("bug_487928.pdf"));
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700197 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700198 EXPECT_TRUE(page);
Tom Sepez6efc0ad2015-06-02 17:11:18 -0700199 DoOpenActions();
200 delegate.AdvanceTime(5000);
201 UnloadPage(page);
202}
Tom Sepez0b133982015-07-28 11:23:22 -0700203
Tom Sepez396e8722015-09-09 10:16:08 -0700204TEST_F(FPDFFormFillEmbeddertest, BUG_507316) {
205 EmbedderTestTimerHandlingDelegate delegate;
206 SetDelegate(&delegate);
207
Wei Li091f7a02015-11-09 12:09:55 -0800208 EXPECT_TRUE(OpenDocument("bug_507316.pdf"));
weili0dadcc62016-08-23 21:10:57 -0700209 FPDF_PAGE page = LoadPage(2);
tsepez8e120292016-08-03 14:03:35 -0700210 EXPECT_TRUE(page);
Tom Sepez396e8722015-09-09 10:16:08 -0700211 DoOpenActions();
212 delegate.AdvanceTime(4000);
213 UnloadPage(page);
214}
215
Tom Sepez0b133982015-07-28 11:23:22 -0700216TEST_F(FPDFFormFillEmbeddertest, BUG_514690) {
Wei Li091f7a02015-11-09 12:09:55 -0800217 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0b133982015-07-28 11:23:22 -0700218 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700219 EXPECT_TRUE(page);
Tom Sepez0b133982015-07-28 11:23:22 -0700220
221 // Test that FORM_OnMouseMove() etc. permit null HANDLES and PAGES.
222 FORM_OnMouseMove(nullptr, page, 0, 10.0, 10.0);
223 FORM_OnMouseMove(form_handle(), nullptr, 0, 10.0, 10.0);
224
225 UnloadPage(page);
226}
Lei Zhang79e893a2015-11-04 16:02:47 -0800227
Tom Sepez4d071792016-02-04 16:53:26 -0800228#ifdef PDF_ENABLE_V8
Lei Zhang79e893a2015-11-04 16:02:47 -0800229TEST_F(FPDFFormFillEmbeddertest, BUG_551248) {
tsepez8e120292016-08-03 14:03:35 -0700230 // Test that timers fire once and intervals fire repeatedly.
Lei Zhang79e893a2015-11-04 16:02:47 -0800231 EmbedderTestTimerHandlingDelegate delegate;
232 SetDelegate(&delegate);
233
Wei Li091f7a02015-11-09 12:09:55 -0800234 EXPECT_TRUE(OpenDocument("bug_551248.pdf"));
Lei Zhang79e893a2015-11-04 16:02:47 -0800235 FPDF_PAGE page = LoadPage(0);
tsepez8e120292016-08-03 14:03:35 -0700236 EXPECT_TRUE(page);
237 DoOpenActions();
238
239 const auto& alerts = delegate.GetAlerts();
240 EXPECT_EQ(0U, alerts.size());
241
242 delegate.AdvanceTime(1000);
243 EXPECT_EQ(0U, alerts.size()); // nothing fired.
244 delegate.AdvanceTime(1000);
245 EXPECT_EQ(1U, alerts.size()); // interval fired.
246 delegate.AdvanceTime(1000);
247 EXPECT_EQ(2U, alerts.size()); // timer fired.
248 delegate.AdvanceTime(1000);
249 EXPECT_EQ(3U, alerts.size()); // interval fired again.
250 delegate.AdvanceTime(1000);
251 EXPECT_EQ(3U, alerts.size()); // nothing fired.
252 delegate.AdvanceTime(1000);
253 EXPECT_EQ(4U, alerts.size()); // interval fired again.
254 delegate.AdvanceTime(1000);
255 EXPECT_EQ(4U, alerts.size()); // nothing fired.
256 UnloadPage(page);
257
258 ASSERT_EQ(4U, alerts.size()); // nothing else fired.
259
260 EXPECT_STREQ(L"interval fired", alerts[0].message.c_str());
261 EXPECT_STREQ(L"Alert", alerts[0].title.c_str());
262 EXPECT_EQ(0, alerts[0].type);
263 EXPECT_EQ(0, alerts[0].icon);
264
265 EXPECT_STREQ(L"timer fired", alerts[1].message.c_str());
266 EXPECT_STREQ(L"Alert", alerts[1].title.c_str());
267 EXPECT_EQ(0, alerts[1].type);
268 EXPECT_EQ(0, alerts[1].icon);
269
270 EXPECT_STREQ(L"interval fired", alerts[2].message.c_str());
271 EXPECT_STREQ(L"Alert", alerts[2].title.c_str());
272 EXPECT_EQ(0, alerts[2].type);
273 EXPECT_EQ(0, alerts[2].icon);
274
275 EXPECT_STREQ(L"interval fired", alerts[3].message.c_str());
276 EXPECT_STREQ(L"Alert", alerts[3].title.c_str());
277 EXPECT_EQ(0, alerts[3].type);
278 EXPECT_EQ(0, alerts[3].icon);
279}
280
281TEST_F(FPDFFormFillEmbeddertest, BUG_620428) {
282 // Test that timers and intervals are cancelable.
283 EmbedderTestTimerHandlingDelegate delegate;
284 SetDelegate(&delegate);
285
286 EXPECT_TRUE(OpenDocument("bug_620428.pdf"));
287 FPDF_PAGE page = LoadPage(0);
288 EXPECT_TRUE(page);
Lei Zhang79e893a2015-11-04 16:02:47 -0800289 DoOpenActions();
290 delegate.AdvanceTime(5000);
291 UnloadPage(page);
292
293 const auto& alerts = delegate.GetAlerts();
tsepez0fa54b82016-08-04 12:07:28 -0700294 ASSERT_EQ(1U, alerts.size());
295 EXPECT_STREQ(L"done", alerts[0].message.c_str());
Lei Zhang79e893a2015-11-04 16:02:47 -0800296}
tsepez8e120292016-08-03 14:03:35 -0700297
tsepez32e693f2016-08-04 12:47:42 -0700298TEST_F(FPDFFormFillEmbeddertest, BUG_634394) {
299 // Cancel timer inside timer callback.
300 EmbedderTestTimerHandlingDelegate delegate;
301 SetDelegate(&delegate);
302
303 EXPECT_TRUE(OpenDocument("bug_634394.pdf"));
304 FPDF_PAGE page = LoadPage(0);
305 EXPECT_TRUE(page);
306 DoOpenActions();
307
308 // Timers fire at most once per AdvanceTime(), allow intervals
309 // to fire several times if possible.
310 delegate.AdvanceTime(1000);
311 delegate.AdvanceTime(1000);
312 delegate.AdvanceTime(1000);
313 delegate.AdvanceTime(1000);
314 delegate.AdvanceTime(1000);
315 UnloadPage(page);
316
317 const auto& alerts = delegate.GetAlerts();
318 EXPECT_EQ(2U, alerts.size());
319}
320
tsepez8ca63de2016-08-05 17:12:27 -0700321TEST_F(FPDFFormFillEmbeddertest, BUG_634716) {
322 EmbedderTestTimerHandlingDelegate delegate;
323 SetDelegate(&delegate);
324
325 EXPECT_TRUE(OpenDocument("bug_634716.pdf"));
326 FPDF_PAGE page = LoadPage(0);
327 EXPECT_TRUE(page);
328 DoOpenActions();
329
330 // Timers fire at most once per AdvanceTime(), allow intervals
331 // to fire several times if possible.
332 delegate.AdvanceTime(1000);
333 delegate.AdvanceTime(1000);
334 delegate.AdvanceTime(1000);
335 delegate.AdvanceTime(1000);
336 delegate.AdvanceTime(1000);
337 UnloadPage(page);
338
339 const auto& alerts = delegate.GetAlerts();
340 EXPECT_EQ(2U, alerts.size());
341}
342
tsepez6cf5eca2017-01-12 11:21:12 -0800343TEST_F(FPDFFormFillEmbeddertest, BUG_679649) {
344 EmbedderTestTimerHandlingDelegate delegate;
345 SetDelegate(&delegate);
346
347 EXPECT_TRUE(OpenDocument("bug_679649.pdf"));
348 FPDF_PAGE page = LoadPage(0);
349 EXPECT_TRUE(page);
350
351 delegate.SetFailNextTimer();
352 DoOpenActions();
353 delegate.AdvanceTime(2000);
354 UnloadPage(page);
355
356 const auto& alerts = delegate.GetAlerts();
357 EXPECT_EQ(0u, alerts.size());
358}
359
Tom Sepezfb7021c2017-05-31 10:29:25 -0700360TEST_F(FPDFFormFillEmbeddertest, BUG_707673) {
361 EmbedderTestTimerHandlingDelegate delegate;
362 SetDelegate(&delegate);
363
364 EXPECT_TRUE(OpenDocument("bug_707673.pdf"));
365 FPDF_PAGE page = LoadPage(0);
366 EXPECT_TRUE(page);
367
368 DoOpenActions();
369 FORM_OnLButtonDown(form_handle(), page, 0, 140, 590);
370 FORM_OnLButtonUp(form_handle(), page, 0, 140, 590);
371 delegate.AdvanceTime(1000);
372 UnloadPage(page);
373
374 const auto& alerts = delegate.GetAlerts();
375 EXPECT_EQ(0u, alerts.size());
376}
377
Tom Sepez4d071792016-02-04 16:53:26 -0800378#endif // PDF_ENABLE_V8
Nicolas Pena742977f2017-04-13 15:28:20 -0400379
380TEST_F(FPDFFormFillEmbeddertest, FormText) {
381#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
382 const char md5_1[] = "5f11dbe575fe197a37c3fb422559f8ff";
383 const char md5_2[] = "35b1a4b679eafc749a0b6fda750c0e8d";
384 const char md5_3[] = "65c64a7c355388f719a752aa1e23f6fe";
385#else
Nicolas Pena00c3cfd2017-07-10 17:29:54 -0400386 const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a";
387 const char md5_2[] = "4526b09382e144d5506ad92149399de6";
388 const char md5_3[] = "80356067d860088864cf50ff85d8459e";
Nicolas Pena742977f2017-04-13 15:28:20 -0400389#endif
390 {
391 EXPECT_TRUE(OpenDocument("text_form.pdf"));
392 FPDF_PAGE page = LoadPage(0);
393 ASSERT_TRUE(page);
394 std::unique_ptr<void, FPDFBitmapDeleter> bitmap1(RenderPage(page));
395 CompareBitmap(bitmap1.get(), 300, 300, md5_1);
396
397 // Click on the textfield
398 EXPECT_EQ(FPDF_FORMFIELD_TEXTFIELD,
399 FPDFPage_HasFormFieldAtPoint(form_handle(), page, 120.0, 120.0));
400 FORM_OnMouseMove(form_handle(), page, 0, 120.0, 120.0);
401 FORM_OnLButtonDown(form_handle(), page, 0, 120.0, 120.0);
402 FORM_OnLButtonUp(form_handle(), page, 0, 120.0, 120.0);
403
404 // Write "ABC"
405 FORM_OnChar(form_handle(), page, 65, 0);
406 FORM_OnChar(form_handle(), page, 66, 0);
407 FORM_OnChar(form_handle(), page, 67, 0);
408 std::unique_ptr<void, FPDFBitmapDeleter> bitmap2(RenderPage(page));
409 CompareBitmap(bitmap2.get(), 300, 300, md5_2);
410
411 // Take out focus by clicking out of the textfield
412 FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
413 FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
414 FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
415 std::unique_ptr<void, FPDFBitmapDeleter> bitmap3(RenderPage(page));
416 CompareBitmap(bitmap3.get(), 300, 300, md5_3);
417
418 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
419
Nicolas Pena3ff54002017-07-05 11:55:35 -0400420 // Close page
Nicolas Pena742977f2017-04-13 15:28:20 -0400421 UnloadPage(page);
Nicolas Pena742977f2017-04-13 15:28:20 -0400422 }
423 // Check saved document
Nicolas Pena3ff54002017-07-05 11:55:35 -0400424 TestAndCloseSaved(300, 300, md5_3);
Nicolas Pena742977f2017-04-13 15:28:20 -0400425}
Diana Gagedce2d722017-06-20 11:17:11 -0700426
Lei Zhang839692f2017-08-25 23:23:57 -0700427TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) {
Diana Gagedce2d722017-06-20 11:17:11 -0700428 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700429 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700430
431 // Test basic selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700432 TypeTextIntoTextField(3, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
433 SelectTextWithKeyboard(3, FWL_VKEY_Left, 123.0, 115.5);
434 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700435}
436
Lei Zhang839692f2017-08-25 23:23:57 -0700437TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicMouse) {
Diana Gagedce2d722017-06-20 11:17:11 -0700438 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700439 CheckSelection(L"");
Diana Gagedce2d722017-06-20 11:17:11 -0700440
441 // Test basic selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700442 TypeTextIntoTextField(3, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
443 SelectTextWithMouse(125.0, 102.0, 115.5);
444 CheckSelection(L"ABC");
Diana Gagedce2d722017-06-20 11:17:11 -0700445}
446
Lei Zhang839692f2017-08-25 23:23:57 -0700447TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsKeyBoard) {
448 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gagedce2d722017-06-20 11:17:11 -0700449
450 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700451 SelectTextWithKeyboard(1, FWL_VKEY_Right, 102.0, 115.5);
452 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700453
454 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700455 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
456 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700457
458 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700459 SelectTextWithKeyboard(6, FWL_VKEY_Left, 170.0, 115.5);
460 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700461
462 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700463 SelectTextWithKeyboard(6, FWL_VKEY_Right, 125.0, 115.5);
464 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700465
466 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700467 SelectTextWithKeyboard(1, FWL_VKEY_Left, 191.0, 115.5);
468 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700469}
470
Lei Zhang839692f2017-08-25 23:23:57 -0700471TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsMouse) {
472 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gagedce2d722017-06-20 11:17:11 -0700473
474 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700475 SelectTextWithMouse(102.0, 106.0, 115.5);
476 CheckSelection(L"A");
Diana Gagedce2d722017-06-20 11:17:11 -0700477
478 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700479 SelectTextWithMouse(191.0, 102.0, 115.5);
480 CheckSelection(L"ABCDEFGHIJKL");
Diana Gagedce2d722017-06-20 11:17:11 -0700481
482 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700483 SelectTextWithMouse(170.0, 125.0, 115.5);
484 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700485
486 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700487 SelectTextWithMouse(125.0, 170.0, 115.5);
488 CheckSelection(L"DEFGHI");
Diana Gagedce2d722017-06-20 11:17:11 -0700489
490 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700491 SelectTextWithMouse(191.0, 186.0, 115.5);
492 CheckSelection(L"L");
Diana Gagedce2d722017-06-20 11:17:11 -0700493}
Diana Gagecb50b5f2017-06-29 09:54:19 -0700494
Lei Zhang839692f2017-08-25 23:23:57 -0700495TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
496 GetSelectedTextEmptyAndBasicNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700497 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700498 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700499
500 // Non-editable comboboxes don't allow selection with keyboard.
Lei Zhang839692f2017-08-25 23:23:57 -0700501 SelectTextWithMouse(102.0, 142.0, 113.0);
502 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700503
504 // Select other another provided option.
Lei Zhang839692f2017-08-25 23:23:57 -0700505 SelectOption(0, 192.0, 110.0);
506 CheckSelection(L"Apple");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700507}
508
Lei Zhang839692f2017-08-25 23:23:57 -0700509TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700510 GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700511 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700512 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700513
514 // Test basic selection of text within user editable combobox using keyboard.
Lei Zhang839692f2017-08-25 23:23:57 -0700515 TypeTextIntoTextField(3, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
516 SelectTextWithKeyboard(3, FWL_VKEY_Left, 128.0, 62.0);
517 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700518
519 // Select a provided option.
Lei Zhang839692f2017-08-25 23:23:57 -0700520 SelectOption(1, 192.0, 60.0);
521 CheckSelection(L"Bar");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700522}
523
Lei Zhang839692f2017-08-25 23:23:57 -0700524TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700525 GetSelectedTextEmptyAndBasicEditableComboBoxMouse) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700526 // Test empty selection.
Lei Zhang839692f2017-08-25 23:23:57 -0700527 CheckSelection(L"");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700528
529 // Test basic selection of text within user editable combobox using mouse.
Lei Zhang839692f2017-08-25 23:23:57 -0700530 TypeTextIntoTextField(3, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
531 SelectTextWithMouse(128.0, 103.0, 62.0);
532 CheckSelection(L"ABC");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700533
534 // Select a provided option.
Lei Zhang839692f2017-08-25 23:23:57 -0700535 SelectOption(2, 192.0, 60.0);
536 CheckSelection(L"Qux");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700537}
538
Lei Zhang839692f2017-08-25 23:23:57 -0700539TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
540 GetSelectedTextFragmentsNormalComboBox) {
Diana Gagecb50b5f2017-06-29 09:54:19 -0700541 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700542 SelectTextWithMouse(102.0, 107.0, 113.0);
543 CheckSelection(L"B");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700544
545 // Test selecting entire string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700546 SelectTextWithMouse(142.0, 102.0, 113.0);
547 CheckSelection(L"Banana");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700548
549 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700550 SelectTextWithMouse(135.0, 117.0, 113.0);
551 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700552
553 // Test selecting middle section in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700554 SelectTextWithMouse(117.0, 135.0, 113.0);
555 CheckSelection(L"nan");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700556
557 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700558 SelectTextWithMouse(142.0, 138.0, 113.0);
559 CheckSelection(L"a");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700560
561 // Select another option and then reset selection as first three chars.
Lei Zhang839692f2017-08-25 23:23:57 -0700562 SelectOption(2, 192.0, 110.0);
563 CheckSelection(L"Cherry");
564 SelectTextWithMouse(102.0, 122.0, 113.0);
565 CheckSelection(L"Che");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700566}
567
Lei Zhang839692f2017-08-25 23:23:57 -0700568TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700569 GetSelectedTextFragmentsEditableComboBoxKeyboard) {
Lei Zhang839692f2017-08-25 23:23:57 -0700570 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700571
572 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700573 SelectTextWithKeyboard(1, FWL_VKEY_Right, 102.0, 62.0);
574 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700575
576 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700577 SelectTextWithKeyboard(10, FWL_VKEY_Left, 178.0, 62.0);
578 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700579
580 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700581 SelectTextWithKeyboard(5, FWL_VKEY_Left, 168.0, 62.0);
582 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700583
584 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700585 SelectTextWithKeyboard(5, FWL_VKEY_Right, 127.0, 62.0);
586 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700587
588 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700589 SelectTextWithKeyboard(1, FWL_VKEY_Left, 178.0, 62.0);
590 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700591
592 // Select a provided option and then reset selection as first two chars.
Lei Zhang839692f2017-08-25 23:23:57 -0700593 SelectOption(0, 192.0, 60.0);
594 CheckSelection(L"Foo");
595 SelectTextWithKeyboard(2, FWL_VKEY_Right, 102.0, 62.0);
596 CheckSelection(L"Fo");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700597}
598
Lei Zhang839692f2017-08-25 23:23:57 -0700599TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gagecb50b5f2017-06-29 09:54:19 -0700600 GetSelectedTextFragmentsEditableComboBoxMouse) {
Lei Zhang839692f2017-08-25 23:23:57 -0700601 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gagecb50b5f2017-06-29 09:54:19 -0700602
603 // Test selecting first character in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700604 SelectTextWithMouse(102.0, 107.0, 62.0);
605 CheckSelection(L"A");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700606
607 // Test selecting entire long string in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700608 SelectTextWithMouse(178.0, 102.0, 62.0);
609 CheckSelection(L"ABCDEFGHIJ");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700610
611 // Test selecting middle section in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700612 SelectTextWithMouse(168.0, 127.0, 62.0);
613 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700614
615 // Test selecting middle selection in forward direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700616 SelectTextWithMouse(127.0, 168.0, 62.0);
617 CheckSelection(L"DEFGH");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700618
619 // Test selecting last character in backwards direction.
Lei Zhang839692f2017-08-25 23:23:57 -0700620 SelectTextWithMouse(178.0, 174.0, 62.0);
621 CheckSelection(L"J");
Diana Gagecb50b5f2017-06-29 09:54:19 -0700622}
Diana Gage1c7f1422017-07-24 11:19:52 -0700623
Lei Zhang839692f2017-08-25 23:23:57 -0700624TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700625 // Select entire contents of text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700626 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
627 SelectTextWithMouse(191.0, 102.0, 115.5);
628 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700629
630 // Test deleting current text selection. Select what remains after deletion to
631 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700632 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -0700633
Lei Zhang839692f2017-08-25 23:23:57 -0700634 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
635 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700636}
637
Lei Zhang839692f2017-08-25 23:23:57 -0700638TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700639 // Select middle section of text.
Lei Zhang839692f2017-08-25 23:23:57 -0700640 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
641 SelectTextWithMouse(170.0, 125.0, 115.5);
642 CheckSelection(L"DEFGHI");
Diana Gage1c7f1422017-07-24 11:19:52 -0700643
644 // Test deleting current text selection. Select what remains after deletion to
645 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700646 FORM_ReplaceSelection(form_handle(), page(), nullptr);
647 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
648 CheckSelection(L"ABCJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700649}
650
Lei Zhang839692f2017-08-25 23:23:57 -0700651TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700652 // Select first few characters of text.
Lei Zhang839692f2017-08-25 23:23:57 -0700653 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
654 SelectTextWithMouse(102.0, 132.0, 115.5);
655 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700656
657 // Test deleting current text selection. Select what remains after deletion to
658 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700659 FORM_ReplaceSelection(form_handle(), page(), nullptr);
660 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
661 CheckSelection(L"EFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700662}
663
Lei Zhang839692f2017-08-25 23:23:57 -0700664TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700665 // Select last few characters of text.
Lei Zhang839692f2017-08-25 23:23:57 -0700666 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
667 SelectTextWithMouse(191.0, 165.0, 115.5);
668 CheckSelection(L"IJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700669
670 // Test deleting current text selection. Select what remains after deletion to
671 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700672 FORM_ReplaceSelection(form_handle(), page(), nullptr);
673 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
674 CheckSelection(L"ABCDEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700675}
676
Lei Zhang839692f2017-08-25 23:23:57 -0700677TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteEmptyTextFieldSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700678 // Do not select text.
Lei Zhang839692f2017-08-25 23:23:57 -0700679 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
680 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700681
682 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700683 FORM_ReplaceSelection(form_handle(), page(), nullptr);
684 SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5);
685 CheckSelection(L"ABCDEFGHIJKL");
Diana Gage1c7f1422017-07-24 11:19:52 -0700686}
687
Lei Zhang839692f2017-08-25 23:23:57 -0700688TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
689 DeleteEditableComboBoxEntireSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700690 // Select entire contents of user-editable combobox text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700691 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
692 SelectTextWithMouse(178.0, 102.0, 62.0);
693 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700694
695 // Test deleting current text selection. Select what remains after deletion to
696 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700697 FORM_ReplaceSelection(form_handle(), page(), nullptr);
698 SelectTextWithMouse(178.0, 102.0, 62.0);
699 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700700}
701
Lei Zhang839692f2017-08-25 23:23:57 -0700702TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
703 DeleteEditableComboBoxSelectionMiddle) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700704 // Select middle section of text.
Lei Zhang839692f2017-08-25 23:23:57 -0700705 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
706 SelectTextWithMouse(168.0, 127.0, 62.0);
707 CheckSelection(L"DEFGH");
Diana Gage1c7f1422017-07-24 11:19:52 -0700708
709 // Test deleting current text selection. Select what remains after deletion to
710 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700711 FORM_ReplaceSelection(form_handle(), page(), nullptr);
712 SelectTextWithMouse(178.0, 102.0, 62.0);
713 CheckSelection(L"ABCIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700714}
715
Lei Zhang839692f2017-08-25 23:23:57 -0700716TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
717 DeleteEditableComboBoxSelectionLeft) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700718 // Select first few characters of text.
Lei Zhang839692f2017-08-25 23:23:57 -0700719 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
720 SelectTextWithMouse(102.0, 132.0, 62.0);
721 CheckSelection(L"ABCD");
Diana Gage1c7f1422017-07-24 11:19:52 -0700722
723 // Test deleting current text selection. Select what remains after deletion to
724 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700725 FORM_ReplaceSelection(form_handle(), page(), nullptr);
726 SelectTextWithMouse(178.0, 102.0, 62.0);
727 CheckSelection(L"EFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700728}
729
Lei Zhang839692f2017-08-25 23:23:57 -0700730TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
731 DeleteEditableComboBoxSelectionRight) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700732 // Select last few characters of text.
Lei Zhang839692f2017-08-25 23:23:57 -0700733 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
734 SelectTextWithMouse(178.0, 152.0, 62.0);
735 CheckSelection(L"GHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700736
737 // Test deleting current text selection. Select what remains after deletion to
738 // check that remaining text is as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700739 FORM_ReplaceSelection(form_handle(), page(), nullptr);
740 SelectTextWithMouse(178.0, 102.0, 62.0);
741 CheckSelection(L"ABCDEF");
Diana Gage1c7f1422017-07-24 11:19:52 -0700742}
743
Lei Zhang839692f2017-08-25 23:23:57 -0700744TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
745 DeleteEmptyEditableComboBoxSelection) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700746 // Do not select text.
Lei Zhang839692f2017-08-25 23:23:57 -0700747 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
748 CheckSelection(L"");
Diana Gage1c7f1422017-07-24 11:19:52 -0700749
750 // Test that attempt to delete empty text selection has no effect.
Lei Zhang839692f2017-08-25 23:23:57 -0700751 FORM_ReplaceSelection(form_handle(), page(), nullptr);
752 SelectTextWithMouse(178.0, 102.0, 62.0);
753 CheckSelection(L"ABCDEFGHIJ");
Diana Gage1c7f1422017-07-24 11:19:52 -0700754}
Diana Gageab390972017-07-28 17:07:39 -0700755
Lei Zhang839692f2017-08-25 23:23:57 -0700756TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInEmptyTextField) {
757 ClickOnFormFieldAtPoint(120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700758
759 // Test inserting text into empty text field.
760 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
761 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700762 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700763
764 // Select entire contents of text field to check that insertion worked
765 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700766 SelectTextWithMouse(195.0, 102.0, 115.5);
767 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700768}
769
Lei Zhang839692f2017-08-25 23:23:57 -0700770TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldLeft) {
771 TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700772
773 // Click on the leftmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700774 ClickOnFormFieldAtPoint(102.0, 115.5);
Diana Gageab390972017-07-28 17:07:39 -0700775
776 // Test inserting text in front of existing text in text field.
777 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
778 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700779 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700780
781 // Select entire contents of text field to check that insertion worked
782 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700783 SelectTextWithMouse(195.0, 102.0, 115.5);
784 CheckSelection(L"HelloABCDEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700785}
786
Lei Zhang839692f2017-08-25 23:23:57 -0700787TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldMiddle) {
788 TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700789
790 // Click on the middle of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700791 ClickOnFormFieldAtPoint(134.0, 115.5);
Diana Gageab390972017-07-28 17:07:39 -0700792
793 // Test inserting text in the middle of existing text in text field.
794 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
795 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700796 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700797
798 // Select entire contents of text field to check that insertion worked
799 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700800 SelectTextWithMouse(195.0, 102.0, 115.5);
801 CheckSelection(L"ABCDHelloEFGH");
Diana Gageab390972017-07-28 17:07:39 -0700802}
803
Lei Zhang839692f2017-08-25 23:23:57 -0700804TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldRight) {
805 TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700806
807 // Click on the rightmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700808 ClickOnFormFieldAtPoint(166.0, 115.5);
Diana Gageab390972017-07-28 17:07:39 -0700809
810 // Test inserting text behind existing text in text field.
811 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
812 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700813 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700814
815 // Select entire contents of text field to check that insertion worked
816 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700817 SelectTextWithMouse(195.0, 102.0, 115.5);
818 CheckSelection(L"ABCDEFGHHello");
Diana Gageab390972017-07-28 17:07:39 -0700819}
820
Lei Zhang839692f2017-08-25 23:23:57 -0700821TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700822 InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) {
Lei Zhang839692f2017-08-25 23:23:57 -0700823 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700824
825 // Select entire string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700826 SelectTextWithKeyboard(12, FWL_VKEY_Left, 195.0, 115.0);
827 CheckSelection(L"ABCDEFGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700828
829 // Test replacing text selection with text to be inserted.
830 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
831 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700832 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700833
834 // Select entire contents of text field to check that insertion worked
835 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700836 SelectTextWithMouse(195.0, 102.0, 115.5);
837 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700838}
839
Lei Zhang839692f2017-08-25 23:23:57 -0700840TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700841 InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) {
Lei Zhang839692f2017-08-25 23:23:57 -0700842 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700843
844 // Select left portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700845 SelectTextWithKeyboard(6, FWL_VKEY_Left, 148.0, 115.0);
846 CheckSelection(L"ABCDEF");
Diana Gageab390972017-07-28 17:07:39 -0700847
848 // Test replacing text selection with text to be inserted.
849 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
850 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700851 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700852
853 // Select entire contents of text field to check that insertion worked
854 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700855 SelectTextWithMouse(195.0, 102.0, 115.5);
856 CheckSelection(L"HelloGHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700857}
858
Lei Zhang839692f2017-08-25 23:23:57 -0700859TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700860 InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) {
Lei Zhang839692f2017-08-25 23:23:57 -0700861 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700862
863 // Select middle portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700864 SelectTextWithKeyboard(6, FWL_VKEY_Left, 171.0, 115.0);
865 CheckSelection(L"DEFGHI");
Diana Gageab390972017-07-28 17:07:39 -0700866
867 // Test replacing text selection with text to be inserted.
868 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
869 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700870 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700871
872 // Select entire contents of text field to check that insertion worked
873 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700874 SelectTextWithMouse(195.0, 102.0, 115.5);
875 CheckSelection(L"ABCHelloJKL");
Diana Gageab390972017-07-28 17:07:39 -0700876}
877
Lei Zhang839692f2017-08-25 23:23:57 -0700878TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700879 InsertTextAndReplaceSelectionInPopulatedTextFieldRight) {
Lei Zhang839692f2017-08-25 23:23:57 -0700880 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -0700881
882 // Select right portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -0700883 SelectTextWithKeyboard(6, FWL_VKEY_Left, 195.0, 115.0);
884 CheckSelection(L"GHIJKL");
Diana Gageab390972017-07-28 17:07:39 -0700885
886 // Test replacing text selection with text to be inserted.
887 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
888 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700889 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700890
891 // Select entire contents of text field to check that insertion worked
892 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700893 SelectTextWithMouse(195.0, 102.0, 115.5);
894 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -0700895}
896
Lei Zhang839692f2017-08-25 23:23:57 -0700897TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
898 InsertTextInEmptyEditableComboBox) {
899 ClickOnFormFieldAtPoint(102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700900
901 // Test inserting text into empty user-editable combobox.
902 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
903 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700904 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700905
906 // Select entire contents of user-editable combobox text field to check that
907 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700908 SelectTextWithMouse(183.0, 102.0, 62.0);
909 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700910}
911
Lei Zhang839692f2017-08-25 23:23:57 -0700912TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
913 InsertTextInPopulatedEditableComboBoxLeft) {
914 TypeTextIntoTextField(6, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700915
916 // Click on the leftmost part of the user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700917 ClickOnFormFieldAtPoint(102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700918
919 // Test inserting text in front of existing text in user-editable combobox.
920 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
921 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700922 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700923
924 // Select entire contents of user-editable combobox text field to check that
925 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700926 SelectTextWithMouse(183.0, 102.0, 62.0);
927 CheckSelection(L"HelloABCDEF");
Diana Gageab390972017-07-28 17:07:39 -0700928}
929
Lei Zhang839692f2017-08-25 23:23:57 -0700930TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
931 InsertTextInPopulatedEditableComboBoxMiddle) {
932 TypeTextIntoTextField(6, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700933
934 // Click on the middle of the user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700935 ClickOnFormFieldAtPoint(126.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700936
937 // Test inserting text in the middle of existing text in user-editable
938 // combobox.
939 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
940 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700941 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700942
943 // Select entire contents of user-editable combobox text field to check that
944 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700945 SelectTextWithMouse(183.0, 102.0, 62.0);
946 CheckSelection(L"ABCHelloDEF");
Diana Gageab390972017-07-28 17:07:39 -0700947}
948
Lei Zhang839692f2017-08-25 23:23:57 -0700949TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
950 InsertTextInPopulatedEditableComboBoxRight) {
951 TypeTextIntoTextField(6, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700952
953 // Click on the rightmost part of the user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700954 ClickOnFormFieldAtPoint(150.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700955
956 // Test inserting text behind existing text in user-editable combobox.
957 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
958 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700959 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700960
961 // Select entire contents of user-editable combobox text field to check that
962 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700963 SelectTextWithMouse(183.0, 102.0, 62.0);
964 CheckSelection(L"ABCDEFHello");
Diana Gageab390972017-07-28 17:07:39 -0700965}
966
Lei Zhang839692f2017-08-25 23:23:57 -0700967TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700968 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) {
Lei Zhang839692f2017-08-25 23:23:57 -0700969 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700970
971 // Select entire string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700972 SelectTextWithKeyboard(10, FWL_VKEY_Left, 183.0, 62.0);
973 CheckSelection(L"ABCDEFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -0700974
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");
Lei Zhang839692f2017-08-25 23:23:57 -0700978 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700979
980 // Select entire contents of user-editable combobox text field to check that
981 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -0700982 SelectTextWithMouse(183.0, 102.0, 62.0);
983 CheckSelection(L"Hello");
Diana Gageab390972017-07-28 17:07:39 -0700984}
985
Lei Zhang839692f2017-08-25 23:23:57 -0700986TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -0700987 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) {
Lei Zhang839692f2017-08-25 23:23:57 -0700988 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -0700989
990 // Select left portion of string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -0700991 SelectTextWithKeyboard(5, FWL_VKEY_Left, 142.0, 62.0);
992 CheckSelection(L"ABCDE");
Diana Gageab390972017-07-28 17:07:39 -0700993
994 // Test replacing text selection with text to be inserted.
995 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
996 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -0700997 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -0700998
999 // Select entire contents of user-editable combobox text field to check that
1000 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001001 SelectTextWithMouse(183.0, 102.0, 62.0);
1002 CheckSelection(L"HelloFGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001003}
1004
Lei Zhang839692f2017-08-25 23:23:57 -07001005TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001006 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) {
Lei Zhang839692f2017-08-25 23:23:57 -07001007 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -07001008
1009 // Select middle portion of string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -07001010 SelectTextWithKeyboard(5, FWL_VKEY_Left, 167.0, 62.0);
1011 CheckSelection(L"DEFGH");
Diana Gageab390972017-07-28 17:07:39 -07001012
1013 // Test replacing text selection with text to be inserted.
1014 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1015 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001016 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001017
1018 // Select entire contents of user-editable combobox text field to check that
1019 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001020 SelectTextWithMouse(183.0, 102.0, 62.0);
1021 CheckSelection(L"ABCHelloIJ");
Diana Gageab390972017-07-28 17:07:39 -07001022}
1023
Lei Zhang839692f2017-08-25 23:23:57 -07001024TEST_F(FPDFFormFillComboBoxFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001025 InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) {
Lei Zhang839692f2017-08-25 23:23:57 -07001026 TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0);
Diana Gageab390972017-07-28 17:07:39 -07001027
1028 // Select right portion of string in user-editable combobox.
Lei Zhang839692f2017-08-25 23:23:57 -07001029 SelectTextWithKeyboard(5, FWL_VKEY_Left, 183.0, 62.0);
1030 CheckSelection(L"FGHIJ");
Diana Gageab390972017-07-28 17:07:39 -07001031
1032 // Test replacing text selection with text to be inserted.
1033 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1034 GetFPDFWideString(L"Hello");
Lei Zhang839692f2017-08-25 23:23:57 -07001035 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001036
1037 // Select entire contents of user-editable combobox text field to check that
1038 // insertion worked as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001039 SelectTextWithMouse(183.0, 102.0, 62.0);
1040 CheckSelection(L"ABCDEHello");
Diana Gageab390972017-07-28 17:07:39 -07001041}
1042
Lei Zhang839692f2017-08-25 23:23:57 -07001043TEST_F(FPDFFormFillTextFormEmbeddertest,
1044 InsertTextInEmptyCharLimitTextFieldOverflow) {
Diana Gageab390972017-07-28 17:07:39 -07001045 // Click on the textfield.
Lei Zhang839692f2017-08-25 23:23:57 -07001046 ClickOnFormFieldAtPoint(195.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001047
1048 // Delete pre-filled contents of text field with char limit.
Lei Zhang839692f2017-08-25 23:23:57 -07001049 SelectTextWithMouse(195.0, 102.0, 60.0);
1050 CheckSelection(L"Elephant");
1051 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001052
1053 // Test inserting text into now empty text field so text to be inserted
1054 // exceeds the char limit and is cut off.
1055 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1056 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001057 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001058
1059 // Select entire contents of text field to check that insertion worked
1060 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001061 SelectTextWithMouse(195.0, 102.0, 60.0);
1062 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001063}
1064
Lei Zhang839692f2017-08-25 23:23:57 -07001065TEST_F(FPDFFormFillTextFormEmbeddertest,
1066 InsertTextInEmptyCharLimitTextFieldFit) {
Diana Gageab390972017-07-28 17:07:39 -07001067 // Click on the textfield.
Lei Zhang839692f2017-08-25 23:23:57 -07001068 ClickOnFormFieldAtPoint(195.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001069
1070 // Delete pre-filled contents of text field with char limit.
Lei Zhang839692f2017-08-25 23:23:57 -07001071 SelectTextWithMouse(195.0, 102.0, 60.0);
1072 CheckSelection(L"Elephant");
1073 FORM_ReplaceSelection(form_handle(), page(), nullptr);
Diana Gageab390972017-07-28 17:07:39 -07001074
1075 // Test inserting text into now empty text field so text to be inserted
1076 // exceeds the char limit and is cut off.
1077 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1078 GetFPDFWideString(L"Zebra");
Lei Zhang839692f2017-08-25 23:23:57 -07001079 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001080
1081 // Select entire contents of text field to check that insertion worked
1082 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001083 SelectTextWithMouse(195.0, 102.0, 60.0);
1084 CheckSelection(L"Zebra");
Diana Gageab390972017-07-28 17:07:39 -07001085}
1086
Lei Zhang839692f2017-08-25 23:23:57 -07001087TEST_F(FPDFFormFillTextFormEmbeddertest,
1088 InsertTextInPopulatedCharLimitTextFieldLeft) {
Diana Gageab390972017-07-28 17:07:39 -07001089 // Click on the leftmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001090 ClickOnFormFieldAtPoint(102.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001091
1092 // Test inserting text in front of existing text in text field.
1093 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1094 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001095 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001096
1097 // Select entire contents of text field to check that insertion worked
1098 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001099 SelectTextWithMouse(195.0, 102.0, 60.0);
1100 CheckSelection(L"HiElephant");
Diana Gageab390972017-07-28 17:07:39 -07001101}
1102
Lei Zhang839692f2017-08-25 23:23:57 -07001103TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001104 InsertTextInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang839692f2017-08-25 23:23:57 -07001105 TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001106
1107 // Click on the middle of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001108 ClickOnFormFieldAtPoint(134.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001109
1110 // Test inserting text in the middle of existing text in text field.
1111 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1112 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001113 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001114
1115 // Select entire contents of text field to check that insertion worked
1116 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001117 SelectTextWithMouse(195.0, 102.0, 60.0);
1118 CheckSelection(L"ElephHiant");
Diana Gageab390972017-07-28 17:07:39 -07001119}
1120
Lei Zhang839692f2017-08-25 23:23:57 -07001121TEST_F(FPDFFormFillTextFormEmbeddertest,
1122 InsertTextInPopulatedCharLimitTextFieldRight) {
1123 TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001124
1125 // Click on the rightmost part of the text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001126 ClickOnFormFieldAtPoint(166.0, 60.0);
Diana Gageab390972017-07-28 17:07:39 -07001127
1128 // Test inserting text behind existing text in text field.
1129 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1130 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001131 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001132
1133 // Select entire contents of text field to check that insertion worked
1134 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001135 SelectTextWithMouse(195.0, 102.0, 60.0);
1136 CheckSelection(L"ElephantHi");
Diana Gageab390972017-07-28 17:07:39 -07001137}
1138
Lei Zhang839692f2017-08-25 23:23:57 -07001139TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001140 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) {
Lei Zhang839692f2017-08-25 23:23:57 -07001141 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001142
1143 // Select entire string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001144 SelectTextWithKeyboard(12, FWL_VKEY_Left, 195.0, 60.0);
1145 CheckSelection(L"Elephant");
Diana Gageab390972017-07-28 17:07:39 -07001146
1147 // Test replacing text selection with text to be inserted.
1148 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1149 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001150 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001151
1152 // Select entire contents of text field to check that insertion worked
1153 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001154 SelectTextWithMouse(195.0, 102.0, 60.0);
1155 CheckSelection(L"Hippopotam");
Diana Gageab390972017-07-28 17:07:39 -07001156}
1157
Lei Zhang839692f2017-08-25 23:23:57 -07001158TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001159 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) {
Lei Zhang839692f2017-08-25 23:23:57 -07001160 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001161
1162 // Select left portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001163 SelectTextWithKeyboard(4, FWL_VKEY_Left, 122.0, 60.0);
1164 CheckSelection(L"Elep");
Diana Gageab390972017-07-28 17:07:39 -07001165
1166 // Test replacing text selection with text to be inserted.
1167 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1168 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001169 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001170
1171 // Select entire contents of text field to check that insertion worked
1172 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001173 SelectTextWithMouse(195.0, 102.0, 60.0);
1174 CheckSelection(L"Hippophant");
Diana Gageab390972017-07-28 17:07:39 -07001175}
1176
Lei Zhang839692f2017-08-25 23:23:57 -07001177TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001178 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) {
Lei Zhang839692f2017-08-25 23:23:57 -07001179 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001180
1181 // Select middle portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001182 SelectTextWithKeyboard(4, FWL_VKEY_Left, 136.0, 60.0);
1183 CheckSelection(L"epha");
Diana Gageab390972017-07-28 17:07:39 -07001184
1185 // Test replacing text selection with text to be inserted.
1186 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1187 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001188 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001189
1190 // Select entire contents of text field to check that insertion worked
1191 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001192 SelectTextWithMouse(195.0, 102.0, 60.0);
1193 CheckSelection(L"ElHippopnt");
Diana Gageab390972017-07-28 17:07:39 -07001194}
1195
Lei Zhang839692f2017-08-25 23:23:57 -07001196TEST_F(FPDFFormFillTextFormEmbeddertest,
Diana Gageab390972017-07-28 17:07:39 -07001197 InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) {
Lei Zhang839692f2017-08-25 23:23:57 -07001198 TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0);
Diana Gageab390972017-07-28 17:07:39 -07001199
1200 // Select right portion of string in text field.
Lei Zhang839692f2017-08-25 23:23:57 -07001201 SelectTextWithKeyboard(4, FWL_VKEY_Left, 152.0, 60.0);
1202 CheckSelection(L"hant");
Diana Gageab390972017-07-28 17:07:39 -07001203
1204 // Test replacing text selection with text to be inserted.
1205 std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert =
1206 GetFPDFWideString(L"Hippopotamus");
Lei Zhang839692f2017-08-25 23:23:57 -07001207 FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get());
Diana Gageab390972017-07-28 17:07:39 -07001208
1209 // Select entire contents of text field to check that insertion worked
1210 // as expected.
Lei Zhang839692f2017-08-25 23:23:57 -07001211 SelectTextWithMouse(195.0, 102.0, 60.0);
1212 CheckSelection(L"ElepHippop");
Diana Gageab390972017-07-28 17:07:39 -07001213}