Unverified Commit 4956bcc2 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

implicit-casts:false in flutter_driver (#45175)

* implicit-casts:false in flutter_driver

* address review comments
parent a5f9b3b0
# Override the parent analysis_options until all the repo has implicit-casts: false
include: ../analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
......@@ -33,7 +33,7 @@ class GetDiagnosticsTree extends CommandWithTarget {
super(finder, timeout: timeout);
/// Deserializes this command from the value generated by [serialize].
GetDiagnosticsTree.deserialize(Map<String, dynamic> json)
GetDiagnosticsTree.deserialize(Map<String, String> json)
: subtreeDepth = int.parse(json['subtreeDepth']),
includeProperties = json['includeProperties'] == 'true',
diagnosticsType = _diagnosticsTypeIndex.lookupBySimpleName(json['diagnosticsType']),
......
......@@ -185,14 +185,14 @@ class BySemanticsLabel extends SerializableFinder {
@override
Map<String, String> serialize() {
if (label is RegExp) {
final RegExp regExp = label;
final RegExp regExp = label as RegExp;
return super.serialize()..addAll(<String, String>{
'label': regExp.pattern,
'isRegExp': 'true',
});
} else {
return super.serialize()..addAll(<String, String>{
'label': label,
'label': label as String,
});
}
}
......@@ -351,9 +351,9 @@ class Descendant extends SerializableFinder {
/// Deserializes the finder from JSON generated by [serialize].
static Descendant deserialize(Map<String, String> json) {
final Map<String, String> jsonOfMatcher =
Map<String, String>.from(jsonDecode(json['of']));
Map<String, String>.from(jsonDecode(json['of']) as Map<String, dynamic>);
final Map<String, String> jsonMatchingMatcher =
Map<String, String>.from(jsonDecode(json['matching']));
Map<String, String>.from(jsonDecode(json['matching']) as Map<String, dynamic>);
return Descendant(
of: SerializableFinder.deserialize(jsonOfMatcher),
matching: SerializableFinder.deserialize(jsonMatchingMatcher),
......@@ -406,9 +406,9 @@ class Ancestor extends SerializableFinder {
/// Deserializes the finder from JSON generated by [serialize].
static Ancestor deserialize(Map<String, String> json) {
final Map<String, String> jsonOfMatcher =
Map<String, String>.from(jsonDecode(json['of']));
Map<String, String>.from(jsonDecode(json['of']) as Map<String, dynamic>);
final Map<String, String> jsonMatchingMatcher =
Map<String, String>.from(jsonDecode(json['matching']));
Map<String, String>.from(jsonDecode(json['matching']) as Map<String, dynamic>);
return Ancestor(
of: SerializableFinder.deserialize(jsonOfMatcher),
matching: SerializableFinder.deserialize(jsonMatchingMatcher),
......@@ -454,7 +454,7 @@ class GetSemanticsIdResult extends Result {
/// Deserializes this result from JSON.
static GetSemanticsIdResult fromJson(Map<String, dynamic> json) {
return GetSemanticsIdResult(json['id']);
return GetSemanticsIdResult(json['id'] as int);
}
@override
......
......@@ -58,7 +58,7 @@ class _DummySshCommandRunner implements SshCommandRunner {
// will wait indefinitely for the `out` directory to be serviced, causing
// a deadlock.
final ProcessResult r = await Process.run(exe, args);
return r.stdout.split('\n');
return (r.stdout as String).split('\n');
} on ProcessException catch (e) {
_log("Error running '$command': $e");
}
......
......@@ -36,7 +36,7 @@ class GetOffset extends CommandWithTarget {
GetOffset(SerializableFinder finder, this.offsetType, { Duration timeout }) : super(finder, timeout: timeout);
/// Deserializes this command from the value generated by [serialize].
GetOffset.deserialize(Map<String, dynamic> json)
GetOffset.deserialize(Map<String, String> json)
: offsetType = _offsetTypeIndex.lookupBySimpleName(json['offsetType']),
super.deserialize(json);
......@@ -75,8 +75,8 @@ class GetOffsetResult extends Result {
/// Deserializes the result from JSON.
static GetOffsetResult fromJson(Map<String, dynamic> json) {
return GetOffsetResult(
dx: json['dx'],
dy: json['dy'],
dx: json['dx'] as double,
dy: json['dy'] as double,
);
}
......
......@@ -46,7 +46,7 @@ class Health extends Result {
/// Deserializes the result from JSON.
static Health fromJson(Map<String, dynamic> json) {
return Health(_healthStatusIndex.lookupBySimpleName(json['status']));
return Health(_healthStatusIndex.lookupBySimpleName(json['status'] as String));
}
@override
......
......@@ -27,7 +27,7 @@ class RenderTree extends Result {
/// Deserializes the result from JSON.
static RenderTree fromJson(Map<String, dynamic> json) {
return RenderTree(json['tree']);
return RenderTree(json['tree'] as String);
}
@override
......
......@@ -40,7 +40,7 @@ class RequestDataResult extends Result {
/// Deserializes the result from JSON.
static RequestDataResult fromJson(Map<String, dynamic> json) {
return RequestDataResult(json['message']);
return RequestDataResult(json['message'] as String);
}
@override
......
......@@ -37,7 +37,7 @@ class SetSemanticsResult extends Result {
/// Deserializes this result from JSON.
static SetSemanticsResult fromJson(Map<String, dynamic> json) {
return SetSemanticsResult(json['changedState']);
return SetSemanticsResult(json['changedState'] as bool);
}
@override
......
......@@ -11,7 +11,7 @@ class GetText extends CommandWithTarget {
GetText(SerializableFinder finder, { Duration timeout }) : super(finder, timeout: timeout);
/// Deserializes this command from the value generated by [serialize].
GetText.deserialize(Map<String, dynamic> json) : super.deserialize(json);
GetText.deserialize(Map<String, String> json) : super.deserialize(json);
@override
String get kind => 'get_text';
......@@ -27,7 +27,7 @@ class GetTextResult extends Result {
/// Deserializes the result from JSON.
static GetTextResult fromJson(Map<String, dynamic> json) {
return GetTextResult(json['text']);
return GetTextResult(json['text'] as String);
}
@override
......@@ -42,7 +42,7 @@ class EnterText extends Command {
const EnterText(this.text, { Duration timeout }) : super(timeout: timeout);
/// Deserializes this command from the value generated by [serialize].
EnterText.deserialize(Map<String, dynamic> json)
EnterText.deserialize(Map<String, String> json)
: text = json['text'],
super.deserialize(json);
......@@ -78,7 +78,7 @@ class SetTextEntryEmulation extends Command {
const SetTextEntryEmulation(this.enabled, { Duration timeout }) : super(timeout: timeout);
/// Deserializes this command from the value generated by [serialize].
SetTextEntryEmulation.deserialize(Map<String, dynamic> json)
SetTextEntryEmulation.deserialize(Map<String, String> json)
: enabled = json['enabled'] == 'true',
super.deserialize(json);
......
......@@ -159,7 +159,7 @@ class NoTransientCallbacks extends SerializableWaitCondition {
/// given JSON map.
///
/// The [json] argument must not be null.
factory NoTransientCallbacks.deserialize(Map<String, dynamic> json) {
factory NoTransientCallbacks.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'NoTransientCallbacksCondition')
throw SerializationException('Error occurred during deserializing the NoTransientCallbacksCondition JSON string: $json');
......@@ -179,7 +179,7 @@ class NoPendingFrame extends SerializableWaitCondition {
/// JSON map.
///
/// The [json] argument must not be null.
factory NoPendingFrame.deserialize(Map<String, dynamic> json) {
factory NoPendingFrame.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'NoPendingFrameCondition')
throw SerializationException('Error occurred during deserializing the NoPendingFrameCondition JSON string: $json');
......@@ -199,7 +199,7 @@ class FirstFrameRasterized extends SerializableWaitCondition {
/// given JSON map.
///
/// The [json] argument must not be null.
factory FirstFrameRasterized.deserialize(Map<String, dynamic> json) {
factory FirstFrameRasterized.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'FirstFrameRasterizedCondition')
throw SerializationException('Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: $json');
......@@ -219,7 +219,7 @@ class NoPendingPlatformMessages extends SerializableWaitCondition {
/// given JSON map.
///
/// The [json] argument must not be null.
factory NoPendingPlatformMessages.deserialize(Map<String, dynamic> json) {
factory NoPendingPlatformMessages.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition')
throw SerializationException('Error occurred during deserializing the NoPendingPlatformMessagesCondition JSON string: $json');
......@@ -242,7 +242,7 @@ class CombinedCondition extends SerializableWaitCondition {
/// given JSON map.
///
/// The [jsonMap] argument must not be null.
factory CombinedCondition.deserialize(Map<String, dynamic> jsonMap) {
factory CombinedCondition.deserialize(Map<String, String> jsonMap) {
assert(jsonMap != null);
if (jsonMap['conditionName'] != 'CombinedCondition')
throw SerializationException('Error occurred during deserializing the CombinedCondition JSON string: $jsonMap');
......@@ -252,7 +252,7 @@ class CombinedCondition extends SerializableWaitCondition {
final List<SerializableWaitCondition> conditions = <SerializableWaitCondition>[];
for (Map<String, dynamic> condition in json.decode(jsonMap['conditions'])) {
conditions.add(_deserialize(condition));
conditions.add(_deserialize(condition.cast<String, String>()));
}
return CombinedCondition(conditions);
}
......@@ -279,7 +279,7 @@ class CombinedCondition extends SerializableWaitCondition {
/// Parses a [SerializableWaitCondition] or its subclass from the given [json] map.
///
/// The [json] argument must not be null.
SerializableWaitCondition _deserialize(Map<String, dynamic> json) {
SerializableWaitCondition _deserialize(Map<String, String> json) {
assert(json != null);
final String conditionName = json['conditionName'];
switch (conditionName) {
......
......@@ -436,7 +436,7 @@ class FlutterDriver {
final Future<Map<String, dynamic>> future = appIsolate.invokeExtension(
_flutterExtensionMethodName,
serialized,
).then<Map<String, dynamic>>((Object value) => value);
).then<Map<String, dynamic>>((Object value) => value as Map<String, dynamic>);
response = await _warnIfSlow<Map<String, dynamic>>(
future: future,
timeout: command.timeout ?? kUnusuallyLongTimeout,
......@@ -450,9 +450,9 @@ class FlutterDriver {
stackTrace,
);
}
if (response['isError'])
if (response['isError'] as bool)
throw DriverError('Error in Flutter application: ${response['response']}');
return response['response'];
return response['response'] as Map<String, dynamic>;
}
void _logCommunication(String message) {
......@@ -850,8 +850,8 @@ class FlutterDriver {
// and a source of flakes.
await Future<void>.delayed(const Duration(seconds: 2));
final Map<String, dynamic> result = await _peer.sendRequest('_flutter.screenshot');
return base64.decode(result['screenshot']);
final Map<String, dynamic> result = await _peer.sendRequest('_flutter.screenshot') as Map<String, dynamic>;
return base64.decode(result['screenshot'] as String);
}
/// Returns the Flags set in the Dart VM as JSON.
......@@ -875,9 +875,9 @@ class FlutterDriver {
/// [getFlagList]: https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md#getflaglist
Future<List<Map<String, dynamic>>> getVmFlags() async {
await _restorePeerConnectionIfNeeded();
final Map<String, dynamic> result = await _peer.sendRequest('getFlagList');
final Map<String, dynamic> result = await _peer.sendRequest('getFlagList') as Map<String, dynamic>;
return result != null
? result['flags'].cast<Map<String,dynamic>>()
? (result['flags'] as List<dynamic>).cast<Map<String,dynamic>>()
: const <Map<String, dynamic>>[];
}
......@@ -924,7 +924,7 @@ class FlutterDriver {
timeout: timeout,
message: 'VM is taking an unusually long time to respond to being told to stop tracing...',
);
return Timeline.fromJson(await _peer.sendRequest(_getVMTimelineMethodName));
return Timeline.fromJson(await _peer.sendRequest(_getVMTimelineMethodName) as Map<String, dynamic>);
} catch (error, stackTrace) {
throw DriverError(
'Failed to stop tracing due to remote error',
......@@ -1239,10 +1239,9 @@ class DriverOffset {
@override
bool operator ==(dynamic other) {
if (other is! DriverOffset)
return false;
final DriverOffset typedOther = other;
return dx == typedOther.dx && dy == typedOther.dy;
return other is DriverOffset
&& other.dx == dx
&& other.dy == dy;
}
@override
......
......@@ -29,20 +29,20 @@ class TimelineEvent {
factory TimelineEvent(Map<String, dynamic> json) {
return TimelineEvent._(
json,
json['name'],
json['cat'],
json['ph'],
json['pid'],
json['tid'],
json['name'] as String,
json['cat'] as String,
json['ph'] as String,
json['pid'] as int,
json['tid'] as int,
json['dur'] != null
? Duration(microseconds: json['dur'])
? Duration(microseconds: json['dur'] as int)
: null,
json['tdur'] != null
? Duration(microseconds: json['tdur'])
? Duration(microseconds: json['tdur'] as int)
: null,
json['ts'],
json['tts'],
json['args'],
json['ts'] as int,
json['tts'] as int,
json['args'] as Map<String, dynamic>,
);
}
......@@ -122,7 +122,7 @@ class TimelineEvent {
}
List<TimelineEvent> _parseEvents(Map<String, dynamic> json) {
final List<dynamic> jsonEvents = json['traceEvents'];
final List<dynamic> jsonEvents = json['traceEvents'] as List<dynamic>;
if (jsonEvents == null)
return null;
......
......@@ -152,14 +152,14 @@ class FlutterDriverExtension {
});
_finders.addAll(<String, FinderConstructor>{
'ByText': (SerializableFinder finder) => _createByTextFinder(finder),
'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder),
'BySemanticsLabel': (SerializableFinder finder) => _createBySemanticsLabelFinder(finder),
'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder),
'ByType': (SerializableFinder finder) => _createByTypeFinder(finder),
'ByText': (SerializableFinder finder) => _createByTextFinder(finder as ByText),
'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder as ByTooltipMessage),
'BySemanticsLabel': (SerializableFinder finder) => _createBySemanticsLabelFinder(finder as BySemanticsLabel),
'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder as ByValueKey),
'ByType': (SerializableFinder finder) => _createByTypeFinder(finder as ByType),
'PageBack': (SerializableFinder finder) => _createPageBackFinder(),
'Ancestor': (SerializableFinder finder) => _createAncestorFinder(finder),
'Descendant': (SerializableFinder finder) => _createDescendantFinder(finder),
'Ancestor': (SerializableFinder finder) => _createAncestorFinder(finder as Ancestor),
'Descendant': (SerializableFinder finder) => _createDescendantFinder(finder as Descendant),
});
}
......@@ -314,9 +314,9 @@ class FlutterDriverExtension {
Finder _createByValueKeyFinder(ByValueKey arguments) {
switch (arguments.keyValueType) {
case 'int':
return find.byKey(ValueKey<int>(arguments.keyValue));
return find.byKey(ValueKey<int>(arguments.keyValue as int));
case 'String':
return find.byKey(ValueKey<String>(arguments.keyValue));
return find.byKey(ValueKey<String>(arguments.keyValue as String));
default:
throw 'Unsupported ByValueKey type: ${arguments.keyValueType}';
}
......@@ -367,7 +367,7 @@ class FlutterDriverExtension {
}
Future<TapResult> _tap(Command command) async {
final Tap tapCommand = command;
final Tap tapCommand = command as Tap;
final Finder computedFinder = await _waitForElement(
_createFinder(tapCommand.finder).hitTestable()
);
......@@ -376,20 +376,20 @@ class FlutterDriverExtension {
}
Future<WaitForResult> _waitFor(Command command) async {
final WaitFor waitForCommand = command;
final WaitFor waitForCommand = command as WaitFor;
await _waitForElement(_createFinder(waitForCommand.finder));
return const WaitForResult();
}
Future<WaitForAbsentResult> _waitForAbsent(Command command) async {
final WaitForAbsent waitForAbsentCommand = command;
final WaitForAbsent waitForAbsentCommand = command as WaitForAbsent;
await _waitForAbsentElement(_createFinder(waitForAbsentCommand.finder));
return const WaitForAbsentResult();
}
Future<Result> _waitForCondition(Command command) async {
assert(command != null);
final WaitForCondition waitForConditionCommand = command;
final WaitForCondition waitForConditionCommand = command as WaitForCondition;
final WaitCondition condition = deserializeCondition(waitForConditionCommand.condition);
await condition.wait();
return null;
......@@ -437,7 +437,7 @@ class FlutterDriverExtension {
}
Future<GetSemanticsIdResult> _getSemanticsId(Command command) async {
final GetSemanticsId semanticsCommand = command;
final GetSemanticsId semanticsCommand = command as GetSemanticsId;
final Finder target = await _waitForElement(_createFinder(semanticsCommand.finder));
final Iterable<Element> elements = target.evaluate();
if (elements.length > 1) {
......@@ -448,7 +448,7 @@ class FlutterDriverExtension {
SemanticsNode node;
while (renderObject != null && node == null) {
node = renderObject.debugSemantics;
renderObject = renderObject.parent;
renderObject = renderObject.parent as RenderObject;
}
if (node == null)
throw StateError('No semantics data found');
......@@ -456,10 +456,10 @@ class FlutterDriverExtension {
}
Future<GetOffsetResult> _getOffset(Command command) async {
final GetOffset getOffsetCommand = command;
final GetOffset getOffsetCommand = command as GetOffset;
final Finder finder = await _waitForElement(_createFinder(getOffsetCommand.finder));
final Element element = finder.evaluate().single;
final RenderBox box = element.renderObject;
final RenderBox box = element.renderObject as RenderBox;
Offset localPoint;
switch (getOffsetCommand.offsetType) {
case OffsetType.topLeft:
......@@ -483,7 +483,7 @@ class FlutterDriverExtension {
}
Future<DiagnosticsTreeResult> _getDiagnosticsTree(Command command) async {
final GetDiagnosticsTree diagnosticsCommand = command;
final GetDiagnosticsTree diagnosticsCommand = command as GetDiagnosticsTree;
final Finder finder = await _waitForElement(_createFinder(diagnosticsCommand.finder));
final Element element = finder.evaluate().single;
DiagnosticsNode diagnosticsNode;
......@@ -502,7 +502,7 @@ class FlutterDriverExtension {
}
Future<ScrollResult> _scroll(Command command) async {
final Scroll scrollCommand = command;
final Scroll scrollCommand = command as Scroll;
final Finder target = await _waitForElement(_createFinder(scrollCommand.finder));
final int totalMoves = scrollCommand.duration.inMicroseconds * scrollCommand.frequency ~/ Duration.microsecondsPerSecond;
final Offset delta = Offset(scrollCommand.dx, scrollCommand.dy) / totalMoves.toDouble();
......@@ -526,22 +526,22 @@ class FlutterDriverExtension {
}
Future<ScrollResult> _scrollIntoView(Command command) async {
final ScrollIntoView scrollIntoViewCommand = command;
final ScrollIntoView scrollIntoViewCommand = command as ScrollIntoView;
final Finder target = await _waitForElement(_createFinder(scrollIntoViewCommand.finder));
await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: scrollIntoViewCommand.alignment ?? 0.0);
return const ScrollResult();
}
Future<GetTextResult> _getText(Command command) async {
final GetText getTextCommand = command;
final GetText getTextCommand = command as GetText;
final Finder target = await _waitForElement(_createFinder(getTextCommand.finder));
// TODO(yjbanov): support more ways to read text
final Text text = target.evaluate().single.widget;
final Text text = target.evaluate().single.widget as Text;
return GetTextResult(text.data);
}
Future<SetTextEntryEmulationResult> _setTextEntryEmulation(Command command) async {
final SetTextEntryEmulation setTextEntryEmulationCommand = command;
final SetTextEntryEmulation setTextEntryEmulationCommand = command as SetTextEntryEmulation;
if (setTextEntryEmulationCommand.enabled) {
_testTextInput.register();
} else {
......@@ -555,18 +555,18 @@ class FlutterDriverExtension {
throw 'Unable to fulfill `FlutterDriver.enterText`. Text emulation is '
'disabled. You can enable it using `FlutterDriver.setTextEntryEmulation`.';
}
final EnterText enterTextCommand = command;
final EnterText enterTextCommand = command as EnterText;
_testTextInput.enterText(enterTextCommand.text);
return const EnterTextResult();
}
Future<RequestDataResult> _requestData(Command command) async {
final RequestData requestDataCommand = command;
final RequestData requestDataCommand = command as RequestData;
return RequestDataResult(_requestDataHandler == null ? 'No requestData Extension registered' : await _requestDataHandler(requestDataCommand.message));
}
Future<SetFrameSyncResult> _setFrameSync(Command command) async {
final SetFrameSync setFrameSyncCommand = command;
final SetFrameSync setFrameSyncCommand = command as SetFrameSync;
_frameSync = setFrameSyncCommand.enabled;
return const SetFrameSyncResult();
}
......@@ -575,7 +575,7 @@ class FlutterDriverExtension {
bool get _semanticsIsEnabled => RendererBinding.instance.pipelineOwner.semanticsOwner != null;
Future<SetSemanticsResult> _setSemantics(Command command) async {
final SetSemantics setSemanticsCommand = command;
final SetSemantics setSemanticsCommand = command as SetSemantics;
final bool semanticsWasEnabled = _semanticsIsEnabled;
if (setSemanticsCommand.enabled && _semantics == null) {
_semantics = RendererBinding.instance.pipelineOwner.ensureSemantics();
......
......@@ -132,13 +132,13 @@ class _InternalNoPendingPlatformMessagesCondition implements WaitCondition {
@override
bool get condition {
final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;
final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger as TestDefaultBinaryMessenger;
return binaryMessenger.pendingMessageCount == 0;
}
@override
Future<void> wait() async {
final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger;
final TestDefaultBinaryMessenger binaryMessenger = ServicesBinding.instance.defaultBinaryMessenger as TestDefaultBinaryMessenger;
while (!condition) {
await binaryMessenger.platformMessagesFinished;
}
......@@ -163,7 +163,7 @@ class _InternalCombinedCondition implements WaitCondition {
assert(condition != null);
if (condition.conditionName != 'CombinedCondition')
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
final CombinedCondition combinedCondition = condition;
final CombinedCondition combinedCondition = condition as CombinedCondition;
if (combinedCondition.conditions == null) {
return const _InternalCombinedCondition(<WaitCondition>[]);
}
......
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