Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,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();
Expand Down
30 changes: 30 additions & 0 deletions packages/cupertino_ui/test/clipboard_utils.dart
Original file line number Diff line number Diff line change
@@ -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 = <String, dynamic>{'text': null};

Future<Object?> handleMethodCall(MethodCall methodCall) async {
switch (methodCall.method) {
case 'Clipboard.getData':
return clipboardData;
case 'Clipboard.hasStrings':
if (hasStringsThrows) {
throw Exception();
}
final clipboardDataMap = clipboardData as Map<String, dynamic>?;

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.

high

Casting clipboardData directly to Map<String, dynamic>? can throw a TypeError at runtime. When platform channel methods like Clipboard.setData are invoked, the arguments are decoded as Map<Object?, Object?> (or Map<dynamic, dynamic>) by the standard message codec. In Dart, a Map<Object?, Object?> cannot be cast to Map<String, dynamic> using as and will result in a TypeError. Using Map<dynamic, dynamic>? is safer and avoids this issue.

Suggested change
final clipboardDataMap = clipboardData as Map<String, dynamic>?;
final clipboardDataMap = clipboardData as Map<dynamic, dynamic>?;

final text = clipboardDataMap?['text'] as String?;
return <String, bool>{'value': text != null && text.isNotEmpty};
case 'Clipboard.setData':
clipboardData = methodCall.arguments;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(<String>['reduced-test-set'])
Expand All @@ -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<CupertinoLocalizations> {
Expand Down
25 changes: 25 additions & 0 deletions packages/cupertino_ui/test/text_selection_toolbar_utils.dart
Original file line number Diff line number Diff line change
@@ -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<void> tapCupertinoOverflowNextButton(WidgetTester tester) async {
await tester.tapAt(tester.getCenter(findCupertinoOverflowNextButton()));
await tester.pumpAndSettle();
}
Loading