Skip to content

Commit

Permalink
Change test to not extend ByteData
Browse files Browse the repository at this point in the history
The test `test/widgets/image_resolution_test.dart` has a test class implementing `ByteData`.
Dart will make it a compile-time error to extend/implement/mix-in most of the types of `dart:typed_data` (breaking change: dart-lang/sdk#45115, implementation: https://dart-review.googlesource.com/c/sdk/+/192186), so this test needs to stop doing so.

This is an attempt at a *minimal change* (because I am not familiar with the code at all). It's definitely possible to make other simplicifcations (like inlining the extension).
  • Loading branch information
lrhn authored Apr 8, 2021
1 parent 98a9618 commit f333918
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions packages/flutter/test/widgets/image_resolution_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import 'package:flutter_test/flutter_test.dart';

import '../image_data.dart';

class TestByteData implements ByteData {
TestByteData(this.scale);
final double scale;
ByteData testByteData(double scale) => ByteData(8)..setFloat64(0, scale);

@override
dynamic noSuchMethod(Invocation invocation) => null;
extension on ByteData {
double get scale => this.getFloat64(0);
}

const String testManifest = '''
Expand All @@ -44,22 +42,22 @@ class TestAssetBundle extends CachingAssetBundle {
late ByteData data;
switch (key) {
case 'assets/image.png':
data = TestByteData(1.0);
data = testByteData(1.0);
break;
case 'assets/1.0x/image.png':
data = TestByteData(10.0); // see "...with a main asset and a 1.0x asset"
data = testByteData(10.0); // see "...with a main asset and a 1.0x asset"
break;
case 'assets/1.5x/image.png':
data = TestByteData(1.5);
data = testByteData(1.5);
break;
case 'assets/2.0x/image.png':
data = TestByteData(2.0);
data = testByteData(2.0);
break;
case 'assets/3.0x/image.png':
data = TestByteData(3.0);
data = testByteData(3.0);
break;
case 'assets/4.0x/image.png':
data = TestByteData(4.0);
data = testByteData(4.0);
break;
}
return SynchronousFuture<ByteData>(data);
Expand Down Expand Up @@ -91,7 +89,7 @@ class TestAssetImage extends AssetImage {
ImageStreamCompleter load(AssetBundleImageKey key, DecoderCallback decode) {
late ImageInfo imageInfo;
key.bundle.load(key.name).then<void>((ByteData data) {
final TestByteData testData = data as TestByteData;
final ByteData testData = data;
final ui.Image image = images[testData.scale]!;
assert(image != null, 'Expected ${testData.scale} to have a key in $images');
imageInfo = ImageInfo(image: image, scale: key.scale);
Expand Down Expand Up @@ -312,12 +310,12 @@ void main() {
Key key = GlobalKey();
await pumpTreeToLayout(tester, buildImageAtRatio(image, key, ratio, false, images, bundle));
expect(getRenderImage(tester, key).size, const Size(200.0, 200.0));
// Verify we got the 10x scaled image, since the TestByteData said it should be 10x.
// Verify we got the 10x scaled image, since the test ByteData said it should be 10x.
expect(getRenderImage(tester, key).image!.height, 480);
key = GlobalKey();
await pumpTreeToLayout(tester, buildImageAtRatio(image, key, ratio, true, images, bundle));
expect(getRenderImage(tester, key).size, const Size(480.0, 480.0));
// Verify we got the 10x scaled image, since the TestByteData said it should be 10x.
// Verify we got the 10x scaled image, since the test ByteData said it should be 10x.
expect(getRenderImage(tester, key).image!.height, 480);
});

Expand Down

0 comments on commit f333918

Please sign in to comment.