fix a typo in trace events for the image cache (#57821)
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer' as developer;
|
||||
import 'dart:isolate' as isolate;
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -31,12 +33,21 @@ void main() {
|
||||
|
||||
test('Image cache tracing', () async {
|
||||
final TestImageStreamCompleter completer1 = TestImageStreamCompleter();
|
||||
final TestImageStreamCompleter completer2 = TestImageStreamCompleter();
|
||||
PaintingBinding.instance.imageCache.putIfAbsent(
|
||||
'Test',
|
||||
() => completer1,
|
||||
);
|
||||
PaintingBinding.instance.imageCache.clear();
|
||||
|
||||
// ignore: invalid_use_of_protected_member
|
||||
completer2.setImage(const ImageInfo(image: TestImage()));
|
||||
PaintingBinding.instance.imageCache.putIfAbsent(
|
||||
'Test2',
|
||||
() => completer2,
|
||||
);
|
||||
PaintingBinding.instance.imageCache.evict('Test2');
|
||||
|
||||
final Timeline timeline = await vmService.getVMTimeline();
|
||||
_expectTimelineEvents(
|
||||
timeline.traceEvents,
|
||||
@@ -59,6 +70,14 @@ void main() {
|
||||
'isolateId': isolateId,
|
||||
}
|
||||
},
|
||||
<String, dynamic>{
|
||||
'name': 'ImageCache.putIfAbsent',
|
||||
'args': <String, dynamic>{'key': 'Test2', 'isolateId': isolateId}
|
||||
},
|
||||
<String, dynamic>{
|
||||
'name': 'ImageCache.evict',
|
||||
'args': <String, dynamic>{'sizeInBytes': 0, 'isolateId': isolateId}
|
||||
},
|
||||
],
|
||||
);
|
||||
}, skip: isBrowser); // uses dart:isolate and io
|
||||
@@ -92,3 +111,19 @@ bool _mapsEqual(Map<String, dynamic> expectedArgs, Map<String, dynamic> args) {
|
||||
}
|
||||
|
||||
class TestImageStreamCompleter extends ImageStreamCompleter {}
|
||||
|
||||
class TestImage implements ui.Image {
|
||||
const TestImage({this.height = 0, this.width = 0});
|
||||
@override
|
||||
final int height;
|
||||
@override
|
||||
final int width;
|
||||
|
||||
@override
|
||||
void dispose() { }
|
||||
|
||||
@override
|
||||
Future<ByteData> toByteData({ ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba }) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ const int _kDefaultSizeBytes = 100 << 20; // 100 MiB
|
||||
///
|
||||
/// A caller can determine whether an image is already in the cache by using
|
||||
/// [containsKey], which will return true if the image is tracked by the cache
|
||||
/// in a pending or compelted state. More fine grained information is available
|
||||
/// in a pending or completed state. More fine grained information is available
|
||||
/// by using the [statusForKey] method.
|
||||
///
|
||||
/// Generally this class is not used directly. The [ImageProvider] class and its
|
||||
@@ -255,7 +255,7 @@ class ImageCache {
|
||||
if (!kReleaseMode) {
|
||||
Timeline.instantSync('ImageCache.evict', arguments: <String, dynamic>{
|
||||
'type': 'keepAlive',
|
||||
'sizeiInBytes': image.sizeBytes,
|
||||
'sizeInBytes': image.sizeBytes,
|
||||
});
|
||||
}
|
||||
_currentSizeBytes -= image.sizeBytes;
|
||||
|
||||
Reference in New Issue
Block a user