Unverified Commit 806c1f81 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Deprecate these old APIs (#116793)

Deprecate these old APIs
parent 54e60004
......@@ -534,6 +534,14 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
String possibleReason = '';
if (lines[lineNumber].trimLeft().startsWith('"')) {
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';
}
......@@ -546,6 +554,8 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
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';
}
} else {
message += messageMatch.namedGroup('message')!;
}
lineNumber += 1;
if (lineNumber >= lines.length) {
......@@ -565,7 +575,7 @@ Future<void> verifyDeprecations(String workingDirectory, { int minimumMatches =
}
}
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 '")) {
throw 'Unexpected deprecation notice indent.';
......
......@@ -94,13 +94,18 @@ Future<void> runProcessWithValidations(
List<String> command,
String workingDirectory, {
@visibleForTesting ProcessManager processManager = const LocalProcessManager(),
bool verbose = true,
}) async {
final ProcessResult result =
processManager.runSync(command, stdoutEncoding: utf8, workingDirectory: workingDirectory);
if (result.exitCode == 0) {
print('Stdout: ${result.stdout}');
if (verbose) {
print('stdout: ${result.stdout}');
}
} else {
print('StdErr: ${result.stderr}');
if (verbose) {
print('stderr: ${result.stderr}');
}
throw CommandException();
}
}
......
......@@ -100,3 +100,8 @@ void test17() { }
'This feature was deprecated after v2.1.0-11.0.pre.'
)
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 {
final String result = await capture(() => verifyDeprecations(testRootPath, minimumMatches: 2), shouldHaveErrors: true);
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: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: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:41: 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. 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: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.',
......
......@@ -118,7 +118,7 @@ void main() async {
),
],
);
await runProcessWithValidations(command, '', processManager: processManager);
await runProcessWithValidations(command, '', processManager: processManager, verbose: false);
expect(processManager, hasNoRemainingExpectations);
});
......@@ -133,7 +133,7 @@ void main() async {
],
);
try {
await runProcessWithValidations(command, '', processManager: processManager);
await runProcessWithValidations(command, '', processManager: processManager, verbose: false);
throw Exception('Exception was not thrown');
} on CommandException catch (e) {
expect(e, isA<Exception>());
......
......@@ -21,7 +21,7 @@ void main() {
await tester.pumpAndSettle();
// TODO(nurhan): https://github.com/flutter/flutter/issues/51885
SystemChannels.textInput.setMockMethodCallHandler(null);
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, null);
// Focus on a TextFormField.
final Finder finder = find.byKey(const Key('input'));
expect(finder, findsOneWidget);
......@@ -39,7 +39,7 @@ void main() {
platformViewsRegistry.getNextPlatformViewId();
// ignore: undefined_prefixed_name, avoid_dynamic_calls
ui.platformViewRegistry.registerViewFactory('MyView', (int viewId) {
++viewInstanceCount;
viewInstanceCount += 1;
return html.DivElement();
});
......
......@@ -13,8 +13,8 @@ void main() {
Future<void> setAppLifeCycleState(AppLifecycleState state) async {
final ByteData? message =
const StringCodec().encodeMessage(state.toString());
await ServicesBinding.instance.defaultBinaryMessenger
.handlePlatformMessage('flutter/lifecycle', message, (_) {});
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
'flutter/lifecycle', message, (_) {});
}
await tester.pumpWidget(
......
......@@ -44,7 +44,7 @@ void main() {
});
try {
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
'flutter/textinput',
messageBytes,
(ByteData? _) {},
......
......@@ -45,13 +45,12 @@ abstract class BinaryMessenger {
/// To register a handler for a given message channel, see [setMessageHandler].
///
/// 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:
// @NotYetDeprecated(
// 'Instead of calling this method, use ServicesBinding.instance.channelBuffers.push. '
// 'In tests, consider using tester.binding.defaultBinaryMessenger.handlePlatformMessage '
// 'or TestDefaultBinaryMessenger.instance.defaultBinaryMessenger.handlePlatformMessage. '
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Instead of calling this method, use ServicesBinding.instance.channelBuffers.push. '
'In tests, consider using tester.binding.defaultBinaryMessenger.handlePlatformMessage '
'or TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.handlePlatformMessage. '
'This feature was deprecated after v3.9.0-19.0.pre.'
)
Future<void> handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback);
/// Send a binary message to the platform plugins on the given channel.
......
......@@ -208,10 +208,11 @@ void main() {
await tester.pump();
int hapticFeedbackCalls = 0;
SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
if (methodCall.method == 'HapticFeedback.vibrate') {
hapticFeedbackCalls++;
hapticFeedbackCalls += 1;
}
return null;
});
// Long press on the scrollbar thumb and expect a vibration after it resizes.
......@@ -966,10 +967,11 @@ void main() {
await tester.pump();
int hapticFeedbackCalls = 0;
SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (MethodCall methodCall) async {
if (methodCall.method == 'HapticFeedback.vibrate') {
hapticFeedbackCalls++;
hapticFeedbackCalls += 1;
}
return null;
});
// 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 {
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') {
final List<dynamic> args = methodCall.arguments as List<dynamic>;
final List<SelectionRect> selectionRects = <SelectionRect>[];
......@@ -847,6 +847,7 @@ void main() {
}
log.add(selectionRects);
}
return null;
});
final TextEditingController controller = TextEditingController();
......@@ -1725,17 +1726,20 @@ void main() {
group('BrowserContextMenu', () {
setUp(() async {
SystemChannels.contextMenu.setMockMethodCallHandler((MethodCall call) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.contextMenu,
(MethodCall call) {
// Just complete successfully, so that BrowserContextMenu thinks that
// the engine successfully received its call.
return Future<void>.value();
});
},
);
await BrowserContextMenu.disableContextMenu();
});
tearDown(() async {
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 {
......@@ -5162,7 +5166,7 @@ void main() {
tester.view.physicalSize = const Size(750.0, 1334.0);
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') {
final List<dynamic> args = methodCall.arguments as List<dynamic>;
final List<SelectionRect> selectionRects = <SelectionRect>[];
......@@ -5174,6 +5178,7 @@ void main() {
}
log.add(selectionRects);
}
return null;
});
final TextEditingController controller = TextEditingController();
......@@ -5297,8 +5302,9 @@ void main() {
testWidgets('selection rects are not sent if scribbleEnabled is false', (WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
SystemChannels.textInput.setMockMethodCallHandler((MethodCall methodCall) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.textInput, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
final TextEditingController controller = TextEditingController();
......
......@@ -1883,7 +1883,7 @@ void main() {
group('BrowserContextMenu', () {
setUp(() async {
SystemChannels.contextMenu.setMockMethodCallHandler((MethodCall call) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.contextMenu, (MethodCall call) {
// Just complete successfully, so that BrowserContextMenu thinks that
// the engine successfully received its call.
return Future<void>.value();
......@@ -1893,7 +1893,7 @@ void main() {
tearDown(() async {
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 {
......
......@@ -311,8 +311,9 @@ void main() {
testWidgets('changes should send setUndoState to the UndoManagerConnection on iOS', (WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
SystemChannels.undoManager.setMockMethodCallHandler((MethodCall methodCall) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.undoManager, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
final FocusNode focusNode = FocusNode();
......
......@@ -6,8 +6,6 @@ import 'package:flutter/services.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
/// [checkMockMessageHandler] methods on [BinaryMessenger] in tests.
///
......@@ -19,21 +17,23 @@ import 'binding.dart';
/// more accurately represents the actual method invocation.
extension TestBinaryMessengerExtension on BinaryMessenger {
/// Shim for [TestDefaultBinaryMessenger.setMockMessageHandler].
// TODO(ianh): deprecate this method: @NotYetDeprecated(
// 'Use tester.binding.defaultBinaryMessenger.setMockMessageHandler or '
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler instead. '
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Use tester.binding.defaultBinaryMessenger.setMockMessageHandler or '
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler instead. '
'For the first argument, pass channel.name. '
'This feature was deprecated after v3.9.0-19.0.pre.'
)
void setMockMessageHandler(String channel, MessageHandler? handler) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler(channel, handler);
}
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
// TODO(ianh): deprecate this method: @NotYetDeprecated(
// 'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead.'
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
'For the first argument, pass channel.name. '
'This feature was deprecated after v3.9.0-19.0.pre.'
)
bool checkMockMessageHandler(String channel, Object? 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.
extension TestBasicMessageChannelExtension<T> on BasicMessageChannel<T> {
/// Shim for [TestDefaultBinaryMessenger.setMockDecodedMessageHandler].
// TODO(ianh): deprecate this method: @NotYetDeprecated(
// 'Use tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler or '
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler instead. '
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Use tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler or '
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler instead. '
'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) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler<T>(this, handler);
}
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
// TODO(ianh): deprecate this method: @NotYetDeprecated(
// 'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
// 'For the first argument, pass channel.name. '
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
'For the first argument, pass channel.name. '
'This feature was deprecated after v3.9.0-19.0.pre.'
)
bool checkMockMessageHandler(Object? 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.
extension TestMethodChannelExtension on MethodChannel {
/// Shim for [TestDefaultBinaryMessenger.setMockMethodCallHandler].
// TODO(ianh): deprecate this method: @NotYetDeprecated(
// 'Use tester.binding.defaultBinaryMessenger.setMockMethodCallHandler or '
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler instead. '
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Use tester.binding.defaultBinaryMessenger.setMockMethodCallHandler or '
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler instead. '
'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) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(this, handler);
}
/// Shim for [TestDefaultBinaryMessenger.checkMockMessageHandler].
// TODO(ianh): deprecate this method: @NotYetDeprecated(
// 'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
// 'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
// 'For the first argument, pass channel.name. '
// 'This feature was deprecated after v2.1.0-10.0.pre.'
// )
@Deprecated(
'Use tester.binding.defaultBinaryMessenger.checkMockMessageHandler or '
'TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler instead. '
'For the first argument, pass channel.name. '
'This feature was deprecated after v3.9.0-19.0.pre.'
)
bool checkMockMethodCallHandler(Object? handler) {
return TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(name, handler);
}
......
......@@ -8,7 +8,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'binding.dart';
import 'deprecated.dart';
import 'test_async_utils.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
/// [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].
///
......@@ -68,13 +67,13 @@ class TestTextInput {
///
/// Called by the binding at the end of a (successful) test when
/// [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].
///
/// The binding uses the [register] and [unregister] methods to control this
/// 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;
......
......@@ -3,19 +3,22 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:{{projectName}}/{{projectName}}_method_channel.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
MethodChannel{{pluginDartClass}} platform = MethodChannel{{pluginDartClass}}();
const MethodChannel channel = MethodChannel('{{projectName}}');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
channel,
(MethodCall methodCall) async {
return '42';
});
},
);
});
tearDown(() {
channel.setMockMethodCallHandler(null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
});
test('getPlatformVersion', () async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment