Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix skwasm's canvasDrawArc declaration and write tests. #41165

Merged
merged 1 commit into from Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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,
Expand Down
74 changes: 74 additions & 0 deletions lib/web_ui/test/ui/canvas_curves_golden_test.dart
@@ -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);
});
}