Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfwl_edit_embeddertest.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "xfa/fwl/cfwl_edit.h"
6
7#include <memory>
8
9#include "core/fxge/cfx_defaultrenderdevice.h"
10#include "public/fpdf_ext.h"
11#include "public/fpdf_formfill.h"
12#include "public/fpdf_fwlevent.h"
13#include "testing/embedder_test.h"
14#include "testing/embedder_test_environment.h"
15#include "testing/embedder_test_timer_handling_delegate.h"
16#include "testing/gtest/include/gtest/gtest.h"
17#include "testing/xfa_js_embedder_test.h"
18
19namespace {
20
21const char kEmailRecommendedFilledChecksum[] =
22 "211e4e46eb347aa2bc7c425556d600b0";
23
24} // namespace
25
27 protected:
28 void SetUp() override {
30 SetDelegate(&delegate_);
31
32 // Arbitrary, picked nice even number, 2020-09-13 12:26:40.
33 FSDK_SetTimeFunction([]() -> time_t { return 1600000000; });
34 FSDK_SetLocaltimeFunction([](const time_t* t) { return gmtime(t); });
35 }
36
40 // TODO(crbug.com/pdfium/11): A page might not have been loaded if a test
41 // is skipped at runtime. This check for a non-null page should be able to
42 // removed once none of the tests are being skipped for Skia.
43 if (page())
46 }
47
48 void CreateAndInitializeFormPDF(const char* filename) {
49 ASSERT_TRUE(OpenDocument(filename));
50 page_ = LoadPage(0);
51 ASSERT_TRUE(page_);
52 }
53
54 FPDF_PAGE page() const { return page_; }
55 EmbedderTestTimerHandlingDelegate delegate() const { return delegate_; }
56
57 private:
58 FPDF_PAGE page_ = nullptr;
59 EmbedderTestTimerHandlingDelegate delegate_;
60};
61
63 CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
64 ASSERT_EQ(0u, delegate().GetAlerts().size());
65}
66
68 CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
69 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
70 for (size_t i = 0; i < 10; ++i)
71 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
72
73 // Mouse selection
74 FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58);
75 FORM_OnLButtonDown(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58);
76
77 // 12 == (2 * strlen(defgh)) + 2 (for \0\0)
78 ASSERT_EQ(12U, FORM_GetSelectedText(form_handle(), page(), nullptr, 0));
79
80 uint16_t buf[6];
81 ASSERT_EQ(12U,
82 FORM_GetSelectedText(form_handle(), page(), &buf, sizeof(buf)));
83 EXPECT_EQ("defgh", GetPlatformString(buf));
84}
85
87 // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
88 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
89 return;
90 }
91
92 CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
93 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
94 for (size_t i = 0; i < 10; ++i)
95 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
96
97 // Mouse selection
98 FORM_OnLButtonDown(form_handle(), page(), 0, 128, 58);
99 FORM_OnMouseMove(form_handle(), page(), FWL_EVENTFLAG_ShiftKey, 152, 58);
100
101 // 12 == (2 * strlen(defgh)) + 2 (for \0\0)
102 ASSERT_EQ(12U, FORM_GetSelectedText(form_handle(), page(), nullptr, 0));
103
104 uint16_t buf[6];
105 ASSERT_EQ(12U,
106 FORM_GetSelectedText(form_handle(), page(), &buf, sizeof(buf)));
107 EXPECT_EQ("defgh", GetPlatformString(buf));
108
109 // TODO(hnakashima): This is incorrect. Visually 'abcdefgh' are selected.
110 const char kDraggedMD5[] = "f131526c8edd04e44de17b2647ec54c8";
111 {
112 ScopedFPDFBitmap page_bitmap =
113 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
114 CompareBitmap(page_bitmap.get(), 612, 792, kDraggedMD5);
115 }
116}
117
119 // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
120 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
121 return;
122 }
123
124 CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
125 const char kBlankMD5[] = "8dda78a3afaf9f7b5210eb81cacc4600";
126 {
127 ScopedFPDFBitmap page_bitmap =
128 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
129 CompareBitmap(page_bitmap.get(), 612, 792, kBlankMD5);
130 }
131
132 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
133 for (size_t i = 0; i < 10; ++i)
134 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
135
136 {
137 ScopedFPDFBitmap page_bitmap =
138 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
139 CompareBitmap(page_bitmap.get(), 612, 792, kEmailRecommendedFilledChecksum);
140 }
141}
142
144 // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
145 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
146 return;
147 }
148
149 CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
150 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
151 for (size_t i = 0; i < 5; ++i)
152 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
153 FORM_OnChar(form_handle(), page(), '\r', 0);
154 for (size_t i = 5; i < 10; ++i)
155 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
156
157 {
158 ScopedFPDFBitmap page_bitmap =
159 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
160 CompareBitmap(page_bitmap.get(), 612, 792, kEmailRecommendedFilledChecksum);
161 }
162}
163
164// Disabled due to flakiness.
166 CreateAndInitializeFormPDF("xfa/xfa_multiline_textfield.pdf");
167 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
168
169 for (size_t i = 0; i < 5; ++i)
170 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
171 FORM_OnChar(form_handle(), page(), '\r', 0);
172 for (size_t i = 5; i < 10; ++i)
173 FORM_OnChar(form_handle(), page(), 'a' + i, 0);
174
175 // Should look like:
176 // abcde
177 // fghij|
178 {
179#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
180 const char kFilledMultilineMD5[] = "fc1f4d5fdb2c5755005fc525b0a60ec9";
181#else
182 const char kFilledMultilineMD5[] = "a5654e027d8b1667c20f3b86d1918003";
183#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
184 ScopedFPDFBitmap page_bitmap =
185 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
186 CompareBitmap(page_bitmap.get(), 612, 792, kFilledMultilineMD5);
187 }
188
189 for (size_t i = 0; i < 4; ++i)
190 FORM_OnKeyDown(form_handle(), page(), FWL_VKEY_Left, 0);
191
192 // Should look like:
193 // abcde
194 // f|ghij
195
196 // Two backspaces is a workaround because left arrow does not behave well
197 // in the first character of a line. It skips back to the previous line.
198 for (size_t i = 0; i < 2; ++i)
199 FORM_OnChar(form_handle(), page(), '\b', 0);
200
201 // Should look like:
202 // abcde|ghij
203 {
204#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
205 const char kMultilineBackspaceMD5[] = "8bb62a8100ff1e1cc113d4033e0d824e";
206#else
207 const char kMultilineBackspaceMD5[] = "a2f1dcab92bb1fb7c2f9ccc70100c989";
208#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
209 ScopedFPDFBitmap page_bitmap =
210 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
211 CompareBitmap(page_bitmap.get(), 612, 792, kMultilineBackspaceMD5);
212 }
213}
214
216 // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
217 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
218 return;
219 }
220
221 CreateAndInitializeFormPDF("xfa/xfa_date_time_edit.pdf");
222
223 // Give focus to date time widget, creating down-arrow button.
224 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
225 FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58);
226 const char kSelectedMD5[] = "1036b8837a9dba75c6bd8f9347ae2eb2";
227 {
228 ScopedFPDFBitmap page_bitmap =
229 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
230 CompareBitmap(page_bitmap.get(), 612, 792, kSelectedMD5);
231 }
232
233 // Click down-arrow button, bringing up calendar widget.
234 FORM_OnLButtonDown(form_handle(), page(), 0, 446, 54);
235 FORM_OnLButtonUp(form_handle(), page(), 0, 446, 54);
236 {
237 ScopedFPDFBitmap page_bitmap =
238 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
239
240 // TODO(tsepez): hermetic fonts.
241 // const char kCalendarOpenMD5[] = "02de64e7e83c82c1ef0ae484d671a51d";
242 // CompareBitmap(page_bitmap.get(), 612, 792, kCalendarOpenMD5);
243 }
244
245 // Click on date on calendar, putting result into field as text.
246 FORM_OnLButtonDown(form_handle(), page(), 0, 100, 162);
247 FORM_OnLButtonUp(form_handle(), page(), 0, 100, 162);
248 {
249 ScopedFPDFBitmap page_bitmap =
250 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
251
252 // TODO(tsepez): hermetic fonts.
253 // const char kFilledMD5[] = "1bce66c11f1c87b8d639ce0076ac36d3";
254 // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
255 }
256}
257
259 CreateAndInitializeFormPDF("xfa/xfa_image_edit.pdf");
260 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
261 const char* filled_checksum = []() {
262 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
263 return "23658ed124114f05518372d41c80e41b";
264 }
265 return "101cf6223fa2403fba4c413a8310ab02";
266 }();
267 ScopedFPDFBitmap page_bitmap = RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
268 CompareBitmap(page_bitmap.get(), 612, 792, filled_checksum);
269}
270
272 CreateAndInitializeFormPDF("xfa/xfa_combobox.pdf");
273
274 // Give focus to widget.
275 FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
276 FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58);
277 {
278 const char* filled_checksum = []() {
279 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
280 return "8c555487e09ee4acf3ace77db5929bdc";
281 }
282 return "dad642ae8a5afce2591ffbcabbfc58dd";
283 }();
284 ScopedFPDFBitmap page_bitmap =
285 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
286 CompareBitmap(page_bitmap.get(), 612, 792, filled_checksum);
287 }
288
289 // Click on down-arrow button, dropdown list appears.
290 FORM_OnLButtonDown(form_handle(), page(), 0, 438, 53);
291 FORM_OnLButtonUp(form_handle(), page(), 0, 438, 53);
292 {
293 ScopedFPDFBitmap page_bitmap =
294 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
295 // TODO(tsepez): hermetic fonts.
296 // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
297 // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
298 }
299
300 // Enter drop-down list, selection highlighted.
301 FORM_OnMouseMove(form_handle(), page(), 0, 253, 107);
302 {
303 ScopedFPDFBitmap page_bitmap =
304 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
305 // TODO(tsepez): hermetic fonts.
306 // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
307 // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
308 }
309
310 // Click on selection, putting result into field.
311 FORM_OnLButtonDown(form_handle(), page(), 0, 253, 107);
312 FORM_OnLButtonUp(form_handle(), page(), 0, 253, 107);
313 {
314 ScopedFPDFBitmap page_bitmap =
315 RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
316 // TODO(tsepez): hermetic fonts.
317 // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
318 // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
319 }
320}
TEST_F(CFWLEditEmbedderTest, Trivial)
EmbedderTestTimerHandlingDelegate delegate() const
void CreateAndInitializeFormPDF(const char *filename)
void SetUp() override
void TearDown() override
void UnloadPage(FPDF_PAGE page)
FPDF_PAGE LoadPage(int page_number)
FPDF_EXPORT void FPDF_CALLCONV FSDK_SetLocaltimeFunction(struct tm *(*func)(const time_t *))
Definition fpdf_ext.cpp:80
FPDF_EXPORT void FPDF_CALLCONV FSDK_SetTimeFunction(time_t(*func)())
Definition fpdf_ext.cpp:75
@ FWL_EVENTFLAG_ShiftKey
@ FWL_VKEY_Left
#define FPDF_ANNOT
Definition fpdfview.h:804