Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 290636c

Browse files
Get unit tests working with dart2wasm (#38784)
1 parent 2722c54 commit 290636c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+514
-767
lines changed

ci/licenses_golden/licenses_flutter

-2
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,6 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_action.dar
20612061
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart + ../../../flutter/LICENSE
20622062
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart + ../../../flutter/LICENSE
20632063
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart + ../../../flutter/LICENSE
2064-
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/ulps.dart + ../../../flutter/LICENSE
20652064
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/util.dart + ../../../flutter/LICENSE
20662065
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/validators.dart + ../../../flutter/LICENSE
20672066
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/vector_math.dart + ../../../flutter/LICENSE
@@ -4543,7 +4542,6 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_action.dart
45434542
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart
45444543
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart
45454544
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
4546-
FILE: ../../../flutter/lib/web_ui/lib/src/engine/ulps.dart
45474545
FILE: ../../../flutter/lib/web_ui/lib/src/engine/util.dart
45484546
FILE: ../../../flutter/lib/web_ui/lib/src/engine/validators.dart
45494547
FILE: ../../../flutter/lib/web_ui/lib/src/engine/vector_math.dart

lib/web_ui/dev/browser_lock.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ chrome:
1313
# `self.m.platform.name.capitalize()` evaluates to. See:
1414
#
1515
# recipe_modules/web_util/api.py
16-
Linux: 1047731
17-
Mac: 1047732
18-
Mac_Arm: 1047734
19-
Win: 1047731
20-
version: '107.0' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)
16+
Linux: 1084013
17+
Mac: 1084013
18+
Mac_Arm: 1084001
19+
Win: 1084062
20+
version: '110.0' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)
2121

2222
firefox:
2323
version: '106.0'

