[web] Add test for Image.network (#22256)

This commit is contained in:
Ferhat 2020-11-05 13:22:29 -08:00 committed by GitHub
parent 39f9855c1f
commit 66eaa06cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -6,8 +6,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
const MethodChannel channel =
OptionalMethodChannel('flutter/web_test_e2e', JSONMethodCodec());
OptionalMethodChannel('flutter/web_test_e2e', JSONMethodCodec());
await channel.invokeMethod<void>(
'setDevicePixelRatio',
'1.5',
@ -26,7 +27,10 @@ class MyAppState extends State<MyApp> {
return MaterialApp(
key: const Key('mainapp'),
title: 'Integration Test App',
home: Image.asset('assets/images/sample_image1.png')
home: Column(children: <Widget>[
Image.asset('assets/images/sample_image1.png'),
Image.network('assets/images/sample_image1.png'),
])
);
}
}

View File

@ -15,10 +15,12 @@ void main() {
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
final html.ImageElement imageElement = html.querySelector('img') as html.ImageElement;
expect(imageElement.naturalWidth, 1.5 * 100);
expect(imageElement.naturalHeight, 1.5 * 100);
expect(imageElement.width, 100);
expect(imageElement.height, 100);
final List<html.ImageElement> imageElements = html.querySelectorAll('img');
expect(imageElements.length, 2);
expect(imageElements[0].naturalWidth, 1.5 * 100);
expect(imageElements[0].naturalHeight, 1.5 * 100);
expect(imageElements[0].width, 100);
expect(imageElements[0].height, 100);
expect(imageElements[1].width, isNot(0));
});
}