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::_; |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 21 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 22 | using FPDFFormFillEmbeddertest = EmbedderTest; |
| 23 | |
| 24 | // A base class for many related tests that involve clicking and typing into |
| 25 | // form fields. |
| 26 | class FPDFFormFillInteractiveEmbeddertest : public FPDFFormFillEmbeddertest { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 27 | protected: |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 28 | 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 Gage | f8c0276 | 2017-07-26 14:20:12 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 39 | 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 Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 60 | ASSERT(form_type == FPDF_FORMFIELD_COMBOBOX || |
| 61 | form_type == FPDF_FORMFIELD_TEXTFIELD); |
| 62 | EXPECT_EQ(form_type, |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 63 | FPDFPage_HasFormFieldAtPoint(form_handle(), page_, x, y)); |
| 64 | ClickOnFormFieldAtPoint(x, y); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 65 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 68 | FORM_OnChar(form_handle(), page_, 'A' + i, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 72 | // 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] | 73 | // shift and specfied left or right arrow key. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 74 | void SelectTextWithKeyboard(int num_chars, |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 75 | int arrow_key, |
| 76 | double x, |
| 77 | double y) { |
| 78 | // Navigate to starting position for selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 79 | ClickOnFormFieldAtPoint(x, y); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 80 | |
| 81 | // Hold down shift (and don't release until entire text is selected). |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 82 | FORM_OnKeyDown(form_handle(), page_, FWL_VKEY_Shift, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 83 | |
| 84 | // Select text char by char via left or right arrow key. |
| 85 | for (int i = 0; i < num_chars; ++i) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 86 | FORM_OnKeyDown(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey); |
| 87 | FORM_OnKeyUp(form_handle(), page_, arrow_key, FWL_EVENTFLAG_ShiftKey); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 88 | } |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 89 | FORM_OnKeyUp(form_handle(), page_, FWL_VKEY_Shift, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 92 | // Uses the mouse to navigate to text field and select text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 93 | void SelectTextWithMouse(double start_x, double end_x, double y) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 94 | // Navigate to starting position and click mouse. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 95 | FORM_OnMouseMove(form_handle(), page_, 0, start_x, y); |
| 96 | FORM_OnLButtonDown(form_handle(), page_, 0, start_x, y); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 97 | |
| 98 | // Hold down mouse until reach end of desired selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 99 | FORM_OnMouseMove(form_handle(), page_, 0, end_x, y); |
| 100 | FORM_OnLButtonUp(form_handle(), page_, 0, end_x, y); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 103 | void CheckSelection(const CFX_WideStringC& expected_string) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 104 | // 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 111 | FORM_GetSelectedText(form_handle(), page_, nullptr, 0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 112 | ASSERT_EQ(expected_length, sel_text_len); |
| 113 | |
| 114 | std::vector<unsigned short> buf(sel_text_len); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 115 | EXPECT_EQ(expected_length, FORM_GetSelectedText(form_handle(), page_, |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 116 | buf.data(), sel_text_len)); |
| 117 | |
| 118 | EXPECT_EQ(expected_string, |
| 119 | CFX_WideString::FromUTF16LE(buf.data(), num_chars)); |
| 120 | } |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 121 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 122 | private: |
| 123 | FPDF_PAGE page_ = nullptr; |
| 124 | }; |
| 125 | |
| 126 | class 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 | |
| 141 | class 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 Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 158 | // 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 160 | void SelectOption(int32_t item_index, double x, double y) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 161 | // 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 167 | ClickOnFormFieldAtPoint(x, y); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 168 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 174 | ClickOnFormFieldAtPoint(x, option_y); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 175 | } |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 176 | }; |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 177 | |
| 178 | TEST_F(FPDFFormFillEmbeddertest, FirstTest) { |
| 179 | EmbedderTestMockDelegate mock; |
| 180 | EXPECT_CALL(mock, Alert(_, _, _, _)).Times(0); |
| 181 | EXPECT_CALL(mock, UnsupportedHandler(_)).Times(0); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 182 | EXPECT_CALL(mock, SetTimer(_, _)).Times(0); |
| 183 | EXPECT_CALL(mock, KillTimer(_)).Times(0); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 184 | SetDelegate(&mock); |
| 185 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 186 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 187 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 188 | EXPECT_TRUE(page); |
Lei Zhang | d27acae | 2015-05-15 15:36:02 -0700 | [diff] [blame] | 189 | UnloadPage(page); |
Tom Sepez | a310e00 | 2015-02-27 13:03:07 -0800 | [diff] [blame] | 190 | } |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 191 | |
| 192 | TEST_F(FPDFFormFillEmbeddertest, BUG_487928) { |
| 193 | EmbedderTestTimerHandlingDelegate delegate; |
| 194 | SetDelegate(&delegate); |
| 195 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 196 | EXPECT_TRUE(OpenDocument("bug_487928.pdf")); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 197 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 198 | EXPECT_TRUE(page); |
Tom Sepez | 6efc0ad | 2015-06-02 17:11:18 -0700 | [diff] [blame] | 199 | DoOpenActions(); |
| 200 | delegate.AdvanceTime(5000); |
| 201 | UnloadPage(page); |
| 202 | } |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 203 | |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 204 | TEST_F(FPDFFormFillEmbeddertest, BUG_507316) { |
| 205 | EmbedderTestTimerHandlingDelegate delegate; |
| 206 | SetDelegate(&delegate); |
| 207 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 208 | EXPECT_TRUE(OpenDocument("bug_507316.pdf")); |
weili | 0dadcc6 | 2016-08-23 21:10:57 -0700 | [diff] [blame] | 209 | FPDF_PAGE page = LoadPage(2); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 210 | EXPECT_TRUE(page); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 211 | DoOpenActions(); |
| 212 | delegate.AdvanceTime(4000); |
| 213 | UnloadPage(page); |
| 214 | } |
| 215 | |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 216 | TEST_F(FPDFFormFillEmbeddertest, BUG_514690) { |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 217 | EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 218 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 219 | EXPECT_TRUE(page); |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 220 | |
| 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 Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 227 | |
Tom Sepez | 4d07179 | 2016-02-04 16:53:26 -0800 | [diff] [blame] | 228 | #ifdef PDF_ENABLE_V8 |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 229 | TEST_F(FPDFFormFillEmbeddertest, BUG_551248) { |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 230 | // Test that timers fire once and intervals fire repeatedly. |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 231 | EmbedderTestTimerHandlingDelegate delegate; |
| 232 | SetDelegate(&delegate); |
| 233 | |
Wei Li | 091f7a0 | 2015-11-09 12:09:55 -0800 | [diff] [blame] | 234 | EXPECT_TRUE(OpenDocument("bug_551248.pdf")); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 235 | FPDF_PAGE page = LoadPage(0); |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 236 | 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 | |
| 281 | TEST_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 Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 289 | DoOpenActions(); |
| 290 | delegate.AdvanceTime(5000); |
| 291 | UnloadPage(page); |
| 292 | |
| 293 | const auto& alerts = delegate.GetAlerts(); |
tsepez | 0fa54b8 | 2016-08-04 12:07:28 -0700 | [diff] [blame] | 294 | ASSERT_EQ(1U, alerts.size()); |
| 295 | EXPECT_STREQ(L"done", alerts[0].message.c_str()); |
Lei Zhang | 79e893a | 2015-11-04 16:02:47 -0800 | [diff] [blame] | 296 | } |
tsepez | 8e12029 | 2016-08-03 14:03:35 -0700 | [diff] [blame] | 297 | |
tsepez | 32e693f | 2016-08-04 12:47:42 -0700 | [diff] [blame] | 298 | TEST_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 | |
tsepez | 8ca63de | 2016-08-05 17:12:27 -0700 | [diff] [blame] | 321 | TEST_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 | |
tsepez | 6cf5eca | 2017-01-12 11:21:12 -0800 | [diff] [blame] | 343 | TEST_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 Sepez | fb7021c | 2017-05-31 10:29:25 -0700 | [diff] [blame] | 360 | TEST_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 Sepez | 4d07179 | 2016-02-04 16:53:26 -0800 | [diff] [blame] | 378 | #endif // PDF_ENABLE_V8 |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 379 | |
| 380 | TEST_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 Pena | 00c3cfd | 2017-07-10 17:29:54 -0400 | [diff] [blame] | 386 | const char md5_1[] = "a5e3ac74c2ee123ec6710e2f0ef8424a"; |
| 387 | const char md5_2[] = "4526b09382e144d5506ad92149399de6"; |
| 388 | const char md5_3[] = "80356067d860088864cf50ff85d8459e"; |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 389 | #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 Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 420 | // Close page |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 421 | UnloadPage(page); |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 422 | } |
| 423 | // Check saved document |
Nicolas Pena | 3ff5400 | 2017-07-05 11:55:35 -0400 | [diff] [blame] | 424 | TestAndCloseSaved(300, 300, md5_3); |
Nicolas Pena | 742977f | 2017-04-13 15:28:20 -0400 | [diff] [blame] | 425 | } |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 426 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 427 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicKeyboard) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 428 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 429 | CheckSelection(L""); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 430 | |
| 431 | // Test basic selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 432 | TypeTextIntoTextField(3, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 433 | SelectTextWithKeyboard(3, FWL_VKEY_Left, 123.0, 115.5); |
| 434 | CheckSelection(L"ABC"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 437 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextEmptyAndBasicMouse) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 438 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 439 | CheckSelection(L""); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 440 | |
| 441 | // Test basic selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 442 | TypeTextIntoTextField(3, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 443 | SelectTextWithMouse(125.0, 102.0, 115.5); |
| 444 | CheckSelection(L"ABC"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 447 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsKeyBoard) { |
| 448 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 449 | |
| 450 | // Test selecting first character in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 451 | SelectTextWithKeyboard(1, FWL_VKEY_Right, 102.0, 115.5); |
| 452 | CheckSelection(L"A"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 453 | |
| 454 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 455 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5); |
| 456 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 457 | |
| 458 | // Test selecting middle section in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 459 | SelectTextWithKeyboard(6, FWL_VKEY_Left, 170.0, 115.5); |
| 460 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 461 | |
| 462 | // Test selecting middle selection in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 463 | SelectTextWithKeyboard(6, FWL_VKEY_Right, 125.0, 115.5); |
| 464 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 465 | |
| 466 | // Test selecting last character in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 467 | SelectTextWithKeyboard(1, FWL_VKEY_Left, 191.0, 115.5); |
| 468 | CheckSelection(L"L"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 471 | TEST_F(FPDFFormFillTextFormEmbeddertest, GetSelectedTextFragmentsMouse) { |
| 472 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 473 | |
| 474 | // Test selecting first character in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 475 | SelectTextWithMouse(102.0, 106.0, 115.5); |
| 476 | CheckSelection(L"A"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 477 | |
| 478 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 479 | SelectTextWithMouse(191.0, 102.0, 115.5); |
| 480 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 481 | |
| 482 | // Test selecting middle section in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 483 | SelectTextWithMouse(170.0, 125.0, 115.5); |
| 484 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 485 | |
| 486 | // Test selecting middle selection in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 487 | SelectTextWithMouse(125.0, 170.0, 115.5); |
| 488 | CheckSelection(L"DEFGHI"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 489 | |
| 490 | // Test selecting last character in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 491 | SelectTextWithMouse(191.0, 186.0, 115.5); |
| 492 | CheckSelection(L"L"); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 493 | } |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 494 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 495 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 496 | GetSelectedTextEmptyAndBasicNormalComboBox) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 497 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 498 | CheckSelection(L""); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 499 | |
| 500 | // Non-editable comboboxes don't allow selection with keyboard. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 501 | SelectTextWithMouse(102.0, 142.0, 113.0); |
| 502 | CheckSelection(L"Banana"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 503 | |
| 504 | // Select other another provided option. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 505 | SelectOption(0, 192.0, 110.0); |
| 506 | CheckSelection(L"Apple"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 509 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 510 | GetSelectedTextEmptyAndBasicEditableComboBoxKeyboard) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 511 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 512 | CheckSelection(L""); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 513 | |
| 514 | // Test basic selection of text within user editable combobox using keyboard. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 515 | TypeTextIntoTextField(3, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 516 | SelectTextWithKeyboard(3, FWL_VKEY_Left, 128.0, 62.0); |
| 517 | CheckSelection(L"ABC"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 518 | |
| 519 | // Select a provided option. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 520 | SelectOption(1, 192.0, 60.0); |
| 521 | CheckSelection(L"Bar"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 524 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 525 | GetSelectedTextEmptyAndBasicEditableComboBoxMouse) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 526 | // Test empty selection. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 527 | CheckSelection(L""); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 528 | |
| 529 | // Test basic selection of text within user editable combobox using mouse. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 530 | TypeTextIntoTextField(3, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 531 | SelectTextWithMouse(128.0, 103.0, 62.0); |
| 532 | CheckSelection(L"ABC"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 533 | |
| 534 | // Select a provided option. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 535 | SelectOption(2, 192.0, 60.0); |
| 536 | CheckSelection(L"Qux"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 539 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 540 | GetSelectedTextFragmentsNormalComboBox) { |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 541 | // Test selecting first character in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 542 | SelectTextWithMouse(102.0, 107.0, 113.0); |
| 543 | CheckSelection(L"B"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 544 | |
| 545 | // Test selecting entire string in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 546 | SelectTextWithMouse(142.0, 102.0, 113.0); |
| 547 | CheckSelection(L"Banana"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 548 | |
| 549 | // Test selecting middle section in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 550 | SelectTextWithMouse(135.0, 117.0, 113.0); |
| 551 | CheckSelection(L"nan"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 552 | |
| 553 | // Test selecting middle section in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 554 | SelectTextWithMouse(117.0, 135.0, 113.0); |
| 555 | CheckSelection(L"nan"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 556 | |
| 557 | // Test selecting last character in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 558 | SelectTextWithMouse(142.0, 138.0, 113.0); |
| 559 | CheckSelection(L"a"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 560 | |
| 561 | // Select another option and then reset selection as first three chars. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 562 | SelectOption(2, 192.0, 110.0); |
| 563 | CheckSelection(L"Cherry"); |
| 564 | SelectTextWithMouse(102.0, 122.0, 113.0); |
| 565 | CheckSelection(L"Che"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 568 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 569 | GetSelectedTextFragmentsEditableComboBoxKeyboard) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 570 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 571 | |
| 572 | // Test selecting first character in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 573 | SelectTextWithKeyboard(1, FWL_VKEY_Right, 102.0, 62.0); |
| 574 | CheckSelection(L"A"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 575 | |
| 576 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 577 | SelectTextWithKeyboard(10, FWL_VKEY_Left, 178.0, 62.0); |
| 578 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 579 | |
| 580 | // Test selecting middle section in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 581 | SelectTextWithKeyboard(5, FWL_VKEY_Left, 168.0, 62.0); |
| 582 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 583 | |
| 584 | // Test selecting middle selection in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 585 | SelectTextWithKeyboard(5, FWL_VKEY_Right, 127.0, 62.0); |
| 586 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 587 | |
| 588 | // Test selecting last character in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 589 | SelectTextWithKeyboard(1, FWL_VKEY_Left, 178.0, 62.0); |
| 590 | CheckSelection(L"J"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 591 | |
| 592 | // Select a provided option and then reset selection as first two chars. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 593 | 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 Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 599 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 600 | GetSelectedTextFragmentsEditableComboBoxMouse) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 601 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 602 | |
| 603 | // Test selecting first character in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 604 | SelectTextWithMouse(102.0, 107.0, 62.0); |
| 605 | CheckSelection(L"A"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 606 | |
| 607 | // Test selecting entire long string in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 608 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 609 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 610 | |
| 611 | // Test selecting middle section in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 612 | SelectTextWithMouse(168.0, 127.0, 62.0); |
| 613 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 614 | |
| 615 | // Test selecting middle selection in forward direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 616 | SelectTextWithMouse(127.0, 168.0, 62.0); |
| 617 | CheckSelection(L"DEFGH"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 618 | |
| 619 | // Test selecting last character in backwards direction. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 620 | SelectTextWithMouse(178.0, 174.0, 62.0); |
| 621 | CheckSelection(L"J"); |
Diana Gage | cb50b5f | 2017-06-29 09:54:19 -0700 | [diff] [blame] | 622 | } |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 623 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 624 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldEntireSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 625 | // Select entire contents of text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 626 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 627 | SelectTextWithMouse(191.0, 102.0, 115.5); |
| 628 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 629 | |
| 630 | // Test deleting current text selection. Select what remains after deletion to |
| 631 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 632 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 633 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 634 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5); |
| 635 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 638 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionMiddle) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 639 | // Select middle section of text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 640 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 641 | SelectTextWithMouse(170.0, 125.0, 115.5); |
| 642 | CheckSelection(L"DEFGHI"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 643 | |
| 644 | // Test deleting current text selection. Select what remains after deletion to |
| 645 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 646 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 647 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5); |
| 648 | CheckSelection(L"ABCJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 651 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionLeft) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 652 | // Select first few characters of text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 653 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 654 | SelectTextWithMouse(102.0, 132.0, 115.5); |
| 655 | CheckSelection(L"ABCD"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 656 | |
| 657 | // Test deleting current text selection. Select what remains after deletion to |
| 658 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 659 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 660 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5); |
| 661 | CheckSelection(L"EFGHIJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 664 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteTextFieldSelectionRight) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 665 | // Select last few characters of text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 666 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 667 | SelectTextWithMouse(191.0, 165.0, 115.5); |
| 668 | CheckSelection(L"IJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 669 | |
| 670 | // Test deleting current text selection. Select what remains after deletion to |
| 671 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 672 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 673 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5); |
| 674 | CheckSelection(L"ABCDEFGH"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 677 | TEST_F(FPDFFormFillTextFormEmbeddertest, DeleteEmptyTextFieldSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 678 | // Do not select text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 679 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
| 680 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 681 | |
| 682 | // Test that attempt to delete empty text selection has no effect. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 683 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 684 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 191.0, 115.5); |
| 685 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 688 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 689 | DeleteEditableComboBoxEntireSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 690 | // Select entire contents of user-editable combobox text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 691 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 692 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 693 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 694 | |
| 695 | // Test deleting current text selection. Select what remains after deletion to |
| 696 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 697 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 698 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 699 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 702 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 703 | DeleteEditableComboBoxSelectionMiddle) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 704 | // Select middle section of text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 705 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 706 | SelectTextWithMouse(168.0, 127.0, 62.0); |
| 707 | CheckSelection(L"DEFGH"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 708 | |
| 709 | // Test deleting current text selection. Select what remains after deletion to |
| 710 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 711 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 712 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 713 | CheckSelection(L"ABCIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 716 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 717 | DeleteEditableComboBoxSelectionLeft) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 718 | // Select first few characters of text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 719 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 720 | SelectTextWithMouse(102.0, 132.0, 62.0); |
| 721 | CheckSelection(L"ABCD"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 722 | |
| 723 | // Test deleting current text selection. Select what remains after deletion to |
| 724 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 725 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 726 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 727 | CheckSelection(L"EFGHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 730 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 731 | DeleteEditableComboBoxSelectionRight) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 732 | // Select last few characters of text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 733 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 734 | SelectTextWithMouse(178.0, 152.0, 62.0); |
| 735 | CheckSelection(L"GHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 736 | |
| 737 | // Test deleting current text selection. Select what remains after deletion to |
| 738 | // check that remaining text is as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 739 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 740 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 741 | CheckSelection(L"ABCDEF"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 744 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 745 | DeleteEmptyEditableComboBoxSelection) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 746 | // Do not select text. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 747 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
| 748 | CheckSelection(L""); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 749 | |
| 750 | // Test that attempt to delete empty text selection has no effect. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 751 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
| 752 | SelectTextWithMouse(178.0, 102.0, 62.0); |
| 753 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 754 | } |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 755 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 756 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInEmptyTextField) { |
| 757 | ClickOnFormFieldAtPoint(120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 758 | |
| 759 | // Test inserting text into empty text field. |
| 760 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 761 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 762 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 763 | |
| 764 | // Select entire contents of text field to check that insertion worked |
| 765 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 766 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 767 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 770 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldLeft) { |
| 771 | TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 772 | |
| 773 | // Click on the leftmost part of the text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 774 | ClickOnFormFieldAtPoint(102.0, 115.5); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 775 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 779 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 780 | |
| 781 | // Select entire contents of text field to check that insertion worked |
| 782 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 783 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 784 | CheckSelection(L"HelloABCDEFGH"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 787 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldMiddle) { |
| 788 | TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 789 | |
| 790 | // Click on the middle of the text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 791 | ClickOnFormFieldAtPoint(134.0, 115.5); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 792 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 796 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 797 | |
| 798 | // Select entire contents of text field to check that insertion worked |
| 799 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 800 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 801 | CheckSelection(L"ABCDHelloEFGH"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 804 | TEST_F(FPDFFormFillTextFormEmbeddertest, InsertTextInPopulatedTextFieldRight) { |
| 805 | TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 806 | |
| 807 | // Click on the rightmost part of the text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 808 | ClickOnFormFieldAtPoint(166.0, 115.5); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 809 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 813 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 814 | |
| 815 | // Select entire contents of text field to check that insertion worked |
| 816 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 817 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 818 | CheckSelection(L"ABCDEFGHHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 821 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 822 | InsertTextAndReplaceSelectionInPopulatedTextFieldWhole) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 823 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 824 | |
| 825 | // Select entire string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 826 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 195.0, 115.0); |
| 827 | CheckSelection(L"ABCDEFGHIJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 828 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 832 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 833 | |
| 834 | // Select entire contents of text field to check that insertion worked |
| 835 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 836 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 837 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 840 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 841 | InsertTextAndReplaceSelectionInPopulatedTextFieldLeft) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 842 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 843 | |
| 844 | // Select left portion of string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 845 | SelectTextWithKeyboard(6, FWL_VKEY_Left, 148.0, 115.0); |
| 846 | CheckSelection(L"ABCDEF"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 847 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 851 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 852 | |
| 853 | // Select entire contents of text field to check that insertion worked |
| 854 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 855 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 856 | CheckSelection(L"HelloGHIJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 859 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 860 | InsertTextAndReplaceSelectionInPopulatedTextFieldMiddle) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 861 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 862 | |
| 863 | // Select middle portion of string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 864 | SelectTextWithKeyboard(6, FWL_VKEY_Left, 171.0, 115.0); |
| 865 | CheckSelection(L"DEFGHI"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 866 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 870 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 871 | |
| 872 | // Select entire contents of text field to check that insertion worked |
| 873 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 874 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 875 | CheckSelection(L"ABCHelloJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 878 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 879 | InsertTextAndReplaceSelectionInPopulatedTextFieldRight) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 880 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 881 | |
| 882 | // Select right portion of string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 883 | SelectTextWithKeyboard(6, FWL_VKEY_Left, 195.0, 115.0); |
| 884 | CheckSelection(L"GHIJKL"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 885 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 889 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 890 | |
| 891 | // Select entire contents of text field to check that insertion worked |
| 892 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 893 | SelectTextWithMouse(195.0, 102.0, 115.5); |
| 894 | CheckSelection(L"ABCDEFHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 897 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 898 | InsertTextInEmptyEditableComboBox) { |
| 899 | ClickOnFormFieldAtPoint(102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 900 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 904 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 905 | |
| 906 | // Select entire contents of user-editable combobox text field to check that |
| 907 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 908 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 909 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 912 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 913 | InsertTextInPopulatedEditableComboBoxLeft) { |
| 914 | TypeTextIntoTextField(6, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 915 | |
| 916 | // Click on the leftmost part of the user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 917 | ClickOnFormFieldAtPoint(102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 918 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 922 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 923 | |
| 924 | // Select entire contents of user-editable combobox text field to check that |
| 925 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 926 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 927 | CheckSelection(L"HelloABCDEF"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 930 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 931 | InsertTextInPopulatedEditableComboBoxMiddle) { |
| 932 | TypeTextIntoTextField(6, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 933 | |
| 934 | // Click on the middle of the user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 935 | ClickOnFormFieldAtPoint(126.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 936 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 941 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 942 | |
| 943 | // Select entire contents of user-editable combobox text field to check that |
| 944 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 945 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 946 | CheckSelection(L"ABCHelloDEF"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 949 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
| 950 | InsertTextInPopulatedEditableComboBoxRight) { |
| 951 | TypeTextIntoTextField(6, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 952 | |
| 953 | // Click on the rightmost part of the user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 954 | ClickOnFormFieldAtPoint(150.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 955 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 959 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 960 | |
| 961 | // Select entire contents of user-editable combobox text field to check that |
| 962 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 963 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 964 | CheckSelection(L"ABCDEFHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 967 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 968 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxWhole) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 969 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 970 | |
| 971 | // Select entire string in user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 972 | SelectTextWithKeyboard(10, FWL_VKEY_Left, 183.0, 62.0); |
| 973 | CheckSelection(L"ABCDEFGHIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 974 | |
| 975 | // Test replacing text selection with text to be inserted. |
| 976 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 977 | GetFPDFWideString(L"Hello"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 978 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 979 | |
| 980 | // Select entire contents of user-editable combobox text field to check that |
| 981 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 982 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 983 | CheckSelection(L"Hello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 986 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 987 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxLeft) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 988 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 989 | |
| 990 | // Select left portion of string in user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 991 | SelectTextWithKeyboard(5, FWL_VKEY_Left, 142.0, 62.0); |
| 992 | CheckSelection(L"ABCDE"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 993 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 997 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 998 | |
| 999 | // Select entire contents of user-editable combobox text field to check that |
| 1000 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1001 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 1002 | CheckSelection(L"HelloFGHIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1005 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1006 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxMiddle) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1007 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1008 | |
| 1009 | // Select middle portion of string in user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1010 | SelectTextWithKeyboard(5, FWL_VKEY_Left, 167.0, 62.0); |
| 1011 | CheckSelection(L"DEFGH"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1012 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1016 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1017 | |
| 1018 | // Select entire contents of user-editable combobox text field to check that |
| 1019 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1020 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 1021 | CheckSelection(L"ABCHelloIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1024 | TEST_F(FPDFFormFillComboBoxFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1025 | InsertTextAndReplaceSelectionInPopulatedEditableComboBoxRight) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1026 | TypeTextIntoTextField(10, FPDF_FORMFIELD_COMBOBOX, 102.0, 62.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1027 | |
| 1028 | // Select right portion of string in user-editable combobox. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1029 | SelectTextWithKeyboard(5, FWL_VKEY_Left, 183.0, 62.0); |
| 1030 | CheckSelection(L"FGHIJ"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1031 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1035 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1036 | |
| 1037 | // Select entire contents of user-editable combobox text field to check that |
| 1038 | // insertion worked as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1039 | SelectTextWithMouse(183.0, 102.0, 62.0); |
| 1040 | CheckSelection(L"ABCDEHello"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1043 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1044 | InsertTextInEmptyCharLimitTextFieldOverflow) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1045 | // Click on the textfield. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1046 | ClickOnFormFieldAtPoint(195.0, 60.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1047 | |
| 1048 | // Delete pre-filled contents of text field with char limit. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1049 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1050 | CheckSelection(L"Elephant"); |
| 1051 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1052 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1057 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1058 | |
| 1059 | // Select entire contents of text field to check that insertion worked |
| 1060 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1061 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1062 | CheckSelection(L"Hippopotam"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1065 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1066 | InsertTextInEmptyCharLimitTextFieldFit) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1067 | // Click on the textfield. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1068 | ClickOnFormFieldAtPoint(195.0, 60.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1069 | |
| 1070 | // Delete pre-filled contents of text field with char limit. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1071 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1072 | CheckSelection(L"Elephant"); |
| 1073 | FORM_ReplaceSelection(form_handle(), page(), nullptr); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1074 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1079 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1080 | |
| 1081 | // Select entire contents of text field to check that insertion worked |
| 1082 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1083 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1084 | CheckSelection(L"Zebra"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1087 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1088 | InsertTextInPopulatedCharLimitTextFieldLeft) { |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1089 | // Click on the leftmost part of the text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1090 | ClickOnFormFieldAtPoint(102.0, 60.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1091 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1095 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1096 | |
| 1097 | // Select entire contents of text field to check that insertion worked |
| 1098 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1099 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1100 | CheckSelection(L"HiElephant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1103 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1104 | InsertTextInPopulatedCharLimitTextFieldMiddle) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1105 | TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1106 | |
| 1107 | // Click on the middle of the text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1108 | ClickOnFormFieldAtPoint(134.0, 60.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1109 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1113 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1114 | |
| 1115 | // Select entire contents of text field to check that insertion worked |
| 1116 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1117 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1118 | CheckSelection(L"ElephHiant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1121 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
| 1122 | InsertTextInPopulatedCharLimitTextFieldRight) { |
| 1123 | TypeTextIntoTextField(8, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1124 | |
| 1125 | // Click on the rightmost part of the text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1126 | ClickOnFormFieldAtPoint(166.0, 60.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1127 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1131 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1132 | |
| 1133 | // Select entire contents of text field to check that insertion worked |
| 1134 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1135 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1136 | CheckSelection(L"ElephantHi"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1139 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1140 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldWhole) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1141 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1142 | |
| 1143 | // Select entire string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1144 | SelectTextWithKeyboard(12, FWL_VKEY_Left, 195.0, 60.0); |
| 1145 | CheckSelection(L"Elephant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1146 | |
| 1147 | // Test replacing text selection with text to be inserted. |
| 1148 | std::unique_ptr<unsigned short, pdfium::FreeDeleter> text_to_insert = |
| 1149 | GetFPDFWideString(L"Hippopotamus"); |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1150 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1151 | |
| 1152 | // Select entire contents of text field to check that insertion worked |
| 1153 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1154 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1155 | CheckSelection(L"Hippopotam"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1158 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1159 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldLeft) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1160 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1161 | |
| 1162 | // Select left portion of string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1163 | SelectTextWithKeyboard(4, FWL_VKEY_Left, 122.0, 60.0); |
| 1164 | CheckSelection(L"Elep"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1165 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1169 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1170 | |
| 1171 | // Select entire contents of text field to check that insertion worked |
| 1172 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1173 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1174 | CheckSelection(L"Hippophant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1177 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1178 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldMiddle) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1179 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1180 | |
| 1181 | // Select middle portion of string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1182 | SelectTextWithKeyboard(4, FWL_VKEY_Left, 136.0, 60.0); |
| 1183 | CheckSelection(L"epha"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1184 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1188 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1189 | |
| 1190 | // Select entire contents of text field to check that insertion worked |
| 1191 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1192 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1193 | CheckSelection(L"ElHippopnt"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1196 | TEST_F(FPDFFormFillTextFormEmbeddertest, |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1197 | InsertTextAndReplaceSelectionInPopulatedCharLimitTextFieldRight) { |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1198 | TypeTextIntoTextField(12, FPDF_FORMFIELD_TEXTFIELD, 120.0, 120.0); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1199 | |
| 1200 | // Select right portion of string in text field. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1201 | SelectTextWithKeyboard(4, FWL_VKEY_Left, 152.0, 60.0); |
| 1202 | CheckSelection(L"hant"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1203 | |
| 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 Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1207 | FORM_ReplaceSelection(form_handle(), page(), text_to_insert.get()); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1208 | |
| 1209 | // Select entire contents of text field to check that insertion worked |
| 1210 | // as expected. |
Lei Zhang | 839692f | 2017-08-25 23:23:57 -0700 | [diff] [blame^] | 1211 | SelectTextWithMouse(195.0, 102.0, 60.0); |
| 1212 | CheckSelection(L"ElepHippop"); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 1213 | } |