lib/web_ui/dev/chrome.dart

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class Chrome extends Browser {
101101
'--start-maximized',
102102
if (debug)
103103
'--auto-open-devtools-for-tabs',
104+
// Always run unit tests at a 1x scale factor
105+
'--force-device-scale-factor=1',
104106
'--disable-extensions',
105107
'--disable-popup-blocking',
106108
// Indicates that the browser is in "browse without sign-in" (Guest session) mode.

lib/web_ui/dev/felt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ENGINE_SRC_DIR="$(dirname $(dirname $(dirname $(dirname ${FELT_DIR}))))"
3030
FLUTTER_DIR="${ENGINE_SRC_DIR}/flutter"
3131
SDK_PREBUILTS_DIR="${FLUTTER_DIR}/prebuilts"
3232

33-
if [ -z "${DART_SDK_DIR}"]
33+
if [ -z "${DART_SDK_DIR}" ]
3434
then
3535
if [[ $KERNEL_NAME == *"Darwin"* ]]
3636
then

lib/web_ui/dev/steps/compile_tests_step.dart

+1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ Future<bool> compileUnitTestToWasm(FilePath input, {required Renderer renderer})
345345
environment.dart2wasmSnapshotPath,
346346

347347
'--dart-sdk=${environment.dartSdkDir.path}',
348+
'--enable-asserts',
348349

349350
// We do not want to auto-select a renderer in tests. As of today, tests
350351
// are designed to run in one specific mode. So instead, we specify the

lib/web_ui/dev/steps/run_tests_step.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ class RunTestsStep implements PipelineStep {
132132
Future<SkiaGoldClient?> _createSkiaClient() async {
133133
final SkiaGoldClient skiaClient = SkiaGoldClient(
134134
environment.webUiSkiaGoldDirectory,
135-
dimensions: <String, String> {'Browser': browserName},
135+
dimensions: <String, String> {
136+
'Browser': browserName,
137+
if (isWasm) 'Wasm': 'true',
138+
},
136139
);
137140

138141
if (await _checkSkiaClient(skiaClient)) {

lib/web_ui/lib/src/engine/browser_detection.dart

+5
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ bool get isFirefox => browserEngine == BrowserEngine.firefox;
226226
/// Whether the current browser is Edge.
227227
bool get isEdge => domWindow.navigator.userAgent.contains('Edg/');
228228

229+
/// Whether we are running from a wasm module compiled with dart2wasm.
230+
/// Note: Currently the ffi library is available from dart2wasm but not dart2js
231+
/// or dartdevc.
232+
bool get isWasm => const bool.fromEnvironment('dart.library.ffi');
233+
229234
/// Use in tests to simulate the detection of iOS 15.
230235
bool? debugIsIOS15;
231236

lib/web_ui/lib/src/engine/canvaskit/canvas.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CkCanvas {
118118

119119
void drawColor(ui.Color color, ui.BlendMode blendMode) {
120120
skCanvas.drawColorInt(
121-
color.value,
121+
color.value.toDouble(),
122122
toSkBlendMode(blendMode),
123123
);
124124
}
@@ -266,7 +266,7 @@ class CkCanvas {
266266
}
267267

268268
void restoreToCount(int count) {
269-
skCanvas.restoreToCount(count);
269+
skCanvas.restoreToCount(count.toDouble());
270270
}
271271

272272
void rotate(double radians) {
@@ -654,7 +654,7 @@ class CkRestoreToCountCommand extends CkPaintCommand {
654654

655655
@override
656656
void apply(SkCanvas canvas) {
657-
canvas.restoreToCount(count);
657+
canvas.restoreToCount(count.toDouble());
658658
}
659659
}
660660

@@ -821,7 +821,7 @@ class CkDrawColorCommand extends CkPaintCommand {
821821
@override
822822
void apply(SkCanvas canvas) {
823823
canvas.drawColorInt(
824-
color.value,
824+
color.value.toDouble(),
825825
toSkBlendMode(blendMode),
826826
);
827827
}

lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart

+30-30
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ extension CanvasKitExtension on CanvasKit {
8888
external SkTextStyle TextStyle(SkTextStyleProperties properties);
8989
external SkSurface MakeWebGLCanvasSurface(DomCanvasElement canvas);
9090
external SkSurface MakeSurface(
91-
int width,
92-
int height,
91+
double width,
92+
double height,
9393
);
9494
external Uint8List getDataBytes(
9595
SkData skData,
@@ -111,11 +111,11 @@ extension CanvasKitExtension on CanvasKit {
111111
external SkTypefaceFactory get Typeface;
112112
external double GetWebGLContext(
113113
DomCanvasElement canvas, SkWebGLContextOptions options);
114-
external SkGrContext MakeGrContext(int glContext);
114+
external SkGrContext MakeGrContext(double glContext);
115115
external SkSurface? MakeOnScreenGLSurface(
116116
SkGrContext grContext,
117-
int width,
118-
int height,
117+
double width,
118+
double height,
119119
ColorSpace colorSpace,
120120
int sampleCount,
121121
int stencil,
@@ -132,7 +132,7 @@ extension CanvasKitExtension on CanvasKit {
132132
external SkImage? MakeImage(
133133
SkImageInfo info,
134134
Uint8List pixels,
135-
int bytesPerRow,
135+
double bytesPerRow,
136136
);
137137
external SkImage? MakeLazyImageFromTextureSource(
138138
Object src,
@@ -194,7 +194,7 @@ extension SkSurfaceExtension on SkSurface {
194194
class SkGrContext {}
195195

196196
extension SkGrContextExtension on SkGrContext {
197-
external void setResourceCacheLimitBytes(int limit);
197+
external void setResourceCacheLimitBytes(double limit);
198198
external void releaseResourcesAndAbandonContext();
199199
external void delete();
200200
}
@@ -952,7 +952,7 @@ extension SkImageExtension on SkImage {
952952
SkMipmapMode mipmapMode,
953953
Float32List? matrix, // 3x3 matrix
954954
);
955-
external Uint8List readPixels(int srcX, int srcY, SkImageInfo imageInfo);
955+
external Uint8List readPixels(double srcX, double srcY, SkImageInfo imageInfo);
956956
external Uint8List? encodeToBytes();
957957
external bool isAliasOf(SkImage other);
958958
external bool isDeleted();
@@ -979,7 +979,7 @@ extension SkShaderNamespaceExtension on SkShaderNamespace {
979979
Float32List colorStops,
980980
SkTileMode tileMode,
981981
Float32List? matrix, // 3x3 matrix
982-
int flags,
982+
double flags,
983983
);
984984

985985
external SkShader MakeTwoPointConicalGradient(
@@ -991,7 +991,7 @@ extension SkShaderNamespaceExtension on SkShaderNamespace {
991991
Float32List colorStops,
992992
SkTileMode tileMode,
993993
Float32List? matrix, // 3x3 matrix
994-
int flags,
994+
double flags,
995995
);
996996

997997
external SkShader MakeSweepGradient(
@@ -1001,7 +1001,7 @@ extension SkShaderNamespaceExtension on SkShaderNamespace {
10011001
Float32List colorStops,
10021002
SkTileMode tileMode,
10031003
Float32List? matrix, // 3x3 matrix
1004-
int flags,
1004+
double flags,
10051005
double startAngle,
10061006
double endAngle,
10071007
);
@@ -1045,7 +1045,7 @@ extension SkPaintExtension on SkPaint {
10451045
external void setStrokeCap(SkStrokeCap cap);
10461046
external void setStrokeJoin(SkStrokeJoin join);
10471047
external void setAntiAlias(bool isAntiAlias);
1048-
external void setColorInt(int color);
1048+
external void setColorInt(double color);
10491049
external void setShader(SkShader? shader);
10501050
external void setMaskFilter(SkMaskFilter? maskFilter);
10511051
external void setColorFilter(SkColorFilter? colorFilter);
@@ -1272,22 +1272,22 @@ external _NativeType get _nativeFloat32ArrayType;
12721272
external _NativeType get _nativeUint32ArrayType;
12731273

12741274
@JS('window.flutterCanvasKit.Malloc')
1275-
external Object _malloc(_NativeType nativeType, int length);
1275+
external Object _malloc(_NativeType nativeType, double length);
12761276

12771277
/// Allocates a [Float32List] of [length] elements, backed by WASM memory,
12781278
/// managed by a [SkFloat32List].
12791279
///
12801280
/// To free the allocated array use [free].
12811281
SkFloat32List mallocFloat32List(int length) {
1282-
return _malloc(_nativeFloat32ArrayType, length) as SkFloat32List;
1282+
return _malloc(_nativeFloat32ArrayType, length.toDouble()) as SkFloat32List;
12831283
}
12841284

12851285
/// Allocates a [Uint32List] of [length] elements, backed by WASM memory,
12861286
/// managed by a [SkUint32List].
12871287
///
12881288
/// To free the allocated array use [free].
12891289
SkUint32List mallocUint32List(int length) {
1290-
return _malloc(_nativeUint32ArrayType, length) as SkUint32List;
1290+
return _malloc(_nativeUint32ArrayType, length.toDouble()) as SkUint32List;
12911291
}
12921292

12931293
/// Frees the WASM memory occupied by a [SkFloat32List] or [SkUint32List].
@@ -1313,7 +1313,7 @@ class SkFloat32List extends MallocObj {}
13131313

13141314
extension SkFloat32ListExtension on SkFloat32List {
13151315
/// The number of objects this pointer refers to.
1316-
external int length;
1316+
external double length;
13171317

13181318
/// Returns the [Float32List] object backed by WASM memory.
13191319
///
@@ -1336,7 +1336,7 @@ class SkUint32List extends MallocObj {}
13361336

13371337
extension SkUint32ListExtension on SkUint32List {
13381338
/// The number of objects this pointer refers to.
1339-
external int length;
1339+
external double length;
13401340

13411341
/// Returns the [Uint32List] object backed by WASM memory.
13421342
///
@@ -1408,7 +1408,7 @@ extension SkPathExtension on SkPath {
14081408
external void addOval(
14091409
Float32List oval,
14101410
bool counterClockWise,
1411-
int startIndex,
1411+
double startIndex,
14121412
);
14131413
external void addPath(
14141414
SkPath other,
@@ -1721,7 +1721,7 @@ extension SkCanvasExtension on SkCanvas {
17211721
SkPaint paint,
17221722
);
17231723
external void drawColorInt(
1724-
int color,
1724+
double color,
17251725
SkBlendMode blendMode,
17261726
);
17271727
external void drawDRRect(
@@ -1806,7 +1806,7 @@ extension SkCanvasExtension on SkCanvas {
18061806
double lightRadius,
18071807
Float32List ambientColor,
18081808
Float32List spotColor,
1809-
int flags,
1809+
double flags,
18101810
);
18111811
external void drawVertices(
18121812
SkVertices vertices,
@@ -1822,7 +1822,7 @@ extension SkCanvasExtension on SkCanvas {
18221822
int? flags,
18231823
);
18241824
external void restore();
1825-
external void restoreToCount(int count);
1825+
external void restoreToCount(double count);
18261826
external void rotate(
18271827
double angleDegrees,
18281828
double px,
@@ -2126,7 +2126,7 @@ extension SkFontExtension on SkFont {
21262126
class SkFontMgr {}
21272127

21282128
extension SkFontMgrExtension on SkFontMgr {
2129-
external String? getFamilyName(int fontId);
2129+
external String? getFamilyName(double fontId);
21302130
external void delete();
21312131
external SkTypeface? MakeTypefaceFromData(Uint8List font);
21322132
}
@@ -2187,8 +2187,8 @@ extension SkParagraphExtension on SkParagraph {
21872187
external double getMinIntrinsicWidth();
21882188
external double getMaxWidth();
21892189
external /* List<SkRectWithDirection> */ List<Object?> getRectsForRange(
2190-
int start,
2191-
int end,
2190+
double start,
2191+
double end,
21922192
SkRectHeightStyle heightStyle,
21932193
SkRectWidthStyle widthStyle,
21942194
);
@@ -2197,7 +2197,7 @@ extension SkParagraphExtension on SkParagraph {
21972197
double x,
21982198
double y,
21992199
);
2200-
external SkTextRange getWordBoundary(int position);
2200+
external SkTextRange getWordBoundary(double position);
22012201
external void layout(double width);
22022202
external void delete();
22032203
}
@@ -2523,8 +2523,8 @@ extension SkDataExtension on SkData {
25232523
@staticInterop
25242524
class SkImageInfo {
25252525
external factory SkImageInfo({
2526-
required int width,
2527-
required int height,
2526+
required double width,
2527+
required double height,
25282528
required SkColorType colorType,
25292529
required SkAlphaType alphaType,
25302530
required ColorSpace colorSpace,
@@ -2543,16 +2543,16 @@ extension SkImageInfoExtension on SkImageInfo {
25432543
external SkImageInfo makeAlphaType(SkAlphaType alphaType);
25442544
external SkImageInfo makeColorSpace(ColorSpace colorSpace);
25452545
external SkImageInfo makeColorType(SkColorType colorType);
2546-
external SkImageInfo makeWH(int width, int height);
2546+
external SkImageInfo makeWH(double width, double height);
25472547
}
25482548

25492549
@JS()
25502550
@anonymous
25512551
@staticInterop
25522552
class SkPartialImageInfo {
25532553
external factory SkPartialImageInfo({
2554-
required int width,
2555-
required int height,
2554+
required double width,
2555+
required double height,
25562556
required SkColorType colorType,
25572557
required SkAlphaType alphaType,
25582558
required ColorSpace colorSpace,

lib/web_ui/lib/src/engine/canvaskit/image.dart

+8-8
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ void skiaDecodeImageFromPixels(
5757
Timer.run(() {
5858
final SkImage? skImage = canvasKit.MakeImage(
5959
SkImageInfo(
60-
width: width,
61-
height: height,
60+
width: width.toDouble(),
61+
height: height.toDouble(),
6262
colorType: format == ui.PixelFormat.rgba8888 ? canvasKit.ColorType.RGBA_8888 : canvasKit.ColorType.BGRA_8888,
6363
alphaType: canvasKit.AlphaType.Premul,
6464
colorSpace: SkColorSpaceSRGB,
6565
),
6666
pixels,
67-
rowBytes ?? 4 * width,
67+
(rowBytes ?? 4 * width).toDouble(),
6868
);
6969

7070
if (skImage == null) {
@@ -266,11 +266,11 @@ class CkImage implements ui.Image, StackTraceDebugger {
266266
alphaType: canvasKit.AlphaType.Premul,
267267
colorType: canvasKit.ColorType.RGBA_8888,
268268
colorSpace: SkColorSpaceSRGB,
269-
width: originalWidth,
270-
height: originalHeight,
269+
width: originalWidth.toDouble(),
270+
height: originalHeight.toDouble(),
271271
),
272272
originalBytes.buffer.asUint8List(),
273-
4 * originalWidth,
273+
(4 * originalWidth).toDouble(),
274274
);
275275
if (skImage == null) {
276276
throw ImageCodecException(
@@ -415,8 +415,8 @@ class CkImage implements ui.Image, StackTraceDebugger {
415415
alphaType: alphaType,
416416
colorType: colorType,
417417
colorSpace: colorSpace,
418-
width: skImage.width().toInt(),
419-
height: skImage.height().toInt(),
418+
width: skImage.width(),
419+
height: skImage.height(),
420420
);
421421
bytes = skImage.readPixels(0, 0, imageInfo);
422422
} else {

0 commit comments

Comments
 (0)