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) {
|
||||
final List<Map<String, dynamic>> jsonEvents = json['traceEvents'];
|
||||
final List<dynamic> jsonEvents = json['traceEvents'];
|
||||
|
||||
if (jsonEvents == 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))
|
||||
.toList();
|
||||
}
|
||||
|
@ -125,10 +125,10 @@ class FlutterDriverExtension {
|
||||
});
|
||||
|
||||
_finders.addAll(<String, FinderConstructor>{
|
||||
'ByText': _createByTextFinder,
|
||||
'ByTooltipMessage': _createByTooltipMessageFinder,
|
||||
'ByValueKey': _createByValueKeyFinder,
|
||||
'ByType': _createByTypeFinder,
|
||||
'ByText': (SerializableFinder finder) => _createByTextFinder(finder),
|
||||
'ByTooltipMessage': (SerializableFinder finder) => _createByTooltipMessageFinder(finder),
|
||||
'ByValueKey': (SerializableFinder finder) => _createByValueKeyFinder(finder),
|
||||
'ByType': (SerializableFinder finder) => _createByTypeFinder(finder),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ void main() {
|
||||
when(mockClient.getVM()).thenReturn(mockVM);
|
||||
when(mockVM.isolates).thenReturn(<VMRunnableIsolate>[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'}));
|
||||
vmServiceConnectFunction = (String url) {
|
||||
return new Future<VMServiceClientConnection>.value(
|
||||
@ -124,7 +124,7 @@ void main() {
|
||||
});
|
||||
|
||||
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'}));
|
||||
final Health result = await driver.checkHealth();
|
||||
expect(result.status, HealthStatus.ok);
|
||||
@ -142,7 +142,7 @@ void main() {
|
||||
});
|
||||
|
||||
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>{
|
||||
'command': 'tap',
|
||||
'timeout': _kSerializedTestTimeout,
|
||||
@ -162,7 +162,7 @@ void main() {
|
||||
});
|
||||
|
||||
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>{
|
||||
'command': 'tap',
|
||||
'timeout': _kSerializedTestTimeout,
|
||||
@ -181,7 +181,7 @@ void main() {
|
||||
});
|
||||
|
||||
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>{
|
||||
'command': 'get_text',
|
||||
'timeout': _kSerializedTestTimeout,
|
||||
@ -204,7 +204,7 @@ void main() {
|
||||
});
|
||||
|
||||
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>{
|
||||
'command': 'waitFor',
|
||||
'finderType': 'ByTooltipMessage',
|
||||
@ -219,7 +219,7 @@ void main() {
|
||||
|
||||
group('waitUntilNoTransientCallbacks', () {
|
||||
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>{
|
||||
'command': 'waitUntilNoTransientCallbacks',
|
||||
'timeout': _kSerializedTestTimeout,
|
||||
@ -356,7 +356,7 @@ void main() {
|
||||
|
||||
group('sendCommand error conditions', () {
|
||||
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
|
||||
return new Completer<Map<String, dynamic>>().future;
|
||||
});
|
||||
@ -370,7 +370,7 @@ void main() {
|
||||
});
|
||||
|
||||
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>{
|
||||
'message': 'This is a failure'
|
||||
}, isError: true);
|
||||
|
Loading…
Reference in New Issue
Block a user