π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Drop the OCR service unit tests
laurenspriem4f176854430c
diff --git a/mobile/apps/photos/plugins/ente_vision/test/vision_text_recognizer_test.dart b/mobile/apps/photos/plugins/ente_vision/test/vision_text_recognizer_test.dartdeleted file mode 100644index 6f1afcaa13..0000000000--- a/mobile/apps/photos/plugins/ente_vision/test/vision_text_recognizer_test.dart+++ /dev/null@@ -1,133 +0,0 @@-import 'package:ente_vision/ente_vision.dart';-import 'package:flutter/services.dart';-import 'package:flutter_test/flutter_test.dart';--void main() {- TestWidgetsFlutterBinding.ensureInitialized();-- const channel = MethodChannel('io.ente.photos.vision/text_recognition');- final recognizer = VisionTextRecognizer(methodChannel: channel);- final calls = <MethodCall>[];- Future<Object?> Function(MethodCall call) reply = (_) async => null;-- setUp(() {- calls.clear();- reply = (_) async => null;- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger- .setMockMethodCallHandler(channel, (call) {- calls.add(call);- return reply(call);- });- });-- tearDown(() {- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger- .setMockMethodCallHandler(channel, null);- });-- test('detectText sends its arguments and returns the native map', () async {- final payload = {- 'blocks': [- {- 'text': 'hello',- 'confidence': 0.9,- 'points': [- {'x': 1.0, 'y': 2.0},- {'x': 10.0, 'y': 2.0},- {'x': 10.0, 'y': 8.0},- {'x': 1.0, 'y': 8.0},- ],- 'characters': <Object?>[],- },- ],- 'imageWidth': 640,- 'imageHeight': 480,- };- reply = (_) async => payload;-- final result = await recognizer.detectText(- imagePath: '/tmp/photo.jpg',- requestId: 'request-1',- );-- expect(calls.single.method, 'textRecognition.detectText');- expect(calls.single.arguments, {- 'imagePath': '/tmp/photo.jpg',- 'includeAllConfidenceScores': false,- 'requestId': 'request-1',- });- expect(result, payload);- });-- test('detectText forwards includeAllConfidenceScores', () async {- await recognizer.detectText(- imagePath: '/tmp/photo.jpg',- includeAllConfidenceScores: true,- );-- expect(calls.single.arguments, {- 'imagePath': '/tmp/photo.jpg',- 'includeAllConfidenceScores': true,- 'requestId': null,- });- });-- test(- 'detectTextRegions sends its arguments and returns the native map',- () async {- final payload = {- 'regions': [- {- 'confidence': 0.75,- 'points': [- {'x': 0.0, 'y': 0.0},- {'x': 5.0, 'y': 0.0},- {'x': 5.0, 'y': 3.0},- {'x': 0.0, 'y': 3.0},- ],- },- ],- 'imageWidth': 320,- 'imageHeight': 240,- };- reply = (_) async => payload;-- final result = await recognizer.detectTextRegions(- imagePath: '/tmp/photo.jpg',- requestId: 'request-2',- );-- expect(calls.single.method, 'textRecognition.detectTextRegions');- expect(calls.single.arguments, {- 'imagePath': '/tmp/photo.jpg',- 'requestId': 'request-2',- });- expect(result, payload);- },- );-- test('cancelRequest sends the request id', () async {- await recognizer.cancelRequest('request-3');-- expect(calls.single.method, 'textRecognition.cancelRequest');- expect(calls.single.arguments, {'requestId': 'request-3'});- });-- test('a null native result becomes an empty map', () async {- final result = await recognizer.detectText(imagePath: '/tmp/photo.jpg');-- expect(result, isEmpty);- });-- test('platform exceptions propagate unchanged', () async {- reply = (_) async =>- throw PlatformException(code: 'CANCELLED', message: 'cancelled');-- await expectLater(- recognizer.detectText(imagePath: '/tmp/photo.jpg', requestId: 'r'),- throwsA(- isA<PlatformException>().having((e) => e.code, 'code', 'CANCELLED'),- ),- );- });-}diff --git a/mobile/apps/photos/test/services/machine_learning/ocr/ocr_models_test.dart b/mobile/apps/photos/test/services/machine_learning/ocr/ocr_models_test.dartdeleted file mode 100644index fae6e3458d..0000000000--- a/mobile/apps/photos/test/services/machine_learning/ocr/ocr_models_test.dart+++ /dev/null@@ -1,180 +0,0 @@-import "package:flutter/widgets.dart";-import "package:flutter_test/flutter_test.dart";-import "package:photos/services/machine_learning/ocr/ocr_models.dart";--void main() {- const quad = [- {"x": 1, "y": 2},- {"x": 11, "y": 2},- {"x": 11, "y": 8.5},- {"x": 1, "y": 8.5},- ];-- group("TextBlock.fromMap", () {- test("parses points and characters", () {- final block = TextBlock.fromMap({- "text": "hello",- "confidence": 0.93,- "points": quad,- "characters": [- {- "text": "h",- "confidence": 0.9,- "points": [- {"x": 1, "y": 2},- {"x": 3, "y": 2},- {"x": 3, "y": 8.5},- {"x": 1, "y": 8.5},- ],- },- "not a map",- ],- });-- expect(block.text, "hello");- expect(block.confidence, 0.93);- expect(block.points, const [- Offset(1, 2),- Offset(11, 2),- Offset(11, 8.5),- Offset(1, 8.5),- ]);- expect(block.characters, hasLength(1));- expect(block.characters.single.text, "h");- expect(block.characters.single.confidence, 0.9);- expect(- block.characters.single.boundingBox,- const Rect.fromLTRB(1, 2, 3, 8.5),- );- expect(block.boundingBox, const Rect.fromLTRB(1, 2, 11, 8.5));- expect(block.center, const Offset(6, 5.25));- });-- test("falls back to the rectangle when points are missing", () {- final block = TextBlock.fromMap({- "text": "rect",- "x": 10,- "y": 20,- "width": 30,- "height": 5,- });-- expect(block.points, const [- Offset(10, 20),- Offset(40, 20),- Offset(40, 25),- Offset(10, 25),- ]);- expect(block.characters, isEmpty);- expect(block.confidence, 0);- });-- test("falls back to the rectangle when points are empty", () {- final block = TextBlock.fromMap({- "points": <Object?>[],- "x": 0,- "y": 0,- "width": 4,- "height": 4,- });-- expect(block.boundingBox, const Rect.fromLTRB(0, 0, 4, 4));- expect(block.text, "");- });-- test("rejects a map without points or rectangle", () {- expect(() => TextBlock.fromMap({"text": "x"}), throwsArgumentError);- });-- test("round trips through toMap", () {- final block = TextBlock.fromMap({- "text": "hello",- "confidence": 0.5,- "points": quad,- "characters": [- {"text": "h", "confidence": 0.4, "points": quad},- ],- });-- final copy = TextBlock.fromMap(block.toMap());-- expect(copy.text, block.text);- expect(copy.confidence, block.confidence);- expect(copy.points, block.points);- expect(copy.characters.single.text, "h");- expect(copy.characters.single.points, block.characters.single.points);- });- });-- test("CharacterBox.fromMap tolerates missing fields", () {- final character = CharacterBox.fromMap(const {});-- expect(character.text, "");- expect(character.confidence, 0);- expect(character.points, isEmpty);- expect(character.boundingBox, Rect.zero);- });-- test("TextRegion.fromMap parses confidence and points", () {- final region = TextRegion.fromMap({"confidence": 0.75, "points": quad});-- expect(region.confidence, 0.75);- expect(region.points, hasLength(4));- expect(region.boundingBox, const Rect.fromLTRB(1, 2, 11, 8.5));- });-- test("TextDetectionResult.fromMap parses blocks and image size", () {- final result = TextDetectionResult.fromMap({- "blocks": [- {"text": "a", "confidence": 1, "points": quad},- "ignored",- ],- "imageWidth": 640,- "imageHeight": 480.0,- });-- expect(result.blocks.single.text, "a");- expect(result.imageSize, const Size(640, 480));- });-- test("TextDetectionResult.fromMap tolerates missing keys", () {- final result = TextDetectionResult.fromMap(const {});-- expect(result.blocks, isEmpty);- expect(result.imageSize, Size.zero);- });-- test("TextRegionDetectionResult.fromMap parses regions and size", () {- final result = TextRegionDetectionResult.fromMap({- "regions": [- {"confidence": 0.6, "points": quad},- ],- "imageWidth": 320,- "imageHeight": 240,- });-- expect(result.regions.single.confidence, 0.6);- expect(result.imageSize, const Size(320, 240));- });-- test("TextRegionDetectionResult.fromMap tolerates missing keys", () {- final result = TextRegionDetectionResult.fromMap(const {});-- expect(result.regions, isEmpty);- expect(result.imageSize, Size.zero);- });-- test("OcrException prints its code and message", () {- const exception = OcrException(- code: "IMAGE_NOT_FOUND",- message: "Image file does not exist",- details: 42,- );-- expect(- exception.toString(),- "OcrException(IMAGE_NOT_FOUND, Image file does not exist)",- );- expect(exception.details, 42);- });-}diff --git a/mobile/apps/photos/test/services/machine_learning/ocr/ocr_service_test.dart b/mobile/apps/photos/test/services/machine_learning/ocr/ocr_service_test.dartdeleted file mode 100644index 6619010886..0000000000--- a/mobile/apps/photos/test/services/machine_learning/ocr/ocr_service_test.dart+++ /dev/null@@ -1,211 +0,0 @@-import "dart:io";--import "package:flutter/widgets.dart";-import "package:flutter_test/flutter_test.dart";-import "package:photos/services/machine_learning/ocr/ocr_backend.dart";-import "package:photos/services/machine_learning/ocr/ocr_models.dart";-import "package:photos/services/machine_learning/ocr_service.dart";--class _FakeBackend implements OcrBackend {- _FakeBackend(this.name);-- final String name;- final List<String> calls = [];- Set<OcrModelComponent>? preparedComponents;-- @override- Future<ModelPreparationStatus> prepareModels(- Set<OcrModelComponent> components,- ) async {- calls.add("prepareModels");- preparedComponents = components;- return ModelPreparationStatus(isReady: true, version: name);- }-- @override- Future<TextDetectionResult> detectText({- required String imagePath,- bool includeAllConfidenceScores = false,- String? requestId,- }) async {- calls.add("detectText:$requestId:$includeAllConfidenceScores");- return const TextDetectionResult(blocks: [], imageSize: Size(1, 1));- }-- @override- Future<TextRegionDetectionResult> detectTextRegions({- required String imagePath,- String? requestId,- }) async {- calls.add("detectTextRegions:$requestId");- return const TextRegionDetectionResult(regions: [], imageSize: Size(1, 1));- }-- @override- Future<void> cancelRequest(String requestId) async {- calls.add("cancelRequest:$requestId");- }-- @override- Future<String> ensureDisplayablePath(String imagePath) async {- calls.add("ensureDisplayablePath");- return "$name:$imagePath";- }-}--class _Harness {- _Harness({- required bool rustOcr,- required bool isAndroid,- required bool isIOS,- }) : rustOcr = rustOcr {- service = OcrService(- rustOcrEnabled: () => this.rustOcr,- isAndroid: isAndroid,- isIOS: isIOS,- createLegacyBackend: () => _create(legacy),- createRustBackend: () => _create(rust),- createVisionBackend: () => _create(vision),- );- }-- bool rustOcr;- late final OcrService service;- final legacy = _FakeBackend("legacy");- final rust = _FakeBackend("rust");- final vision = _FakeBackend("vision");- final created = <String>[];-- OcrBackend _create(_FakeBackend backend) {- created.add(backend.name);- return backend;- }-}--void main() {- late Directory tempDirectory;- late String imagePath;-- setUp(() async {- tempDirectory = await Directory.systemTemp.createTemp("ocr_service_test");- imagePath = "${tempDirectory.path}/photo.jpg";- await File(imagePath).writeAsBytes(const [1, 2, 3]);- });-- tearDown(() async {- await tempDirectory.delete(recursive: true);- });-- test("uses the Rust backend on Android when the flag is on", () async {- final harness = _Harness(rustOcr: true, isAndroid: true, isIOS: false);-- expect(harness.service.backendKind, OcrBackendKind.rust);- final status = await harness.service.prepareModels();- expect(status.version, "rust");- expect(harness.rust.preparedComponents, OcrModelComponent.values.toSet());- expect(harness.created, ["rust"]);- });-- test("uses the Vision backend on iOS when the flag is on", () async {- final harness = _Harness(rustOcr: true, isAndroid: false, isIOS: true);-- expect(harness.service.backendKind, OcrBackendKind.vision);- final status = await harness.service.prepareModels(- components: {OcrModelComponent.detector},- );- expect(status.version, "vision");- expect(harness.vision.preparedComponents, {OcrModelComponent.detector});- expect(harness.created, ["vision"]);- });-- test("uses the legacy backend when the flag is off", () async {- for (final (isAndroid, isIOS) in const [(true, false), (false, true)]) {- final harness = _Harness(- rustOcr: false,- isAndroid: isAndroid,- isIOS: isIOS,- );-- expect(harness.service.backendKind, OcrBackendKind.legacy);- await harness.service.cancelRequest("r");- expect(harness.legacy.calls, ["cancelRequest:r"]);- expect(harness.created, ["legacy"]);- }- });-- test("uses the legacy backend on other platforms even with the flag on", () {- final harness = _Harness(rustOcr: true, isAndroid: false, isIOS: false);-- expect(harness.service.backendKind, OcrBackendKind.legacy);- });-- test("pins the backend chosen on first use", () async {- final harness = _Harness(rustOcr: false, isAndroid: true, isIOS: false);-- await harness.service.cancelRequest("a");- harness.rustOcr = true;- await harness.service.cancelRequest("b");-- expect(harness.legacy.calls, ["cancelRequest:a", "cancelRequest:b"]);- expect(harness.rust.calls, isEmpty);- expect(harness.created, ["legacy"]);- });-- test("detectText forwards to the backend for an existing image", () async {- final harness = _Harness(rustOcr: true, isAndroid: true, isIOS: false);-- final result = await harness.service.detectText(- imagePath: imagePath,- includeAllConfidenceScores: true,- requestId: "r1",- );-- expect(result.imageSize, const Size(1, 1));- expect(harness.rust.calls, ["detectText:r1:true"]);- });-- test(- "detectTextRegions forwards to the backend for an existing image",- () async {- final harness = _Harness(rustOcr: true, isAndroid: false, isIOS: true);-- await harness.service.detectTextRegions(- imagePath: imagePath,- requestId: "r2",- );-- expect(harness.vision.calls, ["detectTextRegions:r2"]);- },- );-- test("rejects a missing image before reaching the backend", () async {- final harness = _Harness(rustOcr: true, isAndroid: true, isIOS: false);- final missingPath = "${tempDirectory.path}/missing.jpg";-- await expectLater(- harness.service.detectText(imagePath: missingPath),- throwsA(- isA<ArgumentError>().having(- (e) => e.message,- "message",- "Image file does not exist at path: $missingPath",- ),- ),- );- await expectLater(- harness.service.detectTextRegions(imagePath: missingPath),- throwsArgumentError,- );- expect(harness.rust.calls, isEmpty);- expect(harness.created, isEmpty);- });-- test("ensureDisplayablePath goes through the selected backend", () async {- final harness = _Harness(rustOcr: true, isAndroid: true, isIOS: false);-- expect(- await harness.service.ensureDisplayablePath("/tmp/photo.heic"),- "rust:/tmp/photo.heic",- );- });-}diff --git a/mobile/apps/photos/test/services/machine_learning/ocr/rust_ocr_backend_test.dart b/mobile/apps/photos/test/services/machine_learning/ocr/rust_ocr_backend_test.dartdeleted file mode 100644index 17eed26eae..0000000000--- a/mobile/apps/photos/test/services/machine_learning/ocr/rust_ocr_backend_test.dart+++ /dev/null@@ -1,147 +0,0 @@-import "package:flutter/widgets.dart";-import "package:flutter_test/flutter_test.dart";-import "package:photos/services/machine_learning/ocr/ocr_models.dart";-import "package:photos/services/machine_learning/ocr/rust_ocr_backend.dart";-import "package:photos/src/rust/api/ocr_api.dart";--void main() {- const quad = [- RustOcrPoint(x: 1, y: 2),- RustOcrPoint(x: 11, y: 2),- RustOcrPoint(x: 11, y: 8.5),- RustOcrPoint(x: 1, y: 8.5),- ];- const offsets = [- Offset(1, 2),- Offset(11, 2),- Offset(11, 8.5),- Offset(1, 8.5),- ];-- test("converts a Rust text detection result", () {- const rustResult = RustTextDetectionResult(- blocks: [- RustTextBlock(- text: "hello",- confidence: 0.91,- points: quad,- characters: [- RustCharacterBox(text: "h", confidence: 0.8, points: quad),- ],- ),- ],- imageWidth: 640,- imageHeight: 480,- );-- final result = textDetectionResultFromRust(rustResult);-- expect(result.imageSize, const Size(640, 480));- final block = result.blocks.single;- expect(block.text, "hello");- expect(block.confidence, 0.91);- expect(block.points, offsets);- expect(block.characters.single.text, "h");- expect(block.characters.single.confidence, 0.8);- expect(block.characters.single.points, offsets);- });-- test("converts a Rust text region detection result", () {- const rustResult = RustTextRegionDetectionResult(- regions: [RustTextRegion(confidence: 0.7, points: quad)],- imageWidth: 320,- imageHeight: 240,- );-- final result = textRegionDetectionResultFromRust(rustResult);-- expect(result.imageSize, const Size(320, 240));- expect(result.regions.single.confidence, 0.7);- expect(result.regions.single.points, offsets);- });-- group("RustOcrError mapping", () {- const imagePath = "/tmp/photo.jpg";- OcrException map(RustOcrError error, {String otherCode = "OTHER"}) =>- ocrExceptionFromRustError(- error,- imagePath: imagePath,- otherCode: otherCode,- );-- test("maps each variant to the legacy code and message", () {- expect(- map(const RustOcrError.imageNotFound(message: "image not found: a")),- isA<OcrException>()- .having((e) => e.code, "code", "IMAGE_NOT_FOUND")- .having(- (e) => e.message,- "message",- "Image file does not exist at path: $imagePath",- )- .having((e) => e.details, "details", "image not found: a"),- );- expect(- map(const RustOcrError.invalidImage(message: "bad bytes")),- isA<OcrException>()- .having((e) => e.code, "code", "IMAGE_DECODE_ERROR")- .having(- (e) => e.message,- "message",- "Failed to decode image: bad bytes",- ),- );- expect(- map(const RustOcrError.cancelled()),- isA<OcrException>()- .having((e) => e.code, "code", "CANCELLED")- .having((e) => e.message, "message", isNotEmpty),- );- expect(- map(const RustOcrError.corruptModel(message: "vocab mismatch")),- isA<OcrException>()- .having((e) => e.code, "code", "MODEL_PREP_ERROR")- .having((e) => e.message, "message", "vocab mismatch"),- );- });-- test("maps other errors to the code of the failing operation", () {- const error = RustOcrError.other(message: "ort failure");-- expect(- map(error, otherCode: "RECOGNITION_ERROR").code,- "RECOGNITION_ERROR",- );- expect(map(error, otherCode: "DETECTION_ERROR").code, "DETECTION_ERROR");- expect(map(error, otherCode: "DETECTION_ERROR").message, "ort failure");- });-- test("messages carry the phrases the text detector widget matches", () {- final missing = map(- const RustOcrError.imageNotFound(message: "image not found: a"),- ).toString().toLowerCase();- final undecodable = map(- const RustOcrError.invalidImage(message: "bad bytes"),- ).toString().toLowerCase();-- expect(missing, contains("image"));- expect(missing, contains("not"));- expect(missing, contains("exist"));- expect(undecodable, contains("failed to decode"));- });- });-- group("without a prepared engine", () {- final backend = RustOcrBackend();-- test("cancelRequest completes", () async {- await backend.cancelRequest("request");- });-- test("ensureDisplayablePath returns every path unchanged", () async {- for (final path in ["/tmp/photo.JPG", "/tmp/photo", "/tmp/photo.heic"]) {- expect(await backend.ensureDisplayablePath(path), path);- }- });- });-}diff --git a/mobile/apps/photos/test/services/machine_learning/ocr/vision_ocr_backend_test.dart b/mobile/apps/photos/test/services/machine_learning/ocr/vision_ocr_backend_test.dartdeleted file mode 100644index bb78038145..0000000000--- a/mobile/apps/photos/test/services/machine_learning/ocr/vision_ocr_backend_test.dart+++ /dev/null@@ -1,166 +0,0 @@-import "package:ente_vision/ente_vision.dart";-import "package:flutter/services.dart";-import "package:flutter/widgets.dart";-import "package:flutter_test/flutter_test.dart";-import "package:photos/services/machine_learning/ocr/ocr_models.dart";-import "package:photos/services/machine_learning/ocr/vision_ocr_backend.dart";--void main() {- TestWidgetsFlutterBinding.ensureInitialized();-- const channel = MethodChannel("io.ente.photos.vision/text_recognition");- final backend = VisionOcrBackend(- recognizer: VisionTextRecognizer(methodChannel: channel),- );- final calls = <MethodCall>[];- Future<Object?> Function(MethodCall call) reply = (_) async => null;-- setUp(() {- calls.clear();- reply = (_) async => null;- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger- .setMockMethodCallHandler(channel, (call) {- calls.add(call);- return reply(call);- });- });-- tearDown(() {- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger- .setMockMethodCallHandler(channel, null);- });-- test("prepareModels is ready without downloading anything", () async {- final status = await backend.prepareModels(- OcrModelComponent.values.toSet(),- );-- expect(status.isReady, isTrue);- expect(status.version, "iOS-Vision");- expect(status.modelPath, "system");- expect(calls, isEmpty);- });-- test("detectText forwards its arguments and parses the result", () async {- reply = (_) async => {- "blocks": [- {- "text": "hello",- "confidence": 0.9,- "points": [- {"x": 1.0, "y": 2.0},- {"x": 10.0, "y": 2.0},- {"x": 10.0, "y": 8.0},- {"x": 1.0, "y": 8.0},- ],- "characters": <Object?>[],- },- ],- "imageWidth": 640,- "imageHeight": 480,- };-- final result = await backend.detectText(- imagePath: "/tmp/photo.jpg",- includeAllConfidenceScores: true,- requestId: "request-1",- );-- expect(calls.single.method, "textRecognition.detectText");- expect(calls.single.arguments, {- "imagePath": "/tmp/photo.jpg",- "includeAllConfidenceScores": true,- "requestId": "request-1",- });- expect(result.blocks.single.text, "hello");- expect(result.blocks.single.boundingBox, const Rect.fromLTRB(1, 2, 10, 8));- expect(result.imageSize, const Size(640, 480));- });-- test(- "detectTextRegions forwards its arguments and parses the result",- () async {- reply = (_) async => {- "regions": [- {- "confidence": 0.75,- "points": [- {"x": 0.0, "y": 0.0},- {"x": 5.0, "y": 0.0},- {"x": 5.0, "y": 3.0},- {"x": 0.0, "y": 3.0},- ],- },- ],- "imageWidth": 320,- "imageHeight": 240,- };-- final result = await backend.detectTextRegions(- imagePath: "/tmp/photo.jpg",- requestId: "request-2",- );-- expect(calls.single.method, "textRecognition.detectTextRegions");- expect(calls.single.arguments, {- "imagePath": "/tmp/photo.jpg",- "requestId": "request-2",- });- expect(result.regions.single.confidence, 0.75);- expect(result.imageSize, const Size(320, 240));- },- );-- test("an empty native result becomes an empty detection", () async {- final result = await backend.detectText(imagePath: "/tmp/photo.jpg");-- expect(result.blocks, isEmpty);- expect(result.imageSize, Size.zero);- });-- test("cancelRequest forwards the request id", () async {- await backend.cancelRequest("request-3");-- expect(calls.single.method, "textRecognition.cancelRequest");- expect(calls.single.arguments, {"requestId": "request-3"});- });-- test("platform exceptions become OcrExceptions", () async {- reply = (_) async => throw PlatformException(- code: "IMAGE_DECODE_ERROR",- message: "Failed to decode image",- details: {"path": "/tmp/photo.jpg"},- );-- await expectLater(- backend.detectText(imagePath: "/tmp/photo.jpg"),- throwsA(- isA<OcrException>()- .having((e) => e.code, "code", "IMAGE_DECODE_ERROR")- .having((e) => e.message, "message", "Failed to decode image")- .having((e) => e.details, "details", {"path": "/tmp/photo.jpg"}),- ),- );- });-- test("a platform exception without a message gets a default one", () async {- reply = (_) async => throw PlatformException(code: "CANCELLED");-- await expectLater(- backend.detectTextRegions(imagePath: "/tmp/photo.jpg"),- throwsA(- isA<OcrException>()- .having((e) => e.code, "code", "CANCELLED")- .having((e) => e.message, "message", "OCR operation failed"),- ),- );- });-- test("ensureDisplayablePath returns the path unchanged", () async {- expect(- await backend.ensureDisplayablePath("/tmp/photo.heic"),- "/tmp/photo.heic",- );- expect(calls, isEmpty);- });-}