feat(ios): 首次启动询问无线数据权限
iOS 在首个接口请求前等待系统无线数据选择,避免未授权时请求被静默拒绝。
This commit is contained in:
1 parent
47df002d8e
commit
b5e9deb4bd
6 files changed
+199
-1
No files matched your search
@@ -0,0 +1,54 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/platform/wireless_data_prompt.dart';
|
||||
|
||||
void main() {
|
||||
setUp(WirelessDataPrompt.resetForTest);
|
||||
tearDown(WirelessDataPrompt.resetForTest);
|
||||
|
||||
test('should_return_immediately_when_disabled', () async {
|
||||
var calls = 0;
|
||||
|
||||
await WirelessDataPrompt.awaitDecision(
|
||||
enabled: false,
|
||||
ask: () async {
|
||||
calls++;
|
||||
},
|
||||
);
|
||||
|
||||
expect(calls, 0);
|
||||
});
|
||||
|
||||
test('should_ask_once_when_enabled', () async {
|
||||
var calls = 0;
|
||||
|
||||
Future<void> ask() async {
|
||||
calls++;
|
||||
}
|
||||
|
||||
await WirelessDataPrompt.awaitDecision(enabled: true, ask: ask);
|
||||
await WirelessDataPrompt.awaitDecision(enabled: true, ask: ask);
|
||||
|
||||
expect(calls, 1);
|
||||
});
|
||||
|
||||
test('should_continue_when_decision_times_out', () async {
|
||||
await WirelessDataPrompt.awaitDecision(
|
||||
enabled: true,
|
||||
ask: () => Completer<void>().future,
|
||||
timeout: const Duration(milliseconds: 20),
|
||||
);
|
||||
});
|
||||
|
||||
test('should_continue_when_ask_fails', () async {
|
||||
await WirelessDataPrompt.awaitDecision(
|
||||
enabled: true,
|
||||
ask: () async {
|
||||
throw StateError('channel missing');
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user