Skip to content

Commit

Permalink
[ui][test] Use physical pixels in in-tree touch tests
Browse files Browse the repository at this point in the history
Note that I didn't touch flutter-embedder-test, since we're hoping to
delete that test soon.

Test: touch-input-test
Change-Id: If19ade41143e5f1cd63165ec420ebd9ee6eb9eae
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/781546
Commit-Queue: Alexander Brusher <abrusher@google.com>
Reviewed-by: Caroline Liu <carolineliu@google.com>
  • Loading branch information
abrush21 authored and gnoliyil committed Jan 27, 2024
1 parent 4ed65c0 commit deb9ce2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/ui/testing/util/portable_ui_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ void PortableUITest::RegisterTouchScreen() {
bool touchscreen_registered = false;
fuchsia::ui::test::input::RegistryRegisterTouchScreenRequest request;
request.set_device(fake_touchscreen_.NewRequest());
request.set_coordinate_unit(fuchsia::ui::test::input::CoordinateUnit::PHYSICAL_PIXELS);
input_registry_->RegisterTouchScreen(
std::move(request), [&touchscreen_registered]() { touchscreen_registered = true; });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ class DynamicHtmlPixelTests : public WebRunnerPixelTest {
auto touch = std::make_unique<fuchsia::ui::input::TouchscreenReport>();
switch (tap_location) {
case TapLocation::kTopLeft:
InjectTapWithRetry(/* x = */ -500, /* y = */ -500);
InjectTapWithRetry(/* x = */ display_width_ / 4, /* y = */ display_height_ / 4);
break;
case TapLocation::kTopRight:
InjectTapWithRetry(/* x = */ 500, /* y = */ -500);
InjectTapWithRetry(/* x = */ 3 * display_width_ / 4, /* y = */ display_height_ / 4);
break;
default:
FX_NOTREACHED();
Expand Down
34 changes: 15 additions & 19 deletions src/ui/tests/integration_input_tests/touch/touch-input-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ constexpr zx::duration kTimeout = zx::min(5);
// Maximum distance between two physical pixel coordinates so that they are considered equal.
constexpr float kEpsilon = 0.5f;

constexpr auto kTouchScreenMaxDim = 1000;
constexpr auto kTouchScreenMinDim = -1000;
// Number of move events to generate for swipe gestures.
constexpr auto kMoveEventCount = 5;

// The dimensions of the fake display used in tests. Used in calculating the expected distance
Expand Down Expand Up @@ -256,8 +255,8 @@ InjectSwipeParams GetLeftSwipeParams() {
}

return {.direction = SwipeGesture::LEFT,
.begin_x = kTouchScreenMaxDim,
.begin_y = 0,
.begin_x = kDisplayWidth,
.begin_y = kDisplayHeight / 2,
.expected_events = std::move(expected_events)};
}

Expand All @@ -276,8 +275,8 @@ InjectSwipeParams GetRightSwipeParams() {
}

return {.direction = SwipeGesture::RIGHT,
.begin_x = kTouchScreenMinDim,
.begin_y = 0,
.begin_x = 0,
.begin_y = kDisplayHeight / 2,
.expected_events = std::move(expected_events)};
}

Expand All @@ -296,8 +295,8 @@ InjectSwipeParams GetUpwardSwipeParams() {
}

return {.direction = SwipeGesture::UP,
.begin_x = 0,
.begin_y = kTouchScreenMaxDim,
.begin_x = kDisplayWidth / 2,
.begin_y = kDisplayHeight,
.expected_events = std::move(expected_events)};
}

Expand All @@ -316,8 +315,8 @@ InjectSwipeParams GetDownwardSwipeParams() {
}

return {.direction = SwipeGesture::DOWN,
.begin_x = 0,
.begin_y = kTouchScreenMinDim,
.begin_x = kDisplayWidth / 2,
.begin_y = 0,
.expected_events = std::move(expected_events)};
}

Expand Down Expand Up @@ -445,11 +444,11 @@ class TouchInputBase : public ui_testing::PortableUITest,
switch (tap_location) {
case TapLocation::kTopLeft:
// center of top right quadrant -> ends up as center of top left quadrant
InjectTap(/* x = */ 500, /* y = */ -500);
InjectTap(/* x = */ 3 * display_width_ / 4, /* y = */ display_height_ / 4);
break;
case TapLocation::kTopRight:
// center of bottom right quadrant -> ends up as center of top right quadrant
InjectTap(/* x = */ 500, /* y = */ 500);
InjectTap(/* x = */ 3 * display_width_ / 4, /* y = */ 3 * display_height_ / 4);
break;
default:
FX_NOTREACHED();
Expand Down Expand Up @@ -479,20 +478,17 @@ class TouchInputBase : public ui_testing::PortableUITest,
FX_NOTREACHED();
}

auto touchscreen_width = kTouchScreenMaxDim - kTouchScreenMinDim;
auto touchscreen_height = kTouchScreenMaxDim - kTouchScreenMinDim;

fuchsia::ui::test::input::TouchScreenSimulateSwipeRequest swipe_request;
swipe_request.mutable_start_location()->x = begin_x;
swipe_request.mutable_start_location()->y = begin_y;
swipe_request.mutable_end_location()->x = begin_x + x_dir * touchscreen_width;
swipe_request.mutable_end_location()->y = begin_y + y_dir * touchscreen_height;
swipe_request.mutable_end_location()->x = begin_x + x_dir * display_width();
swipe_request.mutable_end_location()->y = begin_y + y_dir * display_height();
// Generate move events 50 pixels apart.
swipe_request.set_move_event_count(kMoveEventCount);

InjectSwipe(/* start_x = */ begin_x, /* start_y = */ begin_y,
/* end_x = */ begin_x + x_dir * touchscreen_width,
/* end_y = */ begin_y + y_dir * touchscreen_height,
/* end_x = */ begin_x + x_dir * display_width(),
/* end_y = */ begin_y + y_dir * display_height(),
/* move_event_count = */ kMoveEventCount);
}

Expand Down

0 comments on commit deb9ce2

Please sign in to comment.