From 08b6819660a69cdc83bd133d1074da5813d9e414 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Tue, 26 Jun 2018 15:28:28 +0000 Subject: Write pixel .evt test for dynamic_list_box_allow_multiple_selection. Improve the .evt mechanism to accept mouse clicks with modifiers (such as shift). Bug: pdfium:1105 Change-Id: I6e9c2c1f66b7fde250b55b41ccdf115a311f44f7 Reviewed-on: https://pdfium-review.googlesource.com/36091 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- samples/pdfium_test_event_helper.cc | 171 ++++++++++++++------- testing/SUPPRESSIONS | 2 - .../dynamic_list_box_allow_multiple_selection.evt | 5 + ...box_allow_multiple_selection_expected.pdf.0.png | Bin 0 -> 14435 bytes ...allow_multiple_selection_expected_mac.pdf.0.png | Bin 0 -> 14452 bytes 5 files changed, 121 insertions(+), 57 deletions(-) create mode 100644 testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection.evt create mode 100644 testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected.pdf.0.png create mode 100644 testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected_mac.pdf.0.png diff --git a/samples/pdfium_test_event_helper.cc b/samples/pdfium_test_event_helper.cc index 9643da1ef3..303feee6a4 100644 --- a/samples/pdfium_test_event_helper.cc +++ b/samples/pdfium_test_event_helper.cc @@ -7,10 +7,120 @@ #include #include +#include +#include "public/fpdf_fwlevent.h" #include "public/fpdfview.h" #include "testing/test_support.h" +namespace { +void SendCharCodeEvent(FPDF_FORMHANDLE form, + FPDF_PAGE page, + const std::vector& tokens) { + if (tokens.size() != 2) { + fprintf(stderr, "charcode: bad args\n"); + return; + } + + int keycode = atoi(tokens[1].c_str()); + FORM_OnChar(form, page, keycode, 0); +} + +void SendKeyCodeEvent(FPDF_FORMHANDLE form, + FPDF_PAGE page, + const std::vector& tokens) { + if (tokens.size() != 2) { + fprintf(stderr, "keycode: bad args\n"); + return; + } + + int keycode = atoi(tokens[1].c_str()); + FORM_OnKeyDown(form, page, keycode, 0); + FORM_OnKeyUp(form, page, keycode, 0); +} + +uint32_t GetModifiers(std::string modifiers_string) { + int modifiers = 0; + if (modifiers_string.find("shift") != std::string::npos) + modifiers |= FWL_EVENTFLAG_ShiftKey; + if (modifiers_string.find("control") != std::string::npos) + modifiers |= FWL_EVENTFLAG_ControlKey; + if (modifiers_string.find("alt") != std::string::npos) + modifiers |= FWL_EVENTFLAG_AltKey; + + return modifiers; +} + +void SendMouseDownEvent(FPDF_FORMHANDLE form, + FPDF_PAGE page, + const std::vector& tokens) { + if (tokens.size() != 4 && tokens.size() != 5) { + fprintf(stderr, "mousedown: bad args\n"); + return; + } + + int x = atoi(tokens[2].c_str()); + int y = atoi(tokens[3].c_str()); + uint32_t modifiers = tokens.size() >= 5 ? GetModifiers(tokens[4]) : 0; + + if (tokens[1] == "left") + FORM_OnLButtonDown(form, page, modifiers, x, y); +#ifdef PDF_ENABLE_XFA + else if (tokens[1] == "right") + FORM_OnRButtonDown(form, page, modifiers, x, y); +#endif + else + fprintf(stderr, "mousedown: bad button name\n"); +} + +void SendMouseUpEvent(FPDF_FORMHANDLE form, + FPDF_PAGE page, + const std::vector& tokens) { + if (tokens.size() != 4 && tokens.size() != 5) { + fprintf(stderr, "mouseup: bad args\n"); + return; + } + + int x = atoi(tokens[2].c_str()); + int y = atoi(tokens[3].c_str()); + int modifiers = tokens.size() >= 5 ? GetModifiers(tokens[4]) : 0; + if (tokens[1] == "left") + FORM_OnLButtonUp(form, page, modifiers, x, y); +#ifdef PDF_ENABLE_XFA + else if (tokens[1] == "right") + FORM_OnRButtonUp(form, page, modifiers, x, y); +#endif + else + fprintf(stderr, "mouseup: bad button name\n"); +} + +void SendMouseMoveEvent(FPDF_FORMHANDLE form, + FPDF_PAGE page, + const std::vector& tokens) { + if (tokens.size() != 3) { + fprintf(stderr, "mousemove: bad args\n"); + return; + } + + int x = atoi(tokens[1].c_str()); + int y = atoi(tokens[2].c_str()); + FORM_OnMouseMove(form, page, 0, x, y); +} + +void SendFocusEvent(FPDF_FORMHANDLE form, + FPDF_PAGE page, + const std::vector& tokens) { + if (tokens.size() != 3) { + fprintf(stderr, "focus: bad args\n"); + return; + } + + int x = atoi(tokens[1].c_str()); + int y = atoi(tokens[2].c_str()); + FORM_OnFocus(form, page, 0, x, y); +} +} // namespace + void SendPageEvents(FPDF_FORMHANDLE form, FPDF_PAGE page, const std::string& events) { @@ -21,66 +131,17 @@ void SendPageEvents(FPDF_FORMHANDLE form, continue; auto tokens = StringSplit(command[0], ','); if (tokens[0] == "charcode") { - if (tokens.size() == 2) { - int keycode = atoi(tokens[1].c_str()); - FORM_OnChar(form, page, keycode, 0); - } else { - fprintf(stderr, "charcode: bad args\n"); - } + SendCharCodeEvent(form, page, tokens); } else if (tokens[0] == "keycode") { - if (tokens.size() == 2) { - int keycode = atoi(tokens[1].c_str()); - FORM_OnKeyDown(form, page, keycode, 0); - FORM_OnKeyUp(form, page, keycode, 0); - } else { - fprintf(stderr, "keycode: bad args\n"); - } + SendKeyCodeEvent(form, page, tokens); } else if (tokens[0] == "mousedown") { - if (tokens.size() == 4) { - int x = atoi(tokens[2].c_str()); - int y = atoi(tokens[3].c_str()); - if (tokens[1] == "left") - FORM_OnLButtonDown(form, page, 0, x, y); -#ifdef PDF_ENABLE_XFA - else if (tokens[1] == "right") - FORM_OnRButtonDown(form, page, 0, x, y); -#endif - else - fprintf(stderr, "mousedown: bad button name\n"); - } else { - fprintf(stderr, "mousedown: bad args\n"); - } + SendMouseDownEvent(form, page, tokens); } else if (tokens[0] == "mouseup") { - if (tokens.size() == 4) { - int x = atoi(tokens[2].c_str()); - int y = atoi(tokens[3].c_str()); - if (tokens[1] == "left") - FORM_OnLButtonUp(form, page, 0, x, y); -#ifdef PDF_ENABLE_XFA - else if (tokens[1] == "right") - FORM_OnRButtonUp(form, page, 0, x, y); -#endif - else - fprintf(stderr, "mouseup: bad button name\n"); - } else { - fprintf(stderr, "mouseup: bad args\n"); - } + SendMouseUpEvent(form, page, tokens); } else if (tokens[0] == "mousemove") { - if (tokens.size() == 3) { - int x = atoi(tokens[1].c_str()); - int y = atoi(tokens[2].c_str()); - FORM_OnMouseMove(form, page, 0, x, y); - } else { - fprintf(stderr, "mousemove: bad args\n"); - } + SendMouseMoveEvent(form, page, tokens); } else if (tokens[0] == "focus") { - if (tokens.size() == 3) { - int x = atoi(tokens[1].c_str()); - int y = atoi(tokens[2].c_str()); - FORM_OnFocus(form, page, 0, x, y); - } else { - fprintf(stderr, "focus: bad args\n"); - } + SendFocusEvent(form, page, tokens); } else { fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str()); } diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS index 417d3018e3..ed2973c2ee 100644 --- a/testing/SUPPRESSIONS +++ b/testing/SUPPRESSIONS @@ -328,8 +328,6 @@ bug_492.in * nov8 * # xfa_specific -# TODO(pdfium:1105): Remove after associated bug is fixed -dynamic_list_box_allow_multiple_selection.pdf * * * # TODO(pdfium:1107): Remove after associated bug is fixed standard_symbols.pdf * * * # TODO(pdfium:1095): Remove after associated bug is fixed diff --git a/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection.evt b/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection.evt new file mode 100644 index 0000000000..ec52e98864 --- /dev/null +++ b/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection.evt @@ -0,0 +1,5 @@ +mousedown,left,370,114 +mouseup,left,370,114 + +mousedown,left,370,145,shift +mouseup,left,370,145,shift diff --git a/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected.pdf.0.png b/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected.pdf.0.png new file mode 100644 index 0000000000..da0687a41f Binary files /dev/null and b/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected.pdf.0.png differ diff --git a/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected_mac.pdf.0.png b/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected_mac.pdf.0.png new file mode 100644 index 0000000000..9ba2f38195 Binary files /dev/null and b/testing/resources/pixel/xfa_specific/dynamic_list_box_allow_multiple_selection_expected_mac.pdf.0.png differ -- cgit v1.2.3