From d7c0a6225a2123b9fcb084ebc5f07232a4cf2887 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 25 Jun 2026 00:53:53 +0000 Subject: [PATCH 1/3] Migrate segmented_control_test.dart to SemanticsHandle --- .../segmented_control_test.dart | 142 ++++++++---------- 1 file changed, 62 insertions(+), 80 deletions(-) rename packages/cupertino_ui/{temporarily_disabled_tests => test}/segmented_control_test.dart (95%) diff --git a/packages/cupertino_ui/temporarily_disabled_tests/segmented_control_test.dart b/packages/cupertino_ui/test/segmented_control_test.dart similarity index 95% rename from packages/cupertino_ui/temporarily_disabled_tests/segmented_control_test.dart rename to packages/cupertino_ui/test/segmented_control_test.dart index 6fe991ec7af9..f9d6289345d9 100644 --- a/packages/cupertino_ui/temporarily_disabled_tests/segmented_control_test.dart +++ b/packages/cupertino_ui/test/segmented_control_test.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -@Skip( - 'This file is skipped due to a cross-import that needs to be fixed. Tracked in https://github.com/flutter/flutter/issues/177028.', -) // This file is run as part of a reduced test set in CI on Mac and Windows // machines. @Tags(['reduced-test-set']) @@ -19,8 +16,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/semantics_tester.dart'; - RenderBox getRenderSegmentedControl(WidgetTester tester) { return tester.allRenderObjects.firstWhere((RenderObject currentObject) { return currentObject.toStringShort().contains('_RenderSegmentedControl'); @@ -813,7 +808,7 @@ void main() { }); testWidgets('Segmented control semantics', (WidgetTester tester) async { - final semantics = SemanticsTester(tester); + final SemanticsHandle handle = tester.ensureSemantics(); final children = {}; children[0] = const Text('Child 1'); @@ -841,91 +836,78 @@ void main() { ), ); + // Assert parent role + final SemanticsNode segmentedControlNode = tester.getSemantics( + find.byType(CupertinoSegmentedControl), + ); + expect(segmentedControlNode.role, ui.SemanticsRole.radioGroup); + + // Assert Child 1 (selected) expect( - semantics, - hasSemantics( - TestSemantics.root( - children: [ - TestSemantics.rootChild( - role: SemanticsRole.radioGroup, - children: [ - TestSemantics( - label: 'Child 1', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - SemanticsFlag.hasSelectedState, - SemanticsFlag.isSelected, - SemanticsFlag.isFocusable, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - TestSemantics( - label: 'Child 2', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - // Declares that it is selectable, but not currently selected. - SemanticsFlag.hasSelectedState, - SemanticsFlag.isFocusable, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - ], - ), - ], - ), - ignoreId: true, - ignoreRect: true, - ignoreTransform: true, + find.semantics.byLabel('Child 1'), + isSemantics( + label: 'Child 1', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: true, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, ), ); + // Assert Child 2 (unselected) + expect( + find.semantics.byLabel('Child 2'), + isSemantics( + label: 'Child 2', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: false, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, + ), + ); + + // Tap Child 2 await tester.tap(find.text('Child 2')); await tester.pump(); + // Assert Child 1 (now unselected) expect( - semantics, - hasSemantics( - TestSemantics.root( - children: [ - TestSemantics.rootChild( - role: SemanticsRole.radioGroup, - children: [ - TestSemantics( - label: 'Child 1', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - // Declares that it is selectable, but not currently selected. - SemanticsFlag.hasSelectedState, - SemanticsFlag.isFocusable, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - TestSemantics( - label: 'Child 2', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - SemanticsFlag.hasSelectedState, - SemanticsFlag.isSelected, - SemanticsFlag.isFocusable, - SemanticsFlag.isFocused, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - ], - ), - ], - ), - ignoreId: true, - ignoreRect: true, - ignoreTransform: true, + find.semantics.byLabel('Child 1'), + isSemantics( + label: 'Child 1', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: false, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, + ), + ); + + // Assert Child 2 (now selected and focused) + expect( + find.semantics.byLabel('Child 2'), + isSemantics( + label: 'Child 2', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: true, + isFocusable: true, + isFocused: true, + hasTapAction: true, + hasFocusAction: true, ), ); - semantics.dispose(); + handle.dispose(); }); testWidgets('Non-centered taps work on smaller widgets', (WidgetTester tester) async { From db404a0e596265937ca0521338e42d5075209ea6 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 25 Jun 2026 02:03:26 +0000 Subject: [PATCH 2/3] clean up --- packages/cupertino_ui/test/segmented_control_test.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/cupertino_ui/test/segmented_control_test.dart b/packages/cupertino_ui/test/segmented_control_test.dart index f9d6289345d9..08edac052271 100644 --- a/packages/cupertino_ui/test/segmented_control_test.dart +++ b/packages/cupertino_ui/test/segmented_control_test.dart @@ -836,13 +836,13 @@ void main() { ), ); - // Assert parent role + // Assert parent role. final SemanticsNode segmentedControlNode = tester.getSemantics( find.byType(CupertinoSegmentedControl), ); expect(segmentedControlNode.role, ui.SemanticsRole.radioGroup); - // Assert Child 1 (selected) + // Assert Child 1 (selected). expect( find.semantics.byLabel('Child 1'), isSemantics( @@ -857,7 +857,7 @@ void main() { ), ); - // Assert Child 2 (unselected) + // Assert Child 2 (unselected). expect( find.semantics.byLabel('Child 2'), isSemantics( @@ -876,7 +876,7 @@ void main() { await tester.tap(find.text('Child 2')); await tester.pump(); - // Assert Child 1 (now unselected) + // Assert Child 1 (now unselected). expect( find.semantics.byLabel('Child 1'), isSemantics( @@ -891,7 +891,7 @@ void main() { ), ); - // Assert Child 2 (now selected and focused) + // Assert Child 2 (now selected and focused). expect( find.semantics.byLabel('Child 2'), isSemantics( From 4cf3960393c6aafa11224e506693521f47d19e4e Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Tue, 30 Jun 2026 23:05:02 +0000 Subject: [PATCH 3/3] remove ensureSemantics --- packages/cupertino_ui/test/segmented_control_test.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/cupertino_ui/test/segmented_control_test.dart b/packages/cupertino_ui/test/segmented_control_test.dart index 08edac052271..0cb97bf02fed 100644 --- a/packages/cupertino_ui/test/segmented_control_test.dart +++ b/packages/cupertino_ui/test/segmented_control_test.dart @@ -808,8 +808,6 @@ void main() { }); testWidgets('Segmented control semantics', (WidgetTester tester) async { - final SemanticsHandle handle = tester.ensureSemantics(); - final children = {}; children[0] = const Text('Child 1'); children[1] = const Text('Child 2'); @@ -906,8 +904,6 @@ void main() { hasFocusAction: true, ), ); - - handle.dispose(); }); testWidgets('Non-centered taps work on smaller widgets', (WidgetTester tester) async {