Skip to content

Commit

Permalink
Fix subtle test bug with position rounding.
Browse files Browse the repository at this point in the history
  • Loading branch information
ditman committed Jan 3, 2024
1 parent 10bd379 commit 0a97125
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final Finder clickableWrappedButtonFinder =
find.byKey(const Key('wrapped-transparent-button'));
final Finder clickableButtonFinder = find.byKey(const Key('clickable-button'));
final Finder backgroundFinder =
find.byKey(const ValueKey<String>('background-widget'));
find.byKey(const Key('background-widget'));

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -148,7 +148,11 @@ web.Element _getHtmlElementAt(Offset point) {
// the contents of <flt-glass-name> as an implementation detail.
final web.ShadowRoot glassPaneShadow =
web.document.querySelector('flt-glass-pane')!.shadowRoot!;
return glassPaneShadow.elementFromPoint(point.dx.toInt(), point.dy.toInt());
// Use `round` below to ensure clicks always fall *inside* the located
// element, rather than truncating the decimals.
// Truncating decimals makes some tests fail when a centered element (in high
// DPI) is not exactly aligned to the pixel grid (because the browser *rounds*)
return glassPaneShadow.elementFromPoint(point.dx.round(), point.dy.round());
}

/// Shady API: https://github.com/w3c/csswg-drafts/issues/556
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _MyHomePageState extends State<MyHomePage> {
alignment: Alignment.center,
children: <Widget>[
HtmlElement(
key: const ValueKey<String>('background-widget'),
key: const Key('background-widget'),
onClick: () {
_clickedOn('html-element');
},
Expand Down

0 comments on commit 0a97125

Please sign in to comment.