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

Get unit tests working with dart2wasm #38784

Merged
merged 40 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
06f4920
Fixes for wasm unit tests.
eyebrowsoffire Dec 19, 2022
3bb68e6
Some more unit test fixes.
eyebrowsoffire Dec 21, 2022
011b5d5
More unit test fixes.
eyebrowsoffire Dec 22, 2022
0f9ac30
More unit test fixes.
eyebrowsoffire Dec 22, 2022
0e1a39d
Skip a few more tests due to async issues.
eyebrowsoffire Dec 23, 2022
f7b32a3
Merge branch 'main' into wasm_unit_test_fixes
eyebrowsoffire Dec 23, 2022
b3b7e43
More unit test fixes.
eyebrowsoffire Jan 4, 2023
9f7479e
More unit test fixes.
eyebrowsoffire Jan 4, 2023
f33ef33
More unit test fixes.
eyebrowsoffire Jan 9, 2023
15435ee
More unit test stuff.
eyebrowsoffire Jan 9, 2023
6b7fb18
More unit test fixes.
eyebrowsoffire Jan 9, 2023
5b7c587
More unit test fixes.
eyebrowsoffire Jan 9, 2023
5e06d37
Remove debug print.
eyebrowsoffire Jan 10, 2023
12f4310
More unit test fixes.
eyebrowsoffire Jan 11, 2023
4f1ab64
More unit test fixes.
eyebrowsoffire Jan 11, 2023
f5077b4
Fix unit test.
eyebrowsoffire Jan 11, 2023
23900e5
More unit test fixes.
eyebrowsoffire Jan 11, 2023
f5d4e04
Skipped or removed remaining tests.
eyebrowsoffire Jan 11, 2023
c5e6c95
Add skia client dimension to differentiate wasm from js.
eyebrowsoffire Jan 11, 2023
bedf2e3
Revert an accidental change.
eyebrowsoffire Jan 11, 2023
4bd2b21
Remove stale workaround.
eyebrowsoffire Jan 11, 2023
aa914c6
Merge branch 'main' into wasm_unit_test_fixes
eyebrowsoffire Jan 11, 2023
267138d
Fixups after the merge.
eyebrowsoffire Jan 11, 2023
c6edc91
Bump browser versions.
eyebrowsoffire Jan 11, 2023
5e4d00d
Fix analyzer issues.
eyebrowsoffire Jan 11, 2023
8f547f7
Revert an unnecessary change and update license files.
eyebrowsoffire Jan 11, 2023
9cfd66e
Keep skipping text tests on Safari and Firefox.
eyebrowsoffire Jan 11, 2023
1d38008
Merge branch 'main' into wasm_unit_test_fixes
eyebrowsoffire Jan 12, 2023
6b48f55
Fix as per David's suggestion.
eyebrowsoffire Jan 12, 2023
51e052a
Merge branch 'main' into wasm_unit_test_fixes
eyebrowsoffire Jan 13, 2023
91f39d1
Enable RTL test that works now.
eyebrowsoffire Jan 13, 2023
f614ae3
Tweak some parameters to increase consistency.
eyebrowsoffire Jan 13, 2023
e2766ca
Some fixes as per Mouad's suggestions.
eyebrowsoffire Jan 13, 2023
74a1122
Merge branch 'main' into wasm_unit_test_fixes
eyebrowsoffire Jan 13, 2023
3e0ee0d
Remove workaround for JS object hashCode issues.
eyebrowsoffire Jan 13, 2023
c1d8e4e
Oops, messed up the interval tree implementation.
eyebrowsoffire Jan 13, 2023
68ffc14
Fixup after Jonah's changes.
eyebrowsoffire Jan 13, 2023
ce23f7e
A few more fixups.
eyebrowsoffire Jan 14, 2023
faff65a
Merge branch 'main' into wasm_unit_test_fixes
eyebrowsoffire Jan 18, 2023
16a472a
Unused import.
eyebrowsoffire Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,6 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_action.dar
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/ulps.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/util.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/validators.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/src/engine/vector_math.dart + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4543,7 +4542,6 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_action.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/input_type.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_capitalization.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/ulps.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/util.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/validators.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/vector_math.dart
Expand Down
10 changes: 5 additions & 5 deletions lib/web_ui/dev/browser_lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ chrome:
# `self.m.platform.name.capitalize()` evaluates to. See:
#
# recipe_modules/web_util/api.py
Linux: 1047731
Mac: 1047732
Mac_Arm: 1047734
Win: 1047731
version: '107.0' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)
Linux: 1084013
Mac: 1084013
Mac_Arm: 1084001
Win: 1084062
version: '110.0' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)

