Michael Goderbauer 5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00

132 lines
3.8 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/services.dart';
import 'basic_messaging.dart';
import 'test_step.dart';
Future<TestStepResult> methodCallJsonSuccessHandshake(dynamic payload) async {
const MethodChannel channel = MethodChannel('json-method', JSONMethodCodec());
return _methodCallSuccessHandshake('JSON success($payload)', channel, payload);
}
Future<TestStepResult> methodCallJsonErrorHandshake(dynamic payload) async {
const MethodChannel channel = MethodChannel('json-method', JSONMethodCodec());
return _methodCallErrorHandshake('JSON error($payload)', channel, payload);
}
Future<TestStepResult> methodCallJsonNotImplementedHandshake() async {
const MethodChannel channel = MethodChannel('json-method', JSONMethodCodec());
return _methodCallNotImplementedHandshake('JSON notImplemented()', channel);
}
Future<TestStepResult> methodCallStandardSuccessHandshake(dynamic payload) async {
const MethodChannel channel = MethodChannel(
'std-method',
StandardMethodCodec(ExtendedStandardMessageCodec()),
);
return _methodCallSuccessHandshake('Standard success($payload)', channel, payload);
}
Future<TestStepResult> methodCallStandardErrorHandshake(dynamic payload) async {
const MethodChannel channel = MethodChannel(
'std-method',
StandardMethodCodec(ExtendedStandardMessageCodec()),
);
return _methodCallErrorHandshake('Standard error($payload)', channel, payload);
}
Future<TestStepResult> methodCallStandardNotImplementedHandshake() async {
const MethodChannel channel = MethodChannel(
'std-method',
StandardMethodCodec(ExtendedStandardMessageCodec()),
);
return _methodCallNotImplementedHandshake('Standard notImplemented()', channel);
}
Future<TestStepResult> _methodCallSuccessHandshake(
String description,
MethodChannel channel,
dynamic arguments,
) async {
final List<dynamic> received = <dynamic>[];
channel.setMethodCallHandler((MethodCall call) async {
received.add(call.arguments);
return call.arguments;
});
dynamic result = nothing;
dynamic error = nothing;
try {
result = await channel.invokeMethod<dynamic>('success', arguments);
} catch (e) {
error = e;
}
return resultOfHandshake(
'Method call success handshake',
description,
arguments,
received,
result,
error,
);
}
Future<TestStepResult> _methodCallErrorHandshake(
String description,
MethodChannel channel,
dynamic arguments,
) async {
final List<dynamic> received = <dynamic>[];
channel.setMethodCallHandler((MethodCall call) async {
received.add(call.arguments);
throw PlatformException(code: 'error', details: arguments);
});
dynamic errorDetails = nothing;
dynamic error = nothing;
try {
error = await channel.invokeMethod<dynamic>('error', arguments);
} on PlatformException catch (e) {
errorDetails = e.details;
} catch (e) {
error = e;
}
return resultOfHandshake(
'Method call error handshake',
description,
arguments,
received,
errorDetails,
error,
);
}
Future<TestStepResult> _methodCallNotImplementedHandshake(
String description,
MethodChannel channel,
) async {
final List<dynamic> received = <dynamic>[];
channel.setMethodCallHandler((MethodCall call) async {
received.add(call.arguments);
throw MissingPluginException();
});
dynamic result = nothing;
dynamic error = nothing;
try {
error = await channel.invokeMethod<dynamic>('notImplemented');
} on MissingPluginException {
result = null;
} catch (e) {
error = e;
}
return resultOfHandshake(
'Method call not implemented handshake',
description,
null,
received,
result,
error,
);
}