Skip to content

Commit

Permalink
[web] more null-safe tests (flutter#26712)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov authored Jun 11, 2021
1 parent 201ee6f commit f49c62a
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 177 deletions.
7 changes: 3 additions & 4 deletions lib/web_ui/test/canvaskit/vertices_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 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
Expand All @@ -29,15 +28,15 @@ void testMain() {
canvas.drawVertices(
vertices,
ui.BlendMode.srcOver,
ui.Paint(),
CkPaint(),
);
vertices.delete();
});
// TODO: https://github.com/flutter/flutter/issues/60040
}, skip: isIosSafari);
}

ui.Vertices _testVertices() {
CkVertices _testVertices() {
return ui.Vertices(
ui.VertexMode.triangles,
<ui.Offset>[
Expand All @@ -56,5 +55,5 @@ ui.Vertices _testVertices() {
ui.Color.fromRGBO(0, 0, 255, 1.0),
],
indices: <int>[0, 1, 2],
);
) as CkVertices;
}
5 changes: 2 additions & 3 deletions lib/web_ui/test/engine/image/html_image_codec_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:async';
import 'dart:typed_data';

Expand Down Expand Up @@ -103,7 +102,7 @@ void testMain() async {
group('ImageCodecUrl', () {
test('loads sample image from web', () async {
final Uri uri = Uri.base.resolve('sample_image1.png');
final HtmlCodec codec = await ui.webOnlyInstantiateImageCodecFromUrl(uri);
final HtmlCodec codec = await ui.webOnlyInstantiateImageCodecFromUrl(uri) as HtmlCodec;
final ui.FrameInfo frameInfo = await codec.getNextFrame();
expect(frameInfo.image, isNotNull);
expect(frameInfo.image.width, 100);
Expand All @@ -114,7 +113,7 @@ void testMain() async {
final HtmlCodec codec = await ui.webOnlyInstantiateImageCodecFromUrl(uri,
chunkCallback: (int loaded, int total) {
buffer.write('$loaded/$total,');
});
}) as HtmlCodec;
await codec.getNextFrame();
expect(buffer.toString(), '0/100,100/100,');
});
Expand Down
7 changes: 3 additions & 4 deletions lib/web_ui/test/engine/semantics/accessibility_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// 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:async' show Future;
import 'dart:html';

import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';

const MessageCodec<dynamic> codec = StandardMessageCodec();
const StandardMessageCodec codec = StandardMessageCodec();
const String testMessage = 'This is an tooltip.';
const Map<dynamic, dynamic> testInput = <dynamic, dynamic>{
'data': <dynamic, dynamic>{'message': testMessage}
Expand All @@ -21,7 +20,7 @@ void main() {
}

void testMain() {
AccessibilityAnnouncements accessibilityAnnouncements;
late AccessibilityAnnouncements accessibilityAnnouncements;

group('$AccessibilityAnnouncements', () {
setUp(() {
Expand All @@ -45,7 +44,7 @@ void testMain() {
isNotNull,
);
final LabelElement input =
document.getElementById('accessibility-element');
document.getElementById('accessibility-element') as LabelElement;
expect(input.getAttribute('aria-live'), equals('polite'));
expect(input.text, testMessage);

Expand Down
61 changes: 30 additions & 31 deletions lib/web_ui/test/engine/semantics/semantics_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.9
@TestOn('chrome || safari || firefox')

import 'dart:async';
Expand Down Expand Up @@ -88,7 +87,7 @@ void _testEngineSemanticsOwner() {

// Synthesize a click on the placeholder.
final html.Element placeholder =
appShadowRoot.querySelector('flt-semantics-placeholder');
appShadowRoot.querySelector('flt-semantics-placeholder')!;

expect(placeholder.isConnected, isTrue);

Expand All @@ -101,7 +100,7 @@ void _testEngineSemanticsOwner() {

// On mobile semantics is enabled asynchronously.
if (isMobile) {
while (placeholder.isConnected) {
while (placeholder.isConnected!) {
await Future<void>.delayed(const Duration(milliseconds: 50));
}
}
Expand All @@ -114,7 +113,7 @@ void _testEngineSemanticsOwner() {
expect(semantics().semanticsEnabled, isFalse);

final html.Element placeholder =
appShadowRoot.querySelector('flt-semantics-placeholder');
appShadowRoot.querySelector('flt-semantics-placeholder')!;

expect(placeholder.isConnected, isTrue);

Expand Down Expand Up @@ -159,12 +158,12 @@ void _testEngineSemanticsOwner() {
// Create
renderLabel('Hello');

final Map<int, SemanticsObject> tree = semantics().debugSemanticsTree;
final Map<int, SemanticsObject> tree = semantics().debugSemanticsTree!;
expect(tree.length, 2);
expect(tree[0].id, 0);
expect(tree[0].element.tagName.toLowerCase(), 'flt-semantics');
expect(tree[1].id, 1);
expect(tree[1].label, 'Hello');
expect(tree[0]!.id, 0);
expect(tree[0]!.element.tagName.toLowerCase(), 'flt-semantics');
expect(tree[1]!.id, 1);
expect(tree[1]!.label, 'Hello');

expectSemanticsTree('''
<sem style="$rootSemanticStyle">
Expand Down Expand Up @@ -383,9 +382,9 @@ void _testContainer() {
</sem>''');

final html.Element parentElement =
appShadowRoot.querySelector('flt-semantics');
appShadowRoot.querySelector('flt-semantics')!;
final html.Element container =
appShadowRoot.querySelector('flt-semantics-container');
appShadowRoot.querySelector('flt-semantics-container')!;

if (isMacOrIOS) {
expect(parentElement.style.top, '0px');
Expand Down Expand Up @@ -431,9 +430,9 @@ void _testContainer() {
</sem>''');

final html.Element parentElement =
appShadowRoot.querySelector('flt-semantics');
appShadowRoot.querySelector('flt-semantics')!;
final html.Element container =
appShadowRoot.querySelector('flt-semantics-container');
appShadowRoot.querySelector('flt-semantics-container')!;

expect(parentElement.style.transform, 'matrix(1, 0, 0, 1, 10, 10)');
expect(parentElement.style.transformOrigin, '0px 0px 0px');
Expand Down Expand Up @@ -477,9 +476,9 @@ void _testContainer() {
}

final html.Element parentElement =
appShadowRoot.querySelector('flt-semantics');
appShadowRoot.querySelector('flt-semantics')!;
final html.Element container =
appShadowRoot.querySelector('flt-semantics-container');
appShadowRoot.querySelector('flt-semantics-container')!;

if (isMacOrIOS) {
expect(parentElement.style.top, '0px');
Expand Down Expand Up @@ -550,12 +549,12 @@ void _testVerticalScrolling() {
</sem-c>
</sem>''');

final html.Element scrollable = findScrollable();
final html.Element? scrollable = findScrollable();
expect(scrollable, isNotNull);

// When there's less content than the available size the neutral scrollTop
// is 0.
expect(scrollable.scrollTop, 0);
expect(scrollable!.scrollTop, 0);

semantics().semanticsEnabled = false;
});
Expand All @@ -574,7 +573,7 @@ void _testVerticalScrolling() {
final Zone testZone = Zone.current;

ui.window.onSemanticsAction =
(int id, ui.SemanticsAction action, ByteData args) {
(int id, ui.SemanticsAction action, ByteData? args) {
idLogController.add(id);
actionLogController.add(action);
testZone.run(() {
Expand Down Expand Up @@ -620,7 +619,7 @@ void _testVerticalScrolling() {
</sem-c>
</sem>''');

final html.Element scrollable = findScrollable();
final html.Element? scrollable = findScrollable();
expect(scrollable, isNotNull);

// When there's more content than the available size the neutral scrollTop
Expand All @@ -633,7 +632,7 @@ void _testVerticalScrolling() {
browserMaxScrollDiff = 1;
}

expect(scrollable.scrollTop >= (10 - browserMaxScrollDiff), isTrue);
expect(scrollable!.scrollTop >= (10 - browserMaxScrollDiff), isTrue);

scrollable.scrollTop = 20;
expect(scrollable.scrollTop, 20);
Expand Down Expand Up @@ -702,12 +701,12 @@ void _testHorizontalScrolling() {
</sem-c>
</sem>''');

final html.Element scrollable = findScrollable();
final html.Element? scrollable = findScrollable();
expect(scrollable, isNotNull);

// When there's less content than the available size the neutral
// scrollLeft is 0.
expect(scrollable.scrollLeft, 0);
expect(scrollable!.scrollLeft, 0);

semantics().semanticsEnabled = false;
});
Expand Down Expand Up @@ -753,7 +752,7 @@ void _testHorizontalScrolling() {
</sem-c>
</sem>''');

final html.Element scrollable = findScrollable();
final html.Element? scrollable = findScrollable();
expect(scrollable, isNotNull);

// When there's more content than the available size the neutral scrollTop
Expand All @@ -765,7 +764,7 @@ void _testHorizontalScrolling() {
operatingSystem == OperatingSystem.macOs) {
browserMaxScrollDiff = 1;
}
expect(scrollable.scrollLeft >= (10 - browserMaxScrollDiff), isTrue);
expect(scrollable!.scrollLeft >= (10 - browserMaxScrollDiff), isTrue);

scrollable.scrollLeft = 20;
expect(scrollable.scrollLeft, 20);
Expand Down Expand Up @@ -835,7 +834,7 @@ void _testIncrementables() {
<input aria-valuenow="1" aria-valuetext="d" aria-valuemax="2" aria-valuemin="1">
</sem>''');

final html.InputElement input = appShadowRoot.querySelector('input');
final html.InputElement input = appShadowRoot.querySelector('input') as html.InputElement;
input.value = '2';
input.dispatchEvent(html.Event('change'));

Expand Down Expand Up @@ -869,7 +868,7 @@ void _testIncrementables() {
<input aria-valuenow="1" aria-valuetext="d" aria-valuemax="1" aria-valuemin="0">
</sem>''');

final html.InputElement input = appShadowRoot.querySelector('input');
final html.InputElement input = appShadowRoot.querySelector('input') as html.InputElement;
input.value = '0';
input.dispatchEvent(html.Event('change'));

Expand Down Expand Up @@ -963,7 +962,7 @@ void _testTextField() {
semantics().updateSemantics(builder.build());

final html.Element textField =
appShadowRoot.querySelector('input[data-semantics-role="text-field"]');
appShadowRoot.querySelector('input[data-semantics-role="text-field"]')!;

expect(appShadowRoot.activeElement, isNot(textField));

Expand Down Expand Up @@ -1491,10 +1490,10 @@ void updateNode(
String increasedValue = '',
String decreasedValue = '',
ui.TextDirection textDirection = ui.TextDirection.ltr,
Float64List transform,
Int32List childrenInTraversalOrder,
Int32List childrenInHitTestOrder,
Int32List additionalActions,
Float64List? transform,
Int32List? childrenInTraversalOrder,
Int32List? childrenInHitTestOrder,
Int32List? additionalActions,
}) {
transform ??= Float64List.fromList(Matrix4.identity().storage);
childrenInTraversalOrder ??= Int32List(0);
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/test/engine/services/serialization_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:test/test.dart';
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/test/engine/surface/frame_timings_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 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
Expand All @@ -15,7 +14,7 @@ void main() {

void testMain() {
setUp(() async {
await initializeEngine();
initializeEngine();
});

test('collects frame timings', () async {
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/test/engine/surface/platform_view_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:async';
import 'dart:html' as html;

Expand All @@ -22,7 +21,7 @@ void main() {
}

void testMain() {
PersistedPlatformView view;
late PersistedPlatformView view;

group('PersistedPlatformView', () {
setUp(() async {
Expand Down
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 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine/html/shaders/normalized_gradient.dart';
Expand Down
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 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
Expand All @@ -25,7 +24,7 @@ void testMain() {
')';

setUpAll(() async {
await webOnlyInitializeEngine();
webOnlyInitializeEngine();
});

group('Shader Declarations', () {
Expand Down
Loading

0 comments on commit f49c62a

Please sign in to comment.