Skip to content

simulatedAccessibilityTraversal doesn't account for explicit/force-merging (via MergeSemantics) #135144

@marcianx

Description

@marcianx

Is there an existing issue for this?

Steps to reproduce

  1. Use MergeSemantics to wrap one or more multiple widgets that emit Semantics(container: true) to consolidate the semantics tree.
  2. Test the semantics of the consolidated widget using tester.semantics.simulatedAccessibilityTraversal().

See code further below.

Expected results

Per @goderbauer, simulatedAccessibilityTraversal() should account for the force-merging to enable unit testing of MergeSemantics-based code. Effectively, it should be testing a SemanticsData tree to capture the platform accessibility tree that will be generated from the semantics tree.

Actual results

simulatedAccessibilityTraversal() enumerates the semantics tree as-is, including all SemanticsNodes that are merged upward. It does not use the SemanticsData due to force-merging.

Maybe this is inherent to the API? Should it be deprecated in favor of a new API that emits SemanticsData (and also exposes the number of children so that we can assert when something should be a leaf node)? Is it possible to test the structure of the platform accessibility that will be generated?

Code sample

https://dartpad.dev/?id=06937c78a65c3c3daf75eb81648b1783

Code sample
await tester.pumpWidget(
  MaterialApp(
    home: MergeSemantics(
      child: Semantics(
        container: true,
        label: 'Container',
        child: Semantics(
          button: true,
          container: true,
          label: 'Foo',
          child: const SizedBox(width: 10, height: 10),
        ),
      ),
    ),
  ),
);

// Fails since `simulatedAccessibilityTraversal` doesn't account
// for force-merging.
expect(
  tester.semantics.simulatedAccessibilityTraversal(),
  [containsSemantics(label: 'Container\nFoo', isButton: true)],
);

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)customer: samehereteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions