Open Bug 1835432 Opened 3 years ago Updated 3 years ago

Improve coordinate system safety in APZ mochitests

Categories

(Core :: Panning and Zooming, task, P3)

task

Tracking

()

People

(Reporter: botond, Unassigned)

Details

A recurring pain point in writing APZ mochitests has been that our test utilities take their inputs in a variety of coordinate systems, but unlike in C++, we don't have a type system to enforce that we're passing in the right kinds of coordinates.

For example:

  • promiseNativeMouseEventWithAPZ() and similar functions that take an aTarget parameter, requires CSS coordinates relative to the target
    • Often we use window as the target, in which case this means CSS coordinates relative to the visual viewport.
  • hitTest() requires CSS coordinates relative to the layout viewport
  • Direct calls to nsIDOMWindowUtils.sendNative*() require screen coordinates relative to the screen origin
  • Element.getBoundingClientRect() returns CSS coordinates relative to the layout viewport

Until we have a more systematic way to express these requirements (for example, by adopting Typescript and using different types for different coordinate systems the way we do in C++), I'd like to suggest that we add a way to express coordinate system annotations as runtime values and check/enforce them using runtime checks.

A concrete way this could work:

  • Test helpers that currently accept a pair of coordinates (or a rect etc.) also accept an additional input parameter of e.g. an enum type which specifies what coordinate system the coordinates are in.
  • Test helpers either assert that their input is in the coordinate system they expect, or (if possible) convert their input from the specified coordinate system to the one they need.
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.