-
-
Notifications
You must be signed in to change notification settings - Fork 890
Expand file tree
/
Copy pathglobal_platform_test.dart
More file actions
132 lines (112 loc) · 3.84 KB
/
Copy pathglobal_platform_test.dart
File metadata and controls
132 lines (112 loc) · 3.84 KB
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
import 'dart:async';
import 'package:audioplayers_platform_interface/src/api/audio_context.dart';
import 'package:audioplayers_platform_interface/src/api/global_audio_event.dart';
import 'package:audioplayers_platform_interface/src/global_audioplayers_platform_interface.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'util.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final platform = GlobalAudioplayersPlatformInterface.instance;
final methodCalls = <MethodCall>[];
void clear() {
methodCalls.clear();
}
MethodCall popCall() {
return methodCalls.removeAt(0);
}
MethodCall popLastCall() {
expect(methodCalls, hasLength(1));
return popCall();
}
group('Global Method Channel', () {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('xyz.luan/audioplayers.global'),
(MethodCall methodCall) async {
methodCalls.add(methodCall);
return 1;
},
);
setUp(clear);
test('set AudioContext for Windows', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.windows;
await platform.setGlobalAudioContext(const AudioContext());
final call = popLastCall();
expect(call.method, 'setAudioContext');
expect(call.args, <String, dynamic>{});
});
test('set AudioContext for macOS', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
await platform.setGlobalAudioContext(const AudioContext());
final call = popLastCall();
expect(call.method, 'setAudioContext');
expect(call.args, <String, dynamic>{});
});
test('set AudioContext for Linux', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
await platform.setGlobalAudioContext(const AudioContext());
final call = popLastCall();
expect(call.method, 'setAudioContext');
expect(call.args, <String, dynamic>{});
});
test('set AudioContext for Android', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
await platform.setGlobalAudioContext(const AudioContext());
final call = popLastCall();
expect(call.method, 'setAudioContext');
expect(call.args, {
'isSpeakerphoneOn': true,
'audioMode': 0,
'stayAwake': true,
'contentType': 2,
'usageType': 1,
'audioFocus': 1,
});
});
test('set AudioContext for iOS', () async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await platform.setGlobalAudioContext(const AudioContext());
final call = popLastCall();
expect(call.method, 'setAudioContext');
expect(call.args, {
'category': 'playback',
'options': [
'mixWithOthers',
'defaultToSpeaker',
]
});
});
});
group('Global Event Channel', () {
test('emit global events', () async {
final eventController = StreamController<ByteData>.broadcast();
createNativeEventStream(
channel: 'xyz.luan/audioplayers.global/events',
byteDataStream: eventController.stream,
);
expect(
platform.getGlobalEventStream(),
emitsInOrder(<GlobalAudioEvent>[
const GlobalAudioEvent(
eventType: GlobalAudioEventType.log,
logMessage: 'someLogMessage',
),
]),
);
final byteDataList = <Map<String, dynamic>>[
<String, dynamic>{
'event': 'audio.onLog',
'value': 'someLogMessage',
},
];
for (final byteData in byteDataList) {
eventController.add(
const StandardMethodCodec().encodeSuccessEnvelope(byteData),
);
}
await eventController.close();
});
});
}