[xfa] Cover CFWL_MonthCalendar as part of embedder tests
Precise clicks in a date time picker plus rendering the page in
the intermediate states is required to draw the calendar, pick
a date, and stuff that date into the field.
-- Tests hobbled by cross-platform font issues.
-- Confirmed dumped images on local platform.
-- Add cpwl_edit.h to correspond test per style guide.
Change-Id: I2eab7906583b031d8cc8ca9d4ce9e69aaa7938ce
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93830
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 8b094ad..7529f9c 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -125,6 +125,9 @@
pdfium_embeddertest_source_set("embeddertests") {
sources = [ "cfwl_edit_embeddertest.cpp" ]
- deps = [ "../../fxjs:gc" ]
+ deps = [
+ ":fwl",
+ "../../fxjs:gc",
+ ]
pdfium_root_dir = "../../"
}
diff --git a/xfa/fwl/cfwl_edit_embeddertest.cpp b/xfa/fwl/cfwl_edit_embeddertest.cpp
index 59254c4..a409610 100644
--- a/xfa/fwl/cfwl_edit_embeddertest.cpp
+++ b/xfa/fwl/cfwl_edit_embeddertest.cpp
@@ -2,10 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "xfa/fwl/cfwl_edit.h"
+
+#include <memory>
+
#include "core/fxcrt/widestring.h"
+#include "public/fpdf_ext.h"
#include "public/fpdf_formfill.h"
#include "public/fpdf_fwlevent.h"
#include "testing/embedder_test.h"
+#include "testing/embedder_test_environment.h"
#include "testing/embedder_test_timer_handling_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/xfa_js_embedder_test.h"
@@ -22,9 +28,15 @@
void SetUp() override {
EmbedderTest::SetUp();
SetDelegate(&delegate_);
+
+ // Arbitrary, picked nice even number, 2020-09-13 12:26:40.
+ FSDK_SetTimeFunction([]() -> time_t { return 1600000000; });
+ FSDK_SetLocaltimeFunction([](const time_t* t) { return gmtime(t); });
}
void TearDown() override {
+ FSDK_SetTimeFunction(nullptr);
+ FSDK_SetLocaltimeFunction(nullptr);
UnloadPage(page());
EmbedderTest::TearDown();
}
@@ -206,13 +218,39 @@
#endif
TEST_F(CFWLEditEmbedderTest, MAYBE_DateTimePickerTest) {
CreateAndInitializeFormPDF("xfa/xfa_date_time_edit.pdf");
- FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
- const char kFilledMD5[] = "1036b8837a9dba75c6bd8f9347ae2eb2";
+ // Give focus to date time widget, creating down-arrow button.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58);
+ const char kSelectedMD5[] = "1036b8837a9dba75c6bd8f9347ae2eb2";
{
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
- CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ CompareBitmap(page_bitmap.get(), 612, 792, kSelectedMD5);
+ }
+
+ // Click down-arrow button, bringing up calendar widget.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 446, 54);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 446, 54);
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+
+ // TODO(tsepez): hermetic fonts.
+ // const char kCalendarOpenMD5[] = "02de64e7e83c82c1ef0ae484d671a51d";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kCalendarOpenMD5);
+ }
+
+ // Click on date on calendar, putting result into field as text.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 100, 162);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 100, 162);
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+
+ // TODO(tsepez): hermetic fonts.
+ // const char kFilledMD5[] = "1bce66c11f1c87b8d639ce0076ac36d3";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
}
}