Skip to content

Commit

Permalink
[web] last batch of test null safety (flutter#26719)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov authored Jun 12, 2021
1 parent b807dfd commit b0eb010
Show file tree
Hide file tree
Showing 21 changed files with 926 additions and 914 deletions.
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/picture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EnginePictureRecorder implements ui.PictureRecorder {
bool get isRecording => _isRecording;

@override
ui.Picture endRecording() {
EnginePicture endRecording() {
if (!_isRecording) {
// The mobile version returns an empty picture in this case. To match the
// behavior we produce a blank picture too.
Expand Down
25 changes: 12 additions & 13 deletions lib/web_ui/test/canvaskit/image_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
import 'dart:html' as html;
import 'dart:typed_data';

Expand Down Expand Up @@ -47,7 +46,7 @@ void testMain() {
browserSupportsFinalizationRegistry = false;

Future<void> expectFrameData(ui.FrameInfo frame, List<int> data) async {
final ByteData frameData = await frame.image.toByteData();
final ByteData frameData = (await frame.image.toByteData())!;
expect(frameData.buffer.asUint8List(), Uint8List.fromList(data));
}

Expand All @@ -73,7 +72,7 @@ void testMain() {

test('CkImage toString', () {
final SkImage skImage =
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)!
.makeImageAtCurrentFrame();
final CkImage image = CkImage(skImage);
expect(image.toString(), '[1×1]');
Expand All @@ -83,7 +82,7 @@ void testMain() {

test('CkImage can be explicitly disposed of', () {
final SkImage skImage =
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)!
.makeImageAtCurrentFrame();
final CkImage image = CkImage(skImage);
expect(image.debugDisposed, isFalse);
Expand All @@ -99,7 +98,7 @@ void testMain() {

test('CkImage can be explicitly disposed of when cloned', () async {
final SkImage skImage =
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)!
.makeImageAtCurrentFrame();
final CkImage image = CkImage(skImage);
final SkiaObjectBox<CkImage, SkImage> box = image.box;
Expand Down Expand Up @@ -133,7 +132,7 @@ void testMain() {

test('CkImage toByteData', () async {
final SkImage skImage =
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)!
.makeImageAtCurrentFrame();
final CkImage image = CkImage(skImage);
expect((await image.toByteData()).lengthInBytes, greaterThan(0));
Expand All @@ -145,7 +144,7 @@ void testMain() {
test('CkImage can be resurrected', () {
browserSupportsFinalizationRegistry = false;
final SkImage skImage =
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)
canvasKit.MakeAnimatedImageFromEncoded(kTransparentImage)!
.makeImageAtCurrentFrame();
final CkImage image = CkImage(skImage);
expect(image.box.rawSkiaObject, isNotNull);
Expand Down Expand Up @@ -259,21 +258,21 @@ void testMain() {

class TestHttpRequest implements html.HttpRequest {
@override
String responseType;
String responseType = 'invalid';

@override
int timeout = 10;
int? timeout = 10;

@override
bool withCredentials = false;
bool? withCredentials = false;

@override
void abort() {
throw UnimplementedError();
}

@override
void addEventListener(String type, listener, [bool useCapture]) {
void addEventListener(String type, listener, [bool? useCapture]) {
throw UnimplementedError();
}

Expand Down Expand Up @@ -320,7 +319,7 @@ class TestHttpRequest implements html.HttpRequest {
Stream<html.ProgressEvent> get onTimeout => throw UnimplementedError();

@override
void open(String method, String url, {bool async, String user, String password}) {}
void open(String method, String url, {bool? async, String? user, String? password}) {}

@override
void overrideMimeType(String mime) {
Expand All @@ -331,7 +330,7 @@ class TestHttpRequest implements html.HttpRequest {
int get readyState => throw UnimplementedError();

@override
void removeEventListener(String type, listener, [bool useCapture]) {
void removeEventListener(String type, listener, [bool? useCapture]) {
throw UnimplementedError();
}

Expand Down
7 changes: 3 additions & 4 deletions lib/web_ui/test/engine/image_to_byte_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.6
import 'dart:typed_data';

import 'package:ui/ui.dart';
Expand All @@ -23,21 +22,21 @@ void testMain() async {
});

test('Picture.toImage().toByteData()', () async {
final EnginePictureRecorder recorder = PictureRecorder();
final EnginePictureRecorder recorder = EnginePictureRecorder();
final RecordingCanvas canvas =
recorder.beginRecording(Rect.fromLTRB(0, 0, 2, 2));
canvas.drawColor(Color(0xFFCCDD00), BlendMode.srcOver);
final Picture testPicture = recorder.endRecording();
final Image testImage = await testPicture.toImage(2, 2);
final ByteData bytes =
await testImage.toByteData(format: ImageByteFormat.rawRgba);
(await testImage.toByteData(format: ImageByteFormat.rawRgba))!;
expect(
bytes.buffer.asUint32List(),
<int>[0xFF00DDCC, 0xFF00DDCC, 0xFF00DDCC, 0xFF00DDCC],
);

final ByteData pngBytes =
await testImage.toByteData(format: ImageByteFormat.png);
(await testImage.toByteData(format: ImageByteFormat.png))!;

// PNG-encoding is browser-specific, but the header is standard. We only
// test the header.
Expand Down
Loading

0 comments on commit b0eb010

Please sign in to comment.