Fix skwasm's canvasDrawArc declaration and write tests. (flutter/engine#41165)

Fix skwasm's canvasDrawArc declaration and write tests.
This commit is contained in:
Jackson Gardner 2023-04-13 14:26:17 -07:00 committed by GitHub
parent fb0a83e944
commit 29eb026a0e
2 changed files with 75 additions and 1 deletions

View File

@ -108,7 +108,7 @@ external void canvasDrawCircle(
CanvasHandle canvas, double x, double y, double radius, PaintHandle paint);
@Native<Void Function(CanvasHandle, RawRect, Float, Float, Bool, PaintHandle)>(
symbol: 'canvas_drawCircle', isLeaf: true)
symbol: 'canvas_drawArc', isLeaf: true)
external void canvasDrawArc(
CanvasHandle canvas,
RawRect rect,

View File

@ -0,0 +1,74 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/ui.dart';
import 'package:web_engine_tester/golden_tester.dart';
import 'utils.dart';
void main() {
internalBootstrapBrowserTest(() => testMain);
}
Future<void> testMain() async {
setUpUiTest();
const Rect region = Rect.fromLTWH(0, 0, 300, 300);
test('draw arc', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, region);
canvas.drawArc(
const Rect.fromLTRB(100, 100, 200, 200),
math.pi / 3.0,
4.0 * math.pi / 3.0,
false,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3.0
..color = const Color(0xFFFF00FF)
);
await drawPictureUsingCurrentRenderer(recorder.endRecording());
await matchGoldenFile('ui_canvas_draw_arc.png', region: region);
});
test('draw circle', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, region);
canvas.drawCircle(
const Offset(150, 150),
50,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3.0
..color = const Color(0xFFFF0000)
);
await drawPictureUsingCurrentRenderer(recorder.endRecording());
await matchGoldenFile('ui_canvas_draw_circle.png', region: region);
});
test('draw oval', () async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder, region);
canvas.drawOval(
const Rect.fromLTRB(100, 125, 200, 175),
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3.0
..color = const Color(0xFF00FFFF)
);
await drawPictureUsingCurrentRenderer(recorder.endRecording());
await matchGoldenFile('ui_canvas_draw_oval.png', region: region);
});
}