Gitea CI / Build Windows x64 app (push) Successful in 2m38s
Gitea CI / Check code and tests (push) Successful in 5m19s
Gitea CI / Build Android APK (push) Successful in 3m13s
Gitea CI / Audit and package Windows x64 (push) Successful in 2m49s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 59s
Gitea CI / Gitea CI passed (push) Successful in 2s
91 lines
3.1 KiB
Dart
91 lines
3.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cutdex/workspace/preview_controller_registry.dart';
|
|
import 'package:cutdex_sdk/runtime.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../support/preview_fixture.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
const channel = MethodChannel('registry-startup-test');
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
|
|
test(
|
|
'pending startup exposes its controller and callers share initialization',
|
|
() async {
|
|
final gate = Completer<void>();
|
|
final started = Completer<void>();
|
|
messenger.setMockMethodCallHandler(channel, (call) async {
|
|
expect(call.method, 'capabilities');
|
|
started.complete();
|
|
await gate.future;
|
|
throw PlatformException(code: 'failed', message: 'startup failed');
|
|
});
|
|
final fixture = await createPreviewFixture(
|
|
Uri.parse('file:///fixture.mp4'),
|
|
);
|
|
final registry = PreviewControllerRegistry(
|
|
CutdexRuntime(channel: channel),
|
|
);
|
|
try {
|
|
final pending = registry.prepare(('p', 't'), fixture.timeline);
|
|
final failure = expectLater(pending, throwsA(isA<RuntimeException>()));
|
|
await started.future;
|
|
expect(registry.cached(('p', 't')), isNotNull);
|
|
expect(registry.cached(('p', 't'))!.ready, isFalse);
|
|
expect(registry.prepare(('p', 't'), fixture.timeline), same(pending));
|
|
gate.complete();
|
|
await failure;
|
|
expect(registry.cached(('p', 't')), isNull);
|
|
} finally {
|
|
registry.dispose();
|
|
messenger.setMockMethodCallHandler(channel, null);
|
|
await fixture.workspace.close();
|
|
await fixture.directory.delete(recursive: true);
|
|
}
|
|
},
|
|
);
|
|
|
|
test(
|
|
'invalidating pending startup cannot publish a closed controller',
|
|
() async {
|
|
final gate = Completer<void>();
|
|
final started = Completer<void>();
|
|
messenger.setMockMethodCallHandler(channel, (call) async {
|
|
expect(call.method, 'capabilities');
|
|
started.complete();
|
|
await gate.future;
|
|
return {
|
|
'contractVersion': 1,
|
|
'features': {'playback.preview': 'conditional'},
|
|
};
|
|
});
|
|
final fixture = await createPreviewFixture(
|
|
Uri.parse('file:///fixture.mp4'),
|
|
);
|
|
final registry = PreviewControllerRegistry(
|
|
CutdexRuntime(channel: channel),
|
|
);
|
|
try {
|
|
final pending = registry.prepare(('p', 't'), fixture.timeline);
|
|
final failure = expectLater(pending, throwsStateError);
|
|
await started.future;
|
|
final invalidation = registry.invalidate(('p', 't'));
|
|
expect(registry.cached(('p', 't')), isNull);
|
|
gate.complete();
|
|
await failure;
|
|
await invalidation;
|
|
expect(registry.cached(('p', 't')), isNull);
|
|
} finally {
|
|
registry.dispose();
|
|
messenger.setMockMethodCallHandler(channel, null);
|
|
await fixture.workspace.close();
|
|
await fixture.directory.delete(recursive: true);
|
|
}
|
|
},
|
|
);
|
|
}
|