Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
151 lines
5.1 KiB
Dart
151 lines
5.1 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:meshport_client_core/meshport_client_core.dart';
|
|
import 'package:meshport_lab/features/lab_screen.dart';
|
|
|
|
void main() {
|
|
test('sharing links show decoded Unicode names', () {
|
|
for (final fragment in ['演示节点', '%E6%BC%94%E7%A4%BA%E8%8A%82%E7%82%B9']) {
|
|
expect(
|
|
importProxyNodes('socks5://127.0.0.1:1080#$fragment').nodes.single.name,
|
|
'演示节点',
|
|
);
|
|
}
|
|
});
|
|
test('blank and legacy DNS use default while custom resolver survives', () {
|
|
final p = ProxyProfile();
|
|
p.addNodes(importProxyNodes('socks://127.0.0.1:1080').nodes);
|
|
p.proxyDnsServer = ' ';
|
|
expect(p.runtime()['proxy_dns_server'], ProxyProfile.defaultProxyDns);
|
|
expect(p.runtime()['dns_protection'], true);
|
|
expect(p.validateConnection, returnsNormally);
|
|
final legacy = p.toJson();
|
|
(legacy['runtime'] as Map)['proxy_dns_server'] = '';
|
|
expect(
|
|
ProxyProfile.fromJson(legacy).proxyDnsServer,
|
|
ProxyProfile.defaultProxyDns,
|
|
);
|
|
p.proxyDnsServer = 'tls://resolver.example';
|
|
expect(ProxyProfile.fromJson(p.toJson()).proxyDnsServer, p.proxyDnsServer);
|
|
});
|
|
|
|
test('only initial single node is selected automatically', () {
|
|
final p = ProxyProfile();
|
|
p.addNodes(importProxyNodes('socks://127.0.0.1:1080').nodes);
|
|
final selected = p.selectedId;
|
|
expect(selected, p.nodes.single.id);
|
|
p.addNodes(importProxyNodes('socks://127.0.0.1:1081').nodes);
|
|
expect(p.selectedId, selected);
|
|
final multiple = ProxyProfile();
|
|
multiple.addNodes(
|
|
importProxyNodes('socks://127.0.0.1:1080\nsocks://127.0.0.1:1081').nodes,
|
|
);
|
|
expect(multiple.selectedId, isNull);
|
|
final subscription = ProxyProfile();
|
|
replaceSubscription(
|
|
subscription,
|
|
's',
|
|
importProxyNodes('socks://127.0.0.1:1080', source: 's'),
|
|
DateTime.now(),
|
|
);
|
|
expect(subscription.selectedId, subscription.nodes.single.id);
|
|
replaceSubscription(
|
|
subscription,
|
|
's',
|
|
importProxyNodes('socks://127.0.0.1:1081', source: 's'),
|
|
DateTime.now(),
|
|
);
|
|
expect(subscription.selectedId, isNull);
|
|
});
|
|
|
|
const channel = MethodChannel('meshport/system_vpn');
|
|
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
|
tearDown(
|
|
() =>
|
|
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null),
|
|
);
|
|
|
|
Future<void> openProxy(WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: LabScreen(initializeNative: false)),
|
|
);
|
|
await tester.tap(find.text('代理').last);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('仅代理'), findsOneWidget);
|
|
expect(find.text('网络入口'), findsNothing);
|
|
expect(find.text('编辑 DNS'), findsNothing);
|
|
}
|
|
|
|
Future<void> chooseMode(WidgetTester tester, String mode) async {
|
|
final field = find.byWidgetPredicate(
|
|
(w) =>
|
|
w is DropdownButtonFormField<String> &&
|
|
w.decoration.labelText == '上网模式',
|
|
);
|
|
await tester.ensureVisible(field);
|
|
await tester.tap(field);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text(mode).last);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
testWidgets(
|
|
'automatic saves serialize rapid edits and keep latest value',
|
|
(tester) async {
|
|
final first = Completer<void>();
|
|
final saves = <Map<String, dynamic>>[];
|
|
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
|
call,
|
|
) async {
|
|
if (call.method == 'save_proxy_profile') {
|
|
saves.add(
|
|
jsonDecode(call.arguments as String) as Map<String, dynamic>,
|
|
);
|
|
if (saves.length == 1) await first.future;
|
|
}
|
|
return null;
|
|
});
|
|
await openProxy(tester);
|
|
await chooseMode(tester, '直连');
|
|
await chooseMode(tester, '全局代理');
|
|
expect(saves.length, 1);
|
|
first.complete();
|
|
await tester.pumpAndSettle();
|
|
expect(saves.length, 2);
|
|
expect((saves.last['runtime'] as Map)['mode'], 'global');
|
|
expect(find.text('正在自动保存…'), findsNothing);
|
|
expect(find.text('重试保存'), findsNothing);
|
|
},
|
|
skip: !Platform.isMacOS,
|
|
);
|
|
|
|
testWidgets(
|
|
'failed automatic save offers retry and clears after success',
|
|
(tester) async {
|
|
var fail = true;
|
|
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
|
call,
|
|
) async {
|
|
if (call.method == 'save_proxy_profile' && fail) {
|
|
throw PlatformException(code: 'KEYCHAIN_SAVE');
|
|
}
|
|
return null;
|
|
});
|
|
await openProxy(tester);
|
|
await chooseMode(tester, '直连');
|
|
expect(find.text('重试保存'), findsOneWidget);
|
|
fail = false;
|
|
await tester.ensureVisible(find.text('重试保存'));
|
|
await tester.tap(find.text('重试保存'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('重试保存'), findsNothing);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
skip: !Platform.isMacOS,
|
|
);
|
|
}
|