Unverified Commit aa7e9637 authored by Vyacheslav Egorov's avatar Vyacheslav Egorov Committed by GitHub

Fix several Dart 2 issues in the flutter_driver. (#14749)

* All lists produced by JSON parsing are List<dynamic>. If more
speficic type is required then they need to be explicitly cast, e.g.
using castFrom helper;
* Function of type (ByText) -> Finder is not a subtype of
(SerializableFinder) -> Finder because ByText is in the contravariant
position;
* In Dart 2 typed(any) should be used instead of any in mockito based
tests.
parent 2a6ed0a8
...@@ -122,12 +122,13 @@ class TimelineEvent { ...@@ -122,12 +122,13 @@ class TimelineEvent {
} }
List<TimelineEvent> _parseEvents(Map<String, dynamic> json) { List<TimelineEvent> _parseEvents(Map<String, dynamic> json) {
final List<Map<String, dynamic>> jsonEvents = json['traceEvents']; final List<dynamic> jsonEvents = json['traceEvents'];
if (jsonEvents == null) if (jsonEvents == null)
return null; return null;
return jsonEvents // TODO(vegorov) use instance method version of castFrom when it is available.
return Iterable.castFrom<dynamic, Map<String, dynamic>>(jsonEvents)
.map((Map<String, dynamic> eventJson) => new TimelineEvent(eventJson)) .map((Map<String, dynamic> eventJson) => new TimelineEvent(eventJson))
.toList(); .toList();
} }
...@@ -125,10 +125,10 @@ class FlutterDriverExtension { ...@@ -125,10 +125,10 @@ class FlutterDriverExtension {
}); });
_finders.addAll(<String, FinderConstructor>{ _finders.addAll(<String, FinderConstructor>{
'ByText': _createByTextFinder, 'ByText': (SerializableFinder finder) => _createByTextFinder(finder),
'ByTooltipMessage': _createByTooltipMessageFinder, 'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder),
'ByValueKey': _createByValueKeyFinder, 'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder),
'ByType': _createByTypeFinder, 'ByType': (SerializableFinder finder) => _createByTypeFinder(finder),
}); });
} }
......
...@@ -40,7 +40,7 @@ void main() { ...@@ -40,7 +40,7 @@ void main() {
when(mockClient.getVM()).thenReturn(mockVM); when(mockClient.getVM()).thenReturn(mockVM);
when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[mockIsolate]); when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[mockIsolate]);
when(mockIsolate.loadRunnable()).thenReturn(mockIsolate); when(mockIsolate.loadRunnable()).thenReturn(mockIsolate);
when(mockIsolate.invokeExtension(any, any)).thenAnswer( when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer(
(Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'})); (Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'}));
vmServiceConnectFunction = (String url) { vmServiceConnectFunction = (String url) {
return new Future<VMServiceClientConnection>.value( return new Future<VMServiceClientConnection>.value(
...@@ -124,7 +124,7 @@ void main() { ...@@ -124,7 +124,7 @@ void main() {
}); });
test('checks the health of the driver extension', () async { test('checks the health of the driver extension', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer( when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer(
(Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'})); (Invocation invocation) => makeMockResponse(<String, dynamic>{'status': 'ok'}));
final Health result = await driver.checkHealth(); final Health result = await driver.checkHealth();
expect(result.status, HealthStatus.ok); expect(result.status, HealthStatus.ok);
...@@ -142,7 +142,7 @@ void main() { ...@@ -142,7 +142,7 @@ void main() {
}); });
test('finds by ValueKey', () async { test('finds by ValueKey', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
expect(i.positionalArguments[1], <String, String>{ expect(i.positionalArguments[1], <String, String>{
'command': 'tap', 'command': 'tap',
'timeout': _kSerializedTestTimeout, 'timeout': _kSerializedTestTimeout,
...@@ -162,7 +162,7 @@ void main() { ...@@ -162,7 +162,7 @@ void main() {
}); });
test('sends the tap command', () async { test('sends the tap command', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
expect(i.positionalArguments[1], <String, dynamic>{ expect(i.positionalArguments[1], <String, dynamic>{
'command': 'tap', 'command': 'tap',
'timeout': _kSerializedTestTimeout, 'timeout': _kSerializedTestTimeout,
...@@ -181,7 +181,7 @@ void main() { ...@@ -181,7 +181,7 @@ void main() {
}); });
test('sends the getText command', () async { test('sends the getText command', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
expect(i.positionalArguments[1], <String, dynamic>{ expect(i.positionalArguments[1], <String, dynamic>{
'command': 'get_text', 'command': 'get_text',
'timeout': _kSerializedTestTimeout, 'timeout': _kSerializedTestTimeout,
...@@ -204,7 +204,7 @@ void main() { ...@@ -204,7 +204,7 @@ void main() {
}); });
test('sends the waitFor command', () async { test('sends the waitFor command', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
expect(i.positionalArguments[1], <String, dynamic>{ expect(i.positionalArguments[1], <String, dynamic>{
'command': 'waitFor', 'command': 'waitFor',
'finderType': 'ByTooltipMessage', 'finderType': 'ByTooltipMessage',
...@@ -219,7 +219,7 @@ void main() { ...@@ -219,7 +219,7 @@ void main() {
group('waitUntilNoTransientCallbacks', () { group('waitUntilNoTransientCallbacks', () {
test('sends the waitUntilNoTransientCallbacks command', () async { test('sends the waitUntilNoTransientCallbacks command', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
expect(i.positionalArguments[1], <String, dynamic>{ expect(i.positionalArguments[1], <String, dynamic>{
'command': 'waitUntilNoTransientCallbacks', 'command': 'waitUntilNoTransientCallbacks',
'timeout': _kSerializedTestTimeout, 'timeout': _kSerializedTestTimeout,
...@@ -356,7 +356,7 @@ void main() { ...@@ -356,7 +356,7 @@ void main() {
group('sendCommand error conditions', () { group('sendCommand error conditions', () {
test('local timeout', () async { test('local timeout', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
// completer never competed to trigger timeout // completer never competed to trigger timeout
return new Completer<Map<String, dynamic>>().future; return new Completer<Map<String, dynamic>>().future;
}); });
...@@ -370,7 +370,7 @@ void main() { ...@@ -370,7 +370,7 @@ void main() {
}); });
test('remote error', () async { test('remote error', () async {
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) { when(mockIsolate.invokeExtension(typed(any), typed(any))).thenAnswer((Invocation i) {
return makeMockResponse(<String, dynamic>{ return makeMockResponse(<String, dynamic>{
'message': 'This is a failure' 'message': 'This is a failure'
}, isError: true); }, isError: true);
......
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