1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// 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', message: null, 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,
);
}