Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix semantics_tester #34368

Merged
merged 7 commits into from
Jun 13, 2019
Merged

Fix semantics_tester #34368

merged 7 commits into from
Jun 13, 2019

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Jun 13, 2019

Description

Semantics_tester was broken. If a node had multiple children, it was checking the first and then bailing.

Fixing that has revealed other bugs.

I talked with @GaryQian and I think the test_text tests now have the correct fixes applied in paragraph.dart. Gary to review.

I'm not as confident on the other changes - DatePicker seems like it may be right now, but not sure why we get all those empty nodes. /cc @goderbauer and/or @darrenaustin we get them because there are empty container placeholders there.

Sliver tests I think are right - they were just missing implicit scrolling flags and not caught previously due to this bug.

Semantics traversal test seems like it may be a different bug. It's possible the 64 bit rect stuff impacted this and we didn't catch it because of the brokeness of the tester.

This regression was introduced in #16253, where a return true that used to live in a closure was moved to a for loop.

Related Issues

Fixes #34363

Tests

I added the following tests:

Added a sanity check for the tester. This test fails without these changes. This is similar to a test I was trying to write, and I was confused about why it was passing when it was so clearly wrong.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@@ -202,13 +202,13 @@ void main() {
await tester.test(
textDirection: TextDirection.ltr,
children: children,
expectedTraversal: 'A B C D E F G H I J K L M',
expectedTraversal: 'A B C D E G H F I J K L M',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ... odd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think something's wrong here.

Unfortunately, the regression in semantics_tester was introduced in the same commit where these tests were added. I tried checking out d354096 and modifying the tester so that it's closer to the state in this PR and those tests still pass. I'll try to figure out what's going on here, unless @yjbanov might know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this regressed in f2442b8, which was part of v0.8.0 tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And wasn't caught because the tester was broken)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this sorted out - changed the deflate constant from 0.1 to 1e-15. Anything bigger than 1e-15 was failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed this back to .1. The right fix is to update the traversal logic.

@@ -496,6 +496,17 @@ void main() {
label: routeName,
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't correct, we have to put a sort key on it I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong if things are dumped in traversal order (which I think they are).

I am surprised that it would need a sort key, though. The suggestions come physically after the back button and the text field.

(We should verify that talkback and voiceover do the right thing here on device)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually how things are ordered today. It's not very clear to me why that's the case - even without any changes here. Filed #34432 and added a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline - will close the other bug. Traversal order test was broken and needed to be updated.

@@ -414,7 +414,7 @@ void main() {
TestSemantics(
label: 'INTERRUPTION',
textDirection: TextDirection.rtl,
rect: const Rect.fromLTRB(448.0, 0.0, 488.0, 80.0),
rect: const Rect.fromLTRB(0.0, 0.0, 40.0, 80.0),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GaryQian is this expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may actually be a bug, but I'll look at that separately. I think in practice the rects still show up in the right place after transforms, but it may be better to make sure the values are rolled into here too. I think we can go ahead with this for now in the context of your semantics fix and ill fix this when I take a deeper look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't fix this here, we should at least file an issue and link it from here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have a fix for this that I'll be landing separately. I have a patch ready to go that will be changing this again, but don't want to fiddle with it or risk having yet another piece to worry about as this patch is blcoking the google3 roll now.

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for changes to rect deflate

@@ -2230,7 +2230,7 @@ class _SemanticsSortGroup extends Comparable<_SemanticsSortGroup> {
final List<_BoxEdge> edges = <_BoxEdge>[];
for (SemanticsNode child in nodes) {
// Using a small delta to shrink child rects removes overlapping cases.
final Rect childRect = child.rect.deflate(0.1);
final Rect childRect = child.rect.deflate(1e-15);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be the right fix. The rects are deflated not to remove rounding errors, but to remove minor (even if visible) overlaps from consideration. Crazy idea: what if you not fix this? Instead, change the test, leave a TODO and file a bug to address this more carefully.

/cc @jonahwilliams

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought with this is that removing a trivially small amount like this should still make them not evaluate as overlapping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our original thought here was that even when things are overlapping visibly, if the overlap is smallish, it shouldn't count as overlapping...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That ends up breaking traversal order :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's the vote here? Add the very small deflate, or remove it entirely and add a TODO?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canonical example is the categories on the flutter gallery home page. It should go left to right, but before it was going top to bottom.

If it still goes left to right with this change I'm okay with it. If it doesn't, we might as well remove the deflate and go back to the drawing board

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The categories sample still worked with this change, but it's actually the traversal order we want to change (which was going top to bottom instead of left to right). I've updated that test to go left to right and put back the deflate to 0.1.

@yjbanov
Copy link
Contributor

yjbanov commented Jun 13, 2019

Good catch! Thanks for fixing!

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

children: <TestSemantics>[
TestSemantics(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have all these extra empty nodes? They really shouldn't be here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they're containers/placeholders to make the calendar day fall under the right slot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty placeholders should not have a semantics node, though. I thought we filter those out...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're from the ExcludeSemantics around the weekday header and more empty nodes for the containers for placeholders.

So 7 weekday headers + 5 placeholder containers = 12 empty semantics nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with changing that but I think if we do it should be in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, Can you add a TODO and file an issue so it doesn't get lost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -496,6 +496,17 @@ void main() {
label: routeName,
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong if things are dumped in traversal order (which I think they are).

I am surprised that it would need a sort key, though. The suggestions come physically after the back button and the text field.

(We should verify that talkback and voiceover do the right thing here on device)

@@ -2230,7 +2230,7 @@ class _SemanticsSortGroup extends Comparable<_SemanticsSortGroup> {
final List<_BoxEdge> edges = <_BoxEdge>[];
for (SemanticsNode child in nodes) {
// Using a small delta to shrink child rects removes overlapping cases.
final Rect childRect = child.rect.deflate(0.1);
final Rect childRect = child.rect.deflate(1e-15);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our original thought here was that even when things are overlapping visibly, if the overlap is smallish, it shouldn't count as overlapping...

@@ -0,0 +1,44 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for adding these tests! Thank you!

@goderbauer
Copy link
Member

we get them because there are empty container placeholders there.

What does this mean? Empty containers should not produce a semantics node?

@GaryQian
Copy link
Contributor

Paragraph changes LGTM!

@Piinks Piinks added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Jun 13, 2019
@dnfield dnfield mentioned this pull request Jun 13, 2019
9 tasks
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you!

@dnfield dnfield merged commit ea6b758 into flutter:master Jun 13, 2019
@dnfield dnfield deleted the semantic_test_fix branch June 13, 2019 23:15
kiku-jw pushed a commit to kiku-jw/flutter that referenced this pull request Jun 14, 2019
tango5614 added a commit to tango5614/flutter that referenced this pull request Jun 14, 2019
* master: (24 commits)
  [flutter_tool,fuchsia] Update the install flow for packaging migration. (flutter#34447)
  SliverFillRemaining flag for different use cases (flutter#33627)
  SizedBox documentation (flutter#34424)
  Change API doc link to api.dart.dev (flutter#34388)
  2589785 Roll src/third_party/skia 87e885038893..c3252a04b377 (3 commits) (flutter/engine#9327) (flutter#34484)
  ace5d59 Fix rawTypes errors in Android embedding classes (flutter/engine#9326) (flutter#34481)
  bf0def6 Roll src/third_party/skia 4c4945a25248..87e885038893 (1 commits) (flutter/engine#9325) (flutter#34471)
  Roll engine f1d821d..6f5347c (13 commits) (flutter#34466)
  Allow "from" hero state to survive hero animation in a push transition (flutter#32842)
  Roll pub dependencies (flutter#33677)
  Skip flaky test on Windows (flutter#34464)
  Allow flaky tests to pass or fail and mark web tests as flaky (flutter#34456)
  Dont depend on web SDK unless running tests on chrome (flutter#34457)
  Fix semantics_tester (flutter#34368)
  Include raw value in Diagnostics json for basic types (flutter#34417)
  Refactor Gradle plugin (flutter#34353)
  Allow web tests to fail in cirrus config (flutter#34436)
  skip bottom_sheet (flutter#34430)
  Remove unused flag `--target-platform` from `flutter run` (flutter#34369)
  Extract DiagnosticsNode serializer from WidgetInspector (flutter#34012)
  ...
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SemanticsTester doesn't match correctly on last child
7 participants