mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
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.
This commit is contained in:
parent
2a6ed0a869
commit
aa7e9637ac
@ -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 {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_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() {
|
|||||||
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() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
|||||||
|
|
||||||
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() {
|
|||||||
|
|
||||||
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() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user