44 lines
1.4 KiB
Dart
44 lines
1.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:background_downloader/background_downloader.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
class _FailingStorage implements PersistentStorage {
|
|
final failure = StateError('download storage unavailable');
|
|
@override
|
|
Future<void> initialize() async => throw failure;
|
|
@override
|
|
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
|
}
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
test(
|
|
'Android initialization failure reaches ready instead of unhandled future',
|
|
() async {
|
|
final previous = debugDefaultTargetPlatformOverride;
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = previous);
|
|
final storage = _FailingStorage();
|
|
final unhandled = <Object>[];
|
|
final done = Completer<void>();
|
|
Object? observed;
|
|
runZonedGuarded(() async {
|
|
final downloader = FileDownloader(persistentStorage: storage);
|
|
try {
|
|
await downloader.ready.timeout(const Duration(milliseconds: 200));
|
|
} catch (error) {
|
|
observed = error;
|
|
} finally {
|
|
done.complete();
|
|
}
|
|
}, (error, stack) => unhandled.add(error));
|
|
await done.future;
|
|
expect(observed, same(storage.failure));
|
|
expect(unhandled, isEmpty);
|
|
},
|
|
);
|
|
}
|