mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
parent
54e600049f
commit
806c1f8186
@ -534,6 +534,14 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
|
|||||||
String possibleReason = '';
|
String possibleReason = '';
|
||||||
if (lines[lineNumber].trimLeft().startsWith('"')) {
|
if (lines[lineNumber].trimLeft().startsWith('"')) {
|
||||||
possibleReason = ' You might have used double quotes (") for the string instead of single quotes (\').';
|
possibleReason = ' You might have used double quotes (") for the string instead of single quotes (\').';
|
||||||
|
} else if (!lines[lineNumber].contains("'")) {
|
||||||
|
possibleReason = ' It might be missing the line saying "This feature was deprecated after...".';
|
||||||
|
} else if (!lines[lineNumber].trimRight().endsWith(" '")) {
|
||||||
|
if (lines[lineNumber].contains('This feature was deprecated')) {
|
||||||
|
possibleReason = ' There might not be an explanatory message.';
|
||||||
|
} else {
|
||||||
|
possibleReason = ' There might be a missing space character at the end of the line.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw 'Deprecation notice does not match required pattern.$possibleReason';
|
throw 'Deprecation notice does not match required pattern.$possibleReason';
|
||||||
}
|
}
|
||||||
@ -546,6 +554,8 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
|
|||||||
if (firstChar.toUpperCase() != firstChar) {
|
if (firstChar.toUpperCase() != firstChar) {
|
||||||
throw 'Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo';
|
throw 'Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
message += messageMatch.namedGroup('message')!;
|
||||||
}
|
}
|
||||||
lineNumber += 1;
|
lineNumber += 1;
|
||||||
if (lineNumber >= lines.length) {
|
if (lineNumber >= lines.length) {
|
||||||
@ -565,7 +575,7 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!message.endsWith('.') && !message.endsWith('!') && !message.endsWith('?')) {
|
if (!message.endsWith('.') && !message.endsWith('!') && !message.endsWith('?')) {
|
||||||
throw 'Deprecation notice should be a grammatically correct sentence and end with a period.';
|
throw 'Deprecation notice should be a grammatically correct sentence and end with a period; notice appears to be "$message".';
|
||||||
}
|
}
|
||||||
if (!lines[lineNumber].startsWith("$indent '")) {
|
if (!lines[lineNumber].startsWith("$indent '")) {
|
||||||
throw 'Unexpected deprecation notice indent.';
|
throw 'Unexpected deprecation notice indent.';
|
||||||
|
@ -94,13 +94,18 @@ Future<void> runProcessWithValidations(
|
|||||||
List<String> command,
|
List<String> command,
|
||||||
String workingDirectory, {
|
String workingDirectory, {
|
||||||
@visibleForTesting ProcessManager processManager = const LocalProcessManager(),
|
@visibleForTesting ProcessManager processManager = const LocalProcessManager(),
|
||||||
|
bool verbose = true,
|
||||||
}) async {
|
}) async {
|
||||||
final ProcessResult result =
|
final ProcessResult result =
|
||||||
processManager.runSync(command, stdoutEncoding: utf8, workingDirectory: workingDirectory);
|
processManager.runSync(command, stdoutEncoding: utf8, workingDirectory: workingDirectory);
|
||||||
if (result.exitCode == 0) {
|
if (result.exitCode == 0) {
|
||||||
print('Stdout: ${result.stdout}');
|
if (verbose) {
|
||||||
|
print('stdout: ${result.stdout}');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
print('StdErr: ${result.stderr}');
|
if (verbose) {
|
||||||
|
print('stderr: ${result.stderr}');
|
||||||
|
}
|
||||||
throw CommandException();
|
throw CommandException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,3 +100,8 @@ void test17() { }
|
|||||||
'This feature was deprecated after v2.1.0-11.0.pre.'
|
'This feature was deprecated after v2.1.0-11.0.pre.'
|
||||||
)
|
)
|
||||||
void test18() { }
|
void test18() { }
|
||||||
|
|
||||||
|
@Deprecated( // flutter_ignore: deprecation_syntax, https://github.com/flutter/flutter/issues/000000
|
||||||
|
'Missing the version line. '
|
||||||
|
)
|
||||||
|
void test19() { }
|
||||||
|
@ -45,13 +45,13 @@ void main() {
|
|||||||
test('analyze.dart - verifyDeprecations', () async {
|
test('analyze.dart - verifyDeprecations', () async {
|
||||||
final String result = await capture(() => verifyDeprecations(testRootPath, minimumMatches: 2), shouldHaveErrors: true);
|
final String result = await capture(() => verifyDeprecations(testRootPath, minimumMatches: 2), shouldHaveErrors: true);
|
||||||
final String lines = <String>[
|
final String lines = <String>[
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:12: Deprecation notice does not match required pattern.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:12: Deprecation notice does not match required pattern. There might be a missing space character at the end of the line.',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:18: Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: STYLE_GUIDE_URL',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:18: Deprecation notice should be a grammatically correct sentence and start with a capital letter; see style guide: STYLE_GUIDE_URL',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:25: Deprecation notice should be a grammatically correct sentence and end with a period.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:25: Deprecation notice should be a grammatically correct sentence and end with a period; notice appears to be "Also bad grammar".',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:29: Deprecation notice does not match required pattern.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:29: Deprecation notice does not match required pattern.',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:32: Deprecation notice does not match required pattern.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:32: Deprecation notice does not match required pattern.',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:37: Deprecation notice does not match required pattern.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:37: Deprecation notice does not match required pattern. It might be missing the line saying "This feature was deprecated after...".',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:41: Deprecation notice does not match required pattern.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:41: Deprecation notice does not match required pattern. There might not be an explanatory message.',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:48: End of deprecation notice does not match required pattern.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:48: End of deprecation notice does not match required pattern.',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:51: Unexpected deprecation notice indent.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:51: Unexpected deprecation notice indent.',
|
||||||
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a beta branch version number; please see RELEASES_URL to find the latest beta build version number.',
|
'║ test/analyze-test-input/root/packages/foo/deprecation.dart:70: Deprecation notice does not accurately indicate a beta branch version number; please see RELEASES_URL to find the latest beta build version number.',
|
||||||
|
@ -118,7 +118,7 @@ void main() async {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
await runProcessWithValidations(command, '', processManager: processManager);
|
await runProcessWithValidations(command, '', processManager: processManager, verbose: false);
|
||||||
expect(processManager, hasNoRemainingExpectations);
|
expect(processManager, hasNoRemainingExpectations);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ void main() async {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
await runProcessWithValidations(command, '', processManager: processManager);
|
await runProcessWithValidations(command, '', processManager: processManager, verbose: false);
|
||||||
throw Exception('Exception was not thrown');
|
throw Exception('Exception was not thrown');
|
||||||
} on CommandException catch (e) {
|
} on CommandException catch (e) {
|
||||||
expect(e, isA<Exception>());
|
expect(e, isA<Exception>());
|
||||||
|
@ -21,7 +21,7 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
// TODO(nurhan): https://github.com/flutter/flutter/issues/51885
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/51885
|
||||||
SystemChannels.textInput.setMockMethodCallHandler(null);
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, null);
|
||||||
// Focus on a TextFormField.
|
// Focus on a TextFormField.
|
||||||
final Finder finder = find.byKey(const Key('input'));
|
final Finder finder = find.byKey(const Key('input'));
|
||||||
expect(finder, findsOneWidget);
|
expect(finder, findsOneWidget);
|
||||||
@ -39,7 +39,7 @@ void main() {
|
|||||||
platformViewsRegistry.getNextPlatformViewId();
|
platformViewsRegistry.getNextPlatformViewId();
|
||||||
// ignore: undefined_prefixed_name, avoid_dynamic_calls
|
// ignore: undefined_prefixed_name, avoid_dynamic_calls
|
||||||
ui.platformViewRegistry.registerViewFactory('MyView', (int viewId) {
|
ui.platformViewRegistry.registerViewFactory('MyView', (int viewId) {
|
||||||
++viewInstanceCount;
|
viewInstanceCount += 1;
|
||||||
return html.DivElement();
|
return html.DivElement();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ void main() {
|
|||||||
Future<void> setAppLifeCycleState(AppLifecycleState state) async {
|
Future<void> setAppLifeCycleState(AppLifecycleState state) async {
|
||||||
final ByteData? message =
|
final ByteData? message =
|
||||||
const StringCodec().encodeMessage(state.toString());
|
const StringCodec().encodeMessage(state.toString());
|
||||||
await ServicesBinding.instance.defaultBinaryMessenger
|
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
|
||||||
.handlePlatformMessage('flutter/lifecycle', message, (_) {});
|
'flutter/lifecycle', message, (_) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
|
@ -44,7 +44,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
|
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
|
||||||
'flutter/textinput',
|
'flutter/textinput',
|
||||||
messageBytes,
|
messageBytes,
|
||||||
(ByteData? _) {},
|
(ByteData? _) {},
|
||||||
|
@ -45,13 +45,12 @@ abstract class BinaryMessenger {
|
|||||||
/// To register a handler for a given message channel, see [setMessageHandler].
|
/// To register a handler for a given message channel, see [setMessageHandler].
|
||||||
///
|
///
|
||||||
/// To send a message _to_ a plugin on the platform thread, see [send].
|
/// To send a message _to_ a plugin on the platform thread, see [send].
|
||||||
// TODO(ianh): deprecate this method once cocoon and other customer_tests are migrated:
|
@Deprecated(
|
||||||
// @NotYetDeprecated(
|
'Instead of calling this method, use ServicesBinding.instance.channelBuffers.push. '
|
||||||
// 'Instead of calling this method, use ServicesBinding.instance.channelBuffers.push. '
|
'In tests, consider using tester.binding.defaultBinaryMessenger.handlePlatformMessage '
|
||||||
// 'In tests, consider using tester.binding.defaultBinaryMessenger.handlePlatformMessage '
|
'or TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage. '
|
||||||
// 'or TestDefaultBinaryMessenger.instance.defaultBinaryMessenger.handlePlatformMessage. '
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
)
|
||||||
// )
|
|
||||||
Future<void> handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback);
|
Future<void> handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback);
|
||||||
|
|
||||||
/// Send a binary message to the platform plugins on the given channel.
|
/// Send a binary message to the platform plugins on the given channel.
|
||||||
|
@ -208,10 +208,11 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|
||||||
int hapticFeedbackCalls = 0;
|
int hapticFeedbackCalls = 0;
|
||||||
SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
|
||||||
if (methodCall.method == 'HapticFeedback.vibrate') {
|
if (methodCall.method == 'HapticFeedback.vibrate') {
|
||||||
hapticFeedbackCalls++;
|
hapticFeedbackCalls += 1;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Long press on the scrollbar thumb and expect a vibration after it resizes.
|
// Long press on the scrollbar thumb and expect a vibration after it resizes.
|
||||||
@ -966,10 +967,11 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|
||||||
int hapticFeedbackCalls = 0;
|
int hapticFeedbackCalls = 0;
|
||||||
SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
|
||||||
if (methodCall.method == 'HapticFeedback.vibrate') {
|
if (methodCall.method == 'HapticFeedback.vibrate') {
|
||||||
hapticFeedbackCalls++;
|
hapticFeedbackCalls += 1;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Long press on the scrollbar thumb and expect a vibration after it resizes.
|
// Long press on the scrollbar thumb and expect a vibration after it resizes.
|
||||||
|
@ -835,7 +835,7 @@ void main() {
|
|||||||
|
|
||||||
testWidgets('selection rects re-sent when refocused', (WidgetTester tester) async {
|
testWidgets('selection rects re-sent when refocused', (WidgetTester tester) async {
|
||||||
final List<List<SelectionRect>> log = <List<SelectionRect>>[];
|
final List<List<SelectionRect>> log = <List<SelectionRect>>[];
|
||||||
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, (MethodCall methodCall) async {
|
||||||
if (methodCall.method == 'TextInput.setSelectionRects') {
|
if (methodCall.method == 'TextInput.setSelectionRects') {
|
||||||
final List<dynamic> args = methodCall.arguments as List<dynamic>;
|
final List<dynamic> args = methodCall.arguments as List<dynamic>;
|
||||||
final List<SelectionRect> selectionRects = <SelectionRect>[];
|
final List<SelectionRect> selectionRects = <SelectionRect>[];
|
||||||
@ -847,6 +847,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
log.add(selectionRects);
|
log.add(selectionRects);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
@ -1725,17 +1726,20 @@ void main() {
|
|||||||
|
|
||||||
group('BrowserContextMenu', () {
|
group('BrowserContextMenu', () {
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
SystemChannels.contextMenu.setMockMethodCallHandler((MethodCall call) {
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||||
// Just complete successfully, so that BrowserContextMenu thinks that
|
SystemChannels.contextMenu,
|
||||||
// the engine successfully received its call.
|
(MethodCall call) {
|
||||||
return Future<void>.value();
|
// Just complete successfully, so that BrowserContextMenu thinks that
|
||||||
});
|
// the engine successfully received its call.
|
||||||
|
return Future<void>.value();
|
||||||
|
},
|
||||||
|
);
|
||||||
await BrowserContextMenu.disableContextMenu();
|
await BrowserContextMenu.disableContextMenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
await BrowserContextMenu.enableContextMenu();
|
await BrowserContextMenu.enableContextMenu();
|
||||||
SystemChannels.contextMenu.setMockMethodCallHandler(null);
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.contextMenu, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('web can show flutter context menu when the browser context menu is disabled', (WidgetTester tester) async {
|
testWidgets('web can show flutter context menu when the browser context menu is disabled', (WidgetTester tester) async {
|
||||||
@ -5162,7 +5166,7 @@ void main() {
|
|||||||
tester.view.physicalSize = const Size(750.0, 1334.0);
|
tester.view.physicalSize = const Size(750.0, 1334.0);
|
||||||
|
|
||||||
final List<List<SelectionRect>> log = <List<SelectionRect>>[];
|
final List<List<SelectionRect>> log = <List<SelectionRect>>[];
|
||||||
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, (MethodCall methodCall) {
|
||||||
if (methodCall.method == 'TextInput.setSelectionRects') {
|
if (methodCall.method == 'TextInput.setSelectionRects') {
|
||||||
final List<dynamic> args = methodCall.arguments as List<dynamic>;
|
final List<dynamic> args = methodCall.arguments as List<dynamic>;
|
||||||
final List<SelectionRect> selectionRects = <SelectionRect>[];
|
final List<SelectionRect> selectionRects = <SelectionRect>[];
|
||||||
@ -5174,6 +5178,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
log.add(selectionRects);
|
log.add(selectionRects);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
@ -5297,8 +5302,9 @@ void main() {
|
|||||||
|
|
||||||
testWidgets('selection rects are not sent if scribbleEnabled is false', (WidgetTester tester) async {
|
testWidgets('selection rects are not sent if scribbleEnabled is false', (WidgetTester tester) async {
|
||||||
final List<MethodCall> log = <MethodCall>[];
|
final List<MethodCall> log = <MethodCall>[];
|
||||||
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, (MethodCall methodCall) async {
|
||||||
log.add(methodCall);
|
log.add(methodCall);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
|
@ -1883,7 +1883,7 @@ void main() {
|
|||||||
|
|
||||||
group('BrowserContextMenu', () {
|
group('BrowserContextMenu', () {
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
SystemChannels.contextMenu.setMockMethodCallHandler((MethodCall call) {
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.contextMenu, (MethodCall call) {
|
||||||
// Just complete successfully, so that BrowserContextMenu thinks that
|
// Just complete successfully, so that BrowserContextMenu thinks that
|
||||||
// the engine successfully received its call.
|
// the engine successfully received its call.
|
||||||
return Future<void>.value();
|
return Future<void>.value();
|
||||||
@ -1893,7 +1893,7 @@ void main() {
|
|||||||
|
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
await BrowserContextMenu.enableContextMenu();
|
await BrowserContextMenu.enableContextMenu();
|
||||||
SystemChannels.contextMenu.setMockMethodCallHandler(null);
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.contextMenu, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('web can show flutter context menu when the browser context menu is disabled', (WidgetTester tester) async {
|
testWidgets('web can show flutter context menu when the browser context menu is disabled', (WidgetTester tester) async {
|
||||||
|
@ -311,8 +311,9 @@ void main() {
|
|||||||
|
|
||||||
testWidgets('changes should send setUndoState to the UndoManagerConnection on iOS', (WidgetTester tester) async {
|
testWidgets('changes should send setUndoState to the UndoManagerConnection on iOS', (WidgetTester tester) async {
|
||||||
final List<MethodCall> log = <MethodCall>[];
|
final List<MethodCall> log = <MethodCall>[];
|
||||||
SystemChannels.undoManager.setMockMethodCallHandler((MethodCall methodCall) async {
|
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.undoManager, (MethodCall methodCall) async {
|
||||||
log.add(methodCall);
|
log.add(methodCall);
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
final FocusNode focusNode = FocusNode();
|
final FocusNode focusNode = FocusNode();
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ import 'package:flutter/services.dart';
|
|||||||
|
|
||||||
import 'binding.dart';
|
import 'binding.dart';
|
||||||
|
|
||||||
// TODO(ianh): Once cocoon and other customer_tests are migrated, deprecate these transitional APIs
|
|
||||||
|
|
||||||
/// Shim to support the obsolete [setMockMessageHandler] and
|
/// Shim to support the obsolete [setMockMessageHandler] and
|
||||||
/// [checkMockMessageHandler] methods on [BinaryMessenger] in tests.
|
/// [checkMockMessageHandler] methods on [BinaryMessenger] in tests.
|
||||||
///
|
///
|
||||||
@ -19,21 +17,23 @@ import 'binding.dart';
|
|||||||
/// more accurately represents the actual method invocation.
|
/// more accurately represents the actual method invocation.
|
||||||
extension TestBinaryMessengerExtension on BinaryMessenger {
|
extension TestBinaryMessengerExtension on BinaryMessenger {
|
||||||
/// Shim for [TestDefaultBinaryMessenger.setMockMessageHandler].
|
/// Shim for [TestDefaultBinaryMessenger.setMockMessageHandler].
|
||||||
// TODO(ianh): deprecate this method: @NotYetDeprecated(
|
@Deprecated(
|
||||||
// 'Use tester.binding.defaultBinaryMessenger.setMockMessageHandler or '
|
'Use tester.binding.defaultBinaryMessenger.setMockMessageHandler or '
|
||||||
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler instead. '
|
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler instead. '
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
'For the first argument, pass channel.name. '
|
||||||
// )
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
|
)
|
||||||
void setMockMessageHandler(String channel, MessageHandler? handler) {
|
void setMockMessageHandler(String channel, MessageHandler? handler) {
|
||||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler(channel, handler);
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler(channel, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
|
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
|
||||||
// TODO(ianh): deprecate this method: @NotYetDeprecated(
|
@Deprecated(
|
||||||
// 'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
|
'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
|
||||||
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead.'
|
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
'For the first argument, pass channel.name. '
|
||||||
// )
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
|
)
|
||||||
bool checkMockMessageHandler(String channel, Object? handler) {
|
bool checkMockMessageHandler(String channel, Object? handler) {
|
||||||
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(channel, handler);
|
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(channel, handler);
|
||||||
}
|
}
|
||||||
@ -49,22 +49,23 @@ extension TestBinaryMessengerExtension on BinaryMessenger {
|
|||||||
/// directly. This more accurately represents the actual method invocation.
|
/// directly. This more accurately represents the actual method invocation.
|
||||||
extension TestBasicMessageChannelExtension<T> on BasicMessageChannel<T> {
|
extension TestBasicMessageChannelExtension<T> on BasicMessageChannel<T> {
|
||||||
/// Shim for [TestDefaultBinaryMessenger.setMockDecodedMessageHandler].
|
/// Shim for [TestDefaultBinaryMessenger.setMockDecodedMessageHandler].
|
||||||
// TODO(ianh): deprecate this method: @NotYetDeprecated(
|
@Deprecated(
|
||||||
// 'Use tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler or '
|
'Use tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler or '
|
||||||
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler instead. '
|
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler instead. '
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
'Pass the channel as the first argument. '
|
||||||
// )
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
|
)
|
||||||
void setMockMessageHandler(Future<T> Function(T? message)? handler) {
|
void setMockMessageHandler(Future<T> Function(T? message)? handler) {
|
||||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler<T>(this, handler);
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler<T>(this, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
|
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
|
||||||
// TODO(ianh): deprecate this method: @NotYetDeprecated(
|
@Deprecated(
|
||||||
// 'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
|
'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
|
||||||
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
|
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
|
||||||
// 'For the first argument, pass channel.name. '
|
'For the first argument, pass channel.name. '
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
// )
|
)
|
||||||
bool checkMockMessageHandler(Object? handler) {
|
bool checkMockMessageHandler(Object? handler) {
|
||||||
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(name, handler);
|
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(name, handler);
|
||||||
}
|
}
|
||||||
@ -80,22 +81,23 @@ extension TestBasicMessageChannelExtension<T> on BasicMessageChannel<T> {
|
|||||||
/// This more accurately represents the actual method invocation.
|
/// This more accurately represents the actual method invocation.
|
||||||
extension TestMethodChannelExtension on MethodChannel {
|
extension TestMethodChannelExtension on MethodChannel {
|
||||||
/// Shim for [TestDefaultBinaryMessenger.setMockMethodCallHandler].
|
/// Shim for [TestDefaultBinaryMessenger.setMockMethodCallHandler].
|
||||||
// TODO(ianh): deprecate this method: @NotYetDeprecated(
|
@Deprecated(
|
||||||
// 'Use tester.binding.defaultBinaryMessenger.setMockMethodCallHandler or '
|
'Use tester.binding.defaultBinaryMessenger.setMockMethodCallHandler or '
|
||||||
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler instead. '
|
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler instead. '
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
'Pass the channel as the first argument. '
|
||||||
// )
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
|
)
|
||||||
void setMockMethodCallHandler(Future<dynamic>? Function(MethodCall call)? handler) {
|
void setMockMethodCallHandler(Future<dynamic>? Function(MethodCall call)? handler) {
|
||||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(this, handler);
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(this, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
|
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
|
||||||
// TODO(ianh): deprecate this method: @NotYetDeprecated(
|
@Deprecated(
|
||||||
// 'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
|
'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
|
||||||
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
|
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
|
||||||
// 'For the first argument, pass channel.name. '
|
'For the first argument, pass channel.name. '
|
||||||
// 'This feature was deprecated after v2.1.0-10.0.pre.'
|
'This feature was deprecated after v3.9.0-19.0.pre.'
|
||||||
// )
|
)
|
||||||
bool checkMockMethodCallHandler(Object? handler) {
|
bool checkMockMethodCallHandler(Object? handler) {
|
||||||
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(name, handler);
|
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(name, handler);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'binding.dart';
|
import 'binding.dart';
|
||||||
import 'deprecated.dart';
|
|
||||||
import 'test_async_utils.dart';
|
import 'test_async_utils.dart';
|
||||||
import 'test_text_input_key_handler.dart';
|
import 'test_text_input_key_handler.dart';
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ class TestTextInput {
|
|||||||
///
|
///
|
||||||
/// Called by the binding at the top of a test when
|
/// Called by the binding at the top of a test when
|
||||||
/// [TestWidgetsFlutterBinding.registerTestTextInput] is true.
|
/// [TestWidgetsFlutterBinding.registerTestTextInput] is true.
|
||||||
void register() => SystemChannels.textInput.setMockMethodCallHandler(_handleTextInputCall);
|
void register() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, _handleTextInputCall);
|
||||||
|
|
||||||
/// Removes this object as a mock handler for [SystemChannels.textInput].
|
/// Removes this object as a mock handler for [SystemChannels.textInput].
|
||||||
///
|
///
|
||||||
@ -68,13 +67,13 @@ class TestTextInput {
|
|||||||
///
|
///
|
||||||
/// Called by the binding at the end of a (successful) test when
|
/// Called by the binding at the end of a (successful) test when
|
||||||
/// [TestWidgetsFlutterBinding.registerTestTextInput] is true.
|
/// [TestWidgetsFlutterBinding.registerTestTextInput] is true.
|
||||||
void unregister() => SystemChannels.textInput.setMockMethodCallHandler(null);
|
void unregister() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, null);
|
||||||
|
|
||||||
/// Whether this [TestTextInput] is registered with [SystemChannels.textInput].
|
/// Whether this [TestTextInput] is registered with [SystemChannels.textInput].
|
||||||
///
|
///
|
||||||
/// The binding uses the [register] and [unregister] methods to control this
|
/// The binding uses the [register] and [unregister] methods to control this
|
||||||
/// value when [TestWidgetsFlutterBinding.registerTestTextInput] is true.
|
/// value when [TestWidgetsFlutterBinding.registerTestTextInput] is true.
|
||||||
bool get isRegistered => SystemChannels.textInput.checkMockMethodCallHandler(_handleTextInputCall);
|
bool get isRegistered => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(SystemChannels.textInput.name, _handleTextInputCall);
|
||||||
|
|
||||||
int? _client;
|
int? _client;
|
||||||
|
|
||||||
|
@ -3,19 +3,22 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:{{projectName}}/{{projectName}}_method_channel.dart';
|
import 'package:{{projectName}}/{{projectName}}_method_channel.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
MethodChannel{{pluginDartClass}} platform = MethodChannel{{pluginDartClass}}();
|
MethodChannel{{pluginDartClass}} platform = MethodChannel{{pluginDartClass}}();
|
||||||
const MethodChannel channel = MethodChannel('{{projectName}}');
|
const MethodChannel channel = MethodChannel('{{projectName}}');
|
||||||
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
channel.setMockMethodCallHandler((MethodCall methodCall) async {
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||||
return '42';
|
channel,
|
||||||
});
|
(MethodCall methodCall) async {
|
||||||
|
return '42';
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
channel.setMockMethodCallHandler(null);
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getPlatformVersion', () async {
|
test('getPlatformVersion', () async {
|
||||||
|
Loading…
Reference in New Issue
Block a user