firefox:
version: '106.0'
Expand Down
2 changes: 2 additions & 0 deletions lib/web_ui/dev/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class Chrome extends Browser {
'--start-maximized',
if (debug)
'--auto-open-devtools-for-tabs',
// Always run unit tests at a 1x scale factor
'--force-device-scale-factor=1',
'--disable-extensions',
'--disable-popup-blocking',
// Indicates that the browser is in "browse without sign-in" (Guest session) mode.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/felt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ENGINE_SRC_DIR="$(dirname $(dirname $(dirname $(dirname ${FELT_DIR}))))"
FLUTTER_DIR="${ENGINE_SRC_DIR}/flutter"
SDK_PREBUILTS_DIR="${FLUTTER_DIR}/prebuilts"

if [ -z "${DART_SDK_DIR}"]
if [ -z "${DART_SDK_DIR}" ]
then
if [[ $KERNEL_NAME == *"Darwin"* ]]
then
Expand Down
1 change: 1 addition & 0 deletions lib/web_ui/dev/steps/compile_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Future<bool> compileUnitTestToWasm(FilePath input, {required Renderer renderer})
environment.dart2wasmSnapshotPath,

'--dart-sdk=${environment.dartSdkDir.path}',
'--enable-asserts',

// We do not want to auto-select a renderer in tests. As of today, tests
// are designed to run in one specific mode. So instead, we specify the
Expand Down
5 changes: 4 additions & 1 deletion lib/web_ui/dev/steps/run_tests_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ class RunTestsStep implements PipelineStep {
Future<SkiaGoldClient?> _createSkiaClient() async {
final SkiaGoldClient skiaClient = SkiaGoldClient(
environment.webUiSkiaGoldDirectory,
dimensions: <String, String> {'Browser': browserName},
dimensions: <String, String> {
'Browser': browserName,
if (isWasm) 'Wasm': 'true',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we may end up in a BROWSER x WASM x RENDERER kind of matrix, and I think we only care about BROWSER x MODE where MODE is much more limited than the full matrix. We only care about these modes:

  • HTML-JS
  • CanvasKit-JS
  • Skwasm-Wasm

We don't care about testing these:

  • HTML-Wasm
  • CanvasKit-Wasm
  • Skwasm-JS (for now)

But maybe it's OK to keep this more expressive than we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely do care about testing HTML-Wasm and CanvasKit-Wasm, at least right now. That's what this PR is actually doing, adding tests for those.

},
);

if (await _checkSkiaClient(skiaClient)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/web_ui/lib/src/engine/browser_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ bool get isFirefox => browserEngine == BrowserEngine.firefox;
/// Whether the current browser is Edge.
bool get isEdge => domWindow.navigator.userAgent.contains('Edg/');

/// Whether we are running from a wasm module compiled with dart2wasm.
/// Note: Currently the ffi library is available from dart2wasm but not dart2js
/// or dartdevc.
bool get isWasm => const bool.fromEnvironment('dart.library.ffi');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 != 1.0 would also do the trick, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this, because it's very clearly const. 1 != 1.0 might not be optimized by the baseline compiler to be const.


/// Use in tests to simulate the detection of iOS 15.
bool? debugIsIOS15;

Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/lib/src/engine/canvaskit/canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CkCanvas {

void drawColor(ui.Color color, ui.BlendMode blendMode) {
skCanvas.drawColorInt(
color.value,
color.value.toDouble(),
toSkBlendMode(blendMode),
);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ class CkCanvas {
}

void restoreToCount(int count) {
skCanvas.restoreToCount(count);
skCanvas.restoreToCount(count.toDouble());
}

void rotate(double radians) {
Expand Down Expand Up @@ -654,7 +654,7 @@ class CkRestoreToCountCommand extends CkPaintCommand {

@override
void apply(SkCanvas canvas) {
canvas.restoreToCount(count);
canvas.restoreToCount(count.toDouble());
}
}

Expand Down Expand Up @@ -821,7 +821,7 @@ class CkDrawColorCommand extends CkPaintCommand {
@override
void apply(SkCanvas canvas) {
canvas.drawColorInt(
color.value,
color.value.toDouble(),
toSkBlendMode(blendMode),
);
}
Expand Down
60 changes: 30 additions & 30 deletions lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ extension CanvasKitExtension on CanvasKit {
external SkTextStyle TextStyle(SkTextStyleProperties properties);
external SkSurface MakeWebGLCanvasSurface(DomCanvasElement canvas);
external SkSurface MakeSurface(
int width,
int height,
double width,
double height,
);
external Uint8List getDataBytes(
SkData skData,
Expand All @@ -111,11 +111,11 @@ extension CanvasKitExtension on CanvasKit {
external SkTypefaceFactory get Typeface;
external double GetWebGLContext(
DomCanvasElement canvas, SkWebGLContextOptions options);
external SkGrContext MakeGrContext(int glContext);
external SkGrContext MakeGrContext(double glContext);
external SkSurface? MakeOnScreenGLSurface(
SkGrContext grContext,
int width,
int height,
double width,
double height,
ColorSpace colorSpace,
int sampleCount,
int stencil,
Expand All @@ -132,7 +132,7 @@ extension CanvasKitExtension on CanvasKit {
external SkImage? MakeImage(
SkImageInfo info,
Uint8List pixels,
int bytesPerRow,
double bytesPerRow,
);
external SkImage? MakeLazyImageFromTextureSource(
Object src,
Expand Down Expand Up @@ -194,7 +194,7 @@ extension SkSurfaceExtension on SkSurface {
class SkGrContext {}

extension SkGrContextExtension on SkGrContext {
external void setResourceCacheLimitBytes(int limit);
external void setResourceCacheLimitBytes(double limit);
external void releaseResourcesAndAbandonContext();
external void delete();
}
Expand Down Expand Up @@ -952,7 +952,7 @@ extension SkImageExtension on SkImage {
SkMipmapMode mipmapMode,
Float32List? matrix, // 3x3 matrix
);
external Uint8List readPixels(int srcX, int srcY, SkImageInfo imageInfo);
external Uint8List readPixels(double srcX, double srcY, SkImageInfo imageInfo);
external Uint8List? encodeToBytes();
external bool isAliasOf(SkImage other);
external bool isDeleted();
Expand All @@ -979,7 +979,7 @@ extension SkShaderNamespaceExtension on SkShaderNamespace {
Float32List colorStops,
SkTileMode tileMode,
Float32List? matrix, // 3x3 matrix
int flags,
double flags,
);

external SkShader MakeTwoPointConicalGradient(
Expand All @@ -991,7 +991,7 @@ extension SkShaderNamespaceExtension on SkShaderNamespace {
Float32List colorStops,
SkTileMode tileMode,
Float32List? matrix, // 3x3 matrix
int flags,
double flags,
);

external SkShader MakeSweepGradient(
Expand All @@ -1001,7 +1001,7 @@ extension SkShaderNamespaceExtension on SkShaderNamespace {
Float32List colorStops,
SkTileMode tileMode,
Float32List? matrix, // 3x3 matrix
int flags,
double flags,
double startAngle,
double endAngle,
);
Expand Down Expand Up @@ -1045,7 +1045,7 @@ extension SkPaintExtension on SkPaint {
external void setStrokeCap(SkStrokeCap cap);
external void setStrokeJoin(SkStrokeJoin join);
external void setAntiAlias(bool isAntiAlias);
external void setColorInt(int color);
external void setColorInt(double color);
external void setShader(SkShader? shader);
external void setMaskFilter(SkMaskFilter? maskFilter);
external void setColorFilter(SkColorFilter? colorFilter);
Expand Down Expand Up @@ -1272,22 +1272,22 @@ external _NativeType get _nativeFloat32ArrayType;
external _NativeType get _nativeUint32ArrayType;

@JS('window.flutterCanvasKit.Malloc')
external Object _malloc(_NativeType nativeType, int length);
external Object _malloc(_NativeType nativeType, double length);

/// Allocates a [Float32List] of [length] elements, backed by WASM memory,
/// managed by a [SkFloat32List].
///
/// To free the allocated array use [free].
SkFloat32List mallocFloat32List(int length) {
return _malloc(_nativeFloat32ArrayType, length) as SkFloat32List;
return _malloc(_nativeFloat32ArrayType, length.toDouble()) as SkFloat32List;
}

/// Allocates a [Uint32List] of [length] elements, backed by WASM memory,
/// managed by a [SkUint32List].
///
/// To free the allocated array use [free].
SkUint32List mallocUint32List(int length) {
return _malloc(_nativeUint32ArrayType, length) as SkUint32List;
return _malloc(_nativeUint32ArrayType, length.toDouble()) as SkUint32List;
}

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

extension SkFloat32ListExtension on SkFloat32List {
/// The number of objects this pointer refers to.
external int length;
external double length;

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

extension SkUint32ListExtension on SkUint32List {
/// The number of objects this pointer refers to.
external int length;
external double length;

/// Returns the [Uint32List] object backed by WASM memory.
///
Expand Down Expand Up @@ -1408,7 +1408,7 @@ extension SkPathExtension on SkPath {
external void addOval(
Float32List oval,
bool counterClockWise,
int startIndex,
double startIndex,
);
external void addPath(
SkPath other,
Expand Down Expand Up @@ -1721,7 +1721,7 @@ extension SkCanvasExtension on SkCanvas {
SkPaint paint,
);
external void drawColorInt(
int color,
double color,
SkBlendMode blendMode,
);
external void drawDRRect(
Expand Down Expand Up @@ -1806,7 +1806,7 @@ extension SkCanvasExtension on SkCanvas {
double lightRadius,
Float32List ambientColor,
Float32List spotColor,
int flags,
double flags,
);
external void drawVertices(
SkVertices vertices,
Expand All @@ -1822,7 +1822,7 @@ extension SkCanvasExtension on SkCanvas {
int? flags,
);
external void restore();
external void restoreToCount(int count);
external void restoreToCount(double count);
external void rotate(
double angleDegrees,
double px,
Expand Down Expand Up @@ -2126,7 +2126,7 @@ extension SkFontExtension on SkFont {
class SkFontMgr {}

extension SkFontMgrExtension on SkFontMgr {
external String? getFamilyName(int fontId);
external String? getFamilyName(double fontId);
external void delete();
external SkTypeface? MakeTypefaceFromData(Uint8List font);
}
Expand Down Expand Up @@ -2187,8 +2187,8 @@ extension SkParagraphExtension on SkParagraph {
external double getMinIntrinsicWidth();
external double getMaxWidth();
external /* List<SkRectWithDirection> */ List<Object?> getRectsForRange(
int start,
int end,
double start,
double end,
SkRectHeightStyle heightStyle,
SkRectWidthStyle widthStyle,
);
Expand All @@ -2197,7 +2197,7 @@ extension SkParagraphExtension on SkParagraph {
double x,
double y,
);
external SkTextRange getWordBoundary(int position);
external SkTextRange getWordBoundary(double position);
external void layout(double width);
external void delete();
}
Expand Down Expand Up @@ -2523,8 +2523,8 @@ extension SkDataExtension on SkData {
@staticInterop
class SkImageInfo {
external factory SkImageInfo({
required int width,
required int height,
required double width,
required double height,
required SkColorType colorType,
required SkAlphaType alphaType,
required ColorSpace colorSpace,
Expand All @@ -2543,16 +2543,16 @@ extension SkImageInfoExtension on SkImageInfo {
external SkImageInfo makeAlphaType(SkAlphaType alphaType);
external SkImageInfo makeColorSpace(ColorSpace colorSpace);
external SkImageInfo makeColorType(SkColorType colorType);
external SkImageInfo makeWH(int width, int height);
external SkImageInfo makeWH(double width, double height);
}

@JS()
@anonymous
@staticInterop
class SkPartialImageInfo {
external factory SkPartialImageInfo({
required int width,
required int height,
required double width,
required double height,
required SkColorType colorType,
required SkAlphaType alphaType,
required ColorSpace colorSpace,
Expand Down
16 changes: 8 additions & 8 deletions lib/web_ui/lib/src/engine/canvaskit/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ void skiaDecodeImageFromPixels(
Timer.run(() {
final SkImage? skImage = canvasKit.MakeImage(
SkImageInfo(
width: width,
height: height,
width: width.toDouble(),
height: height.toDouble(),
colorType: format == ui.PixelFormat.rgba8888 ? canvasKit.ColorType.RGBA_8888 : canvasKit.ColorType.BGRA_8888,
alphaType: canvasKit.AlphaType.Premul,
colorSpace: SkColorSpaceSRGB,
),
pixels,
rowBytes ?? 4 * width,
(rowBytes ?? 4 * width).toDouble(),
);

if (skImage == null) {
Expand Down Expand Up @@ -266,11 +266,11 @@ class CkImage implements ui.Image, StackTraceDebugger {
alphaType: canvasKit.AlphaType.Premul,
colorType: canvasKit.ColorType.RGBA_8888,
colorSpace: SkColorSpaceSRGB,
width: originalWidth,
height: originalHeight,
width: originalWidth.toDouble(),
height: originalHeight.toDouble(),
),
originalBytes.buffer.asUint8List(),
4 * originalWidth,
(4 * originalWidth).toDouble(),
);
if (skImage == null) {
throw ImageCodecException(
Expand Down Expand Up @@ -415,8 +415,8 @@ class CkImage implements ui.Image, StackTraceDebugger {
alphaType: alphaType,
colorType: colorType,
colorSpace: colorSpace,
width: skImage.width().toInt(),
height: skImage.height().toInt(),
width: skImage.width(),
height: skImage.height(),
);
bytes = skImage.readPixels(0, 0, imageInfo);
} else {
Expand Down
Loading