From 0528f30b926c2b4d1babe342edac4304e2f31200 Mon Sep 17 00:00:00 2001 From: Qun Cheng Date: Thu, 25 Jun 2026 16:34:23 -0700 Subject: [PATCH] [cupertino_ui] Enable text selection tests --- .../adaptive_text_selection_toolbar_test.dart | 7 ++--- .../cupertino_ui/test/clipboard_utils.dart | 30 +++++++++++++++++++ .../text_selection_test.dart | 5 +--- .../test/text_selection_toolbar_utils.dart | 25 ++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) rename packages/cupertino_ui/{temporarily_disabled_tests => test}/adaptive_text_selection_toolbar_test.dart (97%) create mode 100644 packages/cupertino_ui/test/clipboard_utils.dart rename packages/cupertino_ui/{temporarily_disabled_tests => test}/text_selection_test.dart (99%) create mode 100644 packages/cupertino_ui/test/text_selection_toolbar_utils.dart diff --git a/packages/cupertino_ui/temporarily_disabled_tests/adaptive_text_selection_toolbar_test.dart b/packages/cupertino_ui/test/adaptive_text_selection_toolbar_test.dart similarity index 97% rename from packages/cupertino_ui/temporarily_disabled_tests/adaptive_text_selection_toolbar_test.dart rename to packages/cupertino_ui/test/adaptive_text_selection_toolbar_test.dart index bebc9018531d..92848046a139 100644 --- a/packages/cupertino_ui/temporarily_disabled_tests/adaptive_text_selection_toolbar_test.dart +++ b/packages/cupertino_ui/test/adaptive_text_selection_toolbar_test.dart @@ -2,17 +2,14 @@ // 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.', -) import 'package:cupertino_ui/cupertino_ui.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/clipboard_utils.dart'; -import '../widgets/text_selection_toolbar_utils.dart'; +import 'clipboard_utils.dart'; import 'live_text_utils.dart'; +import 'text_selection_toolbar_utils.dart'; void main() { final mockClipboard = MockClipboard(); diff --git a/packages/cupertino_ui/test/clipboard_utils.dart b/packages/cupertino_ui/test/clipboard_utils.dart new file mode 100644 index 000000000000..f67ca4c1b815 --- /dev/null +++ b/packages/cupertino_ui/test/clipboard_utils.dart @@ -0,0 +1,30 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/services.dart'; + +class MockClipboard { + MockClipboard({this.hasStringsThrows = false}); + + final bool hasStringsThrows; + + dynamic clipboardData = {'text': null}; + + Future handleMethodCall(MethodCall methodCall) async { + switch (methodCall.method) { + case 'Clipboard.getData': + return clipboardData; + case 'Clipboard.hasStrings': + if (hasStringsThrows) { + throw Exception(); + } + final clipboardDataMap = clipboardData as Map?; + final text = clipboardDataMap?['text'] as String?; + return {'value': text != null && text.isNotEmpty}; + case 'Clipboard.setData': + clipboardData = methodCall.arguments; + } + return null; + } +} diff --git a/packages/cupertino_ui/temporarily_disabled_tests/text_selection_test.dart b/packages/cupertino_ui/test/text_selection_test.dart similarity index 99% rename from packages/cupertino_ui/temporarily_disabled_tests/text_selection_test.dart rename to packages/cupertino_ui/test/text_selection_test.dart index 058bcd3e52cc..0ff0aa97e925 100644 --- a/packages/cupertino_ui/temporarily_disabled_tests/text_selection_test.dart +++ b/packages/cupertino_ui/test/text_selection_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']) @@ -18,7 +15,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/clipboard_utils.dart'; +import 'clipboard_utils.dart'; import 'editable_text_utils.dart' show findRenderEditable, textOffsetToPosition; class _LongCupertinoLocalizationsDelegate extends LocalizationsDelegate { diff --git a/packages/cupertino_ui/test/text_selection_toolbar_utils.dart b/packages/cupertino_ui/test/text_selection_toolbar_utils.dart new file mode 100644 index 000000000000..c17218c20946 --- /dev/null +++ b/packages/cupertino_ui/test/text_selection_toolbar_utils.dart @@ -0,0 +1,25 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:cupertino_ui/cupertino_ui.dart'; +import 'package:flutter_test/flutter_test.dart'; + +Finder findCupertinoOverflowNextButton() { + return find.byWidgetPredicate((Widget widget) { + return widget is CustomPaint && + '${widget.painter?.runtimeType}' == '_RightCupertinoChevronPainter'; + }); +} + +Finder findCupertinoOverflowBackButton() { + return find.byWidgetPredicate((Widget widget) { + return widget is CustomPaint && + '${widget.painter?.runtimeType}' == '_LeftCupertinoChevronPainter'; + }); +} + +Future tapCupertinoOverflowNextButton(WidgetTester tester) async { + await tester.tapAt(tester.getCenter(findCupertinoOverflowNextButton())); + await tester.pumpAndSettle(); +}