Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
// 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.',
)
@TestOn('!chrome')
library;

import 'dart:async';
import 'dart:ui';

import 'package:cupertino_ui/cupertino_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

import '../widgets/semantics_tester.dart';

void main() {
late MockNavigatorObserver navigatorObserver;

Expand Down Expand Up @@ -1571,11 +1567,11 @@ void main() {
if (paintColor.value == color.value) {
return true;
}
throw '''
fail('''
For a rect with an expected left-side position: $dx (drawn at ${rect.left}):
Expected a rect with color: $color,
And drew a rect with color: $paintColor.
''';
''');
});
}

Expand Down Expand Up @@ -1653,10 +1649,10 @@ void main() {
final bool isOnScreen = rect.left >= 0 && rect.right <= 600.0;

if (isOnScreen) {
throw '''
fail('''
Expected: no visible rects on-screen.
Found: $rect.
''';
''');
}
}
return true;
Expand Down Expand Up @@ -2045,7 +2041,8 @@ void main() {
WidgetTester tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final semantics = SemanticsTester(tester);
final SemanticsHandle handle = tester.ensureSemantics();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Overriding debugDefaultTargetPlatformOverride without ensuring it is reset in an addTearDown block can leak the iOS platform override to subsequent tests if this test fails. Using addTearDown ensures that both the platform override and the SemanticsHandle are properly cleaned up regardless of test success or failure.

    debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
    addTearDown(() {
      debugDefaultTargetPlatformOverride = null;
    });
    final SemanticsHandle handle = tester.ensureSemantics();
    addTearDown(handle.dispose);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ensureSemantics is no longer needed per @chunhtai.


await tester.pumpWidget(
CupertinoApp(
home: Navigator(
Expand All @@ -2072,24 +2069,18 @@ void main() {
await tester.tap(find.text('tap'));
await tester.pumpAndSettle();

expect(
semantics,
isNot(
includesNodeWith(
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
label: 'Dismiss',
),
),
);
expect(find.semantics.byLabel('Dismiss'), findsNothing);

debugDefaultTargetPlatformOverride = null;
semantics.dispose();
handle.dispose();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since debugDefaultTargetPlatformOverride and handle are now cleaned up automatically via addTearDown, these manual cleanup lines can be removed.

    expect(find.semantics.byLabel('Dismiss'), findsNothing);

});

testWidgets('showCupertinoModalPopup allows for semantics dismiss when set', (
WidgetTester tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final semantics = SemanticsTester(tester);
final SemanticsHandle handle = tester.ensureSemantics();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Overriding debugDefaultTargetPlatformOverride without ensuring it is reset in an addTearDown block can leak the iOS platform override to subsequent tests if this test fails. Using addTearDown ensures that both the platform override and the SemanticsHandle are properly cleaned up regardless of test success or failure.

    debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
    addTearDown(() {
      debugDefaultTargetPlatformOverride = null;
    });
    final SemanticsHandle handle = tester.ensureSemantics();
    addTearDown(handle.dispose);


await tester.pumpWidget(
CupertinoApp(
home: Navigator(
Expand Down Expand Up @@ -2118,14 +2109,12 @@ void main() {
await tester.pumpAndSettle();

expect(
semantics,
includesNodeWith(
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.dismiss],
label: 'Dismiss',
),
find.semantics.byLabel('Dismiss'),
isSemantics(label: 'Dismiss', hasTapAction: true, hasDismissAction: true),
);

debugDefaultTargetPlatformOverride = null;
semantics.dispose();
handle.dispose();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since debugDefaultTargetPlatformOverride and handle are now cleaned up automatically via addTearDown, these manual cleanup lines can be removed.

    expect(
      find.semantics.byLabel('Dismiss'),
      isSemantics(label: 'Dismiss', hasTapAction: true, hasDismissAction: true),
    );

});

testWidgets('showCupertinoModalPopup passes RouteSettings to PopupRoute', (
Expand Down Expand Up @@ -2559,12 +2548,14 @@ void main() {
);
final BuildContext context = tester.element(find.text('Test'));

showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
anchorPoint: const Offset(1000, 0),
unawaited(
showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
anchorPoint: const Offset(1000, 0),
),
);
await tester.pumpAndSettle();

Expand Down Expand Up @@ -2597,11 +2588,13 @@ void main() {
);
final BuildContext context = tester.element(find.text('Test'));

showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
unawaited(
showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
),
);
await tester.pumpAndSettle();

Expand Down Expand Up @@ -2634,11 +2627,13 @@ void main() {
);
final BuildContext context = tester.element(find.text('Test'));

showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
unawaited(
showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
),
);
await tester.pumpAndSettle();

Expand Down Expand Up @@ -2673,12 +2668,14 @@ void main() {
);

final BuildContext context = tester.element(find.text('Test'));
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
anchorPoint: const Offset(1000, 0),
unawaited(
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
anchorPoint: const Offset(1000, 0),
),
);
await tester.pumpAndSettle();

Expand Down Expand Up @@ -2711,11 +2708,13 @@ void main() {
);

final BuildContext context = tester.element(find.text('Test'));
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
unawaited(
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
),
);
await tester.pumpAndSettle();

Expand Down Expand Up @@ -2748,11 +2747,13 @@ void main() {
);

final BuildContext context = tester.element(find.text('Test'));
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
unawaited(
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return const Placeholder();
},
),
);
await tester.pumpAndSettle();

Expand Down Expand Up @@ -3137,10 +3138,12 @@ void main() {
await tester.pump();
expect(focusNode.hasFocus, true);

showCupertinoModalPopup<void>(
context: navigatorKey.currentContext!,
requestFocus: true,
builder: (BuildContext context) => const Text('popup'),
unawaited(
showCupertinoModalPopup<void>(
context: navigatorKey.currentContext!,
requestFocus: true,
builder: (BuildContext context) => const Text('popup'),
),
);
await tester.pumpAndSettle();
expect(FocusScope.of(tester.element(find.text('popup'))).hasFocus, true);
Expand All @@ -3150,10 +3153,12 @@ void main() {
await tester.pumpAndSettle();
expect(focusNode.hasFocus, true);

showCupertinoModalPopup<void>(
context: navigatorKey.currentContext!,
requestFocus: false,
builder: (BuildContext context) => const Text('popup'),
unawaited(
showCupertinoModalPopup<void>(
context: navigatorKey.currentContext!,
requestFocus: false,
builder: (BuildContext context) => const Text('popup'),
),
);
await tester.pumpAndSettle();
expect(FocusScope.of(tester.element(find.text('popup'))).hasFocus, false);
Expand All @@ -3174,10 +3179,12 @@ void main() {
await tester.pump();
expect(focusNode.hasFocus, true);

showCupertinoDialog<void>(
context: navigatorKey.currentContext!,
requestFocus: true,
builder: (BuildContext context) => const Text('dialog'),
unawaited(
showCupertinoDialog<void>(
context: navigatorKey.currentContext!,
requestFocus: true,
builder: (BuildContext context) => const Text('dialog'),
),
);
await tester.pumpAndSettle();
expect(FocusScope.of(tester.element(find.text('dialog'))).hasFocus, true);
Expand All @@ -3187,10 +3194,12 @@ void main() {
await tester.pumpAndSettle();
expect(focusNode.hasFocus, true);

showCupertinoDialog<void>(
context: navigatorKey.currentContext!,
requestFocus: false,
builder: (BuildContext context) => const Text('dialog'),
unawaited(
showCupertinoDialog<void>(
context: navigatorKey.currentContext!,
requestFocus: false,
builder: (BuildContext context) => const Text('dialog'),
),
);
await tester.pumpAndSettle();
expect(FocusScope.of(tester.element(find.text('dialog'))).hasFocus, false);
Expand Down
Loading