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